From 444ad7b8a59fbba12013a83d8e2cd6f931fe5b95 Mon Sep 17 00:00:00 2001 From: skogaby Date: Fri, 20 Mar 2020 20:00:06 -0500 Subject: [PATCH] Make the factory reset button actually clear the EEPROM and reset the config values --- Firmware/OpeNITHM/OpeNITHM.ino | 11 +++++++++++ Firmware/OpeNITHM/SerialProcessor.cpp | 10 ++++++++++ Firmware/OpeNITHM/SerialProcessor.h | 3 +++ OpeNITHMConfig/OpeNITHMConfig/Form1.cs | 9 +++++++++ 4 files changed, 33 insertions(+) diff --git a/Firmware/OpeNITHM/OpeNITHM.ino b/Firmware/OpeNITHM/OpeNITHM.ino index ad13c89..ea27b4a 100644 --- a/Firmware/OpeNITHM/OpeNITHM.ino +++ b/Firmware/OpeNITHM/OpeNITHM.ino @@ -32,10 +32,16 @@ AirSensor *sensor; Output *output; SerialLeds *serialLeds; +void initializeController(); + void setup() { Serial.begin(115200); FastLED.addLeds(leds, 16); + initializeController(); +} + +void initializeController() { // Flash LEDs orange 3 times for (int i = 0; i < 3; i++) { @@ -53,9 +59,11 @@ void setup() { } // Initialize and calibrate touch sensors + if (touchboard != NULL) delete touchboard; touchboard = new AutoTouchboard(); // Initialize the serial LED processor + if (serialLeds != NULL) delete serialLeds; serialLeds = new SerialLeds(); // Initialize the reactive lighting colors, and if they're not in EEPROM, save them @@ -76,6 +84,7 @@ void setup() { // Initialize air sensor // Digital mode calibrations in the constructor // Analog mode will automatically calibrate as it starts being read + if (sensor != NULL) delete sensor; sensor = new AirSensor(500, 50); // Display the number of air sensors that were calibrated @@ -95,6 +104,8 @@ void setup() { serialLightsCounter = 0; // Initialize relevant output method / USB or serial + if (output != NULL) delete output; + #ifdef USB output = new USBOutput(); #else diff --git a/Firmware/OpeNITHM/SerialProcessor.cpp b/Firmware/OpeNITHM/SerialProcessor.cpp index 9edce52..0bf804d 100644 --- a/Firmware/OpeNITHM/SerialProcessor.cpp +++ b/Firmware/OpeNITHM/SerialProcessor.cpp @@ -56,6 +56,16 @@ void SerialProcessor::processConfigCommand(uint8_t* buf) sensor->setAnalogSensitivity(buf[3]); sensor->recalibrate(); break; + case CMD_FACTORY_RESET: + // clear EEPROM and then reset the controller + for (int i = 0 ; i < EEPROM.length() ; i++) + { + EEPROM.write(i, 0); + } + + delay(500); + + initializeController(); default: break; } diff --git a/Firmware/OpeNITHM/SerialProcessor.h b/Firmware/OpeNITHM/SerialProcessor.h index d232dee..26f6d88 100644 --- a/Firmware/OpeNITHM/SerialProcessor.h +++ b/Firmware/OpeNITHM/SerialProcessor.h @@ -20,6 +20,7 @@ #define CMD_CHANGE_OFF_COLOR 0x33 #define CMD_CALIBRATE_SLIDER 0x44 #define CMD_CALIBRATE_AIR_SENSORS 0x55 +#define CMD_FACTORY_RESET 0x66 extern AirSensor *sensor; extern AutoTouchboard *touchboard; @@ -30,6 +31,8 @@ extern CRGB led_on; extern CRGB led_off; extern int serialLightsCounter; +extern void initializeController(); + class SerialProcessor { private: diff --git a/OpeNITHMConfig/OpeNITHMConfig/Form1.cs b/OpeNITHMConfig/OpeNITHMConfig/Form1.cs index a072225..34351a3 100644 --- a/OpeNITHMConfig/OpeNITHMConfig/Form1.cs +++ b/OpeNITHMConfig/OpeNITHMConfig/Form1.cs @@ -30,6 +30,10 @@ namespace OpeNITHMConfig private const int DEFAULT_TOUCH_SENSITIVITY = 15; private const int DEFAULT_AIR_SENSITIVITY = 15; + // default key colors + private Color ON_COLOR = Color.Purple; + private Color OFF_COLOR = Color.Yellow; + /// /// Whether or not the controller is connected /// @@ -276,7 +280,12 @@ namespace OpeNITHMConfig /// private void factoryResetControllerToolStripMenuItem_Click(object sender, EventArgs e) { + colorDialogOn.Color = ON_COLOR; + colorDialogOff.Color = OFF_COLOR; + trkSliderSensitivity.Value = DEFAULT_TOUCH_SENSITIVITY; + trkAirSensitivity.Value = DEFAULT_AIR_SENSITIVITY; + sendCommand(CMD_FACTORY_RESET, new byte[] { }); } } }