From 9e5442ed88d34ab6a875ff9468decf9f9f126043 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 6 Oct 2021 01:20:51 -0400 Subject: cleaner --- mush.ino | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/mush.ino b/mush.ino index e90847e..f517fb5 100644 --- a/mush.ino +++ b/mush.ino @@ -37,23 +37,13 @@ void setup(void) pinMode(PHOTORESISTOR, INPUT); // photo resistor wific = new WiFiClient(); - Serial.begin(115200); + /*Wait for the chip to be initialized completely, and then exit*/ while (sensor.begin()) { Serial.println("failed to init chip, please check if the chip connection is fine"); delay(1000); } - /** - * @brief Set measurement cycle - * @param cycle:in typedef enum{ - * eClosed, //Idle (Measurements are disabled in this mode) - * eCycle_1s, //Constant power mode, IAQ measurement every second - * Ecycle_10s, //Pulse heating mode IAQ measurement every 10 seconds - * eCycle_60s, //Low power pulse heating mode IAQ measurement every 60 seconds - * eCycle_250ms //Constant power mode, sensor measurement every 250ms - * }eCycle_t; - */ sensor.setMeasCycle(sensor.eCycle_250ms); } @@ -65,17 +55,6 @@ void writeBoth(char *buf) } } -void log_reading (float temp_c, float humidity, int photons, uint16_t co2, uint16_t tvoc) -{ - auto fmt = "T: %.2f H: %.2f HI: %.2f Light: %d CO2: %d TVOC: %d\r\n"; - char buf[500]; - - float heat_index_c = dht.computeHeatIndex(temp_c, humidity, false); - - snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c, photons, co2, tvoc); - writeBoth(buf); -} - struct SensorState { float last_reading; @@ -94,10 +73,26 @@ PhotoSensor photoSensor; CO2Sensor cO2Sensor; TVOCSensor tVOCSensor; -SensorState *sensors[] = { &temperatureSensor, &humiditySensor, &photoSensor, &cO2Sensor, &tVOCSensor }; +void log_reading() +{ + float temp_c = temperatureSensor.last_reading; + float humidity = humiditySensor.last_reading; + float heat_index_c = dht.computeHeatIndex(temp_c, humidity, false); + int photons = photoSensor.last_reading; + uint32_t co2 = cO2Sensor.last_reading; + uint32_t tvoc = tVOCSensor.last_reading; + + auto fmt = "T: %.2f H: %.2f HI: %.2f Light: %d CO2: %u TVOC: %u\r\n"; + char buf[500]; + + + snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c, photons, co2, tvoc); + writeBoth(buf); +} void sensor_loop() { + SensorState *sensors[] = { &temperatureSensor, &humiditySensor, &photoSensor, &cO2Sensor, &tVOCSensor }; for (size_t i=0; isense(); @@ -118,7 +113,7 @@ void loop() sensor_loop(); - log_reading(temperatureSensor.last_reading, humiditySensor.last_reading, photoSensor.last_reading, cO2Sensor.last_reading, tVOCSensor.last_reading); + log_reading(); delay(1000); } -- cgit v1.2.3