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

reset() refactor

parent 316d13bc
......@@ -70,7 +70,7 @@ namespace sensor {
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() {
static int32_t previous_measurement_at = 0;
int32_t now = millis();
......@@ -124,11 +124,7 @@ namespace sensor {
scd30.setForcedRecalibrationFactor(config::co2_calibration_level);
Serial.println(F(" Done!"));
Serial.println(F("Sensor calibrated."));
Serial.println(F("Sensor will now restart."));
LedEffects::showKITTWheel(color::green, 5);
//TODO: Add LEDs off and move to util::reset()
FS_LIB.end();
ESP.restart();
resetAmpel();
}
void logToSerial() {
......
......@@ -6,6 +6,7 @@
#include "src/lib/SparkFun_SCD30_Arduino_Library/src/SparkFun_SCD30_Arduino_Library.h" // From: http://librarymanager/All#SparkFun_SCD30
#include "config.h"
#include "led_effects.h"
#include "util.h"
#include "csv_writer.h" // To close filesystem before restart.
#include <Wire.h>
......
......@@ -11,7 +11,7 @@ namespace config {
/*****************************************************************
* 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 brightness_amplitude = 0.5 * (config::max_brightness - config::min_brightness);
......@@ -38,7 +38,7 @@ namespace counter {
uint16_t wheel_offset = 0;
uint16_t kitt_offset = 0;
uint16_t breathing_offset = 0;
} // namespace counter
}
namespace LedEffects {
//On-board LED on D4, aka GPIO02
......@@ -56,18 +56,23 @@ namespace LedEffects {
digitalWrite(ONBOARD_LED_PIN, LOW);
}
void LEDsOff() {
pixels.clear();
pixels.show();
onBoardLEDOff();
}
void setupRing() {
pixels.begin();
pixels.setBrightness(config::max_brightness);
pixels.clear();
LEDsOff();
}
void toggleNightMode() {
config::night_mode = !config::night_mode;
if (config::night_mode) {
Serial.println(F("NIGHT MODE!"));
pixels.clear();
pixels.show();
LEDsOff();
} else {
Serial.println(F("DAY MODE!"));
}
......@@ -172,7 +177,7 @@ namespace LedEffects {
pixels.show();
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 {
void onBoardLEDOff();
void onBoardLEDOn();
void toggleNightMode();
void LEDsOff();
void setupRing();
void redAlert();
......
......@@ -162,8 +162,7 @@ namespace mqtt {
} else if (messageString == "local_ip") {
sendInfoAboutLocalNetwork();
} else if (messageString == "reset") {
FS_LIB.end();
ESP.restart();
resetAmpel();
} else {
LedEffects::showKITTWheel(color::red, 1);
Serial.println(F("Message not supported. Doing nothing."));
......
......@@ -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;
//FIXME: Remove every instance of Strings, to avoid heap fragmentation problems. (Start: "Free heap space : 17104 bytes")
......
......@@ -3,6 +3,7 @@
#include <Arduino.h>
#include "config.h"
#include "wifi_util.h" // To get MAC
#include "csv_writer.h" // To close filesystem before reset
#include <WiFiUdp.h> //required for NTP
#include "src/lib/NTPClient-master/NTPClient.h" // NTP
......@@ -27,4 +28,6 @@ namespace ntp {
extern uint32_t max_loop_duration;
const extern String SENSOR_ID;
void resetAmpel();
#endif
Supports Markdown
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