mirror of
https://github.com/skogaby/OpeNITHM.git
synced 2026-09-22 22:58:16 +03:00
Make the factory reset button actually clear the EEPROM and reset the config values
This commit is contained in:
@@ -32,10 +32,16 @@ AirSensor *sensor;
|
||||
Output *output;
|
||||
SerialLeds *serialLeds;
|
||||
|
||||
void initializeController();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
FastLED.addLeds<LED_TYPE, RGBPIN, LED_ORDER>(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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the controller is connected
|
||||
/// </summary>
|
||||
@@ -276,7 +280,12 @@ namespace OpeNITHMConfig
|
||||
/// <param name="e"></param>
|
||||
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[] { });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user