mirror of
https://github.com/preble/libpinproc
synced 2026-02-24 18:25:23 +01:00
Reworked PRReset() and added kPRResetFlag* #defs.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user