Skip to content

Commit 25f1d44

Browse files
Merge pull request #4 from talbotmcinnis/DefaultPinForSwitchMultiPos
Default pin for switch multi pos
2 parents e98ca28 + dbbe2ab commit 25f1d44

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

releasenotes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v0.3.2
2+
- Added new feature for SwitchMultiPos, allowing a "default" state to be specified for controls that can have a default state. For example, A-10 Emergency Trim without a center detent
3+
```c++
4+
// Center pos is not connected, so define PIN_NC so that it will return to center when no other pin is active
5+
const byte efcpEmerTrimPins[5] = {DcsBios::PIN_NC, 2, 1, 3, 0};
6+
DcsBios::SwitchMultiPos efcpEmerTrim("EFCP_EMER_TRIM", efcpEmerTrimPins, 5);
7+
```
8+
19
## v0.3.1
210
311
- Fix AnalogMultiPos as per [Analog Multipos does not send commands (github.com)](https://github.com/talbotmcinnis/dcs-bios-arduino-library/issues/2)

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)