From 06b8af5393925e431d9d3c57dc532be280c0d37f Mon Sep 17 00:00:00 2001 From: Gerry Stellenberg Date: Mon, 29 Aug 2011 16:19:24 -0500 Subject: [PATCH] Replace concept of virtual switches with switches that don't need to be debounced. This is necessary because all switches 0-255 are used. Defining some as never-debounce makes switch rules available for linked rules. --- include/pinproc.h | 6 +++--- src/PRDevice.cpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/pinproc.h b/include/pinproc.h index 105ae11..0b54160 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -383,9 +383,9 @@ PINPROC_API int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents); #define kPRSwitchPhysicalFirst (0) /**< Switch number of the first physical switch. */ -#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 kPRSwitchPhysicalLast (255) /**< Switch number of the last physical switch. */ +#define kPRSwitchNeverDebounceFirst (192) /**< Switch number of the first switch that doesn't need to debounced. */ +#define kPRSwitchNeverDebounceLast (255) /**< Switch number of the last switch that doesn't need to be debounce. */ #define kPRSwitchCount (256) #define kPRSwitchRulesCount (kPRSwitchCount << 2) /**< Total number of available switch rules. */ diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index 922ee48..d24558b 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -131,7 +131,14 @@ PRResult PRDevice::Reset(uint32_t resetFlags) uint16_t ruleIndex = i; ParseSwitchRuleIndex(ruleIndex, &switchRule->switchNum, &switchRule->eventType); switchRule->driver.polarity = driverGlobalConfig.globalPolarity; - if (switchRule->switchNum >= kPRSwitchVirtualFirst) // Disabled for compiler warning (always true due to data type): && switchRule->switchNum <= kPRSwitchVirtualLast) + + // All of the base switch numbers in the P-ROC are used; so there are no + // full sets of switch rule resources that are available for the freelist for linked rules. + // However, some of the switches are always optos and don't need to be debounced. + // So the debounced rule resources for those switches are available for linked rules. + if (switchRule->switchNum >= kPRSwitchNeverDebounceFirst && + (switchRule->eventType == kPREventTypeSwitchClosedDebounced || + switchRule->eventType == kPREventTypeSwitchOpenDebounced)) freeSwitchRuleIndexes.push(ruleIndex); } @@ -142,7 +149,7 @@ PRResult PRDevice::Reset(uint32_t resetFlags) for (i = 0; i < kPRSwitchCount; i++) { // Send blank rule for each event type to Device if necessary - if ((resetFlags & kPRResetFlagUpdateDevice) && i <= kPRSwitchPhysicalLast) + if (resetFlags & kPRResetFlagUpdateDevice) { SwitchUpdateRule(i, kPREventTypeSwitchOpenDebounced, &emptySwitchRule, NULL, 0, false); SwitchUpdateRule(i, kPREventTypeSwitchClosedDebounced, &emptySwitchRule, NULL, 0, false); @@ -589,12 +596,6 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR const int burstSize = 4; uint32_t burst[burstSize]; - if (switchNum > kPRSwitchPhysicalLast) // Always true due to data type. - { - PRSetLastErrorText("Switch rule out of range 0-%d", kPRSwitchPhysicalLast); - return kPRFailure; - } - // If more the base rule will link to others, ensure free indexes exists for // the links. if (numDrivers > 0 && freeSwitchRuleIndexes.size() < (uint32_t)(numDrivers-1)) // -1 because the first switch rule holds the first driver.