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:
@@ -415,6 +415,10 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
RunLoop(proc);
|
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:
|
// Destroy the P-ROC device handle:
|
||||||
PRDelete(proc);
|
PRDelete(proc);
|
||||||
proc = kPRHandleInvalid;
|
proc = kPRHandleInvalid;
|
||||||
|
|||||||
@@ -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 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 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
|
/** @} */ // 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 {
|
typedef struct PRDriverGlobalConfig {
|
||||||
bool_t enableOutputs; // Formerly enable_direct_outputs
|
bool_t enableOutputs; // Formerly enable_direct_outputs
|
||||||
bool_t globalPolarity;
|
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 kPRSwitchPhysicalLast (223) /**< Switch number of the last physical switch. */
|
||||||
#define kPRSwitchVirtualFirst (224) /**< Switch number of the first virtual switch. */
|
#define kPRSwitchVirtualFirst (224) /**< Switch number of the first virtual switch. */
|
||||||
#define kPRSwitchVirtualLast (255) /**< Switch number of the last 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 {
|
typedef struct PRSwitchConfig {
|
||||||
bool_t clear; // Drive the clear output
|
bool_t clear; // Drive the clear output
|
||||||
|
|||||||
@@ -32,12 +32,12 @@
|
|||||||
|
|
||||||
PRDevice::PRDevice(PRMachineType machineType) : machineType(machineType)
|
PRDevice::PRDevice(PRMachineType machineType) : machineType(machineType)
|
||||||
{
|
{
|
||||||
Reset();
|
// Reset internally maintainted driver and switch structures, but do not update the device.
|
||||||
|
Reset(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
PRDevice::~PRDevice()
|
PRDevice::~PRDevice()
|
||||||
{
|
{
|
||||||
Shutdown();
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,34 +58,50 @@ PRDevice* PRDevice::Create(PRMachineType machineType)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->Reset();
|
// Reset internally maintainted driver and switch structures, but do not update the device.
|
||||||
|
dev->Reset(false);
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PRDevice::Reset()
|
void PRDevice::Reset(bool updateDevice)
|
||||||
{
|
{
|
||||||
bool defaultPolarity = machineType != kPRMachineWPC;
|
bool defaultPolarity = machineType != kPRMachineWPC;
|
||||||
int i;
|
int i;
|
||||||
memset(&driverGlobalConfig, 0x00, sizeof(PRDriverGlobalConfig));
|
memset(&driverGlobalConfig, 0x00, sizeof(PRDriverGlobalConfig));
|
||||||
for (i = 0; i < maxDrivers; i++)
|
for (i = 0; i < kPRDriverCount; i++)
|
||||||
{
|
{
|
||||||
PRDriverState *driver = &drivers[i];
|
PRDriverState *driver = &drivers[i];
|
||||||
memset(driver, 0x00, sizeof(PRDriverState));
|
memset(driver, 0x00, sizeof(PRDriverState));
|
||||||
driver->driverNum = i;
|
driver->driverNum = i;
|
||||||
driver->polarity = defaultPolarity;
|
driver->polarity = defaultPolarity;
|
||||||
|
if (updateDevice) DriverUpdateState(driver);
|
||||||
}
|
}
|
||||||
for (i = 0; i < maxDriverGroups; i++)
|
for (i = 0; i < kPRDriverGroupsMax; i++)
|
||||||
{
|
{
|
||||||
PRDriverGroupConfig *group = &driverGroups[i];
|
PRDriverGroupConfig *group = &driverGroups[i];
|
||||||
memset(group, 0x00, sizeof(PRDriverGroupConfig));
|
memset(group, 0x00, sizeof(PRDriverGroupConfig));
|
||||||
group->groupNum = i;
|
group->groupNum = i;
|
||||||
group->polarity = defaultPolarity;
|
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];
|
PRSwitchRuleInternal *switchRule = &switchRules[i];
|
||||||
memset(switchRule, 0x00, sizeof(PRSwitchRule));
|
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;
|
uint16_t ruleIndex = i;
|
||||||
ParseSwitchRuleIndex(ruleIndex, &switchRule->switchNum, &switchRule->eventType);
|
ParseSwitchRuleIndex(ruleIndex, &switchRule->switchNum, &switchRule->eventType);
|
||||||
switchRule->driver.polarity = defaultPolarity;
|
switchRule->driver.polarity = defaultPolarity;
|
||||||
@@ -100,32 +116,6 @@ void PRDevice::Reset()
|
|||||||
// TODO: Assign defaults based on machineType. Some may have already been done above.
|
// 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)
|
int PRDevice::GetEvents(PREvent *events, int maxEvents)
|
||||||
{
|
{
|
||||||
SortReturningData();
|
SortReturningData();
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class PRDevice
|
|||||||
public:
|
public:
|
||||||
static PRDevice *Create(PRMachineType machineType);
|
static PRDevice *Create(PRMachineType machineType);
|
||||||
~PRDevice();
|
~PRDevice();
|
||||||
|
void Reset(bool updateDevice);
|
||||||
protected:
|
protected:
|
||||||
PRDevice(PRMachineType machineType);
|
PRDevice(PRMachineType machineType);
|
||||||
|
|
||||||
@@ -121,8 +122,6 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
// Local Device State
|
// Local Device State
|
||||||
void Shutdown();
|
|
||||||
void Reset();
|
|
||||||
PRMachineType machineType;
|
PRMachineType machineType;
|
||||||
PRDriverGlobalConfig driverGlobalConfig;
|
PRDriverGlobalConfig driverGlobalConfig;
|
||||||
PRDriverGroupConfig driverGroups[maxDriverGroups];
|
PRDriverGroupConfig driverGroups[maxDriverGroups];
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ PR_EXPORT void PRDelete(PRHandle handle)
|
|||||||
delete (PRDevice*)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
|
// Events
|
||||||
|
|
||||||
/** Get all of the available events that have been received. */
|
/** Get all of the available events that have been received. */
|
||||||
|
|||||||
Reference in New Issue
Block a user