Skip to content

Commit

Permalink
Merge pull request #3 from talbotmcinnis/Fix-AnalogMultipos
Browse files Browse the repository at this point in the history
Fix analog multipos
  • Loading branch information
talbotmcinnis authored Dec 5, 2020
2 parents 87513ff + 0648127 commit f914624
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 67 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ sentence=Connect input and output devices to the DCS: World flight simulator usi
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.
url=https://github.com/DCSFlightpanels/dcs-bios
category=Other
version=0.3.0
version=0.3.1
4 changes: 4 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.3.1

- Fix AnalogMultiPos as per [Analog Multipos does not send commands (github.com)](https://github.com/talbotmcinnis/dcs-bios-arduino-library/issues/2)

## v0.3.0

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.
Expand Down
78 changes: 12 additions & 66 deletions src/internal/AnalogMultiPos.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ namespace DcsBios {
private:
const char *msg_;
char pin_;
char numOfSteps;
int divisor;
char lastState_;
unsigned char numOfSteps;
unsigned char lastState_;
unsigned long period = 750;
unsigned long time_now = 0;

char readState()
unsigned char readState()
{
float fAnalogPct = analogRead(pin_) / 1024;

char result = (char)((numOfSteps-1) * fAnalogPct);

return result;
unsigned char state = map(analogRead(pin_), 0, 1023, 0, numOfSteps);
return state;
}

void resetState()
Expand All @@ -35,75 +31,25 @@ namespace DcsBios {
{
if (millis() > time_now + period)
{
char state = readState();

unsigned char state = readState();
time_now = millis();
if (state != lastState_)
{
if (state == 0)
{
if (tryToSendDcsBiosMessage(msg_, "0"))
lastState_ = state;
}
else if (state == 1)
{
if (tryToSendDcsBiosMessage(msg_, "1"))
lastState_ = state;
}
else if (state == 2)
{
if (tryToSendDcsBiosMessage(msg_, "2"))
lastState_ = state;
}
else if (state == 3)
{
if (tryToSendDcsBiosMessage(msg_, "3"))
lastState_ = state;
}
else if (state == 4)
{
if (tryToSendDcsBiosMessage(msg_, "4"))
lastState_ = state;
}
else if (state == 5) {
if (tryToSendDcsBiosMessage(msg_, "5"))
lastState_ = state;
}
else if (state == 6) {
if (tryToSendDcsBiosMessage(msg_, "6"))
lastState_ = state;
}
else if (state == 7)
{
if (tryToSendDcsBiosMessage(msg_, "7"))
lastState_ = state;
}
else if (state == 8)
{
if (tryToSendDcsBiosMessage(msg_, "8"))
lastState_ = state;
}
else if (state == 9)
{
if (tryToSendDcsBiosMessage(msg_, "9"))
lastState_ = state;
}
else if (state == 10)
{
if (tryToSendDcsBiosMessage(msg_, "10"))
{
char cstr[5];
itoa(state, cstr, 10);

if (tryToSendDcsBiosMessage(msg_, cstr))
lastState_ = state;
}
}
}
}

public:
AnalogMultiPosT(const char *msg, char pin, char numOfSteps_, int divisor_) :
AnalogMultiPosT(const char *msg, char pin, char numOfSteps_) :
PollingInput(pollIntervalMs)
{
msg_ = msg;
pin_ = pin;
divisor = divisor_;
lastState_ = readState();
numOfSteps = numOfSteps_;
}
Expand Down

0 comments on commit f914624

Please sign in to comment.