Skip to content

Commit b16c6b1

Browse files
Merge pull request #35 from DCSFlightpanels/InvertableLeds
Add reverse parameter to LED (from No1sonuk)
2 parents 4986b7b + 07aecdc commit b16c6b1

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

examples/OneOfEverything/OneOfEverything.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,22 @@ const int ANALOG_OUT_PIN_A = 16;
7777
// A single LED
7878
DcsBios::Dimmer defaultDimmerExample(0x1012, OUT_PIN_A);
7979
DcsBios::LED masterCaution(0x1012, 0x0800, OUT_PIN_A);
80+
81+
DcsBios::LED invertedLedExample(0x1012, 0x0800, OUT_PIN_A, true);
82+
8083
// An analog output with a value that comes from a DCS address
8184
DcsBios::Dimmer dimmerExample(0x1012, ANALOG_OUT_PIN_A);
85+
86+
// An inverted demo that also demonstrates a custom range. By the min (200) being greater than max (0), the inverted behaviour is created.
8287
DcsBios::Dimmer invertedDimmerExample(0x1012, ANALOG_OUT_PIN_A, 200, 0);
88+
89+
// A dimmer where the user provided a mapping function. In this case a simple modulus stepper, but could include non-linear functions, conditions, etc.
8390
unsigned int myValueMapper(unsigned int dcsValue)
8491
{
8592
return dcsValue % 10;
8693
}
8794
DcsBios::Dimmer mappedDimmerExample(0x1012, ANALOG_OUT_PIN_A, myValueMapper);
95+
8896
// A servo motor controlleed from DCS, i.e. a guage.
8997
DcsBios::ServoOutput servoExample(0x1012, ANALOG_OUT_PIN_A, 544, 2400);
9098

releasenotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fix Switch2Pos state reset logic, and improve it's internal debounce logic for a few edge cases.
44
- Add DualModeButton for first multi-seat support. Originally developed for use in Apache cockpits where one switch toggles the function of a physical button between front and back seat DCS control.
55
- Included AerialElectron's Concentric Rotary Encoder Emulator. Useful for simpits with a rotary that has a pushbutton, to emulate controlling two different dcs cockpit controls, especially if the dcs controls are dual-ring concentric rotaries. Thanks for the contribution AerialElectron!
6+
- Integrated No1sonuk's inverted LED support. LEDs now take an optional parameter which can be used to have an SimPit LED operate opposite to a DcsPit LED.
67

78
## v0.3.7
89
- Integrate 2 and 3 position Matrix switches, thanks to Dehuman for the starting point!

src/internal/Leds.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ namespace DcsBios {
1010
private:
1111
unsigned int mask;
1212
unsigned char pin;
13+
bool reverse;
1314
public:
14-
LED(unsigned int address, unsigned int mask, char pin) : Int16Buffer(address), mask(mask), pin(pin) {
15+
LED(unsigned int address, unsigned int mask, char pin, bool reverse = false) : Int16Buffer(address), mask(mask), pin(pin), reverse(reverse) {
1516
pinMode(pin, OUTPUT);
1617
}
1718
virtual void loop() {
1819
if (hasUpdatedData()) {
19-
if (getData() & mask) {
20-
digitalWrite(pin, 1);
21-
} else {
22-
digitalWrite(pin, 0);
23-
}
20+
bool state = getData() & mask;
21+
if (reverse) state = !state;
22+
23+
digitalWrite(pin, state);
2424
}
2525
}
2626
};

0 commit comments

Comments
 (0)