private void LoadUIFromConfig(LoadFromConfigDelegateArgs args) { // Check the selected custom-sensors. List <ThresholdSettings.PanelAndSensor> customSensors = ThresholdSettings.GetCustomSensors(); for (int sensor = 0; sensor < 4; ++sensor) { SensorSelectionButtons[sensor].IsChecked = IsSensorEnabled(customSensors, sensor); } }
private void RefreshSliderActiveProperty() { if (Type == "custom-sensors") { SliderActive = ThresholdSettings.GetCustomSensors().Count > 0; } else { SliderActive = ThresholdEnabled; } }
protected override void OnClick() { Properties.Settings.Default.AdvancedMode = !Properties.Settings.Default.AdvancedMode; if (!Properties.Settings.Default.AdvancedMode) { // Sync thresholds when we exit advanced mode. XXX: not needed since MainWindow is recreating // sliders anyway ThresholdSettings.SyncSliderThresholds(); } // Refresh the UI. LoadUIFromConfig(ActivePad.GetFirstActivePadConfig()); }
private void SaveToSettings() { if (Type == "inner-sensors") { Properties.Settings.Default.UseInnerSensorThresholds = (bool)IsChecked; } else if (Type == "outer-sensors") { Properties.Settings.Default.UseOuterSensorThresholds = (bool)IsChecked; } Helpers.SaveApplicationSettings(); // Sync thresholds after enabling or disabling a slider. ThresholdSettings.SyncSliderThresholds(); CurrentSMXDevice.singleton.FireConfigurationChanged(this); }
void CreateThresholdSliders() { // Remove and recreate threshold sliders. ThresholdSliderContainer.Children.Clear(); foreach (string sliderName in ThresholdSettings.thresholdSliderNames) { if (!IsThresholdSliderShown(sliderName)) { continue; } ThresholdSlider slider = CreateThresholdSlider(sliderName); DockPanel.SetDock(slider, Dock.Top); slider.Margin = new Thickness(0, 8, 0, 0); ThresholdSliderContainer.Children.Add(slider); } ThresholdSettings.SyncSliderThresholds(); }
private void ClickedSensorButton(int sensor) { // Toggle the clicked sensor. Console.WriteLine("Clicked sensor " + sensor); List <ThresholdSettings.PanelAndSensor> customSensors = ThresholdSettings.GetCustomSensors(); bool enabled = !IsSensorEnabled(customSensors, sensor); if (enabled) { customSensors.Add(new ThresholdSettings.PanelAndSensor(Panel, sensor)); } else { customSensors.Remove(new ThresholdSettings.PanelAndSensor(Panel, sensor)); } ThresholdSettings.SetCustomSensors(customSensors); // Sync thresholds after changing custom sensors. ThresholdSettings.SyncSliderThresholds(); CurrentSMXDevice.singleton.FireConfigurationChanged(this); }
// 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 <ThresholdSettings.PanelAndSensor> GetControlledSensors(bool includeOverridden) { return(ThresholdSettings.GetControlledSensorsForSliderType(Type, AdvancedModeEnabled, includeOverridden)); }
bool IsThresholdSliderShown(string type) { bool AdvancedModeEnabled = Properties.Settings.Default.AdvancedMode; SMX.SMXConfig config = ActivePad.GetFirstActivePadConfig(); bool[] enabledPanels = config.GetEnabledPanels(); // 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 custom-sensors, the // up button has nothing left to control, so we'll hide it. // // Don't do this for custom, inner-sensors or outer-sensors. Those are always shown in // advanced mode. List <ThresholdSettings.PanelAndSensor> panelAndSensors = ThresholdSettings.GetControlledSensorsForSliderType(type, AdvancedModeEnabled, false); if (type == "custom-sensors" || type == "inner-sensors" || type == "outer-sensors") { if (!AdvancedModeEnabled || !config.fsr()) { return(false); } } else { 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(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(enabledPanels[3] || enabledPanels[5] || enabledPanels[8]); case "corner": return(enabledPanels[0] || enabledPanels[2] || enabledPanels[6] || enabledPanels[8]); default: return(true); } }
// Export configurable values in SMXConfig to a JSON string. public static string ExportSettingsToJSON(SMX.SMXConfig config) { // The user only uses one of low or high thresholds. Only export the // settings the user is actually using. Dictionary <string, Object> dict = new Dictionary <string, Object>(); if (config.fsr()) { List <int> fsrLowThresholds = new List <int>(); for (int panel = 0; panel < 9; ++panel) { fsrLowThresholds.Add(config.panelSettings[panel].fsrLowThreshold[0]); } dict.Add("fsrLowThresholds", fsrLowThresholds); List <int> fsrHighThresholds = new List <int>(); for (int panel = 0; panel < 9; ++panel) { fsrHighThresholds.Add(config.panelSettings[panel].fsrHighThreshold[0]); } dict.Add("fsrHighThresholds", fsrHighThresholds); } else { List <int> panelLowThresholds = new List <int>(); for (int panel = 0; panel < 9; ++panel) { panelLowThresholds.Add(config.panelSettings[panel].loadCellLowThreshold); } dict.Add("panelLowThresholds", panelLowThresholds); List <int> panelHighThresholds = new List <int>(); for (int panel = 0; panel < 9; ++panel) { panelHighThresholds.Add(config.panelSettings[panel].loadCellHighThreshold); } dict.Add("panelHighThresholds", panelHighThresholds); } // Store the enabled panel mask as a simple list of which panels are selected. bool[] enabledPanels = config.GetEnabledPanels(); List <int> enabledPanelList = new List <int>(); for (int panel = 0; panel < 9; ++panel) { if (enabledPanels[panel]) { enabledPanelList.Add(panel); } } dict.Add("enabledPanels", enabledPanelList); // Store panel colors. List <string> panelColors = new List <string>(); for (int PanelIndex = 0; PanelIndex < 9; ++PanelIndex) { // Scale colors from the hardware value back to the 0-255 value we use in the UI. Color color = Color.FromRgb(config.stepColor[PanelIndex * 3 + 0], config.stepColor[PanelIndex * 3 + 1], config.stepColor[PanelIndex * 3 + 2]); color = Helpers.UnscaleColor(color); panelColors.Add(Helpers.ColorToString(color)); } dict.Add("panelColors", panelColors); dict.Add("advancedMode", Properties.Settings.Default.AdvancedMode); dict.Add("useOuterSensorThresholds", Properties.Settings.Default.UseOuterSensorThresholds); dict.Add("useInnerSensorThresholds", Properties.Settings.Default.UseInnerSensorThresholds); dict.Add("customSensors", ThresholdSettings.GetCustomSensorsJSON()); return(SMXJSON.SerializeJSON.Serialize(dict)); }
// Import a saved JSON configuration to an SMXConfig. public static void ImportSettingsFromJSON(string json, ref SMX.SMXConfig config) { Dictionary <string, Object> dict; try { dict = SMXJSON.ParseJSON.Parse <Dictionary <string, Object> >(json); } catch (ParseError e) { MessageBox.Show(e.Message, "Error importing configuration", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // Read the thresholds. If any values are missing, we'll leave the value in config alone. if (config.fsr()) { List <Object> newPanelLowThresholds = dict.Get("fsrLowThresholds", new List <Object>()); List <Object> newPanelHighThresholds = dict.Get("fsrHighThresholds", new List <Object>()); for (int panel = 0; panel < 9; ++panel) { for (int sensor = 0; sensor < 4; ++sensor) { config.panelSettings[panel].fsrLowThreshold[sensor] = (byte)newPanelLowThresholds.Get(panel, (int)config.panelSettings[panel].fsrLowThreshold[sensor]); config.panelSettings[panel].fsrHighThreshold[sensor] = (byte)newPanelHighThresholds.Get(panel, (int)config.panelSettings[panel].fsrHighThreshold[sensor]); } } } else { List <Object> newPanelLowThresholds = dict.Get("panelLowThresholds", new List <Object>()); List <Object> newPanelHighThresholds = dict.Get("panelHighThresholds", new List <Object>()); for (int panel = 0; panel < 9; ++panel) { config.panelSettings[panel].loadCellLowThreshold = newPanelLowThresholds.Get(panel, config.panelSettings[panel].loadCellLowThreshold); config.panelSettings[panel].loadCellHighThreshold = newPanelHighThresholds.Get(panel, config.panelSettings[panel].loadCellHighThreshold); } } List <Object> enabledPanelList = dict.Get <List <Object> >("enabledPanels", null); if (enabledPanelList != null) { bool[] enabledPanels = new bool[9]; for (int i = 0; i < enabledPanelList.Count; ++i) { int panel = enabledPanelList.Get(i, 0); // Sanity check: if (panel < 0 || panel >= 9) { continue; } enabledPanels[panel] = true; } config.SetEnabledPanels(enabledPanels); } List <Object> panelColors = dict.Get <List <Object> >("panelColors", null); if (panelColors != null) { for (int PanelIndex = 0; PanelIndex < 9 && PanelIndex < panelColors.Count; ++PanelIndex) { string colorString = panelColors.Get(PanelIndex, "#FFFFFF"); Color color = Helpers.ParseColorString(colorString); color = Helpers.ScaleColor(color); config.stepColor[PanelIndex * 3 + 0] = color.R; config.stepColor[PanelIndex * 3 + 1] = color.G; config.stepColor[PanelIndex * 3 + 2] = color.B; } } // Older exported settings don't have advancedMode. Set it to true if it's missing. Properties.Settings.Default.AdvancedMode = dict.Get <bool>("advancedMode", true); Properties.Settings.Default.UseOuterSensorThresholds = dict.Get <bool>("useOuterSensorThresholds", false); Properties.Settings.Default.UseInnerSensorThresholds = dict.Get <bool>("useInnerSensorThresholds", false); List <object> customSensors = dict.Get <List <object> >("customSensors", null); if (customSensors != null) { ThresholdSettings.SetCustomSensorsJSON(customSensors); } }