Refactor the way threshold sliders are associated with sensors.

This makes it possible to have sliders that influence arbitrary sensors.
master
Glenn Maynard 5 years ago
parent 8620da2405
commit dbb4ecc530
  1. 47
      smx-config/ConfigPresets.cs
  2. 86
      smx-config/Helpers.cs
  3. 42
      smx-config/MainWindow.xaml.cs
  4. 4
      smx-config/SMX.cs
  5. 82
      smx-config/Widgets.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<int> GetPanelsToSyncUnifiedThresholds(int fromPanel)
{
List<int> result = new List<int>();
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];
}
}
}
}

@ -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<string, int> panelNameToIndex = new Dictionary<string, int>() {
{ "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<PanelAndSensor> GetControlledSensorsForSliderType(string Type, bool advancedMode)
{
List<PanelAndSensor> result = new List<PanelAndSensor>();
// 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<int> saveToPanels = new List<int>();
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<PanelAndSensor> GetAuxSensors()
{
List<PanelAndSensor> result = new List<PanelAndSensor>();
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
{

@ -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<ThresholdSettings.PanelAndSensor> 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;

@ -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;
}

@ -136,57 +136,52 @@ namespace smx_config
});
}
Dictionary<string, int> panelNameToIndex = new Dictionary<string, int>() {
{ "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<ThresholdSettings.PanelAndSensor> GetControlledSensors()
{
return ThresholdSettings.GetControlledSensorsForSliderType(Type, AdvancedModeEnabled);
}
private void SetValueToConfig(ref SMX.SMXConfig config)
{
int panelIdx = panelNameToIndex[Type];
if(!config.fsr())
List<ThresholdSettings.PanelAndSensor> 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;

Loading…
Cancel
Save