Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] : DcsBios::Potentiometer min & max values are not limiting the travel of the in-game lever #60

Open
psjshep opened this issue May 14, 2024 · 5 comments

Comments

@psjshep
Copy link

psjshep commented May 14, 2024

DCS-BIOS version
DCS Unified 2.9.3

DCS-BIOS Control
PLT_FLAPS_LEVER when using DcsBios::Potentiometer

Describe the bug

  • Using a 100k linear potentiometer on a Leonardo board, connected to Analog port A0
  • DcsBios::Potentiometer function being used for the PLT_FLAPS_LEVER and a min & max value of 0 & 500 for F14
  • In-game, the flaps lever starts to move from the closed position to the open position. When the open (max travel in-game) is reached, the flap lever quickly snaps to the closed position - the function seems to causing the lever to continuously loop back to the closed position each time the in-game max is reached

To Reproduce

  1. Arduino code :
#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"

void setup() {
// the flaps lever at 100% or 65535 is up (flaps up)
  DcsBios::Potentiometer pltFlapsLever("PLT_FLAPS_LEVER", A0,false,700,1023);
  DcsBios::setup();
}

void loop() {
  DcsBios::loop();
}
  1. fire up DCS-Bios Bridge or the socat cmd file to communicate with the Leonardo port
  2. Run DCS, Instant Action, F14 tomcat anywhere, in-cockpit, move pot whilst looking at flaps lever

Expected behavior

once the max value is reached, the movement should stop & not loop around

Screenshots

n/a

Additional context

@psjshep
Copy link
Author

psjshep commented May 14, 2024

@psjshep
Copy link
Author

psjshep commented May 14, 2024

I am not a C++ programmer, but the following snippets seem to work for me to constrain the values within input_min & input_max :

in Potentiometers.h

....
			void pollInput() {
				unsigned int state; 
				if (reverse_)
					// psjshep
//					state = map(analogRead(pin_), input_min_, input_max_, 65535, 0);
					state = map(constrain(analogRead(pin_),input_min_,input_max_), input_min_, input_max_, 65535, 0);
				else
					// psjshep
//					state = map(analogRead(pin_), input_min_, input_max_, 0, 65535);
					state = map(constrain(analogRead(pin_),input_min_,input_max_), input_min_, input_max_, 0, 65535);
...


There is similar logic below in the public declaration so I suppose a similar change would be needed there?


@charliefoxtwo
Copy link
Member

Tested with bort and appears to behave as expected. Moving this to the arduino repo

@charliefoxtwo charliefoxtwo transferred this issue from DCS-Skunkworks/dcs-bios May 15, 2024
@psjshep
Copy link
Author

psjshep commented May 16, 2024

Tested with bort and appears to behave as expected. Moving this to the arduino repo

not sure what you mean by "behave as expected"?

Is the function, when supplied with a min/max, supposed to reset to the minimum when maximum is reached?

Or do you mean the PLT_FLAPS_LEVER call does move the flaps so the call behaves as expected?

@charliefoxtwo
Copy link
Member

I mean bios appears to be behaving properly. When the lever is moved to the maximum value via bort or any other test tool or command, it does not reset to minimum.

There may be a bug in the arduino library calling bios - I don't know, I don't do any arduino development with bios - so I've moved the issue to that repository so those who are more familiar with this code can evaluate the issue you're experiencing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants