diff --git a/smx-config/ConfigPresets.cs b/smx-config/ConfigPresets.cs index cbfeaf1..e8a0c20 100644 --- a/smx-config/ConfigPresets.cs +++ b/smx-config/ConfigPresets.cs @@ -113,27 +113,46 @@ namespace smx_config 200, 219, 212, 225); } + // Return the extra panels that the given panel's sensitivities control when + // advanced threshold mode is off. + static public List GetPanelsToSyncUnifiedThresholds(int fromPanel) + { + List result = new List(); + switch(fromPanel) + { + case 7: // down (cardinal) + result.Add(3); // left + result.Add(5); // right + break; + case 2: // up-right (corners) + result.Add(0); // up-left + result.Add(6); // down-left + result.Add(8); // down-right + break; + } + return result; + } + // The simplified configuration scheme sets thresholds for up, center, cardinal directions // and corners. Rev1 firmware uses those only. Copy cardinal directions (down) to the // other cardinal directions (except for up, which already had its own setting) and corners // to the other corners. static public void SyncUnifiedThresholds(ref SMX.SMXConfig config) { - // left = right = down (cardinal) - config.panelSettings[3].loadCellLowThreshold = config.panelSettings[5].loadCellLowThreshold = config.panelSettings[7].loadCellLowThreshold; - config.panelSettings[3].loadCellHighThreshold = config.panelSettings[5].loadCellHighThreshold = config.panelSettings[7].loadCellHighThreshold; - - // UL = DL = DR = UR (corners) - config.panelSettings[0].loadCellLowThreshold = config.panelSettings[6].loadCellLowThreshold = config.panelSettings[8].loadCellLowThreshold = config.panelSettings[2].loadCellLowThreshold; - config.panelSettings[0].loadCellHighThreshold = config.panelSettings[6].loadCellHighThreshold = config.panelSettings[8].loadCellHighThreshold = config.panelSettings[2].loadCellHighThreshold; - - // Do the same for FSR thresholds. - for(int sensor = 0; sensor < 4; ++sensor) + for(int fromPanel = 0; fromPanel < 9; ++fromPanel) { - config.panelSettings[3].fsrLowThreshold[sensor] = config.panelSettings[5].fsrLowThreshold[sensor] = config.panelSettings[7].fsrLowThreshold[sensor]; - config.panelSettings[3].fsrHighThreshold[sensor] = config.panelSettings[5].fsrHighThreshold[sensor] = config.panelSettings[7].fsrHighThreshold[sensor]; - config.panelSettings[0].fsrLowThreshold[sensor] = config.panelSettings[6].fsrLowThreshold[sensor] = config.panelSettings[8].fsrLowThreshold[sensor] = config.panelSettings[2].fsrLowThreshold[sensor]; - config.panelSettings[0].fsrHighThreshold[sensor] = config.panelSettings[6].fsrHighThreshold[sensor] = config.panelSettings[8].fsrHighThreshold[sensor] = config.panelSettings[2].fsrHighThreshold[sensor]; + foreach(int toPanel in GetPanelsToSyncUnifiedThresholds(fromPanel)) + { + config.panelSettings[toPanel].loadCellLowThreshold = config.panelSettings[fromPanel].loadCellLowThreshold; + config.panelSettings[toPanel].loadCellHighThreshold = config.panelSettings[fromPanel].loadCellHighThreshold; + + // Do the same for FSR thresholds. + for(int sensor = 0; sensor < 4; ++sensor) + { + config.panelSettings[toPanel].fsrLowThreshold[sensor] = config.panelSettings[fromPanel].fsrLowThreshold[sensor]; + config.panelSettings[toPanel].fsrHighThreshold[sensor] = config.panelSettings[fromPanel].fsrHighThreshold[sensor]; + } + } } } diff --git a/smx-config/Helpers.cs b/smx-config/Helpers.cs index a50404f..177d049 100644 --- a/smx-config/Helpers.cs +++ b/smx-config/Helpers.cs @@ -377,6 +377,92 @@ namespace smx_config public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); } + // The threshold sliders in the advanced tab affect different panels and sensors depending + // on the user's settings. This handles managing which sensors each slider controls. + static class ThresholdSettings + { + public struct PanelAndSensor + { + public PanelAndSensor(int panel, int sensor) + { + this.panel = panel; + this.sensor = sensor; + } + public int panel; + public int sensor; + }; + + // These correspond with ThresholdSlider.Type. + static Dictionary panelNameToIndex = new Dictionary() { + { "up-left", 0 }, + { "up", 1 }, + { "up-right", 2 }, + { "left", 3 }, + { "center", 4 }, + { "right", 5 }, + { "down-left", 6 }, + { "down", 7 }, + { "down-right", 8 }, + + // The cardinal and corner sliders write to the down and up-right panels, and + // are then synced to the other panels. + { "cardinal", 7 }, + { "corner", 2 }, + }; + + static public List GetControlledSensorsForSliderType(string Type, bool advancedMode) + { + List result = new List(); + + // Check if this slider is shown in this mode. + if(advancedMode) + { + // Hide the combo sliders in advanced mode. + if(Type == "cardinal" || Type == "corner") + return result; + } + + if(!advancedMode) + { + // Only these sliders are shown in normal mode. + if(Type != "up" && Type != "center" && Type != "cardinal" && Type != "corner") + return result; + } + + // If advanced mode is disabled, save to all panels this slider affects. The down arrow controls + // all four cardinal panels. (If advanced mode is enabled we'll never be a different cardinal + // direction, since those widgets won't exist.) If it's disabled, just write to our own panel. + List saveToPanels = new List(); + int ourPanelIdx = panelNameToIndex[Type]; + saveToPanels.Add(ourPanelIdx); + if(!advancedMode) + saveToPanels.AddRange(ConfigPresets.GetPanelsToSyncUnifiedThresholds(ourPanelIdx)); + + foreach(int panelIdx in saveToPanels) + { + for(int sensor = 0; sensor < 4; ++sensor) + { + PanelAndSensor panelAndSensor = new PanelAndSensor(panelIdx, sensor); + result.Add(panelAndSensor); + } + } + + return result; + } + + // Return the sensors that are controlled by the aux threshold slider. The other + // threshold sliders will leave these alone. + static public List GetAuxSensors() + { + List result = new List(); + result.Add(new PanelAndSensor(1,0)); + result.Add(new PanelAndSensor(1,1)); + result.Add(new PanelAndSensor(1,2)); + result.Add(new PanelAndSensor(1,3)); + return result; + } + } + // This class just makes it easier to assemble binary command packets. public class CommandBuffer { diff --git a/smx-config/MainWindow.xaml.cs b/smx-config/MainWindow.xaml.cs index a3386e9..da3f0a0 100644 --- a/smx-config/MainWindow.xaml.cs +++ b/smx-config/MainWindow.xaml.cs @@ -94,22 +94,33 @@ namespace smx_config SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig(); bool[] enabledPanels = config.GetEnabledPanels(); - // Up and center are shown in both modes. + // Check the list of sensors this slider controls. If the list is empty, don't show it. + // For example, if the user adds all four sensors on the up panel to aux, the up button + // has nothing left to control, so we'll hide it. + List panelAndSensors = ThresholdSettings.GetControlledSensorsForSliderType(type, AdvancedModeEnabled); + if(panelAndSensors.Count == 0) + return false; + + // Hide thresholds that only affect panels that are disabled, so we don't show + // corner panel sliders in advanced mode if the corner panels are disabled. We + // don't handle this in GetControlledSensorsForSliderType, since we do want cardinal + // and corner to write thresholds to disabled panels, so they're in sync if they're + // turned back on. switch(type) { - case "up-left": return AdvancedModeEnabled && enabledPanels[0]; - case "up": return enabledPanels[1]; - case "up-right": return AdvancedModeEnabled && enabledPanels[2]; - case "left": return AdvancedModeEnabled && enabledPanels[3]; - case "center": return enabledPanels[4]; - case "right": return AdvancedModeEnabled && enabledPanels[5]; - case "down-left": return AdvancedModeEnabled && enabledPanels[6]; - case "down": return AdvancedModeEnabled && enabledPanels[7]; - case "down-right": return AdvancedModeEnabled && enabledPanels[8]; + case "up-left": return enabledPanels[0]; + case "up": return enabledPanels[1]; + case "up-right": return enabledPanels[2]; + case "left": return enabledPanels[3]; + case "center": return enabledPanels[4]; + case "right": return enabledPanels[5]; + case "down-left": return enabledPanels[6]; + case "down": return enabledPanels[7]; + case "down-right": return enabledPanels[8]; // Show cardinal and corner if at least one panel they affect is enabled. - case "cardinal": return !AdvancedModeEnabled && (enabledPanels[3] || enabledPanels[5] || enabledPanels[8]); - case "corner": return !AdvancedModeEnabled && (enabledPanels[0] || enabledPanels[2] || enabledPanels[6] || enabledPanels[8]); + case "cardinal": return enabledPanels[3] || enabledPanels[5] || enabledPanels[8]; + case "corner": return enabledPanels[0] || enabledPanels[2] || enabledPanels[6] || enabledPanels[8]; default: return true; } } @@ -276,8 +287,11 @@ namespace smx_config SMX.SMXConfig config = activePad.Item2; for(int panelIdx = 0; panelIdx < 9; ++panelIdx) { - if(config.ShowThresholdWarning(panelIdx)) - ShowThresholdWarningText = true; + for(int sensor = 0; sensor < 4; ++sensor) + { + if(config.ShowThresholdWarning(panelIdx, sensor)) + ShowThresholdWarningText = true; + } } } ThresholdWarningText.Visibility = ShowThresholdWarningText? Visibility.Visible : Visibility.Hidden; diff --git a/smx-config/SMX.cs b/smx-config/SMX.cs index a48e2bf..9b4ec45 100644 --- a/smx-config/SMX.cs +++ b/smx-config/SMX.cs @@ -118,7 +118,7 @@ namespace SMX // // Higher low threshold values make the panel respond to the panel being released more // quickly. It shouldn't be set too low. - public bool ShowThresholdWarning(int panel) + public bool ShowThresholdWarning(int panel, int sensor) { if(!fsr()) return false; @@ -127,7 +127,7 @@ namespace SMX if(!GetEnabledPanels()[panel]) return false; - int lower = panelSettings[panel].fsrLowThreshold[0]; + int lower = panelSettings[panel].fsrLowThreshold[sensor]; int MinimumRecommendedLowThreshold = 140; return lower < MinimumRecommendedLowThreshold; } diff --git a/smx-config/Widgets.cs b/smx-config/Widgets.cs index 02fc949..c504c95 100644 --- a/smx-config/Widgets.cs +++ b/smx-config/Widgets.cs @@ -136,57 +136,52 @@ namespace smx_config }); } - Dictionary panelNameToIndex = new Dictionary() { - { "up-left", 0 }, - { "up", 1 }, - { "up-right", 2 }, - { "left", 3 }, - { "center", 4 }, - { "right", 5 }, - { "down-left", 6 }, - { "down", 7 }, - { "down-right", 8 }, - - // The cardinal and corner sliders write to the down and up-right panels, and - // are then synced to the other panels by SyncUnifiedThresholds. - { "cardinal", 7 }, - { "corner", 2 }, - }; + // Return the panel/sensors this widget controls. + // + // This returns values for FSRs. We don't configure individual sensors with load cells, + // and the sensor value will be ignored. + private List GetControlledSensors() + { + return ThresholdSettings.GetControlledSensorsForSliderType(Type, AdvancedModeEnabled); + } + + private void SetValueToConfig(ref SMX.SMXConfig config) { - int panelIdx = panelNameToIndex[Type]; - if(!config.fsr()) + List panelAndSensors = GetControlledSensors(); + foreach(ThresholdSettings.PanelAndSensor panelAndSensor in panelAndSensors) { - byte lower = (byte) slider.LowerValue; - byte upper = (byte) slider.UpperValue; - config.panelSettings[panelIdx].loadCellLowThreshold = lower; - config.panelSettings[panelIdx].loadCellHighThreshold = upper; - } else { - byte lower = (byte) slider.LowerValue; - byte upper = (byte) slider.UpperValue; - for(int sensor = 0; sensor < 4; ++sensor) + if(!config.fsr()) { - config.panelSettings[panelIdx].fsrLowThreshold[sensor] = lower; - config.panelSettings[panelIdx].fsrHighThreshold[sensor] = upper; + byte lower = (byte) slider.LowerValue; + byte upper = (byte) slider.UpperValue; + config.panelSettings[panelAndSensor.panel].loadCellLowThreshold = lower; + config.panelSettings[panelAndSensor.panel].loadCellHighThreshold = upper; + } else { + byte lower = (byte) slider.LowerValue; + byte upper = (byte) slider.UpperValue; + config.panelSettings[panelAndSensor.panel].fsrLowThreshold[panelAndSensor.sensor] = lower; + config.panelSettings[panelAndSensor.panel].fsrHighThreshold[panelAndSensor.sensor] = upper; } } - - // If we're not in advanced mode, sync the cardinal value to each of the panel values. - if(!AdvancedModeEnabled) - ConfigPresets.SyncUnifiedThresholds(ref config); } private void GetValueFromConfig(SMX.SMXConfig config, out int lower, out int upper) { - int panelIdx = panelNameToIndex[Type]; + lower = upper = 0; - if(!config.fsr()) + // Use the first controlled sensor. The rest should be the same. + foreach(ThresholdSettings.PanelAndSensor panelAndSensor in GetControlledSensors()) { - lower = config.panelSettings[panelIdx].loadCellLowThreshold; - upper = config.panelSettings[panelIdx].loadCellHighThreshold; - } else { - lower = config.panelSettings[panelIdx].fsrLowThreshold[0]; - upper = config.panelSettings[panelIdx].fsrHighThreshold[0]; + if(!config.fsr()) + { + lower = config.panelSettings[panelAndSensor.panel].loadCellLowThreshold; + upper = config.panelSettings[panelAndSensor.panel].loadCellHighThreshold; + } else { + lower = config.panelSettings[panelAndSensor.panel].fsrLowThreshold[panelAndSensor.sensor]; + upper = config.panelSettings[panelAndSensor.panel].fsrHighThreshold[panelAndSensor.sensor]; + } + return; } } @@ -245,8 +240,13 @@ namespace smx_config UpperLabel.Content = upper.ToString(); } - int panelIdx = panelNameToIndex[Type]; - bool ShowThresholdWarning = config.ShowThresholdWarning(panelIdx); + bool ShowThresholdWarning = false; + foreach(ThresholdSettings.PanelAndSensor panelAndSensor in GetControlledSensors()) + { + if(config.ShowThresholdWarning(panelAndSensor.panel, panelAndSensor.sensor)) + ShowThresholdWarning = true; + } + ThresholdWarning.Visibility = ShowThresholdWarning? Visibility.Visible:Visibility.Hidden; UpdatingUI = false;