diff --git a/smx-config/DiagnosticsWidgets.cs b/smx-config/DiagnosticsWidgets.cs index f8df1cf..2f41b6a 100644 --- a/smx-config/DiagnosticsWidgets.cs +++ b/smx-config/DiagnosticsWidgets.cs @@ -56,7 +56,10 @@ namespace smx_config Warning = !args.controller[SelectedPad].test_data.bHaveDataFromPanel[PanelIndex] || args.controller[SelectedPad].test_data.AnySensorsOnPanelNotResponding(PanelIndex) || args.controller[SelectedPad].test_data.AnyBadJumpersOnPanel(PanelIndex); - + + // Only show this panel button if the panel's input is enabled. + SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig(args); + Visibility = ShouldBeDisplayed(config)? Visibility.Visible:Visibility.Collapsed; }); onConfigChange.RefreshOnInputChange = true; onConfigChange.RefreshOnTestDataChange = true; @@ -67,11 +70,18 @@ namespace smx_config base.OnClick(); // Select this panel. - Console.WriteLine(SelectedPanel + " -> " + Panel); SelectedPanel = Panel; CurrentSMXDevice.singleton.FireConfigurationChanged(this); } + + // Return true if this button should be displayed. + private bool ShouldBeDisplayed(SMX.SMXConfig config) + { + bool[] enabledPanels = config.GetEnabledPanels(); + int PanelIndex = Panel % 9; + return enabledPanels[PanelIndex]; + } } public class LevelBar: Control @@ -244,6 +254,10 @@ namespace smx_config private void Refresh(LoadFromConfigDelegateArgs args) { + // First, make sure a valid panel is selected. + SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig(args); + SelectValidPanel(config); + RefreshSelectedPanel(); P1Diagnostics.Visibility = args.controller[0].info.connected? Visibility.Visible:Visibility.Collapsed; @@ -267,8 +281,8 @@ namespace smx_config } NoResponseFromSensors.Visibility = AnySensorsNotResponding? Visibility.Visible:Visibility.Collapsed; BadSensorDIPSwitches.Visibility = HaveIncorrectSensorDIP? Visibility.Visible:Visibility.Collapsed; + // Adjust the DIP labels to match the PCB. - SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig(args); bool DIPLabelsOnLeft = config.masterVersion < 4; DIPLabelRight.Visibility = DIPLabelsOnLeft? Visibility.Collapsed:Visibility.Visible; DIPLabelLeft.Visibility = DIPLabelsOnLeft? Visibility.Visible:Visibility.Collapsed; @@ -329,8 +343,19 @@ namespace smx_config } } + + // If the selected panel isn't enabled for input, select another one. + private void SelectValidPanel(SMX.SMXConfig config) + { + bool[] enabledPanels = config.GetEnabledPanels(); + int SelectedPanelIndex = SelectedPanel % 9; + + // If we're not selected, or this button is visible, we don't need to do anything. + if(!enabledPanels[SelectedPanelIndex]) + SelectedPanel = config.GetFirstEnabledPanel(); + } - // Update the selected color picker based on the value of selectedButton. + // Update the selected diagnostics button based on the value of selectedButton. private void RefreshSelectedPanel() { LoadFromConfigDelegateArgs args = CurrentSMXDevice.singleton.GetState(); diff --git a/smx-config/SMX.cs b/smx-config/SMX.cs index 70785b1..abfb8f8 100644 --- a/smx-config/SMX.cs +++ b/smx-config/SMX.cs @@ -150,6 +150,20 @@ namespace SMX if(panels[8]) enabledSensors[4] |= 0xF0; } + // Return the index of the first enabled panel, or 1 (up) if no panels + // are enabled. + public int GetFirstEnabledPanel() + { + bool[] enabledPanels = GetEnabledPanels(); + for(int i = 0; i < 9; ++i) + { + if(enabledPanels[i]) + return i; + } + + return 0; + } + // The layout of this structure (and the underlying C struct) matches the firmware configuration // data. This is a bit inconvenient for the panel thresholds which aren't contiguous, so these // helpers just convert them to and from arrays.