Skip to content

Commit f914624

Browse files
Merge pull request #3 from talbotmcinnis/Fix-AnalogMultipos
Fix analog multipos
2 parents 87513ff + 0648127 commit f914624

File tree

3 files changed

+17
-67
lines changed

3 files changed

+17
-67
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ sentence=Connect input and output devices to the DCS: World flight simulator usi
55
paragraph=DCS-BIOS is a piece of software that can extract data from DCS: World and sends them to an Arduino. It also accepts commands over the serial port. This library talks to DCS-BIOS and allows you to connect any component your Arduino can communicate with to your virtual cockpit.
66
url=https://github.com/DCSFlightpanels/dcs-bios
77
category=Other
8-
version=0.3.0
8+
version=0.3.1

releasenotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.3.1
2+
3+
- Fix AnalogMultiPos as per [Analog Multipos does not send commands (github.com)](https://github.com/talbotmcinnis/dcs-bios-arduino-library/issues/2)
4+
15
## v0.3.0
26

37
First version released after forking from the dcs-bios repo. Several changes are included and only vaguely documented as the primary developer becomes oriented within the project.

src/internal/AnalogMultiPos.h

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ namespace DcsBios {
1111
private:
1212
const char *msg_;
1313
char pin_;
14-
char numOfSteps;
15-
int divisor;
16-
char lastState_;
14+
unsigned char numOfSteps;
15+
unsigned char lastState_;
1716
unsigned long period = 750;
1817
unsigned long time_now = 0;
1918

20-
char readState()
19+
unsigned char readState()
2120
{
22-
float fAnalogPct = analogRead(pin_) / 1024;
23-
24-
char result = (char)((numOfSteps-1) * fAnalogPct);
25-
26-
return result;
21+
unsigned char state = map(analogRead(pin_), 0, 1023, 0, numOfSteps);
22+
return state;
2723
}
2824

2925
void resetState()
@@ -35,75 +31,25 @@ namespace DcsBios {
3531
{
3632
if (millis() > time_now + period)
3733
{
38-
char state = readState();
39-
34+
unsigned char state = readState();
4035
time_now = millis();
4136
if (state != lastState_)
42-
{
43-
if (state == 0)
44-
{
45-
if (tryToSendDcsBiosMessage(msg_, "0"))
46-
lastState_ = state;
47-
}
48-
else if (state == 1)
49-
{
50-
if (tryToSendDcsBiosMessage(msg_, "1"))
51-
lastState_ = state;
52-
}
53-
else if (state == 2)
54-
{
55-
if (tryToSendDcsBiosMessage(msg_, "2"))
56-
lastState_ = state;
57-
}
58-
else if (state == 3)
59-
{
60-
if (tryToSendDcsBiosMessage(msg_, "3"))
61-
lastState_ = state;
62-
}
63-
else if (state == 4)
64-
{
65-
if (tryToSendDcsBiosMessage(msg_, "4"))
66-
lastState_ = state;
67-
}
68-
else if (state == 5) {
69-
if (tryToSendDcsBiosMessage(msg_, "5"))
70-
lastState_ = state;
71-
}
72-
else if (state == 6) {
73-
if (tryToSendDcsBiosMessage(msg_, "6"))
74-
lastState_ = state;
75-
}
76-
else if (state == 7)
77-
{
78-
if (tryToSendDcsBiosMessage(msg_, "7"))
79-
lastState_ = state;
80-
}
81-
else if (state == 8)
82-
{
83-
if (tryToSendDcsBiosMessage(msg_, "8"))
84-
lastState_ = state;
85-
}
86-
else if (state == 9)
87-
{
88-
if (tryToSendDcsBiosMessage(msg_, "9"))
89-
lastState_ = state;
90-
}
91-
else if (state == 10)
92-
{
93-
if (tryToSendDcsBiosMessage(msg_, "10"))
37+
{
38+
char cstr[5];
39+
itoa(state, cstr, 10);
40+
41+
if (tryToSendDcsBiosMessage(msg_, cstr))
9442
lastState_ = state;
95-
}
9643
}
9744
}
9845
}
9946

10047
public:
101-
AnalogMultiPosT(const char *msg, char pin, char numOfSteps_, int divisor_) :
48+
AnalogMultiPosT(const char *msg, char pin, char numOfSteps_) :
10249
PollingInput(pollIntervalMs)
10350
{
10451
msg_ = msg;
10552
pin_ = pin;
106-
divisor = divisor_;
10753
lastState_ = readState();
10854
numOfSteps = numOfSteps_;
10955
}

0 commit comments

Comments
 (0)