Commit 9b11a49b authored by Eric Duminil's avatar Eric Duminil
Browse files

reset() refactor

parent 316d13bc
...@@ -70,7 +70,7 @@ namespace sensor { ...@@ -70,7 +70,7 @@ namespace sensor {
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF."); Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
} }
//NOTE: should time offset be used to reset measurement_timestep? //NOTE: should time offset be used to adjust measurement_timestep?
void checkTimerDeviation() { void checkTimerDeviation() {
static int32_t previous_measurement_at = 0; static int32_t previous_measurement_at = 0;
int32_t now = millis(); int32_t now = millis();
...@@ -124,11 +124,7 @@ namespace sensor { ...@@ -124,11 +124,7 @@ namespace sensor {
scd30.setForcedRecalibrationFactor(config::co2_calibration_level); scd30.setForcedRecalibrationFactor(config::co2_calibration_level);
Serial.println(F(" Done!")); Serial.println(F(" Done!"));
Serial.println(F("Sensor calibrated.")); Serial.println(F("Sensor calibrated."));
Serial.println(F("Sensor will now restart.")); resetAmpel();
LedEffects::showKITTWheel(color::green, 5);
//TODO: Add LEDs off and move to util::reset()
FS_LIB.end();
ESP.restart();
} }
void logToSerial() { void logToSerial() {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/lib/SparkFun_SCD30_Arduino_Library/src/SparkFun_SCD30_Arduino_Library.h" // From: http://librarymanager/All#SparkFun_SCD30 #include "src/lib/SparkFun_SCD30_Arduino_Library/src/SparkFun_SCD30_Arduino_Library.h" // From: http://librarymanager/All#SparkFun_SCD30
#include "config.h" #include "config.h"
#include "led_effects.h" #include "led_effects.h"
#include "util.h"
#include "csv_writer.h" // To close filesystem before restart. #include "csv_writer.h" // To close filesystem before restart.
#include <Wire.h> #include <Wire.h>
......
...@@ -11,7 +11,7 @@ namespace config { ...@@ -11,7 +11,7 @@ namespace config {
/***************************************************************** /*****************************************************************
* Configuration (calculated from above values) * * Configuration (calculated from above values) *
*****************************************************************/ *****************************************************************/
namespace config //TODO: Use a class instead. NightMode could then be another state. namespace config //TODO: Use a class instead. NightMode could then be another state.
{ {
const float average_brightness = 0.5 * (config::max_brightness + config::min_brightness); const float average_brightness = 0.5 * (config::max_brightness + config::min_brightness);
const float brightness_amplitude = 0.5 * (config::max_brightness - config::min_brightness); const float brightness_amplitude = 0.5 * (config::max_brightness - config::min_brightness);
...@@ -38,7 +38,7 @@ namespace counter { ...@@ -38,7 +38,7 @@ namespace counter {
uint16_t wheel_offset = 0; uint16_t wheel_offset = 0;
uint16_t kitt_offset = 0; uint16_t kitt_offset = 0;
uint16_t breathing_offset = 0; uint16_t breathing_offset = 0;
} // namespace counter }
namespace LedEffects { namespace LedEffects {
//On-board LED on D4, aka GPIO02 //On-board LED on D4, aka GPIO02
...@@ -56,18 +56,23 @@ namespace LedEffects { ...@@ -56,18 +56,23 @@ namespace LedEffects {
digitalWrite(ONBOARD_LED_PIN, LOW); digitalWrite(ONBOARD_LED_PIN, LOW);
} }
void LEDsOff() {
pixels.clear();
pixels.show();
onBoardLEDOff();
}
void setupRing() { void setupRing() {
pixels.begin(); pixels.begin();
pixels.setBrightness(config::max_brightness); pixels.setBrightness(config::max_brightness);
pixels.clear(); LEDsOff();
} }
void toggleNightMode() { void toggleNightMode() {
config::night_mode = !config::night_mode; config::night_mode = !config::night_mode;
if (config::night_mode) { if (config::night_mode) {
Serial.println(F("NIGHT MODE!")); Serial.println(F("NIGHT MODE!"));
pixels.clear(); LEDsOff();
pixels.show();
} else { } else {
Serial.println(F("DAY MODE!")); Serial.println(F("DAY MODE!"));
} }
...@@ -172,7 +177,7 @@ namespace LedEffects { ...@@ -172,7 +177,7 @@ namespace LedEffects {
pixels.show(); pixels.show();
counter::breathing_offset += 1; counter::breathing_offset += 1;
} }
delay(co2 > 1600 ? 50 : 100); // faster breathing for higher CO2 values delay(co2 > 1600 ? 50 : 100); // faster breathing for higher CO2 values
} }
/** /**
......
...@@ -22,6 +22,7 @@ namespace LedEffects { ...@@ -22,6 +22,7 @@ namespace LedEffects {
void onBoardLEDOff(); void onBoardLEDOff();
void onBoardLEDOn(); void onBoardLEDOn();
void toggleNightMode(); void toggleNightMode();
void LEDsOff();
void setupRing(); void setupRing();
void redAlert(); void redAlert();
......
...@@ -162,8 +162,7 @@ namespace mqtt { ...@@ -162,8 +162,7 @@ namespace mqtt {
} else if (messageString == "local_ip") { } else if (messageString == "local_ip") {
sendInfoAboutLocalNetwork(); sendInfoAboutLocalNetwork();
} else if (messageString == "reset") { } else if (messageString == "reset") {
FS_LIB.end(); resetAmpel();
ESP.restart();
} else { } else {
LedEffects::showKITTWheel(color::red, 1); LedEffects::showKITTWheel(color::red, 1);
Serial.println(F("Message not supported. Doing nothing.")); Serial.println(F("Message not supported. Doing nothing."));
......
...@@ -38,6 +38,14 @@ namespace ntp { ...@@ -38,6 +38,14 @@ namespace ntp {
} }
} }
void resetAmpel() {
Serial.print("Resetting");
FS_LIB.end();
LedEffects::LEDsOff();
delay(1000);
ESP.restart();
}
uint32_t max_loop_duration = 0; uint32_t max_loop_duration = 0;
//FIXME: Remove every instance of Strings, to avoid heap fragmentation problems. (Start: "Free heap space : 17104 bytes") //FIXME: Remove every instance of Strings, to avoid heap fragmentation problems. (Start: "Free heap space : 17104 bytes")
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "config.h" #include "config.h"
#include "wifi_util.h" // To get MAC #include "wifi_util.h" // To get MAC
#include "csv_writer.h" // To close filesystem before reset
#include <WiFiUdp.h> //required for NTP #include <WiFiUdp.h> //required for NTP
#include "src/lib/NTPClient-master/NTPClient.h" // NTP #include "src/lib/NTPClient-master/NTPClient.h" // NTP
...@@ -27,4 +28,6 @@ namespace ntp { ...@@ -27,4 +28,6 @@ namespace ntp {
extern uint32_t max_loop_duration; extern uint32_t max_loop_duration;
const extern String SENSOR_ID; const extern String SENSOR_ID;
void resetAmpel();
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment