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

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.

This commit is contained in:
Gerry Stellenberg
2011-08-29 16:19:24 -05:00
parent 72ae845727
commit 06b8af5393
2 changed files with 12 additions and 11 deletions

View File

@@ -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 kPRSwitchPhysicalFirst (0) /**< Switch number of the first physical switch. */
#define kPRSwitchPhysicalLast (223) /**< Switch number of the last physical switch. */ #define kPRSwitchPhysicalLast (255) /**< Switch number of the last physical switch. */
#define kPRSwitchVirtualFirst (224) /**< Switch number of the first virtual switch. */ #define kPRSwitchNeverDebounceFirst (192) /**< Switch number of the first switch that doesn't need to debounced. */
#define kPRSwitchVirtualLast (255) /**< Switch number of the last virtual switch. */ #define kPRSwitchNeverDebounceLast (255) /**< Switch number of the last switch that doesn't need to be debounce. */
#define kPRSwitchCount (256) #define kPRSwitchCount (256)
#define kPRSwitchRulesCount (kPRSwitchCount << 2) /**< Total number of available switch rules. */ #define kPRSwitchRulesCount (kPRSwitchCount << 2) /**< Total number of available switch rules. */

View File

@@ -131,7 +131,14 @@ PRResult PRDevice::Reset(uint32_t resetFlags)
uint16_t ruleIndex = i; uint16_t ruleIndex = i;
ParseSwitchRuleIndex(ruleIndex, &switchRule->switchNum, &switchRule->eventType); ParseSwitchRuleIndex(ruleIndex, &switchRule->switchNum, &switchRule->eventType);
switchRule->driver.polarity = driverGlobalConfig.globalPolarity; 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); freeSwitchRuleIndexes.push(ruleIndex);
} }
@@ -142,7 +149,7 @@ PRResult PRDevice::Reset(uint32_t resetFlags)
for (i = 0; i < kPRSwitchCount; i++) for (i = 0; i < kPRSwitchCount; i++)
{ {
// Send blank rule for each event type to Device if necessary // 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, kPREventTypeSwitchOpenDebounced, &emptySwitchRule, NULL, 0, false);
SwitchUpdateRule(i, kPREventTypeSwitchClosedDebounced, &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; const int burstSize = 4;
uint32_t burst[burstSize]; 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 // If more the base rule will link to others, ensure free indexes exists for
// the links. // the links.
if (numDrivers > 0 && freeSwitchRuleIndexes.size() < (uint32_t)(numDrivers-1)) // -1 because the first switch rule holds the first driver. if (numDrivers > 0 && freeSwitchRuleIndexes.size() < (uint32_t)(numDrivers-1)) // -1 because the first switch rule holds the first driver.