From eee2af5c91006be5137c41f631394dc7e4749219 Mon Sep 17 00:00:00 2001 From: Anya Date: Fri, 6 Oct 2023 12:37:49 -0400 Subject: [PATCH] rgb_driver --- platformio.ini | 182 +++++++++++++++++---- src/datalogger.cpp | 34 ++-- src/sensors/drivers/BME280_driver.cpp | 2 +- src/sensors/drivers/atlas_co2_driver.cpp | 16 +- src/sensors/drivers/atlas_co2_driver.h | 4 +- src/sensors/drivers/registry.cpp | 35 +++-- src/sensors/drivers/registry.h | 2 + src/sensors/drivers/rgb_driver.cpp | 192 +++++++++++++++++++++++ src/sensors/drivers/rgb_driver.h | 81 ++++++++++ src/system/command.cpp | 6 +- 10 files changed, 482 insertions(+), 72 deletions(-) create mode 100644 src/sensors/drivers/rgb_driver.cpp create mode 100644 src/sensors/drivers/rgb_driver.h diff --git a/platformio.ini b/platformio.ini index a400892..8af56bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,35 +8,155 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +#Select the default buil here. +[platformio] +default_envs = NUCLEO-F103RB-co2-rgb + +#RB: not all drivers will fit [env:NUCLEO-F103RB] -platform = ststm32 -board_build.core = maple ;source https://github.com/rogerclarkmelbourne/Arduino_STM32 -board = genericSTM32F103RB -framework = arduino -build_flags = - -DSTM32 - -fpermissive - -DUSE_HSI_CLOCK - -Os - -DPRODUCTION_FIRMWARE_BUILD -build_unflags = -O2 -# -std=gnu++17 -#build_unflags = -std=gnu++11 -board_build.f_cpu = 64000000L -lib_deps = - ; git@github.com:ZavenArra/ModularSensors.git#stm32f1 - https://github.com/ZavenArra/ModularSensors.git#stm32f1 - ; https://github.com/deepwinter/Adafruit_BluefruitLE_nRF51.git - https://github.com/WaterBearSondes/DS3231.git - https://github.com/WaterBearSondes/atlas_OEM.git - https://github.com/greiman/SdFat.git#1.1.4 - https://github.com/DaveGamble/cJSON.git - https://github.com/ZavenArra/CmdArduino.git - https://github.com/adafruit/DHT-sensor-library.git - https://github.com/adafruit/Adafruit_AHTX0.git - https://github.com/adafruit/Adafruit_BME280_Library.git - ;adafruit/DHT sensor library -monitor_speed = 115200 -debug_port = /dev/ttyACM0 -check_tool = cppcheck -check_flags = --enable=all + platform = ststm32 + board_build.core = maple ;source https://github.com/rogerclarkmelbourne/Arduino_STM32 + board = genericSTM32F103RB + framework = arduino + build_flags = + -DSTM32 + -fpermissive + -DUSE_HSI_CLOCK + -Os + -DPRODUCTION_FIRMWARE_BUILD + -DRRIV_ANALOG + + build_unflags = -O2 + # -std=gnu++17 + #build_unflags = -std=gnu++11 + board_build.f_cpu = 64000000L + lib_deps = + ; git@github.com:ZavenArra/ModularSensors.git#stm32f1 + https://github.com/ZavenArra/ModularSensors.git#stm32f1 + ; https://github.com/deepwinter/Adafruit_BluefruitLE_nRF51.git + https://github.com/WaterBearSondes/DS3231.git + https://github.com/WaterBearSondes/atlas_OEM.git + https://github.com/greiman/SdFat.git#1.1.4 + https://github.com/DaveGamble/cJSON.git + https://github.com/ZavenArra/CmdArduino.git + https://github.com/adafruit/DHT-sensor-library.git + https://github.com/adafruit/Adafruit_AHTX0.git + https://github.com/adafruit/Adafruit_BME280_Library.git + ;adafruit/DHT sensor library + monitor_speed = 115200 + debug_port = /dev/ttyACM0 + check_tool = cppcheck + check_flags = --enable=all +#RB: ch4 & dht +[env:NUCLEO-F103RB-ch4-dht] + platform = ststm32 + board_build.core = maple ;source https://github.com/rogerclarkmelbourne/Arduino_STM32 + board = genericSTM32F103RB + framework = arduino + build_flags = + -DSTM32 + -fpermissive + -DUSE_HSI_CLOCK + -Os + -DPRODUCTION_FIRMWARE_BUILD + -DRRIV_ANALOG + -DRRIV_DHT22 + + build_unflags = -O2 + # -std=gnu++17 + #build_unflags = -std=gnu++11 + board_build.f_cpu = 64000000L + lib_deps = + ; git@github.com:ZavenArra/ModularSensors.git#stm32f1 + https://github.com/ZavenArra/ModularSensors.git#stm32f1 + ; https://github.com/deepwinter/Adafruit_BluefruitLE_nRF51.git + https://github.com/WaterBearSondes/DS3231.git + https://github.com/WaterBearSondes/atlas_OEM.git + https://github.com/greiman/SdFat.git#1.1.4 + https://github.com/DaveGamble/cJSON.git + https://github.com/ZavenArra/CmdArduino.git + https://github.com/adafruit/DHT-sensor-library.git + https://github.com/adafruit/Adafruit_AHTX0.git + https://github.com/adafruit/Adafruit_BME280_Library.git + ;adafruit/DHT sensor library + monitor_speed = 115200 + debug_port = /dev/ttyACM0 + check_tool = cppcheck + check_flags = --enable=all +#RB: co2 & rgb +[env:NUCLEO-F103RB-co2-rgb] + platform = ststm32 + board_build.core = maple ;source https://github.com/rogerclarkmelbourne/Arduino_STM32 + board = genericSTM32F103RB + framework = arduino + build_flags = + -DSTM32 + -fpermissive + -DUSE_HSI_CLOCK + -Os + -DPRODUCTION_FIRMWARE_BUILD + -DRRIV_CO2 + -DRRIV_RGB + -DCONT_PWR + + build_unflags = -O2 + # -std=gnu++17 + #build_unflags = -std=gnu++11 + board_build.f_cpu = 64000000L + lib_deps = + ; git@github.com:ZavenArra/ModularSensors.git#stm32f1 + https://github.com/ZavenArra/ModularSensors.git#stm32f1 + ; https://github.com/deepwinter/Adafruit_BluefruitLE_nRF51.git + https://github.com/WaterBearSondes/DS3231.git + https://github.com/WaterBearSondes/atlas_OEM.git + https://github.com/greiman/SdFat.git#1.1.4 + https://github.com/DaveGamble/cJSON.git + https://github.com/ZavenArra/CmdArduino.git + https://github.com/adafruit/DHT-sensor-library.git + https://github.com/adafruit/Adafruit_AHTX0.git + https://github.com/adafruit/Adafruit_BME280_Library.git + ;adafruit/DHT sensor library + monitor_speed = 115200 + debug_port = /dev/ttyACM0 + check_tool = cppcheck + check_flags = --enable=all + +#RE: more space +[env:NUCLEO-F103RE] + platform = ststm32 + board_build.core = maple ;source https://github.com/rogerclarkmelbourne/Arduino_STM32 + board = genericSTM32F103RE + framework = arduino + build_flags = + -DSTM32 + -fpermissive + -DUSE_HSI_CLOCK + -Os + -DPRODUCTION_FIRMWARE_BUILD + -DRRIV_ANALOG + -DRRIV_ATLAS_EC + -DRRIV_DHT22 + -DRRIV_CO2 + -DRRIV_RGB + -DRRIV_AHT + build_unflags = -O2 + # -std=gnu++17 + #build_unflags = -std=gnu++11 + board_build.f_cpu = 64000000L + lib_deps = + ; git@github.com:ZavenArra/ModularSensors.git#stm32f1 + https://github.com/ZavenArra/ModularSensors.git#stm32f1 + ; https://github.com/deepwinter/Adafruit_BluefruitLE_nRF51.git + https://github.com/WaterBearSondes/DS3231.git + https://github.com/WaterBearSondes/atlas_OEM.git + https://github.com/greiman/SdFat.git#1.1.4 + https://github.com/DaveGamble/cJSON.git + https://github.com/ZavenArra/CmdArduino.git + https://github.com/adafruit/DHT-sensor-library.git + https://github.com/adafruit/Adafruit_AHTX0.git + https://github.com/adafruit/Adafruit_BME280_Library.git + ;adafruit/DHT sensor library + monitor_speed = 115200 + debug_port = /dev/ttyACM0 + check_tool = cppcheck + check_flags = --enable=all \ No newline at end of file diff --git a/src/datalogger.cpp b/src/datalogger.cpp index b0f0185..4d26e69 100644 --- a/src/datalogger.cpp +++ b/src/datalogger.cpp @@ -35,6 +35,8 @@ // #include "sensors/drivers/air_pump.h" // #include "sensors/drivers/generic_actuator.h" + + void Datalogger::sleepMCU(uint32 milliseconds) { if(milliseconds < 5) @@ -131,6 +133,9 @@ Datalogger::Datalogger(datalogger_settings_type *settings) void Datalogger::setup() { + #ifdef CONT_PWR + debug("continuous power ON"); + #endif startCustomWatchDog(); setupHardwarePins(); @@ -231,6 +236,7 @@ void Datalogger::testMeasurementCycle() void Datalogger::loop() { + if (inMode(deploy_on_trigger)) { deploy(); // if deploy returns false here, the trigger setup has a fatal coding defect not detecting invalid conditions for deployment @@ -270,11 +276,10 @@ void Datalogger::loop() return; } - // otherwise go to sleep fileSystemWriteCache->flushCache(); - //AE actuator hook could go here: is this before or after measurement? + SLEEP: stopAndAwaitTrigger(); initializeMeasurementCycle(); @@ -288,7 +293,13 @@ void Datalogger::loop() if (inMode(logging) || inMode(deploy_on_trigger)) { // processCLI may have moved logger into a deployed mode - goto SLEEP; + #ifdef CONT_PWR + debug("skip sleep"); + #endif + #ifndef CONT_PWR + debug("to sleep"); + goto SLEEP; + #endif } else if (inMode(interactive)) { @@ -473,8 +484,6 @@ void Datalogger::initializeBurst() void Datalogger::initializeMeasurementCycle() { - //AE actuate hook before measurement could go here - // notify(F("setting base time")); currentEpoch = timestamp(); offsetMillis = millis(); @@ -503,7 +512,7 @@ void Datalogger::initializeMeasurementCycle() sensorsWarmedUp = true; for (unsigned short i = 0; i < sensorCount; i++) { - // notify("check isWarmed"); + notify("check isWarmed"); if (!drivers[i]->isWarmedUp()) { // TODO: enhancement, ask the sensor driver if we should sleep MCU for a while @@ -512,7 +521,6 @@ void Datalogger::initializeMeasurementCycle() } } } - //AE actuator call could go here } @@ -687,7 +695,7 @@ void Datalogger::setConfiguration(cJSON *config) notify("Invalid site name"); } - const cJSON* loggerNameJSON = cJSON_GetObjectItemCaseSensitive(config, "loggerName"); + const cJSON* loggerNameJSON = cJSON_GetObjectItemCaseSensitive(config, "logger_name"); if(loggerNameJSON != NULL && cJSON_IsString(loggerNameJSON) && strlen(loggerNameJSON->valuestring) <= 7) { strcpy(settings.loggerName, loggerNameJSON->valuestring); @@ -695,7 +703,7 @@ void Datalogger::setConfiguration(cJSON *config) notify("Invalid logger name"); } - const cJSON* deploymentIdentifierJSON = cJSON_GetObjectItemCaseSensitive(config, "deploymentIdentifier"); + const cJSON* deploymentIdentifierJSON = cJSON_GetObjectItemCaseSensitive(config, "deployment_identifier"); if(deploymentIdentifierJSON != NULL && cJSON_IsString(deploymentIdentifierJSON) && strlen(deploymentIdentifierJSON->valuestring) <= 15) { strcpy(settings.deploymentIdentifier, deploymentIdentifierJSON->valuestring); @@ -711,7 +719,7 @@ void Datalogger::setConfiguration(cJSON *config) notify("Invalid interval"); } - const cJSON * burstNumberJson = cJSON_GetObjectItemCaseSensitive(config, "burstNumber"); + const cJSON * burstNumberJson = cJSON_GetObjectItemCaseSensitive(config, "burst_number"); if(burstNumberJson != NULL && cJSON_IsNumber(burstNumberJson) && burstNumberJson->valueint > 0) { settings.burstNumber = (byte) burstNumberJson->valueint; @@ -719,7 +727,7 @@ void Datalogger::setConfiguration(cJSON *config) notify("Invalid burst number"); } - const cJSON * startUpDelayJson = cJSON_GetObjectItemCaseSensitive(config, "startUpDelay"); + const cJSON * startUpDelayJson = cJSON_GetObjectItemCaseSensitive(config, "start_up_delay"); if(startUpDelayJson != NULL && cJSON_IsNumber(startUpDelayJson) && startUpDelayJson->valueint >= 0) { settings.startUpDelay = (byte) startUpDelayJson->valueint; @@ -727,12 +735,12 @@ void Datalogger::setConfiguration(cJSON *config) notify("Invalid start up delay"); } - const cJSON * interBurstDelayJson = cJSON_GetObjectItemCaseSensitive(config, "interBurstDelay"); + const cJSON * interBurstDelayJson = cJSON_GetObjectItemCaseSensitive(config, "burst_delay"); if(interBurstDelayJson != NULL && cJSON_IsNumber(interBurstDelayJson) && interBurstDelayJson->valueint >= 0) { settings.interBurstDelay = (byte) interBurstDelayJson->valueint; } else { - notify("Invalid inter burst delay"); + notify("Invalid burst delay"); } storeDataloggerConfiguration(); diff --git a/src/sensors/drivers/BME280_driver.cpp b/src/sensors/drivers/BME280_driver.cpp index 4842c50..86e12ec 100644 --- a/src/sensors/drivers/BME280_driver.cpp +++ b/src/sensors/drivers/BME280_driver.cpp @@ -88,7 +88,7 @@ bool BME280Driver::takeMeasurement() measurementTaken = true; // if(measurementTaken) // { - // addValueToBurstSummaryMean("temperature", temperature); + // addValueToBurstSummaryMean("temperature", temperature); // addValueToBurstSummaryMean("pressure", pressure); // } diff --git a/src/sensors/drivers/atlas_co2_driver.cpp b/src/sensors/drivers/atlas_co2_driver.cpp index e854371..f3feb52 100644 --- a/src/sensors/drivers/atlas_co2_driver.cpp +++ b/src/sensors/drivers/atlas_co2_driver.cpp @@ -19,6 +19,7 @@ #include "system/logs.h" // for debug() and notify() #define CO2_TAG "co2" +#define TEMP_TAG "temp" AtlasCO2Driver::AtlasCO2Driver() { @@ -77,14 +78,14 @@ bool AtlasCO2Driver::takeMeasurement() bool measurementTaken = modularSensorDriver->addSingleMeasurementResult(); if(measurementTaken) { - value = modularSensorDriver->sensorValues[0]; + co2 = modularSensorDriver->sensorValues[0]; modularSensorDriver->clearValues(); measurementTaken = true; - addValueToBurstSummaryMean(CO2_TAG, value); + addValueToBurstSummaryMean(CO2_TAG, co2); } else { - value = -1; + co2 = -1; } @@ -93,7 +94,7 @@ bool AtlasCO2Driver::takeMeasurement() const char * AtlasCO2Driver::getRawDataString() { - sprintf(dataString, "%d", value); + sprintf(dataString, "%d", co2); return dataString; } @@ -102,13 +103,6 @@ const char * AtlasCO2Driver::getSummaryDataString() sprintf(dataString, "%0.2f", getBurstSummaryMean(CO2_TAG)); return dataString; } -// const char *AtlasCO2Driver::getRawDataString() -// { -// // debug("configuring driver template dataString"); -// // process data string for .csv -// sprintf(dataString, "%d,%d",value,0); -// return dataString; -// } const char *AtlasCO2Driver::getBaseColumnHeaders() { diff --git a/src/sensors/drivers/atlas_co2_driver.h b/src/sensors/drivers/atlas_co2_driver.h index 89b32a8..3544891 100644 --- a/src/sensors/drivers/atlas_co2_driver.h +++ b/src/sensors/drivers/atlas_co2_driver.h @@ -69,8 +69,8 @@ class AtlasCO2Driver : public I2CProtocolSensorDriver /*value(s) to be placed in dataString, should correspond to number of column headers and entries in dataString*/ - int value; // sensor raw return(s) to be added to dataString - const char *baseColumnHeaders = "CO2_ppm,temperature_C"; // will be written to .csv + int co2; // sensor raw return(s) to be added to dataString + const char *baseColumnHeaders = "CO2_ppm"; // will be written to .csv char dataString[30]; // will be written to .csv void addCalibrationParametersToJSON(cJSON *json); diff --git a/src/sensors/drivers/registry.cpp b/src/sensors/drivers/registry.cpp index c070470..038d669 100644 --- a/src/sensors/drivers/registry.cpp +++ b/src/sensors/drivers/registry.cpp @@ -16,6 +16,7 @@ #define AIR_PUMP 0x0005 #define BME280 0x0006 #define ADAFRUIT_AHTX0_SENSOR 0x0007 +#define ATLAS_RGB_SENSOR 0x0008 // Step 2: Add a #define for the next available integer code #define DRIVER_TEMPLATE 0xFFFE @@ -23,24 +24,36 @@ void buildDriverSensorMap() { - +#ifdef RRIV_ANALOG setupSensorMaps(GENERIC_ANALOG_SENSOR, F(GENERIC_ANALOG_DRIVER_TYPE_STRING)); +#endif - //setupSensorMaps(ATLAS_EC_OEM_SNSOR, F(ATLAS_EC_OEM_TYPE_STRING)); +#ifdef RRIV_ATLAS_EC + setupSensorMaps(ATLAS_EC_OEM_SENSOR, F(ATLAS_EC_OEM_TYPE_STRING)); +#endif - //setupSensorMaps(DRIVER_TEMPLATE, F(DRIVER_TEMPLATE_TYPE_STRING)); - - // setupSensorMaps(ADAFRUIT_DHT22_SENSOR, F(ADAFRUIT_DHT22_TYPE_STRING)); +// setupSensorMaps(DRIVER_TEMPLATE, F(DRIVER_TEMPLATE_TYPE_STRING)); - // setupSensorMaps(ATLAS_CO2_SENSOR, F(ATLAS_CO2_DRIVER_TYPE_STRING)); +#ifdef RRIV_DHT22 + setupSensorMaps(ADAFRUIT_DHT22_SENSOR, F(ADAFRUIT_DHT22_TYPE_STRING)); +#endif - // setupSensorMaps(GENERIC_ACTUATOR, F(GENERIC_ACTUATOR_TYPE_STRING)); +#ifdef RRIV_CO2 + setupSensorMaps(ATLAS_CO2_SENSOR, F(ATLAS_CO2_DRIVER_TYPE_STRING)); // 4848 bytes +#endif - // setupSensorMaps(AIR_PUMP, F(AIR_PUMP_TYPE_STRING)); +#ifdef RRIV_RGB + setupSensorMaps(ATLAS_RGB_SENSOR, F(RGB_DRIVER_TYPE_STRING)); // 4848 bytes +#endif - //setupSensorMaps(BME280, F(BME280_TYPE_STRING)); + // Step 3: call setupSensorMaps with the class name, code, and type string for your sensor + // setupSensorMaps<$CLASS_NAME>($SENSOR_CODE, F($SENSOR_STRING_NAME)); + // $CLASS_NAME is the C++ class of the sensor + // $SENSOR_CODE is the define added in step 2 above for this sensor + // $SENSOR_STRING_NAME is the define for human readable sensor name found in the .h for this sensor driver +#ifdef RRIV_AHT setupSensorMaps(ADAFRUIT_AHTX0_SENSOR, F(ADAFRUIT_DHTX0_TYPE_STRING)); - +#endif //Step 3: call setupSensorMaps with the class name, code, and type string for your sensor -} +} \ No newline at end of file diff --git a/src/sensors/drivers/registry.h b/src/sensors/drivers/registry.h index 60e2b8b..3edc3f5 100644 --- a/src/sensors/drivers/registry.h +++ b/src/sensors/drivers/registry.h @@ -9,6 +9,8 @@ #include "air_pump.h" #include "BME280_driver.h" #include "adafruit_ahtx0.h" +#include "atlas_co2_driver.h" +#include "rgb_driver.h" #define MAX_SENSOR_TYPE 0xFFFE diff --git a/src/sensors/drivers/rgb_driver.cpp b/src/sensors/drivers/rgb_driver.cpp new file mode 100644 index 0000000..4e33983 --- /dev/null +++ b/src/sensors/drivers/rgb_driver.cpp @@ -0,0 +1,192 @@ +#include "sensors/drivers/rgb_driver.h" +#include "system/logs.h" // for debug() and notify() + + +#define RGBI2CADDRESS 0x70 +#define RGBDELAY 300 + +#define RGB_TAG "rgb" + +rgbDriver::rgbDriver() +{ + // debug("allocating driver template"); +} + +rgbDriver::~rgbDriver(){} + +const char * rgbDriver::getSensorTypeString() +{ + return sensorTypeString; +} + +configuration_bytes_partition rgbDriver::getDriverSpecificConfigurationBytes() +{ + configuration_bytes_partition partition; + memcpy(&partition, &configuration, sizeof(driver_configuration)); + return partition; +} + +bool rgbDriver::configureDriverFromJSON(cJSON *json) +{ +} + + +void rgbDriver::configureSpecificConfigurationsFromBytes(configuration_bytes_partition configurationPartition) +{ + memcpy(&configuration, &configurationPartition, sizeof(driver_configuration)); +} + +void rgbDriver::appendDriverSpecificConfigurationJSON(cJSON * json) +{ + // debug("appeding driver specific driver template json"); + + //driver specific config, customize + addCalibrationParametersToJSON(json); +} + +void rgbDriver::setup() +{ + const char * turnOnRGBParameterCommand = "O,RGB,1"; + const char * turnOnLUXParameterCommand = "O,LUX,1"; + const char * turnOnCIEParameterCommand = "O,CIE,1"; + + wire->beginTransmission(RGBI2CADDRESS); + wire->write(turnOnRGBParameterCommand); + wire->endTransmission(); + + delay(RGBDELAY); + + wire->beginTransmission(RGBI2CADDRESS); + wire->write(turnOnLUXParameterCommand); + wire->endTransmission(); + + delay(RGBDELAY); + + wire->beginTransmission(RGBI2CADDRESS); + wire->write(turnOnCIEParameterCommand); + wire->endTransmission(); + + delay(RGBDELAY); +} + +void rgbDriver::stop() +{ + const char * sleepCommand = "Sleep"; + wire->beginTransmission(RGBI2CADDRESS); + wire->write(sleepCommand); + wire->endTransmission(); +} + +bool rgbDriver::takeMeasurement() +{ + // debug("taking measurement from driver template"); + // return true if measurement taken store in class value(s), false if not + const char *RGBRead = "R"; + wire->beginTransmission(RGBI2CADDRESS); + wire->write(RGBRead); + wire->endTransmission(); + + delay(RGBDELAY); + + wire->requestFrom(RGBI2CADDRESS, 43, 1); + + byte code = wire->read(); // the first byte is the response code, we read this separately. + + switch (code) + { // switch case based on what the response code is. + case 1: // decimal 1. + debug("Success"); // means the command was successful. + break; // exits the switch case. + + case 2: // decimal 2. + notify("Failed"); // means the command has failed. + return false; + break; // exits the switch case. + + case 254: // decimal 254. + notify("Pending"); // means the command has not yet been finished calculating. + return false; + break; // exits the switch case. + + case 255: // decimal 255. + notify("No Data"); // means there is no further data to send. + return false; + break; // exits the switch case. + } + + int i = 0; + while (wire->available()) + { // are there bytes to receive. + char readByte = wire->read(); // receive a byte. + value[i] = readByte; // load this byte into our array. + i += 1; // incur the counter for the array element. + if (readByte == 0) + { // if we see that we have been sent a null command. + break; // exit the while loop. + } + } + return true; +} + +const char *rgbDriver::getRawDataString() +{ + // debug("configuring driver template dataString"); + // process data string for .csv + //sprintf(dataString, "%d,%d",value,int(value*31.83)); + sprintf(dataString, "%s",value); + return dataString; +} + +const char * rgbDriver::getSummaryDataString() +{ + sprintf(dataString, "%0.2f", getBurstSummaryMean(RGB_TAG)); + return dataString; +} + +const char *rgbDriver::getBaseColumnHeaders() +{ + // for debug column headers defined in the .h + // debug("getting driver template base column headers"); + return baseColumnHeaders; +} + +void rgbDriver::initCalibration() +{ + // debug("init driver template sensor calibration"); +} + +void rgbDriver::calibrationStep(char *step, int arg_cnt, char ** args) +{ + // for intermediary steps of calibration process + // debug("driver template calibration steps"); +} + +void rgbDriver::addCalibrationParametersToJSON(cJSON *json) +{ + // follows structure of calibration parameters in .h + // debug("add driver template calibration parameters to json"); + cJSON_AddNumberToObject(json, "calibration_time", configuration.cal_timestamp); +} + +void rgbDriver::setDriverDefaults() +{ + // debug("setting driver template driver defaults"); + // set default values for driver struct specific values + configuration.cal_timestamp = 0; +} + +unsigned int rgbDriver::millisecondsUntilNextReadingAvailable() +{ + return 1000; // 1 reading per second +} + +bool rgbDriver::isWarmedUp() +{ + return true; +} + +int rgbDriver::millisecondsToWarmUp() +{ + int warmupTime = 5000; + return warmupTime; +} \ No newline at end of file diff --git a/src/sensors/drivers/rgb_driver.h b/src/sensors/drivers/rgb_driver.h new file mode 100644 index 0000000..43894c3 --- /dev/null +++ b/src/sensors/drivers/rgb_driver.h @@ -0,0 +1,81 @@ +/* + * RRIV - Open Source Environmental Data Logging Platform + * Copyright (C) 20202 Zaven Arra zaven.arra@gmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ +#ifndef RGB_DRIVER +#define RGB_DRIVER + +#include "sensors/sensor.h" + + +#define RGB_DRIVER_TYPE_STRING "atlas_rgb" + +class rgbDriver : public I2CProtocolSensorDriver +{ + // configuration parameters specific to this driver + typedef struct + { + unsigned long long cal_timestamp; // 8 bytes for epoch time of calibration + } driver_configuration; + + public: + // Constructor + rgbDriver(); + ~rgbDriver(); + + // + // Interface Implementation + // + const char * getSensorTypeString(); + void setup(); + void stop(); + bool takeMeasurement(); + const char * getRawDataString(); + const char * getSummaryDataString(); + const char * getBaseColumnHeaders(); + void initCalibration(); + void calibrationStep(char *step, int arg_cnt, char ** args); + //previous uint32 + unsigned int millisecondsUntilNextReadingAvailable(); + bool isWarmedUp(); + int millisecondsToWarmUp(); + + protected: + void configureSpecificConfigurationsFromBytes(configuration_bytes_partition configurations); + configuration_bytes_partition getDriverSpecificConfigurationBytes(); + bool configureDriverFromJSON(cJSON *json); + void appendDriverSpecificConfigurationJSON(cJSON *json); + void setDriverDefaults(); + + private: + //sensor specific variables, functions, etc. + const char *sensorTypeString = RGB_DRIVER_TYPE_STRING; + driver_configuration configuration; + + /*value(s) to be placed in dataString, should correspond to number of + column headers and entries in dataString*/ + char value[42]; // sensor raw return(s) to be added to dataString + // Example of data string from instrument. May be incorrect. + // XXX,XXX,XXX,xyY,X.XXX,X.XXX,XXX,Lux,XXXXX + const char *baseColumnHeaders = "r,g,b,lux,lux_value,xyY,xyY_x,xyY_y,xyY_Y"; // will be written to .csv + char dataString[16]; // will be written to .csv + uint32 setupTime; // for unix time of setup to track when ready to take samples + int timeDiff; + + void addCalibrationParametersToJSON(cJSON *json); +}; + +#endif \ No newline at end of file diff --git a/src/system/command.cpp b/src/system/command.cpp index b4c219a..070e38b 100644 --- a/src/system/command.cpp +++ b/src/system/command.cpp @@ -276,7 +276,7 @@ void CommandInterface::_setInterval(int size) void setBurstSize(int arg_cnt, char **args) { if(arg_cnt < 2){ - invalidArgumentsMessage(F("set-burst_size NUMBER_OF_MEASUREMENTS_IN_BURST")); + invalidArgumentsMessage(F("set-burst-size NUMBER_OF_MEASUREMENTS_IN_BURST")); return; } @@ -398,8 +398,8 @@ void CommandInterface::_getConfig() cJSON_Delete(dataloggerConfiguration); - debug("sensorCount is:"); - debug(short(this->datalogger->sensorCount)); + // debug("sensorCount is:"); + // debug(short(this->datalogger->sensorCount)); for(unsigned short i=0; idatalogger->sensorCount; i++) { cJSON * sensorConfiguration= this->datalogger->getSensorConfiguration(i);