Skip to content

Commit 576d2d0

Browse files
author
FloH
committed
enable virtual shift-mode button for IFR-1
1 parent be20d63 commit 576d2d0

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

MobiFlight/Joysticks/Octavi/OctaviHandler.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public OctaviHandler(JoystickDefinition definition = null)
5454
var context = new Context(state, true, stateName + "^");
5555
this.contexts.Add(context);
5656
}
57+
5758
foreach (var context in contexts)
5859
{
5960
// Encoders
@@ -69,6 +70,18 @@ public OctaviHandler(JoystickDefinition definition = null)
6970
if (!definition.Inputs.Any(JoystickInput => JoystickInput.Id == (int) context.state))
7071
{
7172
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"));
74+
}
75+
else
76+
{
77+
/* Will be used to raise the "we are shifted now" flag
78+
* Can be used to control a "shifted" variable that turns output pin 7 on/off
79+
* We need two buttons, because context switching forces "unshifting",
80+
* so the shift state always has to be sent explicitly
81+
* (i.e. not a variable that will be toggled when a single button is pressed can be used)
82+
* States that do not support a shift mode will always be "unshifted".
83+
*/
84+
buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_ENC_SW), ToButton($"Button_{(context.isShifted ? "" : "UN")}SHIFT_SW"));
7285
}
7386

7487
// DCT, MENU, CLR, ENT, CDI, OBS, MSG, FLP, VNAV, PROC
@@ -86,6 +99,9 @@ public OctaviHandler(JoystickDefinition definition = null)
8699
buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_BTN_AP_ALT), ToButton($"Button_{context.name}_VNAV"));
87100
buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_BTN_AP_VS), ToButton($"Button_{context.name}_PROC"));
88101
}
102+
/* else: why can't we use these buttons out of FMS-States?
103+
* e.g. Context COM1 Button -D-> could be used to set the radio to VATSIM Unicom "122.800"
104+
*/
89105

90106
// AP, HDG, NAV, APR, ALT, VS (AP context only for now to not mess up the ordering of buttons)
91107
if (context.state == OctaviReport.OctaviState.STATE_AP)
@@ -137,7 +153,14 @@ private int ToButton(string buttonName)
137153
// "Shift Mode" for supported contexts
138154
if (report.contextState != lastReport.contextState)
139155
{
140-
isInShiftMode = false; // reset shift mode on context change
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))
158+
{
159+
var inputEvent = pressed.HasFlag(OctaviReport.OctaviButtons.HID_ENC_SW) ? MobiFlightButton.InputEvent.PRESS : MobiFlightButton.InputEvent.RELEASE;
160+
buttonEvents.Add((buttonIndex, inputEvent));
161+
}
162+
163+
isInShiftMode = false;
141164
}
142165
else if (pressed.HasFlag(OctaviReport.OctaviButtons.HID_ENC_SW) && this.definition.Inputs.Any(JoystickInput => JoystickInput.Id == (int)report.contextState))
143166
{

0 commit comments

Comments
 (0)