diff --git a/examples/pinproctest/pinproctest.cpp b/examples/pinproctest/pinproctest.cpp index 8e2f198..923f1a9 100644 --- a/examples/pinproctest/pinproctest.cpp +++ b/examples/pinproctest/pinproctest.cpp @@ -417,7 +417,7 @@ int main(int argc, const char **argv) // 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. + PRReset(proc, kPRResetFlagUpdateDevice); // Reset the device structs and write them into the device. // Destroy the P-ROC device handle: PRDelete(proc); diff --git a/include/pinproc.h b/include/pinproc.h index fc791ab..4cf3eeb 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -90,7 +90,15 @@ 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. */ + +#define kPRResetFlagDefault (0) /**< Only resets state in memory and does not write changes to the device. */ +#define kPRResetFlagUpdateDevice (1) /**< Instructs PRReset() to update the device once it has reset the configuration to its defaults. */ + +/** + * @brief Resets internally maintained driver and switch rule structures. + * @param resetFlags Specify #kPRResetFlagDefault to only reset the configuration in host memory. #kPRResetFlagUpdateDevice will write the default configuration to the device, effectively disabling all drivers and switch rules. + */ +PR_EXPORT PRResult PRReset(PRHandle handle, uint32_t resetFlags); /** @} */ // End of Device Creation & Deletion diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index ae69440..1b21f65 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -33,7 +33,7 @@ PRDevice::PRDevice(PRMachineType machineType) : machineType(machineType) { // Reset internally maintainted driver and switch structures, but do not update the device. - Reset(false); + Reset(kPRResetFlagDefault); } PRDevice::~PRDevice() @@ -58,13 +58,10 @@ PRDevice* PRDevice::Create(PRMachineType machineType) return NULL; } - // Reset internally maintainted driver and switch structures, but do not update the device. - dev->Reset(false); - return dev; } -void PRDevice::Reset(bool updateDevice) +PRResult PRDevice::Reset(uint32_t resetFlags) { bool defaultPolarity = machineType != kPRMachineWPC; int i; @@ -75,7 +72,7 @@ void PRDevice::Reset(bool updateDevice) memset(driver, 0x00, sizeof(PRDriverState)); driver->driverNum = i; driver->polarity = defaultPolarity; - if (updateDevice) DriverUpdateState(driver); + if (resetFlags & kPRResetFlagUpdateDevice) DriverUpdateState(driver); } for (i = 0; i < kPRDriverGroupsMax; i++) { @@ -95,7 +92,7 @@ void PRDevice::Reset(bool updateDevice) memset(switchRule, 0x00, sizeof(PRSwitchRule)); // Send blank rule for each event type to Device if necessary - if (updateDevice && i <= kPRSwitchPhysicalLast) { + if ((resetFlags & kPRResetFlagUpdateDevice) && i <= kPRSwitchPhysicalLast) { SwitchUpdateRule(i, kPREventTypeSwitchOpenDebounced, &emptySwitchRule, NULL, 0); SwitchUpdateRule(i, kPREventTypeSwitchClosedDebounced, &emptySwitchRule, NULL, 0); SwitchUpdateRule(i, kPREventTypeSwitchOpenNondebounced, &emptySwitchRule, NULL, 0); @@ -105,7 +102,7 @@ void PRDevice::Reset(bool updateDevice) uint16_t ruleIndex = i; ParseSwitchRuleIndex(ruleIndex, &switchRule->switchNum, &switchRule->eventType); switchRule->driver.polarity = defaultPolarity; - if (switchRule->switchNum >= kPRSwitchVirtualFirst && switchRule->switchNum <= kPRSwitchVirtualLast) + if (switchRule->switchNum >= kPRSwitchVirtualFirst) // Disabled for compiler warning (always true due to data type): && switchRule->switchNum <= kPRSwitchVirtualLast) freeSwitchRuleIndexes.push(ruleIndex); } @@ -114,6 +111,7 @@ void PRDevice::Reset(bool updateDevice) num_collected_bytes = 0; // TODO: Assign defaults based on machineType. Some may have already been done above. + return kPRSuccess; } int PRDevice::GetEvents(PREvent *events, int maxEvents) diff --git a/src/PRDevice.h b/src/PRDevice.h index cd4e20a..128598c 100644 --- a/src/PRDevice.h +++ b/src/PRDevice.h @@ -44,7 +44,7 @@ class PRDevice public: static PRDevice *Create(PRMachineType machineType); ~PRDevice(); - void Reset(bool updateDevice); + PRResult Reset(uint32_t resetFlags); protected: PRDevice(PRMachineType machineType); diff --git a/src/pinproc.cpp b/src/pinproc.cpp index 9d57655..2617236 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -73,9 +73,9 @@ PR_EXPORT void PRDelete(PRHandle 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) +PR_EXPORT PRResult PRReset(PRHandle handle, uint32_t resetFlags) { - return handleAsDevice->Reset(updateDevice); + return handleAsDevice->Reset(resetFlags); } // Events