Skip to content

Commit a0a709e

Browse files
Merge pull request #33 from DCSFlightpanels/DualSeatSwitched
Dual seat switched
2 parents dfb8f28 + 06428f5 commit a0a709e

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define DCSBIOS_DEFAULT_SERIAL
2+
#include <DcsBios.h>
3+
4+
// 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.
5+
DcsBios::DualModeButton myPinL2(23, 27, "PLT_MPD_L_L2", "CPG_MPD_L_L2");
6+
7+
void setup() {
8+
DcsBios::setup();
9+
}
10+
11+
void loop() {
12+
DcsBios::loop();
13+
}

examples/OneOfEverything/OneOfEverything.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ DcsBios::ActionButton iffDec("IFF_CODE", "INC", 1);
1515
// Used when a physical switch is a momentary button, but needs to sent alternating arguments each time it is pressed
1616
DcsBios::ToggleButton toggleButtonExample("MSG_0", "ARG_0", "ARG_1", 1);
1717

18+
// 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");
20+
1821
// Switches
1922
////////////
2023
// A standard two position on/off

releasenotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## vNext
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.
4+
- 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.
45

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

src/DcsBios.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ do not come with their own build system, we are just putting everything into the
129129
#include "internal/AnalogMultiPos.h"
130130
#include "internal/RotarySwitch.h"
131131
#include "internal/MatrixSwitches.h"
132+
#include "internal/DualModeButton.h"
132133

133134
namespace DcsBios {
134135
template<unsigned int first, unsigned int second>

src/internal/DualModeButton.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#ifndef __DCSBIOS_DUALMODEBUTTON_H
2+
#define __DCSBIOS_DUALMODEBUTTON_H
3+
4+
#include "Arduino.h"
5+
6+
namespace DcsBios {
7+
template <unsigned long pollIntervalMs = POLL_EVERY_TIME>
8+
class DualModeButtonT : PollingInput, public ResettableInput {
9+
private:
10+
char modePin_;
11+
12+
const char* msgMode1_;
13+
const char* msgMode2_;
14+
15+
char buttonPin_;
16+
17+
char lastState_;
18+
char lastMode_;
19+
20+
void resetState()
21+
{
22+
lastState_ = (lastState_==0)?-1:0;
23+
lastMode_ = -1;
24+
}
25+
26+
void pollInput() {
27+
char mode = digitalRead(modePin_);
28+
char state = digitalRead(buttonPin_);
29+
30+
if(mode != lastMode_)
31+
{
32+
// Switched seat. If we had a button held, make sure to release it
33+
if( lastState_ == LOW)
34+
{
35+
tryToSendDcsBiosMessage(lastMode_?msgMode2_:msgMode1_, "0");
36+
lastMode_ = mode;
37+
lastState_ = HIGH;
38+
}
39+
}
40+
41+
if (state != lastState_) {
42+
tryToSendDcsBiosMessage(lastMode_?msgMode2_:msgMode1_, state ? "0":"1");
43+
lastState_ = state;
44+
}
45+
}
46+
public:
47+
DualModeButtonT(
48+
char modePin,
49+
char buttonPin,
50+
const char* msgMode1,
51+
const char* msgMode2 ) :
52+
PollingInput(pollIntervalMs)
53+
{
54+
modePin_ = modePin;
55+
buttonPin_ = buttonPin;
56+
msgMode1_ = msgMode1;
57+
msgMode2_ = msgMode2;
58+
59+
pinMode(modePin_, INPUT_PULLUP);
60+
pinMode(buttonPin_, INPUT_PULLUP);
61+
lastState_ = digitalRead(buttonPin_);
62+
lastMode_ = digitalRead(modePin_);
63+
}
64+
65+
void SetControl( const char* msgMode1, const char* msgMode2 )
66+
{
67+
msgMode1_ = msgMode1;
68+
msgMode2_ = msgMode2;
69+
}
70+
71+
void resetThisState()
72+
{
73+
this->resetState();
74+
}
75+
};
76+
typedef DualModeButtonT<> DualModeButton;
77+
}
78+
79+
#endif

0 commit comments

Comments
 (0)