@@ -6,6 +6,8 @@ namespace MobiFlight.Joysticks.Octavi
66{
77 internal class OctaviHandler
88 {
9+ private const string Unshift_VButton_Name = "Button_UNSHIFT_SW" ;
10+
911 private bool isInShiftMode = false ;
1012 private OctaviReport lastReport = new OctaviReport ( ) ;
1113 private readonly List < string > buttons = new List < string > ( ) ;
@@ -70,7 +72,7 @@ public OctaviHandler(JoystickDefinition definition = null)
7072 if ( ! definition . Inputs . Any ( JoystickInput => JoystickInput . Id == ( int ) context . state ) )
7173 {
7274 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" ) ) ;
75+ // buttonMappings.Add((context.state, context.isShifted, OctaviReport.OctaviButtons.HID_ENC_SW), ToButton(Unshift_VButton_Name ));
7476 }
7577 else
7678 {
@@ -81,7 +83,7 @@ public OctaviHandler(JoystickDefinition definition = null)
8183 * (i.e. not a variable that will be toggled when a single button is pressed can be used)
8284 * States that do not support a shift mode will always be "unshifted".
8385 */
84- buttonMappings . Add ( ( context . state , context . isShifted , OctaviReport . OctaviButtons . HID_ENC_SW ) , ToButton ( $ "Button_ { ( context . isShifted ? "" : "UN" ) } SHIFT_SW" ) ) ;
86+ buttonMappings . Add ( ( context . state , context . isShifted , OctaviReport . OctaviButtons . HID_ENC_SW ) , ToButton ( context . isShifted ? Shift_VButton_Name : Unshift_VButton_Name ) ) ;
8587 }
8688
8789 // DCT, MENU, CLR, ENT, CDI, OBS, MSG, FLP, VNAV, PROC
@@ -121,6 +123,12 @@ public OctaviHandler(JoystickDefinition definition = null)
121123 }
122124 }
123125
126+ if ( buttons . IndexOf ( Unshift_VButton_Name ) < 0 )
127+ {
128+ /* create at least the Button index for the virtual unshift event on context change. */
129+ _ = ToButton ( Unshift_VButton_Name ) ;
130+ }
131+
124132 JoystickButtonNames = buttons . AsReadOnly ( ) ;
125133 }
126134
@@ -153,17 +161,20 @@ private int ToButton(string buttonName)
153161 // "Shift Mode" for supported contexts
154162 if ( report . contextState != lastReport . contextState )
155163 {
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 ) )
164+ // reset shift mode on context changes (and synthesize unshift press/release)
165+ int unshift_vButton = buttons . IndexOf ( Unshift_VButton_Name ) ;
166+
167+ if ( unshift_vButton >= 0 )
158168 {
159- var inputEvent = pressed . HasFlag ( OctaviReport . OctaviButtons . HID_ENC_SW ) ? MobiFlightButton . InputEvent . PRESS : MobiFlightButton . InputEvent . RELEASE ;
160- buttonEvents . Add ( ( buttonIndex , inputEvent ) ) ;
169+ buttonEvents . Add ( ( unshift_vButton , MobiFlightButton . InputEvent . PRESS ) ) ;
170+ buttonEvents . Add ( ( unshift_vButton , MobiFlightButton . InputEvent . RELEASE ) ) ;
161171 }
162172
163173 isInShiftMode = false ;
164174 }
165175 else if ( pressed . HasFlag ( OctaviReport . OctaviButtons . HID_ENC_SW ) && this . definition . Inputs . Any ( JoystickInput => JoystickInput . Id == ( int ) report . contextState ) )
166176 {
177+ /* Button events will be generated by finding the corrensponding ButtonMapping in the loop at the end. */
167178 isInShiftMode = ! isInShiftMode ;
168179 }
169180
0 commit comments