Skip to content

Commit 041a657

Browse files
committed
Added default state behaviour for NC pins in SwitchMultiPos
1 parent e98ca28 commit 041a657

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/DcsBios.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#define PRR0 PRR
2626
#endif
2727

28+
namespace DcsBios {
29+
const unsigned char PIN_NC = 0xFF;
30+
}
31+
2832
/*
2933
The following is an ugly hack to work with the Arduino IDE's build system.
3034
The DCS-BIOS Arduino Library is configured with #defines such as DCSBIOS_RS485_MASTER or DCSBIOS_RS485_SLAVE <address>.

src/internal/Switches.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,17 @@ namespace DcsBios {
140140
char lastState_;
141141
bool reverse_;
142142
char readState() {
143-
unsigned char i;
144-
for (i=0; i<numberOfPins_; i++) {
145-
if (digitalRead(pins_[i]) == LOW && reverse_ == false) return i;
146-
else if (digitalRead(pins_[i]) == HIGH && reverse_ == true) return i;
143+
unsigned char ncPinIdx = lastState_;
144+
for (unsigned char i=0; i<numberOfPins_; i++) {
145+
if( pins_[i] == PIN_NC)
146+
ncPinIdx = i;
147+
else
148+
{
149+
if (digitalRead(pins_[i]) == LOW && reverse_ == false) return i;
150+
else if (digitalRead(pins_[i]) == HIGH && reverse_ == true) return i;
151+
}
147152
}
148-
return lastState_;
153+
return ncPinIdx;
149154
}
150155
void resetState()
151156
{
@@ -172,7 +177,8 @@ namespace DcsBios {
172177
numberOfPins_ = numberOfPins;
173178
unsigned char i;
174179
for (i=0; i<numberOfPins; i++) {
175-
pinMode(pins[i], INPUT_PULLUP);
180+
if( pins[i] != PIN_NC)
181+
pinMode(pins[i], INPUT_PULLUP);
176182
}
177183
lastState_ = readState();
178184
}

0 commit comments

Comments
 (0)