Skip to content

Commit bba89d4

Browse files
committed
Add reverse parameter to LED (from No1sonuk)
1 parent 3ea820d commit bba89d4

File tree

3 files changed

+49
-27
lines changed

3 files changed

+49
-27
lines changed

examples/OneOfEverything/OneOfEverything.ino

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,93 @@
77
*#2 - Provide a very basic testing suite that developers can use to ensure that changes do not break existing sketches
88
*/
99

10+
// Some made-up pin assignments just to make the examples more readable
11+
const int PIN_A = 1;
12+
const int PIN_B = 2;
13+
const int ANALOG_PIN_A = 6;
14+
1015
// Buttons
1116
///////////
1217
// The simplest push button, a single momentary button on a single pin, which sends ARG_0 to MSG_0
13-
DcsBios::ActionButton iffDec("IFF_CODE", "INC", 1);
18+
DcsBios::ActionButton iffDec("IFF_CODE", "INC", PIN_A);
1419

1520
// Used when a physical switch is a momentary button, but needs to sent alternating arguments each time it is pressed
16-
DcsBios::ToggleButton toggleButtonExample("MSG_0", "ARG_0", "ARG_1", 1);
21+
DcsBios::ToggleButton toggleButtonExample("MSG_0", "ARG_0", "ARG_1", PIN_A);
1722

1823
// A dual mode button with a master switch which toggles the function of a physical pit button between two different DCS functions. Think multi-seat aircraft.
19-
DcsBios::DualModeButton dualModeButtonExample(0, 1, "MSG_INMODE0", "MSG_INMODE1");
24+
DcsBios::DualModeButton dualModeButtonExample(PIN_A, PIN_B, "MSG_INMODE0", "MSG_INMODE1");
2025

2126
// Switches
2227
////////////
2328
// A standard two position on/off
24-
DcsBios::Switch2Pos switch2PosExample("MSG_0", 1);
29+
DcsBios::Switch2Pos switch2PosExample("MSG_0", PIN_A);
2530
// A three position on/off/on switch
26-
DcsBios::Switch3Pos switch3PosExample("MSG_0", 1, 2);
31+
DcsBios::Switch3Pos switch3PosExample("MSG_0", PIN_A, PIN_B);
2732
// A multiple position switch, often a rotary switch
2833
const byte multiPosPins[4] = {1,2,3,4};
2934
DcsBios::SwitchMultiPos switchMulitPosExample("MSG_0", multiPosPins, 4);
3035
// A switch that has a cover in DCS that must be opened before the switch itself can be activated
31-
DcsBios::SwitchWithCover2Pos pltLaunchbarAbort("PLT_LAUNCHBAR_ABORT", "PLT_LAUNCHBAR_ABORT_COVER", 6);
36+
DcsBios::SwitchWithCover2Pos pltLaunchbarAbort("PLT_LAUNCHBAR_ABORT", "PLT_LAUNCHBAR_ABORT_COVER", PIN_A);
3237

3338
// Analogs
3439
///////////
35-
// Use an analog input, divided into discrete steps
36-
DcsBios::AnalogMultiPos analogMultiPosExample("MSG_0", 1, 10);
40+
// Use an analog input, divided into (10) discrete steps
41+
DcsBios::AnalogMultiPos analogMultiPosExample("MSG_0", ANALOG_PIN_A, 10);
3742

3843
// Other stuff
3944
// A Binary Coded Decimal wheel usually displaying digits for numeric entry, i.e. IFF code wheels.
40-
DcsBios::BcdWheel bcdWheelExample("MSG_0", 1, 2);
45+
DcsBios::BcdWheel bcdWheelExample("MSG_0", PIN_A, PIN_B);
4146
// A special case of bcdWheel that will send a radio frequency instead of raw digit
4247
DcsBios::RadioPreset radioPresetExample("MSG_0", 1, 2, 3, 4, 5);
4348

4449
// Spinning things
4550
///////////////////
51+
const int DATAPIN = 1;
52+
const int CLKPIN = 2;
53+
const int SWPIN = 3;
54+
4655
// Rotary encoder on two pins to send INC/DEC arguments when rotated
47-
DcsBios::RotaryEncoder rotaryEncoderExample("MSG_0", "ARG_DEC", "ARG_INC", 1, 2);
56+
DcsBios::RotaryEncoder rotaryEncoderExample("MSG_0", "ARG_DEC", "ARG_INC", PIN_A, PIN_B);
4857
// A rotary encoder which will send larger increments when used continuously. Originally written for faster gross adjustments to HSI.
49-
DcsBios::RotaryAcceleratedEncoder rotaryAcceleratedEncoderExample("MSG_0", "ARG_DEC", "ARG_INC", "FAST_INC", "FAST_DEC", 1, 2);
58+
DcsBios::RotaryAcceleratedEncoder rotaryAcceleratedEncoderExample("MSG_0", "ARG_DEC", "ARG_INC", "FAST_INC", "FAST_DEC", PIN_A, PIN_B);
59+
// A rotary with pushbutton, used to emulate a concentric rotary encoder. Pushing the button toggles between two functions
60+
DcsBios::EmulatedConcentricRotaryEncoder ilsRightKnob("ILS_KHZ", "DEC", "INC", "ILS_VOL", "-4500", "+4500", DATAPIN, CLKPIN, SWPIN);
61+
5062
// A linear/analog axis on a single pin
51-
DcsBios::Potentiometer potentiometerExample("MSG_0", 1);
63+
DcsBios::Potentiometer potentiometerExample("MSG_0", ANALOG_PIN_A);
5264
// A linear axis control where the physical or electrical range of the input does utilize the full 0 to 1023 range.
53-
DcsBios::Potentiometer clippedPotentiometerExample("MSG_0", false, 256, 768);
65+
DcsBios::Potentiometer clippedPotentiometerExample("MSG_0", ANALOG_PIN_A, false, 256, 768);
5466

5567
// An inverted version of a linear axis control
56-
DcsBios::Potentiometer invertedPotentiometerExample("MSG_0", 1, true);
68+
DcsBios::Potentiometer invertedPotentiometerExample("MSG_0", ANALOG_PIN_A, true);
5769

5870
// Rotary encoder being used to control something that is an N-pos switch in DCS. 3 represents the number of positions of the switch in DCS.
59-
DcsBios::RotarySwitch rotarySwitchExample("MSG_0", 1, 2, 3);
71+
DcsBios::RotarySwitch rotarySwitchExample("MSG_0", PIN_A, PIN_B, 3);
6072

6173
// Outputs
6274
///////////
75+
const int OUT_PIN_A = 15;
76+
const int ANALOG_OUT_PIN_A = 16;
6377
// A single LED
64-
DcsBios::Dimmer defaultDimmerExample(0x1012, 5);
65-
DcsBios::LED masterCaution(0x1012, 0x0800, 13);
78+
DcsBios::Dimmer defaultDimmerExample(0x1012, OUT_PIN_A);
79+
DcsBios::LED masterCaution(0x1012, 0x0800, OUT_PIN_A);
80+
DcsBios::LED invertedLedExample(0x1012, 0x0800, OUT_PIN_A, true);
81+
6682
// An analog output with a value that comes from a DCS address
67-
DcsBios::Dimmer dimmerExample(0x1012, 13);
68-
DcsBios::Dimmer invertedDimmerExample(0x1012, 5, 200, 0);
83+
DcsBios::Dimmer dimmerExample(0x1012, ANALOG_OUT_PIN_A);
84+
85+
// An inverted demo that also demonstrates a custom range. By the min (200) being greater than max (0), the inverted behaviour is created.
86+
DcsBios::Dimmer invertedDimmerExample(0x1012, ANALOG_OUT_PIN_A, 200, 0);
87+
88+
// A dimmer where the user provided a mapping function. In this case a simple modulus stepper, but could include non-linear functions, conditions, etc.
6989
unsigned int myValueMapper(unsigned int dcsValue)
7090
{
7191
return dcsValue % 10;
7292
}
73-
DcsBios::Dimmer mappedDimmerExample(0x1012, 5, myValueMapper);
93+
DcsBios::Dimmer mappedDimmerExample(0x1012, ANALOG_OUT_PIN_A, myValueMapper);
94+
7495
// A servo motor controlleed from DCS, i.e. a guage.
75-
DcsBios::ServoOutput servoExample(0x1012, 13, 544, 2400);
96+
DcsBios::ServoOutput servoExample(0x1012, ANALOG_OUT_PIN_A, 544, 2400);
7697

7798
void setup() {
7899
DcsBios::setup();

releasenotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Added input_min and input_max optional parameters to PotentiometerEWMA to allow a user to calibrate their analog inputs if their physical control does not utilize the full range available to the controller.
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.
5+
- 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.
56

67
## v0.3.7
78
- 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)