Skip to content

Commit 714a690

Browse files
author
FloH
committed
fixed vButton for shift initialisation
1 parent 576d2d0 commit 714a690

File tree

3 files changed

+12241
-6
lines changed

3 files changed

+12241
-6
lines changed

MobiFlight/Joysticks/Octavi/OctaviHandler.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace MobiFlight.Joysticks.Octavi
66
{
77
internal class OctaviHandler
88
{
9+
private const string Shift_VButton_Name = "Button_UNSHIFT_SW";
10+
private const string Unshift_VButton_Name = "Button_UNSHIFT_SW";
11+
912
private bool isInShiftMode = false;
1013
private OctaviReport lastReport = new OctaviReport();
1114
private readonly List<string> buttons = new List<string>();
@@ -70,7 +73,7 @@ public OctaviHandler(JoystickDefinition definition = null)
7073
if (!definition.Inputs.Any(JoystickInput => JoystickInput.Id == (int) context.state))
7174
{
7275
buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_ENC_SW), ToButton($"Button_{context.name}_CRSR"));
73-
buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_ENC_SW), ToButton($"Button_UNSHIFT_SW"));
76+
//buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_ENC_SW), ToButton(Unshift_VButton_Name));
7477
}
7578
else
7679
{
@@ -81,7 +84,7 @@ public OctaviHandler(JoystickDefinition definition = null)
8184
* (i.e. not a variable that will be toggled when a single button is pressed can be used)
8285
* States that do not support a shift mode will always be "unshifted".
8386
*/
84-
buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_ENC_SW), ToButton($"Button_{(context.isShifted ? "" : "UN")}SHIFT_SW"));
87+
buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_ENC_SW), ToButton(context.isShifted ? Shift_VButton_Name : Unshift_VButton_Name));
8588
}
8689

8790
// DCT, MENU, CLR, ENT, CDI, OBS, MSG, FLP, VNAV, PROC
@@ -121,6 +124,12 @@ public OctaviHandler(JoystickDefinition definition = null)
121124
}
122125
}
123126

127+
if (buttons.IndexOf(Unshift_VButton_Name) < 0)
128+
{
129+
/* create at least the Button index for the virtual unshift event on context change. */
130+
_ = ToButton(Unshift_VButton_Name);
131+
}
132+
124133
JoystickButtonNames = buttons.AsReadOnly();
125134
}
126135

@@ -153,17 +162,20 @@ private int ToButton(string buttonName)
153162
// "Shift Mode" for supported contexts
154163
if (report.contextState != lastReport.contextState)
155164
{
156-
// reset shift mode on context changes (and synthesize unshift press)
157-
if (buttonMappings.TryGetValue((lastReport.contextState, false, OctaviReport.OctaviButtons.HID_ENC_SW), out int buttonIndex))
165+
// reset shift mode on context changes (and synthesize unshift press/release)
166+
int unshift_vButton = buttons.IndexOf(Unshift_VButton_Name);
167+
168+
if (unshift_vButton >= 0)
158169
{
159-
var inputEvent = pressed.HasFlag(OctaviReport.OctaviButtons.HID_ENC_SW) ? MobiFlightButton.InputEvent.PRESS : MobiFlightButton.InputEvent.RELEASE;
160-
buttonEvents.Add((buttonIndex, inputEvent));
170+
buttonEvents.Add((unshift_vButton, MobiFlightButton.InputEvent.PRESS));
171+
buttonEvents.Add((unshift_vButton, MobiFlightButton.InputEvent.RELEASE));
161172
}
162173

163174
isInShiftMode = false;
164175
}
165176
else if (pressed.HasFlag(OctaviReport.OctaviButtons.HID_ENC_SW) && this.definition.Inputs.Any(JoystickInput => JoystickInput.Id == (int)report.contextState))
166177
{
178+
/* Button events will be generated by finding the corrensponding ButtonMapping in the loop at the end. */
167179
isInShiftMode = !isInShiftMode;
168180
}
169181

0 commit comments

Comments
 (0)