Commit 7109e2ab authored by Eric Duminil's avatar Eric Duminil
Browse files

Use reference instead of pointer

parent 9fcfb4fc
Pipeline #5768 passed with stage
in 2 minutes and 21 seconds
......@@ -83,9 +83,9 @@ namespace sensor {
scd30.reset();
Serial.print(F("Setting temperature offset to -"));
Serial.print(abs(*config::temperature_offset));
Serial.print(abs(config::temperature_offset));
Serial.println(F(" K."));
scd30.setTemperatureOffset(abs(*config::temperature_offset)); // setTemperatureOffset only accepts positive numbers, but shifts the temperature down.
scd30.setTemperatureOffset(abs(config::temperature_offset)); // setTemperatureOffset only accepts positive numbers, but shifts the temperature down.
delay(100);
Serial.print(F("Temperature offset is : -"));
......@@ -93,7 +93,7 @@ namespace sensor {
Serial.println(F(" K"));
Serial.print(F("Auto-calibration is "));
Serial.println(*config::auto_calibrate_sensor ? "ON." : "OFF.");
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
// SCD30 has its own timer.
//NOTE: The timer seems to be inaccurate, though, possibly depending on voltage. Should it be offset?
......@@ -157,8 +157,8 @@ namespace sensor {
void calibrate() {
Serial.print(F("Calibrating SCD30 now..."));
scd30.setAltitudeCompensation(*config::altitude_above_sea_level);
scd30.setForcedRecalibrationFactor(*config::co2_calibration_level);
scd30.setAltitudeCompensation(config::altitude_above_sea_level);
scd30.setForcedRecalibrationFactor(config::co2_calibration_level);
Serial.println(F(" Done!"));
Serial.println(F("Sensor calibrated."));
switchState(BOOTUP); // In order to stop the calibration and select the desired timestep.
......@@ -197,12 +197,12 @@ namespace sensor {
switchState(READY);
Serial.println(F("Sensor acclimatization finished."));
Serial.print(F("Setting SCD30 timestep to "));
Serial.print(*config::measurement_timestep);
Serial.print(config::measurement_timestep);
Serial.println(F(" s."));
if (*config::measurement_timestep < 10) {
if (config::measurement_timestep < 10) {
Serial.println(F("WARNING: Timesteps shorter than 10s can lead to unreliable measurements!"));
}
scd30.setMeasurementInterval(*config::measurement_timestep); // [s]
scd30.setMeasurementInterval(config::measurement_timestep); // [s]
}
// Check for pre-calibration states first, because we do not want to
......@@ -292,7 +292,7 @@ namespace sensor {
}
void setAutoCalibration(int32_t autoCalibration) {
*config::auto_calibrate_sensor = autoCalibration;
config::auto_calibrate_sensor = autoCalibration;
scd30.setAutoSelfCalibration(autoCalibration);
Serial.print(F("Setting auto-calibration to : "));
Serial.println(autoCalibration ? F("On.") : F("Off."));
......@@ -304,7 +304,7 @@ namespace sensor {
Serial.print(timestep);
Serial.println(F("s (change will only be applied after next measurement)."));
scd30.setMeasurementInterval(timestep);
*config::measurement_timestep = timestep;
config::measurement_timestep = timestep;
led_effects::showKITTWheel(color::green, 1);
}
}
......@@ -312,8 +312,8 @@ namespace sensor {
void calibrateSensorToSpecificPPM(int32_t calibrationLevel) {
if (calibrationLevel >= 400 && calibrationLevel <= 2000) {
Serial.print(F("Force calibration, at "));
*config::co2_calibration_level = calibrationLevel;
Serial.print(*config::co2_calibration_level);
config::co2_calibration_level = calibrationLevel;
Serial.print(config::co2_calibration_level);
Serial.println(F(" ppm."));
startCalibrationProcess();
}
......@@ -322,8 +322,8 @@ namespace sensor {
void calibrateSensorRightNow(int32_t calibrationLevel) {
if (calibrationLevel >= 400 && calibrationLevel <= 2000) {
Serial.print(F("Force calibration, right now, at "));
*config::co2_calibration_level = calibrationLevel;
Serial.print(*config::co2_calibration_level);
config::co2_calibration_level = calibrationLevel;
Serial.print(config::co2_calibration_level);
Serial.println(F(" ppm."));
calibrate();
}
......
......@@ -162,7 +162,7 @@ namespace csv_writer {
void logIfTimeHasCome(const char *timeStamp, const int16_t &co2, const float &temperature, const float &humidity) {
unsigned long now = seconds();
if (now - last_written_at > *config::csv_interval) {
if (now - last_written_at > config::csv_interval) {
last_written_at = now;
log(timeStamp, co2, temperature, humidity);
}
......@@ -172,9 +172,9 @@ namespace csv_writer {
* Callbacks for sensor commands *
*****************************************************************/
void setCSVinterval(int32_t csv_interval) {
*config::csv_interval = csv_interval;
config::csv_interval = csv_interval;
Serial.print(F("Setting CSV Interval to : "));
Serial.print(*config::csv_interval);
Serial.print(config::csv_interval);
Serial.println("s.");
led_effects::showKITTWheel(color::green, 1);
}
......
......@@ -73,12 +73,12 @@ namespace led_effects {
void setupRing() {
Serial.print(F("Ring : "));
Serial.print(*config::led_count);
Serial.print(config::led_count);
Serial.println(F(" LEDs."));
pixels.updateLength(*config::led_count);
pixels.updateLength(config::led_count);
if (*config::led_count == 12) {
if (config::led_count == 12) {
config::co2_ticks[7] = 1200;
config::co2_ticks[8] = 1400;
config::co2_ticks[9] = 1600;
......@@ -98,7 +98,7 @@ namespace led_effects {
config::led_hues[9] = 0;
config::led_hues[10] = 0;
config::led_hues[11] = 0;
} else if (*config::led_count == 16) {
} else if (config::led_count == 16) {
config::co2_ticks[7] = 1100;
config::co2_ticks[8] = 1200;
config::co2_ticks[9] = 1300;
......@@ -128,9 +128,10 @@ namespace led_effects {
config::led_hues[15] = 0;
} else {
// "Only 12 and 16 LEDs rings are currently supported."
config::display_led = false;
}
pixels.begin();
pixels.setBrightness(*config::max_brightness);
pixels.setBrightness(config::max_brightness);
LEDsOff();
sensor_console::defineIntCommand("led", turnLEDsOnOff, F("0/1 (Turns LEDs on/off)"));
sensor_console::defineIntCommand("color", showColor, F("0xFF0015 (Shows color, specified as RGB, for debugging)"));
......@@ -160,7 +161,7 @@ namespace led_effects {
static uint16_t kitt_offset = 0;
pixels.clear();
for (int j = kitt_tail; j >= 0; j--) {
int ledNumber = abs((kitt_offset - j + *led_count) % (2 * *led_count) - *led_count) % *led_count; // Triangular function
int ledNumber = abs((kitt_offset - j + led_count) % (2 * led_count) - led_count) % led_count; // Triangular function
pixels.setPixelColor(ledNumber, color * pixels.gamma8(255 - j * 76) / 255);
}
pixels.show();
......@@ -171,8 +172,8 @@ namespace led_effects {
// Simulate a moving LED with tail. First LED starts at 0, and moves along a triangular function. The tail follows, with decreasing brightness.
// Takes approximately 1s for each direction.
void showKITTWheel(uint32_t color, uint16_t duration_s) {
pixels.setBrightness(*config::max_brightness);
for (int i = 0; i < duration_s * *config::led_count; ++i) {
pixels.setBrightness(config::max_brightness);
for (int i = 0; i < duration_s * config::led_count; ++i) {
showWaitingLED(color);
}
}
......@@ -200,8 +201,8 @@ namespace led_effects {
*/
void breathe(int16_t co2) {
static uint8_t breathing_offset = 0;
uint8_t brightness_amplitude = *config::max_brightness - *config::min_brightness;
uint16_t brightness = *config::min_brightness + pixels.sine8(breathing_offset) * brightness_amplitude / 255;
uint8_t brightness_amplitude = config::max_brightness - config::min_brightness;
uint16_t brightness = config::min_brightness + pixels.sine8(breathing_offset) * brightness_amplitude / 255;
pixels.setBrightness(brightness);
pixels.show();
breathing_offset += co2 > config::poor_air_quality_ppm ? 6 : 3; // breathing speed. +3 looks like slow human breathing.
......@@ -214,13 +215,13 @@ namespace led_effects {
if (!config::display_led) {
return;
}
pixels.setBrightness(*config::max_brightness);
for (int ledId = 0; ledId < *config::led_count; ++ledId) {
pixels.setBrightness(config::max_brightness);
for (int ledId = 0; ledId < config::led_count; ++ledId) {
uint8_t brightness = getLedBrightness(co2, ledId);
pixels.setPixelColor(ledId, pixels.ColorHSV(config::led_hues[ledId], 255, brightness));
}
pixels.show();
if (*config::max_brightness > *config::min_brightness) {
if (config::max_brightness > config::min_brightness) {
breathe(co2);
}
}
......@@ -232,10 +233,10 @@ namespace led_effects {
static uint16_t wheel_offset = 0;
static uint16_t sine_offset = 0;
unsigned long t0 = millis();
pixels.setBrightness(*config::max_brightness);
pixels.setBrightness(config::max_brightness);
while (millis() - t0 < duration_ms) {
for (int i = 0; i < *config::led_count; i++) {
pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / *config::led_count + wheel_offset));
for (int i = 0; i < config::led_count; i++) {
pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / config::led_count + wheel_offset));
wheel_offset += (pixels.sine8(sine_offset++ / 50) - 127) / 2;
}
pixels.show();
......@@ -252,7 +253,7 @@ namespace led_effects {
return;
}
for (int i = 0; i < 10; i++) {
pixels.setBrightness(static_cast<int>(*config::max_brightness * (1 - i * 0.1)));
pixels.setBrightness(static_cast<int>(config::max_brightness * (1 - i * 0.1)));
delay(50);
pixels.fill(color::red);
pixels.show();
......@@ -275,7 +276,7 @@ namespace led_effects {
pixels.fill(color::blue);
pixels.show();
int countdown;
for (countdown = *config::led_count; countdown >= 0 && !digitalRead(0); countdown--) {
for (countdown = config::led_count; countdown >= 0 && !digitalRead(0); countdown--) {
pixels.setPixelColor(countdown, color::black);
pixels.show();
Serial.println(countdown);
......
......@@ -271,16 +271,16 @@ namespace web_config {
*/
namespace config {
// CSV
uint16_t *csv_interval = &web_config::csvTimestepParam.value();
uint16_t &csv_interval = web_config::csvTimestepParam.value();
// Sensor
uint16_t *measurement_timestep = &web_config::timestepParam.value(); // [s] Value between 2 and 1800 (range for SCD30 sensor).
uint16_t *altitude_above_sea_level = &web_config::altitudeParam.value(); // [m]
uint16_t *co2_calibration_level = &web_config::atmosphericCO2Param.value(); // [ppm]
bool *auto_calibrate_sensor = &web_config::autoCalibrateParam.value(); // [true / false]
float *temperature_offset = &web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant.
uint8_t *max_brightness = &web_config::maxBrightnessParam.value();
uint8_t *min_brightness = &web_config::minBrightnessParam.value();
uint16_t *led_count = &web_config::ledCountParam.value();
uint16_t &measurement_timestep = web_config::timestepParam.value(); // [s] Value between 2 and 1800 (range for SCD30 sensor).
uint16_t &altitude_above_sea_level = web_config::altitudeParam.value(); // [m]
uint16_t &co2_calibration_level = web_config::atmosphericCO2Param.value(); // [ppm]
bool &auto_calibrate_sensor = web_config::autoCalibrateParam.value(); // [true / false]
float &temperature_offset = web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant.
uint8_t &max_brightness = web_config::maxBrightnessParam.value();
uint8_t &min_brightness = web_config::minBrightnessParam.value();
uint16_t &led_count = web_config::ledCountParam.value();
}
......@@ -10,19 +10,19 @@
#endif
namespace config {
extern uint16_t *csv_interval; // [s]
extern uint16_t &csv_interval; // [s]
// Sensor
extern uint16_t *measurement_timestep; // [s] Value between 2 and 1800 (range for SCD30 sensor).
extern uint16_t *altitude_above_sea_level; // [m]
extern uint16_t *co2_calibration_level; // [ppm]
extern bool *auto_calibrate_sensor; // [true / false]
extern float *temperature_offset; // [K] Sign isn't relevant.
extern uint16_t &measurement_timestep; // [s] Value between 2 and 1800 (range for SCD30 sensor).
extern uint16_t &altitude_above_sea_level; // [m]
extern uint16_t &co2_calibration_level; // [ppm]
extern bool &auto_calibrate_sensor; // [true / false]
extern float &temperature_offset; // [K] Sign isn't relevant.
// LED
extern uint8_t *max_brightness;
extern uint8_t *min_brightness;
extern uint16_t *led_count;
extern uint8_t &max_brightness;
extern uint8_t &min_brightness;
extern uint16_t &led_count;
}
namespace web_config {
......
......@@ -245,9 +245,9 @@ namespace web_server {
// Body
snprintf_P(content, sizeof(content), body_template, ampel.sensorId, sensor::co2, sensor::temperature,
sensor::humidity, sensor::timestamp, *config::measurement_timestep,
sensor::humidity, sensor::timestamp, config::measurement_timestep,
#ifdef AMPEL_CSV
csv_writer::last_successful_write, *config::csv_interval, csv_writer::getAvailableSpace() / 1024,
csv_writer::last_successful_write, config::csv_interval, csv_writer::getAvailableSpace() / 1024,
#endif
#ifdef AMPEL_MQTT
mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval,
......@@ -256,9 +256,9 @@ namespace web_server {
lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission,
config::lorawan_sending_interval,
#endif
*config::temperature_offset, *config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId, ampel.sensorId,
wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(), esp_get_max_free_block_size(), esp_get_heap_fragmentation(),
ampel.max_loop_duration, ampel.board, ampel.version, dd, hh, mm, ss);
config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId, ampel.sensorId,
wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(), esp_get_max_free_block_size(),
esp_get_heap_fragmentation(), ampel.max_loop_duration, ampel.board, ampel.version, dd, hh, mm, ss);
// Serial.print(F(" - Body size : "));
// Serial.print(strlen(content));
......
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