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

SwitchMultiPos Enhancement for Swtiches.h #58

Closed

Conversation

Arribe
Copy link

@Arribe Arribe commented Mar 14, 2024

Description

The current version of the SwitchMultiPos has an issue for non-shorting multi-position rotary switches when one of the positions isn't connected to an Arduino pin. While using PIN_NC to default to a position that's not hooked up to a pin the switch's DCSBios output bounces between the default position and the next selected pin. This is caused by the fact that in the middle of a rotation step none of the pins are connected to ground. By adding debounce logic to the multi-position switch , the time when the switch is between steps is ignored.

Closes #57

Testing

This was tested both in the console, and in DCS. The example was ran for an F/A-18, INS switch. In particular having this switch bounce to the off position at each step of the turn after aligning the INS would be extremely annoying. After the debounce logic was added the switch rotates as expected and doesn't bounce to the default position.

In addition to testing for the case with PIN_NC set, the scenario where all pins are connected continues to work.

Example Code:

// Off, position 0 is the default. 
const byte insSwPins[8] = {DcsBios::PIN_NC , INS_CV, INS_GND, INS_NAV, INS_IFA, INS_GYRO, INS_GB, INS_TEST };
DcsBios::SwitchMultiPos insSw("INS_SW", insSwPins, 8);

Output Prior to SwitchMultiPos Update:
Similar results occur regardless of which position is default / not connected to an Arduino pin.

< 2024/03/12 01:16:56.000594716 length=9 from=0 to=8
INS_SW 1
< 2024/03/12 01:16:57.000511709 length=9 from=9 to=17
INS_SW 0
< 2024/03/12 01:16:57.000540683 length=9 from=18 to=26
INS_SW 2
< 2024/03/12 01:16:58.000313749 length=9 from=27 to=35
INS_SW 0
< 2024/03/12 01:16:58.000339712 length=9 from=36 to=44
INS_SW 3
< 2024/03/12 01:16:59.000293774 length=9 from=45 to=53
INS_SW 0
< 2024/03/12 01:16:59.000311738 length=9 from=54 to=62
INS_SW 4
< 2024/03/12 01:17:00.000244804 length=9 from=63 to=71
INS_SW 0
< 2024/03/12 01:17:00.000252780 length=9 from=72 to=80
INS_SW 5
< 2024/03/12 01:17:01.000094833 length=9 from=81 to=89
INS_SW 0
< 2024/03/12 01:17:01.000108801 length=9 from=90 to=98
INS_SW 6
< 2024/03/12 01:17:01.000877842 length=9 from=99 to=107
INS_SW 0
< 2024/03/12 01:17:01.000893833 length=9 from=108 to=116
INS_SW 7
< 2024/03/12 01:17:03.000888931 length=9 from=117 to=125
INS_SW 0
< 2024/03/12 01:17:03.000898897 length=9 from=126 to=134
INS_SW 6
< 2024/03/12 01:17:04.000461950 length=9 from=135 to=143
INS_SW 0
< 2024/03/12 01:17:04.000517959 length=9 from=144 to=152
INS_SW 5
< 2024/03/12 01:17:05.000116980 length=9 from=153 to=161
INS_SW 0
< 2024/03/12 01:17:05.000135019 length=9 from=162 to=170
INS_SW 4
< 2024/03/12 01:17:05.000567011 length=7 from=171 to=177
INS_SW < 2024/03/12 01:17:05.000567955 length=2 from=178 to=179
0
< 2024/03/12 01:17:05.000587964 length=9 from=180 to=188
INS_SW 3
< 2024/03/12 01:17:06.000308028 length=9 from=189 to=197
INS_SW 0
< 2024/03/12 01:17:06.000320981 length=9 from=198 to=206
INS_SW 2
< 2024/03/12 01:17:06.000743993 length=9 from=207 to=215
INS_SW 0
< 2024/03/12 01:17:06.000794995 length=9 from=216 to=224
INS_SW 1
< 2024/03/12 01:17:07.000279069 length=9 from=225 to=233
INS_SW 0

Output After Logic Fix Added
Position 0 is still the default

2024/03/12 13:16:59.000273270 length=9 from=0 to=8
INS_SW 1
< 2024/03/12 13:16:59.000888323 length=9 from=9 to=17
INS_SW 2
< 2024/03/12 13:17:00.000422295 length=9 from=18 to=26
INS_SW 3
< 2024/03/12 13:17:01.000168319 length=9 from=27 to=35
INS_SW 4
< 2024/03/12 13:17:02.000346360 length=9 from=36 to=44
INS_SW 5
< 2024/03/12 13:17:03.000001381 length=9 from=45 to=53
INS_SW 6
< 2024/03/12 13:17:03.000665372 length=9 from=54 to=62
INS_SW 7
< 2024/03/12 13:17:05.000718483 length=9 from=63 to=71
INS_SW 6
< 2024/03/12 13:17:06.000204529 length=9 from=72 to=80
INS_SW 5
< 2024/03/12 13:17:06.000752495 length=9 from=81 to=89
INS_SW 4
< 2024/03/12 13:17:07.000203534 length=9 from=90 to=98
INS_SW 3
< 2024/03/12 13:17:08.000289591 length=9 from=99 to=107
INS_SW 2
< 2024/03/12 13:17:08.000815586 length=9 from=108 to=116
INS_SW 1
< 2024/03/12 13:17:09.000377607 length=9 from=117 to=125
INS_SW 0

The current version of the SwitchMultiPos has an issue for non-shorting multi-position rotary switches when one of the positions isn't connected to an Arduino pin.  While using PIN_NC to default to a position that's not hooked up tp a pin the switch's DCSBios output bounces between the default position and the next selected pin.  In the middle of a rotation step none of the pins are connected to ground.  By adding debounce logic to the multi-position switch , the time when the switch is between positions is ignored.
@kbastronomics
Copy link

SwitchMultiPos Enhancement for Swtiches.h
adding a delay will not solve the issue correctly and only make it harder for reads to occure in a timely maner
it hiding the real issue of PIN_NC is being sent instead of ignored

@Arribe Arribe closed this Mar 14, 2024
@Arribe
Copy link
Author

Arribe commented Mar 14, 2024

I give up...I'll leave it to the DCS Bios maintainers to fix. Though I do note that the use case from version 0.3.2 is that PIN_NC needs to be sent as a default. It just doesn't work as coded for a break-before-make switch. We don't want to suppress the default position outright, but only have it sent when no other positions are truly selected vs in the middle of the rotation between steps.

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

Successfully merging this pull request may close these issues.

SwitchMultiPos not correctly accounting for PIN_NC and instead sends the PIN_NC value
2 participants