From 9facc935485a6b9dbffb5a9197d810f683ed1ab8 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 23 Apr 2019 21:16:28 -0500 Subject: [PATCH] 8-bit FSR thresholds. --- sdk/SMX.h | 10 +++++----- smx-config/ConfigPresets.cs | 8 ++++---- smx-config/DiagnosticsWidgets.cs | 4 +++- smx-config/Helpers.cs | 4 ++-- smx-config/SMX.cs | 10 +++++----- smx-config/Widgets.cs | 6 +++--- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/sdk/SMX.h b/sdk/SMX.h index 279d4c4..44d8d0d 100644 --- a/sdk/SMX.h +++ b/sdk/SMX.h @@ -160,14 +160,14 @@ struct packed_sensor_settings_t { uint8_t loadCellHighThreshold; // FSR thresholds: - uint16_t fsrLowThreshold[4]; - uint16_t fsrHighThreshold[4]; + uint8_t fsrLowThreshold[4]; + uint8_t fsrHighThreshold[4]; // This must be left unchanged. uint16_t reserved; }; -static_assert(sizeof(packed_sensor_settings_t) == 20, "Incorrect packed_sensor_settings_t size"); +static_assert(sizeof(packed_sensor_settings_t) == 12, "Incorrect packed_sensor_settings_t size"); // The configuration for a connected controller. This can be retrieved with SMX_GetConfig // and modified with SMX_SetConfig. @@ -258,11 +258,11 @@ struct SMXConfig // Pad the struct to 250 bytes. This keeps this struct size from changing // as we add fields, so the ABI doesn't change. Applications should leave // any data in here unchanged when calling SMX_SetConfig. - uint8_t padding[13]; + uint8_t padding[85]; }; #pragma pack(pop) -static_assert(offsetof(SMXConfig, padding) == 237, "Incorrect padding alignment"); +static_assert(offsetof(SMXConfig, padding) == 165, "Incorrect padding alignment"); static_assert(sizeof(SMXConfig) == 250, "Expected 250 bytes"); // The values (except for Off) correspond with the protocol and must not be changed. diff --git a/smx-config/ConfigPresets.cs b/smx-config/ConfigPresets.cs index f8d4059..e7d1d29 100644 --- a/smx-config/ConfigPresets.cs +++ b/smx-config/ConfigPresets.cs @@ -63,7 +63,7 @@ namespace smx_config static private void SetPreset(ref SMX.SMXConfig config, byte loadCellLow, byte loadCellHigh, byte loadCellLowCenter, byte loadCellHighCenter, - UInt16 fsrLow, UInt16 fsrHigh, UInt16 fsrLowCenter, UInt16 fsrHighCenter) + byte fsrLow, byte fsrHigh, byte fsrLowCenter, byte fsrHighCenter) { for(int panel = 0; panel < 9; ++panel) { @@ -96,21 +96,21 @@ namespace smx_config { SetPreset(ref config, 20, 25, 20, 30, - 275, 300, 275, 300); + 100, 112, 100, 112); } static private void SetNormalPreset(ref SMX.SMXConfig config) { SetPreset(ref config, 33, 42, 35, 60, - 650, 700, 845, 895); + 162, 175, 212, 225); } static private void SetLowPreset(ref SMX.SMXConfig config) { SetPreset(ref config, 70, 80, 100, 120, - 800, 875, 845, 895); + 200, 219, 212, 225); } // The simplified configuration scheme sets thresholds for up, center, cardinal directions diff --git a/smx-config/DiagnosticsWidgets.cs b/smx-config/DiagnosticsWidgets.cs index 2f41b6a..e72785f 100644 --- a/smx-config/DiagnosticsWidgets.cs +++ b/smx-config/DiagnosticsWidgets.cs @@ -325,7 +325,9 @@ namespace smx_config // Scale differently depending on if this is an FSR panel or a load cell panel. bool isFSR = controllerData.config.masterVersion >= 4 && (controllerData.config.configFlags & SMX.SMXConfigFlags.PlatformFlags_FSR) != 0; - float maxValue = isFSR? 1023:500; + if(isFSR) + value >>= 2; + float maxValue = isFSR? 250:500; LevelBars[sensor].Value = value / maxValue; LevelBarText[sensor].Content = value; LevelBars[sensor].Error = false; diff --git a/smx-config/Helpers.cs b/smx-config/Helpers.cs index f5c740a..5ec546f 100644 --- a/smx-config/Helpers.cs +++ b/smx-config/Helpers.cs @@ -592,8 +592,8 @@ namespace smx_config { 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]); + 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]); } } } diff --git a/smx-config/SMX.cs b/smx-config/SMX.cs index b3706d6..7d58867 100644 --- a/smx-config/SMX.cs +++ b/smx-config/SMX.cs @@ -34,10 +34,10 @@ namespace SMX // FSR thresholds (16-bit): [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public UInt16[] fsrLowThreshold; + public Byte[] fsrLowThreshold; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public UInt16[] fsrHighThreshold; + public Byte[] fsrHighThreshold; // This must be left unchanged. public UInt16 reserved; @@ -88,7 +88,7 @@ namespace SMX public Byte preDetailsDelayMilliseconds; // Pad this struct to exactly 250 bytes. - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 13)] + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 85)] public Byte[] padding; // It would be simpler to set flags to [MarshalAs(UnmanagedType.U8)], but @@ -213,8 +213,8 @@ namespace SMX result.platformStripColor = new Byte[3]; for(int panel = 0; panel < 9; ++panel) { - result.panelSettings[panel].fsrLowThreshold = new UInt16[4]; - result.panelSettings[panel].fsrHighThreshold = new UInt16[4]; + result.panelSettings[panel].fsrLowThreshold = new Byte[4]; + result.panelSettings[panel].fsrHighThreshold = new Byte[4]; } return result; } diff --git a/smx-config/Widgets.cs b/smx-config/Widgets.cs index bba9832..bc29802 100644 --- a/smx-config/Widgets.cs +++ b/smx-config/Widgets.cs @@ -166,8 +166,8 @@ namespace smx_config config.panelSettings[panelIdx].loadCellLowThreshold = lower; config.panelSettings[panelIdx].loadCellHighThreshold = upper; } else { - UInt16 lower = (UInt16) slider.LowerValue; - UInt16 upper = (UInt16) slider.UpperValue; + byte lower = (byte) slider.LowerValue; + byte upper = (byte) slider.UpperValue; for(int sensor = 0; sensor < 4; ++sensor) { config.panelSettings[panelIdx].fsrLowThreshold[sensor] = lower; @@ -222,7 +222,7 @@ namespace smx_config { // 16-bit FSR thresholds. slider.Minimum = 5; - slider.Maximum = 1023; + slider.Maximum = 250; slider.MinimumDistance = 5; } else { // 8-bit load cell thresholds