From 50354d5a15db9fb97905225a5bea4c72e3ac9465 Mon Sep 17 00:00:00 2001 From: NickGuyver <29263310+NickGuyver@users.noreply.github.com> Date: Sun, 15 Sep 2024 11:14:22 -0700 Subject: [PATCH 1/7] initial commit Functionally working, web is broken in the following ways: 1 - Error Rate title shows regardless of Forced Circularity being checked, but the selection box hides as expected 2 - Selecting a value saves, but when reloading the webpage there is an error and it thinks it's set to 0% --- headers/addons/analog.h | 6 +++- proto/config.proto | 1 + src/addons/analog.cpp | 7 +++-- src/config_utils.cpp | 1 + src/configs/webconfig.cpp | 2 ++ www/server/app.js | 1 + www/src/Addons/Analog.tsx | 44 +++++++++++++++++++++++++++++ www/src/Locales/en/AddonsConfig.jsx | 1 + 8 files changed, 59 insertions(+), 4 deletions(-) diff --git a/headers/addons/analog.h b/headers/addons/analog.h index a8fbcd38e..ad1784e22 100644 --- a/headers/addons/analog.h +++ b/headers/addons/analog.h @@ -69,6 +69,10 @@ #define SMOOTHING_FACTOR 5 #endif +#ifndef ANALOG_ERROR +#define ANALOG_ERROR 0 +#endif + // Analog Module Name #define AnalogName "Analog" @@ -88,7 +92,7 @@ class AnalogInput : public GPAddon { static float readPin(int pin, uint16_t center, bool autoCalibrate); static float emaCalculation(float ema_value, float smoothing_factor, float ema_previous); static uint16_t map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max); - static float magnitudeCalculation(float x, float y, float& x_magnitude, float& y_magnitude); + static float magnitudeCalculation(float x, float y, float& x_magnitude, float& y_magnitude, float error); static void radialDeadzone(float& x, float& y, float in_deadzone, float out_deadzone, float x_magnitude, float y_magnitude, float magnitude, bool circularity); }; diff --git a/proto/config.proto b/proto/config.proto index b0f96d39d..6ad82f15c 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -353,6 +353,7 @@ message AnalogOptions optional uint32 outer_deadzone = 13; optional bool analog_smoothing = 14; optional float smoothing_factor = 15; + optional float analog_error = 16; } message TurboOptions diff --git a/src/addons/analog.cpp b/src/addons/analog.cpp index 37dfa668a..e0cd9c154 100644 --- a/src/addons/analog.cpp +++ b/src/addons/analog.cpp @@ -66,6 +66,7 @@ void AnalogInput::process() bool ema_option = analogOptions.analog_smoothing; float ema_smoothing = analogOptions.smoothing_factor / 1000.0f; + float error_rate = analogOptions.analog_error; struct adc_pair { @@ -137,7 +138,7 @@ void AnalogInput::process() if (in_deadzone >= 0.0f || analogOptions.forced_circularity == true) { adc_pairs[i].xy_magnitude = magnitudeCalculation(adc_pairs[i].x_value, adc_pairs[i].y_value, - adc_pairs[i].x_magnitude, adc_pairs[i].y_magnitude); + adc_pairs[i].x_magnitude, adc_pairs[i].y_magnitude, error_rate); if (in_deadzone >= 0.0f) { if (adc_pairs[i].xy_magnitude < in_deadzone) { @@ -196,11 +197,11 @@ uint16_t AnalogInput::map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } -float AnalogInput::magnitudeCalculation(float x, float y, float& x_magnitude, float& y_magnitude) { +float AnalogInput::magnitudeCalculation(float x, float y, float& x_magnitude, float& y_magnitude, float error) { x_magnitude = x - ANALOG_CENTER; y_magnitude = y - ANALOG_CENTER; - return std::sqrt((x_magnitude * x_magnitude) + (y_magnitude * y_magnitude)); + return error * std::sqrt((x_magnitude * x_magnitude) + (y_magnitude * y_magnitude)); } void AnalogInput::radialDeadzone(float& x, float& y, float in_deadzone, float out_deadzone, float x_magnitude, float y_magnitude, float xy_magnitude, bool circularity) { diff --git a/src/config_utils.cpp b/src/config_utils.cpp index fed18dcab..ae8539784 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -538,6 +538,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) INIT_UNSET_PROPERTY(config.addonOptions.analogOptions, auto_calibrate, !!AUTO_CALIBRATE_ENABLED); INIT_UNSET_PROPERTY(config.addonOptions.analogOptions, analog_smoothing, !!ANALOG_SMOOTHING_ENABLED); INIT_UNSET_PROPERTY(config.addonOptions.analogOptions, smoothing_factor, !!SMOOTHING_FACTOR); + INIT_UNSET_PROPERTY(config.addonOptions.analogOptions, analog_error, ANALOG_ERROR); // addonOptions.turboOptions INIT_UNSET_PROPERTY(config.addonOptions.turboOptions, enabled, !!TURBO_ENABLED); diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index 24b766cba..1cc44bb67 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -1398,6 +1398,7 @@ std::string setAddonOptions() docToValue(analogOptions.auto_calibrate, doc, "auto_calibrate"); docToValue(analogOptions.analog_smoothing, doc, "analog_smoothing"); docToValue(analogOptions.smoothing_factor, doc, "smoothing_factor"); + docToValue(analogOptions.analog_error, doc, "analog_error"); docToValue(analogOptions.enabled, doc, "AnalogInputEnabled"); BootselButtonOptions& bootselButtonOptions = Storage::getInstance().getAddonOptions().bootselButtonOptions; @@ -1824,6 +1825,7 @@ std::string getAddonOptions() writeDoc(doc, "auto_calibrate", analogOptions.auto_calibrate); writeDoc(doc, "analog_smoothing", analogOptions.analog_smoothing); writeDoc(doc, "smoothing_factor", analogOptions.smoothing_factor); + writeDoc(doc, "analog_error", analogOptions.analog_error); writeDoc(doc, "AnalogInputEnabled", analogOptions.enabled); const BootselButtonOptions& bootselButtonOptions = Storage::getInstance().getAddonOptions().bootselButtonOptions; diff --git a/www/server/app.js b/www/server/app.js index ffb33d157..6e2e92f11 100644 --- a/www/server/app.js +++ b/www/server/app.js @@ -431,6 +431,7 @@ app.get('/api/getAddonsOptions', (req, res) => { auto_calibrate: 0, analog_smoothing: 0, smoothing_factor: 5, + analog_error: 1.0, bootselButtonMap: 0, buzzerPin: -1, buzzerEnablePin: -1, diff --git a/www/src/Addons/Analog.tsx b/www/src/Addons/Analog.tsx index c9f082e2e..29f12eb7b 100644 --- a/www/src/Addons/Analog.tsx +++ b/www/src/Addons/Analog.tsx @@ -22,6 +22,25 @@ const INVERT_MODES = [ { label: 'X/Y Axis', value: 3 }, ]; +const ANALOG_ERROR_RATES = [ + { label: '0%', value: 1.0 }, + { label: '1%', value: 0.99 }, + { label: '2%', value: 0.979 }, + { label: '3%', value: 0.969 }, + { label: '4%', value: 0.958 }, + { label: '5%', value: 0.946 }, + { label: '6%', value: 0.934 }, + { label: '7%', value: 0.922 }, + { label: '8%', value: 0.911 }, + { label: '9%', value: 0.9 }, + { label: '10%', value: 0.89 }, + { label: '11%', value: 0.876 }, + { label: '12%', value: 0.863 }, + { label: '13%', value: 0.848 }, + { label: '14%', value: 0.834 }, + { label: '15%', value: 0.821 }, +]; + export const analogScheme = { AnalogInputEnabled: yup.number().required().label('Analog Input Enabled'), analogAdc1PinX: yup @@ -81,6 +100,10 @@ export const analogScheme = { .number() .label('Smoothing Factor') .validateRangeWhenValue('AnalogInputEnabled', 0, 100), + analog_error: yup + .number() + .label('Error Rate') + .validateSelectionWhenValue('AnalogInputEnabled', ANALOG_ERROR_RATES), }; export const analogState = { @@ -99,6 +122,7 @@ export const analogState = { auto_calibrate: 0, analog_smoothing: 0, smoothing_factor: 5, + analog_error: 1.0, }; const Analog = ({ values, errors, handleChange, handleCheckbox }) => { @@ -277,6 +301,26 @@ const Analog = ({ values, errors, handleChange, handleCheckbox }) => { handleChange(e); }} /> + Date: Sun, 15 Sep 2024 21:29:33 +0200 Subject: [PATCH 2/7] Convert FormSelect to ts, add types for label. add support for hiding with prop --- www/src/Components/FormSelect.jsx | 19 ------------------- www/src/Components/FormSelect.tsx | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 19 deletions(-) delete mode 100644 www/src/Components/FormSelect.jsx create mode 100644 www/src/Components/FormSelect.tsx diff --git a/www/src/Components/FormSelect.jsx b/www/src/Components/FormSelect.jsx deleted file mode 100644 index 226a3256a..000000000 --- a/www/src/Components/FormSelect.jsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; -import { Form } from 'react-bootstrap'; - -const FormSelect = ({ - label = null, - error = null, - groupClassName = '', - ...props -}) => { - return ( - - {label && {label}} - - {error} - - ); -}; - -export default FormSelect; diff --git a/www/src/Components/FormSelect.tsx b/www/src/Components/FormSelect.tsx new file mode 100644 index 000000000..d89773c77 --- /dev/null +++ b/www/src/Components/FormSelect.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import { Form, FormSelectProps } from 'react-bootstrap'; + +type FormSelectTypes = { + label?: string; + error?: string; + groupClassName?: string; + hidden?: boolean; +} & FormSelectProps; + +const FormSelect = ({ + label, + error, + groupClassName = '', + hidden = false, + ...props +}: FormSelectTypes) => { + return ( + + ); +}; + +export default FormSelect; From 8728384ac66eba4ad7b84628e0cbfa18f59c5b4a Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 15 Sep 2024 21:30:08 +0200 Subject: [PATCH 3/7] Reorder checkboxes for better flow --- www/src/Addons/Analog.tsx | 70 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/www/src/Addons/Analog.tsx b/www/src/Addons/Analog.tsx index 29f12eb7b..55a62e9a5 100644 --- a/www/src/Addons/Analog.tsx +++ b/www/src/Addons/Analog.tsx @@ -131,6 +131,7 @@ const Analog = ({ values, errors, handleChange, handleCheckbox }) => { const availableAnalogPins = ANALOG_PINS.filter( (pin) => !usedPins?.includes(pin), ); + return (
Date: Sun, 15 Sep 2024 21:35:48 +0200 Subject: [PATCH 4/7] Fix key error for focus mode --- www/src/Addons/FocusMode.tsx | 59 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/www/src/Addons/FocusMode.tsx b/www/src/Addons/FocusMode.tsx index ac444fb8e..606ee89e4 100644 --- a/www/src/Addons/FocusMode.tsx +++ b/www/src/Addons/FocusMode.tsx @@ -93,36 +93,35 @@ const FocusMode = ({ /> - {BUTTON_MASKS_OPTIONS.map((mask) => - values.focusModeButtonLockMask & mask.value ? ( - { - setFieldValue( - 'focusModeButtonLockMask', - (values.focusModeButtonLockMask ^ mask.value) | - e.target.value, - ); - }} - > - {BUTTON_MASKS_OPTIONS.map((o, i) => ( - - ))} - - ) : ( - <> - ), + {BUTTON_MASKS_OPTIONS.map( + (mask) => + Boolean(values.focusModeButtonLockMask & mask.value) && ( + { + setFieldValue( + 'focusModeButtonLockMask', + (values.focusModeButtonLockMask ^ mask.value) | + e.target.value, + ); + }} + > + {BUTTON_MASKS_OPTIONS.map((o, i) => ( + + ))} + + ), )} Date: Sun, 15 Sep 2024 21:37:32 +0200 Subject: [PATCH 5/7] Remove logging used to check values --- www/src/Addons/Analog.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/www/src/Addons/Analog.tsx b/www/src/Addons/Analog.tsx index 55a62e9a5..f5b75ed7e 100644 --- a/www/src/Addons/Analog.tsx +++ b/www/src/Addons/Analog.tsx @@ -302,14 +302,11 @@ const Analog = ({ values, errors, handleChange, handleCheckbox }) => { isInvalid={errors.analog_error} onChange={handleChange} > - {ANALOG_ERROR_RATES.map( - (o, i) => - console.log(o, 'hehu') || ( - - ), - )} + {ANALOG_ERROR_RATES.map((o, i) => ( + + ))}