Add support for importing/exporting FSR thresholds to disk.
This commit is contained in:
parent
4c07c5572e
commit
05f4100d98
@ -526,7 +526,23 @@ namespace smx_config
|
|||||||
// Export configurable values in SMXConfig to a JSON string.
|
// Export configurable values in SMXConfig to a JSON string.
|
||||||
public static string ExportSettingsToJSON(SMX.SMXConfig config)
|
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>();
|
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>();
|
List<int> panelLowThresholds = new List<int>();
|
||||||
for(int panel = 0; panel < 9; ++panel)
|
for(int panel = 0; panel < 9; ++panel)
|
||||||
panelLowThresholds.Add(config.panelSettings[panel].loadCellLowThreshold);
|
panelLowThresholds.Add(config.panelSettings[panel].loadCellLowThreshold);
|
||||||
@ -536,6 +552,7 @@ namespace smx_config
|
|||||||
for(int panel = 0; panel < 9; ++panel)
|
for(int panel = 0; panel < 9; ++panel)
|
||||||
panelLowThresholds.Add(config.panelSettings[panel].loadCellHighThreshold);
|
panelLowThresholds.Add(config.panelSettings[panel].loadCellHighThreshold);
|
||||||
dict.Add("panelHighThresholds", panelHighThresholds);
|
dict.Add("panelHighThresholds", panelHighThresholds);
|
||||||
|
}
|
||||||
|
|
||||||
// Store the enabled panel mask as a simple list of which panels are selected.
|
// Store the enabled panel mask as a simple list of which panels are selected.
|
||||||
bool[] enabledPanels = config.GetEnabledPanels();
|
bool[] enabledPanels = config.GetEnabledPanels();
|
||||||
@ -567,13 +584,29 @@ namespace smx_config
|
|||||||
Dictionary<string, Object> dict = SMXJSON.ParseJSON.Parse<Dictionary<string, Object>>(json);
|
Dictionary<string, Object> dict = SMXJSON.ParseJSON.Parse<Dictionary<string, Object>>(json);
|
||||||
|
|
||||||
// Read the thresholds. If any values are missing, we'll leave the value in config alone.
|
// Read the thresholds. If any values are missing, we'll leave the value in config alone.
|
||||||
List<Object> newPanelLowThresholds = dict.Get("panelLowThresholds", new List<Object>());
|
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 panel = 0; panel < 9; ++panel)
|
||||||
config.panelSettings[panel].loadCellLowThreshold = newPanelLowThresholds.Get(panel, config.panelSettings[panel].loadCellLowThreshold);
|
{
|
||||||
|
for(int sensor = 0; sensor < 4; ++sensor)
|
||||||
|
{
|
||||||
|
config.panelSettings[panel].fsrLowThreshold[sensor] = (UInt16) newPanelLowThresholds.Get(panel, (int) config.panelSettings[panel].fsrLowThreshold[sensor]);
|
||||||
|
config.panelSettings[panel].fsrHighThreshold[sensor] = (UInt16) 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>());
|
List<Object> newPanelHighThresholds = dict.Get("panelHighThresholds", new List<Object>());
|
||||||
for(int panel = 0; panel < 9; ++panel)
|
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);
|
config.panelSettings[panel].loadCellHighThreshold = newPanelHighThresholds.Get(panel, config.panelSettings[panel].loadCellHighThreshold);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Object> enabledPanelList = dict.Get<List<Object>>("enabledPanels", null);
|
List<Object> enabledPanelList = dict.Get<List<Object>>("enabledPanels", null);
|
||||||
if(enabledPanelList != null)
|
if(enabledPanelList != null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user