From 9dd98f94094b948fb960a9546dc16180b8310e4c Mon Sep 17 00:00:00 2001 From: akerr501 Date: Wed, 2 Sep 2020 16:38:02 -0700 Subject: [PATCH] Final updates --- .../SmartRock_Workshop/SmartRock_Workshop.ino | 133 ++++++++++++++++++ .../Lab Examples/SmartRock_Workshop/config.h | 33 +++++ src/Sensors/Analog.cpp | 2 +- 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 examples/Lab Examples/SmartRock_Workshop/SmartRock_Workshop.ino create mode 100644 examples/Lab Examples/SmartRock_Workshop/config.h diff --git a/examples/Lab Examples/SmartRock_Workshop/SmartRock_Workshop.ino b/examples/Lab Examples/SmartRock_Workshop/SmartRock_Workshop.ino new file mode 100644 index 000000000..1fa69959f --- /dev/null +++ b/examples/Lab Examples/SmartRock_Workshop/SmartRock_Workshop.ino @@ -0,0 +1,133 @@ +/////////////////////////////////////////////////////////////////////////////// + +// This is a basic example that demonstrates usage of the Hypnos board +// Deep sleep functionality. + +// The Hypnos board includes +// - SD +// - DS3231 RTC +// - Ability to power of peripherals + +// Further details about the Hypnos board can be found here: +// https://github.com/OPEnSLab-OSU/OPEnS-Lab-Home/wiki/Hypnos + +/////////////////////////////////////////////////////////////////////////////// + +#include + +// Include configuration +const char* json_config = +#include "config.h" +; + +// Set enabled modules +LoomFactory< + Enable::Internet::Disabled, + Enable::Sensors::Enabled, + Enable::Radios::Enabled, + Enable::Actuators::Enabled, + Enable::Max::Enabled +> ModuleFactory{}; + +LoomManager Loom{ &ModuleFactory }; + + +const int switchPin = 9; +int switchPos = 0; + +volatile bool rtc_flag = false; + +void wakeISR_RTC() { + // disable the interrupt + detachInterrupt(12); + rtc_flag = true; +} + +void setup() +{ + + pinMode(switchPin, INPUT); + // Needs to be done for Hypno Board + pinMode(5, OUTPUT); // Enable control of 3.3V rail + pinMode(6, OUTPUT); // Enable control of 5V rail + pinMode(12, INPUT_PULLUP); // Enable waiting for RTC interrupt, MUST use a pullup since signal is active low + pinMode(13, OUTPUT); + + //digitalWrite(switchPin, HIGH); + //See Above + digitalWrite(5, LOW); // Enable 3.3V rail + digitalWrite(6, HIGH); // Enable 5V rail + digitalWrite(13, LOW); + + Loom.begin_serial(true); + Loom.parse_config(json_config); + Loom.print_config(); + + // Register an interrupt on the RTC alarm pin + Loom.InterruptManager().register_ISR(12, wakeISR_RTC, LOW, ISR_Type::IMMEDIATE); + + LPrintln("\n ** Setup Complete ** "); + Serial.flush(); +} + + +void loop() +{ + //re-enable pin upon wake up + pinMode(switchPin, INPUT); + + ///////////////////////////////////////////// + //change interval depending the on position of pin + //interval is the variable that gets passed to TimeSpan function below + switchPos = digitalRead(switchPin); + int secs = 0; + int mins = 0; + if (switchPos == HIGH) { + mins = 1200; + }else{ + secs = 1; + } + ///////////////////////////////////////////// + + digitalWrite(5, LOW); // Disable 3.3V rail + digitalWrite(6, HIGH); // Disable 5V rail + digitalWrite(13, HIGH); + + // As it turns out, if the SD card is initialized and you change + // the states of the pins to ANY VALUE, the SD card will fail to + // write. As a result, we ensure that the board has been turned + // off at least once before we make any changes to the pin states + if (rtc_flag) { + pinMode(23, OUTPUT); + pinMode(24, OUTPUT); + pinMode(10, OUTPUT); + + delay(1000); + + Loom.power_up(); + } + + + Loom.measure(); + Loom.package(); + Loom.display_data(); + Loom.SDCARD().log(); + + // set the RTC alarm to a duration of 10 seconds with TimeSpan + Loom.InterruptManager().RTC_alarm_duration(TimeSpan(0,0,mins,secs)); + Loom.InterruptManager().reconnect_interrupt(12); + + digitalWrite(13, LOW); + digitalWrite(5, HIGH); // Enable 3.3V rail + digitalWrite(6, LOW); // Enable 5V rail + pinMode(23, INPUT); + pinMode(24, INPUT); + pinMode(10, INPUT); + + // Sleep Manager autmatically calls power_down on every sensor before sleeping + // And power_up after waking. + + rtc_flag = false; + Loom.SleepManager().sleep(); + while (!rtc_flag); +} diff --git a/examples/Lab Examples/SmartRock_Workshop/config.h b/examples/Lab Examples/SmartRock_Workshop/config.h new file mode 100644 index 000000000..877da35ed --- /dev/null +++ b/examples/Lab Examples/SmartRock_Workshop/config.h @@ -0,0 +1,33 @@ +"{\ + 'general':\ + {\ + 'name':'Device',\ + 'instance':1\ + },\ + 'components':[\ + {\ + 'name':'Analog',\ + 'params':[8,12,true,false,true,false,false,false,5,0,4,0,0,0]\ + },\ + {\ + 'name':'SD',\ + 'params': [true,1000,10,'data',true]\ + },\ + {\ + 'name':'DS3231',\ + 'params':[11, true]\ + },\ + {\ + 'name':'Interrupt_Manager',\ + 'params':'default'\ + },\ + {\ + 'name':'Sleep_Manager',\ + 'params':[true,false,1]\ + },\ + {\ + 'name':'MS5803',\ + 'params':[119]\ + }\ + ]\ +}" diff --git a/src/Sensors/Analog.cpp b/src/Sensors/Analog.cpp index 57115ad3e..8da97bcc9 100644 --- a/src/Sensors/Analog.cpp +++ b/src/Sensors/Analog.cpp @@ -305,7 +305,7 @@ float Loom_Analog::convert_turbidity(const uint16_t analog) const // return -1120.4 * (voltage * voltage) + (5742.3 * voltage) - 4352.9; - return analog // turbidity values are fairly qualitative, just returning the analog value for now + return analog; // turbidity values are fairly qualitative, just returning the analog value for now } ///////////////////////////////////////////////////////////////////////////////