diff --git a/smx-config/App.config b/smx-config/App.config index fba0990..0cbd0a0 100644 --- a/smx-config/App.config +++ b/smx-config/App.config @@ -13,6 +13,9 @@ False + + + diff --git a/smx-config/Helpers.cs b/smx-config/Helpers.cs index 177d049..5b52770 100644 --- a/smx-config/Helpers.cs +++ b/smx-config/Helpers.cs @@ -381,6 +381,7 @@ namespace smx_config // on the user's settings. This handles managing which sensors each slider controls. static class ThresholdSettings { + [Serializable] public struct PanelAndSensor { public PanelAndSensor(int panel, int sensor) @@ -408,10 +409,75 @@ namespace smx_config // are then synced to the other panels. { "cardinal", 7 }, { "corner", 2 }, + + // The aux threshold allows giving a list of specific sensors different thresholds. + { "aux", -1 }, }; + // Save and load the list of aux sensors to settings. These aren't saved to the pad, we just + // keep them in application settings. + static List cachedAuxSensors; + static public void SetAuxSensors(List panelAndSensors) + { + List result = new List(); + foreach(PanelAndSensor panelAndSensor in panelAndSensors) + { + List panelAndSensorArray = new List() { panelAndSensor.panel, panelAndSensor.sensor }; + result.Add(panelAndSensorArray); + } + + Properties.Settings.Default.AuxSensors = SerializeJSON.Serialize(result); + Properties.Settings.Default.Save(); + + // Clear the cache. Set it to null instead of assigning panelAndSensors to it to force + // it to re-parse at least once, to catch problems early. + cachedAuxSensors = null; + } + + // Return the sensors that are controlled by the aux threshold slider. The other + // threshold sliders will leave these alone. + static public List GetAuxSensors() + { +// Properties.Settings.Default.AuxSensors = "[[0,0], [1,0]]"; + // This is only ever changed with calls to SetSavedAuxSensors. + if(cachedAuxSensors != null) + return Helpers.DeepClone(cachedAuxSensors); + + List result = new List(); + if(Properties.Settings.Default.AuxSensors == "") + return result; + + try { + // This is a list of [panel,sensor] arrays: + // [[0,0], [0,1], [1,0]] + List sensors = SMXJSON.ParseJSON.Parse>(Properties.Settings.Default.AuxSensors); + foreach(object panelAndSensorObj in sensors) + { + List panelAndSensor = (List) panelAndSensorObj; + int panel = panelAndSensor.Get(0, -1); + int sensor = panelAndSensor.Get(1, -1); + if(panel == -1 || sensor == -1) + continue; + + result.Add(new PanelAndSensor(panel, sensor)); + } + } catch(ParseError) { + return result; + } + + cachedAuxSensors = result; + // SetAuxSensors(result); // XXX + + // SetSavedAuxSensors(result); + return Helpers.DeepClone(cachedAuxSensors); + } + static public List GetControlledSensorsForSliderType(string Type, bool advancedMode) { + // The aux threshold slider always controls the aux sensors. + if(Type == "aux") + return GetAuxSensors(); + List result = new List(); // Check if this slider is shown in this mode. @@ -432,6 +498,7 @@ namespace smx_config // 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 auxSensors = GetAuxSensors(); List saveToPanels = new List(); int ourPanelIdx = panelNameToIndex[Type]; saveToPanels.Add(ourPanelIdx); @@ -442,25 +509,17 @@ namespace smx_config { for(int sensor = 0; sensor < 4; ++sensor) { + // Ignore sensors controlled by the aux threshold. PanelAndSensor panelAndSensor = new PanelAndSensor(panelIdx, sensor); + if(auxSensors.Contains(panelAndSensor)) + continue; + 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. diff --git a/smx-config/MainWindow.xaml b/smx-config/MainWindow.xaml index 94f884d..12192aa 100644 --- a/smx-config/MainWindow.xaml +++ b/smx-config/MainWindow.xaml @@ -931,6 +931,11 @@ instead of only panels with sensors.