Skip to content

Commit 07aecdc

Browse files
Merge branch 'master' into InvertableLeds
2 parents bba89d4 + 4986b7b commit 07aecdc

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

examples/OneOfEverything/OneOfEverything.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ 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+
8081
DcsBios::LED invertedLedExample(0x1012, 0x0800, OUT_PIN_A, true);
8182

8283
// An analog output with a value that comes from a DCS address

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+
- 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!
56
- 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

src/internal/Encoders.h

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ namespace DcsBios {
294294

295295
//To emulate dual concentric rotary encoders/resolvers/potentiometers using a rotary encoder with a push button.
296296
//Secondary message is used when push button or switch is enabled.
297-
298297
template <unsigned long pollIntervalMs = POLL_EVERY_TIME, StepsPerDetent stepsPerDetent = ONE_STEP_PER_DETENT>
299298
class EmulatedConcentricRotaryEncoderT : PollingInput, public ResettableInput {
300299
private:
@@ -306,29 +305,27 @@ namespace DcsBios {
306305
const char* incArg2_;
307306
char pinA_;
308307
char pinB_;
309-
char pinC_; //Integrated button pin
308+
char pinToggle_; //Integrated button pin
310309
bool msg1Mode_;
311310
char prevMode_;
312311
char lastState_;
313312
signed char delta_;
314313

315314
char readState() {
316-
return (digitalRead(pinA_) << 1) | digitalRead(pinB_);
317-
}
318-
319-
void checkPress() {
320315
char currentMode;
321-
msg1Mode_ = ((currentMode = digitalRead(pinC_)) != prevMode_)?!msg1Mode_:msg1Mode_;
316+
msg1Mode_ = ((currentMode = digitalRead(pinToggle_)) != prevMode_)?!msg1Mode_:msg1Mode_;
322317
prevMode_ = currentMode;
318+
319+
return (digitalRead(pinA_) << 1) | digitalRead(pinB_);
323320
}
324321

325322
void resetState() {
323+
msg1Mode_ = !msg1Mode_;
326324
lastState_ = (lastState_==0)?-1:0;
327325
}
328326

329327
void pollInput() {
330328
char state = readState();
331-
checkPress();
332329
switch(lastState_) {
333330
case 0:
334331
if (state == 2) delta_--;
@@ -349,47 +346,42 @@ namespace DcsBios {
349346
}
350347
lastState_ = state;
351348

352-
if ((delta_ >= stepsPerDetent) && (msg1Mode_)) {
353-
if (tryToSendDcsBiosMessage(msg1_, incArg1_))
354-
delta_ -= stepsPerDetent;
355-
}
356-
if ((delta_ <= -stepsPerDetent) && (msg1Mode_)) {
357-
if (tryToSendDcsBiosMessage(msg1_, decArg1_))
358-
delta_ += stepsPerDetent;
359-
}
360-
if ((delta_ >= stepsPerDetent) && (!msg1Mode_)) {
361-
if (tryToSendDcsBiosMessage(msg2_, incArg2_))
349+
if (delta_ >= stepsPerDetent) {
350+
if (tryToSendDcsBiosMessage(msg1Mode_?msg1_:msg2_, msg1Mode_?incArg1_:incArg2_))
362351
delta_ -= stepsPerDetent;
363352
}
364-
if ((delta_ <= -stepsPerDetent) && (!msg1Mode_)) {
365-
if (tryToSendDcsBiosMessage(msg2_, decArg2_))
353+
if (delta_ <= -stepsPerDetent) {
354+
if (tryToSendDcsBiosMessage(msg1Mode_?msg1_:msg2_, msg1Mode_?decArg1_:decArg2_))
366355
delta_ += stepsPerDetent;
367356
}
368357
}
369358
public:
370359
EmulatedConcentricRotaryEncoderT(const char* msg1, const char* decArg1, const char* incArg1, const char* msg2, const char* decArg2, const char* incArg2, char pinA, char pinB, char pinC) :
371-
PollingInput(pollIntervalMs) {
360+
PollingInput(pollIntervalMs)
361+
{
372362
msg1_ = msg1;
373363
decArg1_ = decArg1;
374364
incArg1_ = incArg1;
375365
msg2_ = msg2;
376366
decArg2_ = decArg2;
377367
incArg2_ = incArg2;
368+
378369
pinA_ = pinA;
379370
pinB_ = pinB;
380-
pinC_ = pinC;
371+
pinToggle_ = pinC;
381372
msg1Mode_ = true;
382-
prevMode_ = 1;
373+
383374
pinMode(pinA_, INPUT_PULLUP);
384375
pinMode(pinB_, INPUT_PULLUP);
385-
pinMode(pinC_, INPUT_PULLUP);
386-
prevMode_ = digitalRead(pinC_); //Prevents defaulting to secondary action on initialization
376+
pinMode(pinToggle_, INPUT_PULLUP);
377+
prevMode_ = digitalRead(pinToggle_); //Prevents defaulting to secondary action on initialization
378+
387379
delta_ = 0;
388380
lastState_ = readState();
389381
}
390382

391383
void SetControl(const char* msg) {
392-
msg1_ = msg;
384+
msg1_ = msg; // Note this won't work to remap the second message
393385
}
394386

395387

0 commit comments

Comments
 (0)