Commit 78d66790 authored by Eric Duminil's avatar Eric Duminil
Browse files

No more circular dependency

parent f510d621
...@@ -113,7 +113,7 @@ namespace sensor { ...@@ -113,7 +113,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."));
resetAmpel(); ESP.restart(); // softer than ESP.reset
} }
void logToSerial() { void logToSerial() {
......
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
# error Board should be either ESP8266 or ESP832 # error Board should be either ESP8266 or ESP832
#endif #endif
#include "led_effects.h"
#include "config.h" #include "config.h"
#include "util.h"
#include "led_effects.h"
namespace config { namespace config {
extern uint16_t csv_interval; // [s] extern uint16_t csv_interval; // [s]
} }
......
...@@ -139,14 +139,14 @@ namespace led_effects { ...@@ -139,14 +139,14 @@ namespace led_effects {
pixels.show(); pixels.show();
} }
void showRainbowWheel(int duration_s, uint16_t hue_increment) { void showRainbowWheel(int duration_ms, uint16_t hue_increment) {
if (config::night_mode) { if (config::night_mode) {
return; return;
} }
static uint16_t wheel_offset = 0; static uint16_t wheel_offset = 0;
unsigned long t0 = seconds(); unsigned long t0 = millis();
pixels.setBrightness(config::max_brightness); pixels.setBrightness(config::max_brightness);
while (seconds() < t0 + duration_s) { while (millis() < t0 + duration_ms) {
for (int i = 0; i < NUMPIXELS; i++) { for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / NUMPIXELS + wheel_offset)); pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / NUMPIXELS + wheel_offset));
wheel_offset += hue_increment; wheel_offset += hue_increment;
......
#ifndef LED_EFFECTS_H_INCLUDED #ifndef LED_EFFECTS_H_INCLUDED
#define LED_EFFECTS_H_INCLUDED #define LED_EFFECTS_H_INCLUDED
#include <Arduino.h> #include <Arduino.h>
#include "util.h"
#include "config.h" #include "config.h"
// Adafruit NeoPixel (Arduino library for controlling single-wire-based LED pixels and strip) // Adafruit NeoPixel (Arduino library for controlling single-wire-based LED pixels and strip)
...@@ -30,7 +29,7 @@ namespace led_effects { ...@@ -30,7 +29,7 @@ namespace led_effects {
int countdownToZero(); int countdownToZero();
void showWaitingLED(uint32_t color); void showWaitingLED(uint32_t color);
void showKITTWheel(uint32_t color, uint16_t duration_s = 2); void showKITTWheel(uint32_t color, uint16_t duration_s = 2);
void showRainbowWheel(int duration_s = 1, uint16_t hue_increment = 50); void showRainbowWheel(int duration_ms = 1000, uint16_t hue_increment = 50);
void displayCO2color(uint16_t co2); void displayCO2color(uint16_t co2);
} }
#endif #endif
...@@ -167,7 +167,7 @@ namespace mqtt { ...@@ -167,7 +167,7 @@ namespace mqtt {
} else if (messageString == "local_ip") { } else if (messageString == "local_ip") {
sendInfoAboutLocalNetwork(); sendInfoAboutLocalNetwork();
} else if (messageString == "reset") { } else if (messageString == "reset") {
resetAmpel(); ESP.restart(); // softer than ESP.reset()
} else { } else {
led_effects::showKITTWheel(color::red, 1); led_effects::showKITTWheel(color::red, 1);
Serial.println(F("Message not supported. Doing nothing.")); Serial.println(F("Message not supported. Doing nothing."));
......
...@@ -38,16 +38,6 @@ namespace ntp { ...@@ -38,16 +38,6 @@ namespace ntp {
} }
} }
void resetAmpel() {
Serial.print(F("Resetting"));
#ifdef AMPEL_CSV
FS_LIB.end();
#endif
led_effects::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")
......
...@@ -2,20 +2,17 @@ ...@@ -2,20 +2,17 @@
#define AMPEL_UTIL_H_INCLUDED #define AMPEL_UTIL_H_INCLUDED
#include <Arduino.h> #include <Arduino.h>
#include "config.h" #include "config.h"
#ifdef AMPEL_CSV
# include "csv_writer.h" // To close filesystem before reset
#endif
#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
#if defined(ESP8266) #if defined(ESP8266)
# define BOARD "ESP8266" # define BOARD "ESP8266"
# include <ESP8266WiFi.h> # include <ESP8266WiFi.h> // required to get MAC address
# define get_free_heap_size() system_get_free_heap_size() # define get_free_heap_size() system_get_free_heap_size()
#elif defined(ESP32) #elif defined(ESP32)
# define BOARD "ESP32" # define BOARD "ESP32"
# include <WiFi.h> # include <WiFi.h> // required to get MAC address
# define get_free_heap_size() esp_get_free_heap_size() # define get_free_heap_size() esp_get_free_heap_size()
#else #else
# define BOARD "Unknown" # define BOARD "Unknown"
...@@ -43,6 +40,4 @@ namespace util { ...@@ -43,6 +40,4 @@ namespace util {
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
#ifndef WIFI_UTIL_H_INCLUDED #ifndef WIFI_UTIL_H_INCLUDED
#define WIFI_UTIL_H_INCLUDED #define WIFI_UTIL_H_INCLUDED
#include "led_effects.h"
#include "config.h" #include "config.h"
#include "util.h"
#include "led_effects.h"
void WiFiConnect(const String &hostname); void WiFiConnect(const String &hostname);
#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