From 8f280ce77bb263b74b5100008fa81b9712c80526 Mon Sep 17 00:00:00 2001 From: Talbot McInnis Date: Fri, 27 Nov 2020 22:03:42 -0500 Subject: [PATCH 1/2] More effort on AnalogMultipos. "Works for me" --- src/internal/AnalogMultiPos.h | 78 ++++++----------------------------- 1 file changed, 12 insertions(+), 66 deletions(-) diff --git a/src/internal/AnalogMultiPos.h b/src/internal/AnalogMultiPos.h index 45b7279..eeecb9f 100644 --- a/src/internal/AnalogMultiPos.h +++ b/src/internal/AnalogMultiPos.h @@ -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() @@ -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_; } From 064812722465bed68e8a4999717f4d6676cc836e Mon Sep 17 00:00:00 2001 From: Talbot McInnis Date: Sat, 5 Dec 2020 11:41:35 -0500 Subject: [PATCH 2/2] 0.3.1 --- library.properties | 2 +- releasenotes.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 388f79c..32bbc85 100644 --- a/library.properties +++ b/library.properties @@ -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 diff --git a/releasenotes.md b/releasenotes.md index 595a11f..c15dfb4 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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.