1
0
mirror of https://github.com/preble/libpinproc synced 2026-02-24 18:25:23 +01:00

Made PRDevice::Reset public for use in pinproctest and added a parameter to allow the disabled driver and switch rule structures to be written to the P-ROC.

This commit is contained in:
gstellenberg
2009-05-27 19:10:44 -05:00
parent a26a9f5ce8
commit 06442264a1
5 changed files with 39 additions and 35 deletions

View File

@@ -415,6 +415,10 @@ int main(int argc, const char **argv)
RunLoop(proc);
// Clean up P-ROC.
printf("Disabling P-ROC drivers and switch rules...\n");
PRReset(proc,true); // Reset the device structs and write them into the device.
// Destroy the P-ROC device handle:
PRDelete(proc);
proc = kPRHandleInvalid;

View File

@@ -90,6 +90,7 @@ typedef enum PRMachineType {
PR_EXPORT PRHandle PRCreate(PRMachineType machineType); /**< Create a new P-ROC device handle. Only one handle per device may be created. This handle must be destroyed with PRDelete() when it is no longer needed. Returns #kPRHandleInvalid if an error occurred. */
PR_EXPORT void PRDelete(PRHandle handle); /**< Destroys an existing P-ROC device handle. */
PR_EXPORT void PRReset(PRHandle handle, bool updateDevice); /**< Resets internally maintained driver and switch rule structures and optionally writes those to the P-ROC to turn off drivers and switch rules. */
/** @} */ // End of Device Creation & Deletion
@@ -98,6 +99,9 @@ PR_EXPORT void PRDelete(PRHandle handle); /**< Destroys an existin
* @{
*/
#define kPRDriverGroupsMax (26) /**< Number of available driver groups. */
#define kPRDriverCount (256) /**< Total number of drivers */
typedef struct PRDriverGlobalConfig {
bool_t enableOutputs; // Formerly enable_direct_outputs
bool_t globalPolarity;
@@ -235,6 +239,7 @@ PR_EXPORT int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents);
#define kPRSwitchPhysicalLast (223) /**< Switch number of the last physical switch. */
#define kPRSwitchVirtualFirst (224) /**< Switch number of the first virtual switch. */
#define kPRSwitchVirtualLast (255) /**< Switch number of the last virtual switch. */
#define kPRSwitchRulesCount ((kPRSwitchVirtualLast + 1) << 2) /**< Total number of available switch rules. */
typedef struct PRSwitchConfig {
bool_t clear; // Drive the clear output

View File

@@ -32,12 +32,12 @@
PRDevice::PRDevice(PRMachineType machineType) : machineType(machineType)
{
Reset();
// Reset internally maintainted driver and switch structures, but do not update the device.
Reset(false);
}
PRDevice::~PRDevice()
{
Shutdown();
Close();
}
@@ -58,34 +58,50 @@ PRDevice* PRDevice::Create(PRMachineType machineType)
return NULL;
}
dev->Reset();
// Reset internally maintainted driver and switch structures, but do not update the device.
dev->Reset(false);
return dev;
}
void PRDevice::Reset()
void PRDevice::Reset(bool updateDevice)
{
bool defaultPolarity = machineType != kPRMachineWPC;
int i;
memset(&driverGlobalConfig, 0x00, sizeof(PRDriverGlobalConfig));
for (i = 0; i < maxDrivers; i++)
for (i = 0; i < kPRDriverCount; i++)
{
PRDriverState *driver = &drivers[i];
memset(driver, 0x00, sizeof(PRDriverState));
driver->driverNum = i;
driver->polarity = defaultPolarity;
if (updateDevice) DriverUpdateState(driver);
}
for (i = 0; i < maxDriverGroups; i++)
for (i = 0; i < kPRDriverGroupsMax; i++)
{
PRDriverGroupConfig *group = &driverGroups[i];
memset(group, 0x00, sizeof(PRDriverGroupConfig));
group->groupNum = i;
group->polarity = defaultPolarity;
}
for (i = 0; i < maxSwitchRules; i++)
// Create empty switch rule for clearing the rules in the device.
PRSwitchRule emptySwitchRule;
memset(&emptySwitchRule, 0x00, sizeof(PRSwitchRule));
for (i = 0; i < kPRSwitchRulesCount; i++)
{
PRSwitchRuleInternal *switchRule = &switchRules[i];
memset(switchRule, 0x00, sizeof(PRSwitchRule));
// Send blank rule for each event type to Device if necessary
if (updateDevice && i <= kPRSwitchPhysicalLast) {
SwitchUpdateRule(i, kPREventTypeSwitchOpenDebounced, &emptySwitchRule, NULL, 0);
SwitchUpdateRule(i, kPREventTypeSwitchClosedDebounced, &emptySwitchRule, NULL, 0);
SwitchUpdateRule(i, kPREventTypeSwitchOpenNondebounced, &emptySwitchRule, NULL, 0);
SwitchUpdateRule(i, kPREventTypeSwitchClosedNondebounced, &emptySwitchRule, NULL, 0);
}
uint16_t ruleIndex = i;
ParseSwitchRuleIndex(ruleIndex, &switchRule->switchNum, &switchRule->eventType);
switchRule->driver.polarity = defaultPolarity;
@@ -100,32 +116,6 @@ void PRDevice::Reset()
// TODO: Assign defaults based on machineType. Some may have already been done above.
}
void PRDevice::Shutdown()
{
int i;
PRDriverState driverState;
PRSwitchRule switchRule;
// Deactivate all drivers
for (i = 0; i < maxDrivers; i++)
{
// Get each driver's current state just in case polarity was changed from the default.
DriverGetState(i, &driverState);
driverState.state = false;
DriverUpdateState(&driverState);
}
// Deactivate all switch rules
switchRule.notifyHost = false;
for (i = kPRSwitchPhysicalFirst; i < kPRSwitchPhysicalLast; i++)
{
SwitchUpdateRule(i, kPREventTypeSwitchOpenDebounced, &switchRule, NULL, 0);
SwitchUpdateRule(i, kPREventTypeSwitchClosedDebounced, &switchRule, NULL, 0);
SwitchUpdateRule(i, kPREventTypeSwitchOpenNondebounced, &switchRule, NULL, 0);
SwitchUpdateRule(i, kPREventTypeSwitchClosedNondebounced, &switchRule, NULL, 0);
}
}
int PRDevice::GetEvents(PREvent *events, int maxEvents)
{
SortReturningData();

View File

@@ -44,6 +44,7 @@ class PRDevice
public:
static PRDevice *Create(PRMachineType machineType);
~PRDevice();
void Reset(bool updateDevice);
protected:
PRDevice(PRMachineType machineType);
@@ -121,8 +122,6 @@ protected:
// Local Device State
void Shutdown();
void Reset();
PRMachineType machineType;
PRDriverGlobalConfig driverGlobalConfig;
PRDriverGroupConfig driverGroups[maxDriverGroups];

View File

@@ -72,6 +72,12 @@ PR_EXPORT void PRDelete(PRHandle handle)
delete (PRDevice*)handle;
}
/** Resets internally maintained driver and switch rule structures and optionally writes those to the P-ROC device. */
PR_EXPORT void PRReset(PRHandle handle, bool updateDevice)
{
return handleAsDevice->Reset(updateDevice);
}
// Events
/** Get all of the available events that have been received. */