From 8652793afa9a1845fc834e10826ffa7220dd479e Mon Sep 17 00:00:00 2001 From: jahnavithota2011 <34670246+jahnavithota2011@users.noreply.github.com> Date: Sun, 6 Feb 2022 23:23:39 -0500 Subject: [PATCH 01/14] Create PollingSensors.h --- libs/sensors/include/PollingSensors.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 libs/sensors/include/PollingSensors.h diff --git a/libs/sensors/include/PollingSensors.h b/libs/sensors/include/PollingSensors.h new file mode 100644 index 00000000..389e22ca --- /dev/null +++ b/libs/sensors/include/PollingSensors.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Sensor.h" +#include "mbed.h" + +class PollingSensors final : Sensor { + public: + PollingSensors(PinName clk, PinName miso, PinName cs = NC); + float read() override; + float alternateRead() override; + bool getStatus() const override; + [[nodiscard]] bool reset() override; + [[nodiscard]] bool update() override; + + //Add functions specific to sensor modules +}; From 7e801165c98cafcbbfab8716fb5836ad3781b2b3 Mon Sep 17 00:00:00 2001 From: jahnavithota2011 <34670246+jahnavithota2011@users.noreply.github.com> Date: Sun, 6 Feb 2022 23:39:58 -0500 Subject: [PATCH 02/14] Update PollingSensors.h --- libs/sensors/include/PollingSensors.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/sensors/include/PollingSensors.h b/libs/sensors/include/PollingSensors.h index 389e22ca..9e489c3a 100644 --- a/libs/sensors/include/PollingSensors.h +++ b/libs/sensors/include/PollingSensors.h @@ -11,6 +11,5 @@ class PollingSensors final : Sensor { bool getStatus() const override; [[nodiscard]] bool reset() override; [[nodiscard]] bool update() override; - - //Add functions specific to sensor modules + // Add functions specific to sensor modules }; From 994c81ac3a84102558675e184a94d6778bb9cba7 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 19:54:20 -0500 Subject: [PATCH 03/14] small errors --- libs/sensors/CMakeLists.txt | 10 + libs/sensors/include/PollingSensors.h | 48 ++- libs/sensors/src/PollingSensors.cpp | 30 ++ .../include/PinNames.h | 347 +++++++++--------- 4 files changed, 255 insertions(+), 180 deletions(-) create mode 100644 libs/sensors/src/PollingSensors.cpp diff --git a/libs/sensors/CMakeLists.txt b/libs/sensors/CMakeLists.txt index 835cb5c9..e3eb9625 100644 --- a/libs/sensors/CMakeLists.txt +++ b/libs/sensors/CMakeLists.txt @@ -21,3 +21,13 @@ target_link_libraries(CurrentSensor Sensor mbed-os ) +add_library(PollingSensors STATIC) +target_sources(PollingSensors PRIVATE src/PollingSensors.cpp) +target_include_directories(PollingSensors PUBLIC include) +target_link_libraries(PollingSensors + PRIVATE + Sensor + mbed-os + Logger + ) + diff --git a/libs/sensors/include/PollingSensors.h b/libs/sensors/include/PollingSensors.h index 9e489c3a..8721e273 100644 --- a/libs/sensors/include/PollingSensors.h +++ b/libs/sensors/include/PollingSensors.h @@ -3,13 +3,41 @@ #include "Sensor.h" #include "mbed.h" -class PollingSensors final : Sensor { - public: - PollingSensors(PinName clk, PinName miso, PinName cs = NC); - float read() override; - float alternateRead() override; - bool getStatus() const override; - [[nodiscard]] bool reset() override; - [[nodiscard]] bool update() override; - // Add functions specific to sensor modules -}; +namespace Sensor { + class PollingSensors final : Sensor { + public: + PollingSensors(); + +// float read() override; +// +// float alternateRead() override; +// +// bool getStatus() const override; +// +// [[nodiscard]] bool reset() override; +// +// [[nodiscard]] bool update() override; + + /* Functions specific to sensor modules*/ + + /* This function returns Moisture sensor value + * 0-300 - dry + * 300-700 - humid + * 700-900 - wet + * Returns -1 for fault + * */ + float moisture_monitoring(); + + /* This function returns CO2 sensor value in ppm\ + * Returns -1 for fault and 0 for preheating + * */ + float C02_monitoring(); + + private: + /*Pins configuration for moisture sensing*/ + AnalogIn moisture_in_adc; + + /*Pins configuration for CO2 sensing*/ + AnalogIn CO2_in_adc; + }; +} \ No newline at end of file diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp new file mode 100644 index 00000000..3ff34dfd --- /dev/null +++ b/libs/sensors/src/PollingSensors.cpp @@ -0,0 +1,30 @@ +#include "PollingSensors.h" + +#include "Logger.h" + +PollingSensors::PollingSensors() : moisture_in_adc(MOISTURE_IN), CO2_in_adc(CO2_IN) {} + +// The function currently logs a status message. Can be changed to return just a float indicating the sensor value +float moisture_monitoring() { + float moisture_reading = (moisture_in_adc.read_voltage() * 5.0) / 1023.0; + + if (moisture_reading < 0 && moisture_reading > 900) { + Utility::logger << "!!! MOISTURE FAULT:" << moisture_reading << "\n"; + return -1; + } + return moisture_reading; +} + +float C02_monitoring() { + float CO2_reading = CO2_in_adc.read_voltage() * 1000; + + if (CO2_reading <= 0) { + Utility::logger << "!!! CO2 FAULT:" << CO2_reading << "\n"; + return -1; + } else if (CO2_reading < 400) { + Utility::logger << "!!! CO2 PREHEATING:" << CO2_reading << "\n"; + return 0; + } + float concentration = ((CO2_reading - 400) * 50.0) / 16.0; + return concentration; +} diff --git a/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h b/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h index 5edb3c5a..fd96d79e 100644 --- a/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h +++ b/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h @@ -37,186 +37,193 @@ extern "C" { #endif -typedef enum { ALT0 = 0x100, ALT1 = 0x200, ALT2 = 0x300, ALT3 = 0x400 } ALTx; +typedef enum { + ALT0 = 0x100, ALT1 = 0x200, ALT2 = 0x300, ALT3 = 0x400 +} ALTx; typedef enum { - PA_0 = 0x00, - PA_0_ALT0 = PA_0 | ALT0, - PA_0_ALT1 = PA_0 | ALT1, - PA_1 = 0x01, - PA_1_ALT0 = PA_1 | ALT0, - PA_1_ALT1 = PA_1 | ALT1, - PA_2 = 0x02, - PA_3 = 0x03, - PA_4 = 0x04, - PA_4_ALT0 = PA_4 | ALT0, - PA_5 = 0x05, - PA_5_ALT0 = PA_5 | ALT0, - PA_6 = 0x06, - PA_6_ALT0 = PA_6 | ALT0, - PA_7 = 0x07, - PA_7_ALT0 = PA_7 | ALT0, - PA_7_ALT1 = PA_7 | ALT1, - PA_7_ALT2 = PA_7 | ALT2, - PA_8 = 0x08, - PA_9 = 0x09, - PA_10 = 0x0A, - PA_11 = 0x0B, - PA_12 = 0x0C, - PA_13 = 0x0D, - PA_14 = 0x0E, - PA_15 = 0x0F, - PA_15_ALT0 = PA_15 | ALT0, - - PB_0 = 0x10, - PB_0_ALT0 = PB_0 | ALT0, - PB_0_ALT1 = PB_0 | ALT1, - PB_1 = 0x11, - PB_1_ALT0 = PB_1 | ALT0, - PB_1_ALT1 = PB_1 | ALT1, - PB_2 = 0x12, - PB_3 = 0x13, - PB_3_ALT0 = PB_3 | ALT0, - PB_4 = 0x14, - PB_4_ALT0 = PB_4 | ALT0, - PB_4_ALT1 = PB_4 | ALT1, - PB_5 = 0x15, - PB_5_ALT0 = PB_5 | ALT0, - PB_5_ALT1 = PB_5 | ALT1, - PB_6 = 0x16, - PB_7 = 0x17, - PB_8 = 0x18, - PB_8_ALT0 = PB_8 | ALT0, - PB_8_ALT1 = PB_8 | ALT1, - PB_9 = 0x19, - PB_9_ALT0 = PB_9 | ALT0, - PB_9_ALT1 = PB_9 | ALT1, - PB_10 = 0x1A, - PB_12 = 0x1C, - PB_13 = 0x1D, - PB_14 = 0x1E, - PB_14_ALT0 = PB_14 | ALT0, - PB_14_ALT1 = PB_14 | ALT1, - PB_15 = 0x1F, - PB_15_ALT0 = PB_15 | ALT0, - PB_15_ALT1 = PB_15 | ALT1, - - PC_0 = 0x20, - PC_0_ALT0 = PC_0 | ALT0, - PC_0_ALT1 = PC_0 | ALT1, - PC_1 = 0x21, - PC_1_ALT0 = PC_1 | ALT0, - PC_1_ALT1 = PC_1 | ALT1, - PC_2 = 0x22, - PC_2_ALT0 = PC_2 | ALT0, - PC_2_ALT1 = PC_2 | ALT1, - PC_3 = 0x23, - PC_3_ALT0 = PC_3 | ALT0, - PC_3_ALT1 = PC_3 | ALT1, - PC_4 = 0x24, - PC_4_ALT0 = PC_4 | ALT0, - PC_5 = 0x25, - PC_5_ALT0 = PC_5 | ALT0, - PC_6 = 0x26, - PC_6_ALT0 = PC_6 | ALT0, - PC_7 = 0x27, - PC_7_ALT0 = PC_7 | ALT0, - PC_8 = 0x28, - PC_8_ALT0 = PC_8 | ALT0, - PC_9 = 0x29, - PC_9_ALT0 = PC_9 | ALT0, - PC_10 = 0x2A, - PC_10_ALT0 = PC_10 | ALT0, - PC_11 = 0x2B, - PC_11_ALT0 = PC_11 | ALT0, - PC_12 = 0x2C, - PC_13 = 0x2D, - PC_14 = 0x2E, - PC_15 = 0x2F, - - PD_2 = 0x32, - - PH_0 = 0x70, - PH_1 = 0x71, - - // ADC internal channels - ADC_TEMP = 0xF0, - ADC_VREF = 0xF1, - ADC_VBAT = 0xF2, - - // Not connected - NC = (int)0xFFFFFFFF, + PA_0 = 0x00, + PA_0_ALT0 = PA_0 | ALT0, + PA_0_ALT1 = PA_0 | ALT1, + PA_1 = 0x01, + PA_1_ALT0 = PA_1 | ALT0, + PA_1_ALT1 = PA_1 | ALT1, + PA_2 = 0x02, + PA_3 = 0x03, + PA_4 = 0x04, + PA_4_ALT0 = PA_4 | ALT0, + PA_5 = 0x05, + PA_5_ALT0 = PA_5 | ALT0, + PA_6 = 0x06, + PA_6_ALT0 = PA_6 | ALT0, + PA_7 = 0x07, + PA_7_ALT0 = PA_7 | ALT0, + PA_7_ALT1 = PA_7 | ALT1, + PA_7_ALT2 = PA_7 | ALT2, + PA_8 = 0x08, + PA_9 = 0x09, + PA_10 = 0x0A, + PA_11 = 0x0B, + PA_12 = 0x0C, + PA_13 = 0x0D, + PA_14 = 0x0E, + PA_15 = 0x0F, + PA_15_ALT0 = PA_15 | ALT0, + + PB_0 = 0x10, + PB_0_ALT0 = PB_0 | ALT0, + PB_0_ALT1 = PB_0 | ALT1, + PB_1 = 0x11, + PB_1_ALT0 = PB_1 | ALT0, + PB_1_ALT1 = PB_1 | ALT1, + PB_2 = 0x12, + PB_3 = 0x13, + PB_3_ALT0 = PB_3 | ALT0, + PB_4 = 0x14, + PB_4_ALT0 = PB_4 | ALT0, + PB_4_ALT1 = PB_4 | ALT1, + PB_5 = 0x15, + PB_5_ALT0 = PB_5 | ALT0, + PB_5_ALT1 = PB_5 | ALT1, + PB_6 = 0x16, + PB_7 = 0x17, + PB_8 = 0x18, + PB_8_ALT0 = PB_8 | ALT0, + PB_8_ALT1 = PB_8 | ALT1, + PB_9 = 0x19, + PB_9_ALT0 = PB_9 | ALT0, + PB_9_ALT1 = PB_9 | ALT1, + PB_10 = 0x1A, + PB_12 = 0x1C, + PB_13 = 0x1D, + PB_14 = 0x1E, + PB_14_ALT0 = PB_14 | ALT0, + PB_14_ALT1 = PB_14 | ALT1, + PB_15 = 0x1F, + PB_15_ALT0 = PB_15 | ALT0, + PB_15_ALT1 = PB_15 | ALT1, + + PC_0 = 0x20, + PC_0_ALT0 = PC_0 | ALT0, + PC_0_ALT1 = PC_0 | ALT1, + PC_1 = 0x21, + PC_1_ALT0 = PC_1 | ALT0, + PC_1_ALT1 = PC_1 | ALT1, + PC_2 = 0x22, + PC_2_ALT0 = PC_2 | ALT0, + PC_2_ALT1 = PC_2 | ALT1, + PC_3 = 0x23, + PC_3_ALT0 = PC_3 | ALT0, + PC_3_ALT1 = PC_3 | ALT1, + PC_4 = 0x24, + PC_4_ALT0 = PC_4 | ALT0, + PC_5 = 0x25, + PC_5_ALT0 = PC_5 | ALT0, + PC_6 = 0x26, + PC_6_ALT0 = PC_6 | ALT0, + PC_7 = 0x27, + PC_7_ALT0 = PC_7 | ALT0, + PC_8 = 0x28, + PC_8_ALT0 = PC_8 | ALT0, + PC_9 = 0x29, + PC_9_ALT0 = PC_9 | ALT0, + PC_10 = 0x2A, + PC_10_ALT0 = PC_10 | ALT0, + PC_11 = 0x2B, + PC_11_ALT0 = PC_11 | ALT0, + PC_12 = 0x2C, + PC_13 = 0x2D, + PC_14 = 0x2E, + PC_15 = 0x2F, + + PD_2 = 0x32, + + PH_0 = 0x70, + PH_1 = 0x71, + + // ADC internal channels + ADC_TEMP = 0xF0, + ADC_VREF = 0xF1, + ADC_VBAT = 0xF2, + + // Not connected + NC = (int) 0xFFFFFFFF, #ifdef MBED_CONF_TARGET_STDIO_UART_TX - STDIO_UART_TX = NC, + STDIO_UART_TX = NC, #else - STDIO_UART_TX = NC, + STDIO_UART_TX = NC, #endif #ifdef MBED_CONF_TARGET_STDIO_UART_RX - STDIO_UART_RX = NC, + STDIO_UART_RX = NC, #else - STDIO_UART_RX = NC, + STDIO_UART_RX = NC, #endif - /**** UI ****/ - LED1 = PC_0, - LED_R = PC_1, - LED_G = PC_2, - LED_B = PC_3, - - BUTTON_1 = PA_2, - - /**** Servo Pins *****/ - SRVO_PWM_SHVL = PB_2, - SRVO_PWM_LID = PB_10, - - /**** Actuator Pins ****/ - MTR_PWM_ELVTR = PA_6, - MTR_DIR_ELVTR = PC_5, - MTR_PWM_CENTFGE = PA_7, - MTR_DIR_CENTFGE = PC_4, - - /**** Limit Switch Pins ****/ - LIM_SW_CENTFGE_DN = PB_8, - LIM_SW_CENTFGE_UP = PC_13, - LIM_SW_ELVTR_DN = PC_14, - LIM_SW_ELVTR_UP = PC_15, - - /**** Encoder Pins ****/ - ENC_A_LIFT = PB_6, - ENC_B_LIFT = PB_7, - ENC_MISO_CENTFGE = PB_4, - ENC_SCK_CENTFGE = PA_5, - ENC_CS_CENTFGE = PA_4, - - /**** Serial Interface Pins ****/ - CAN1_TX = PA_12, - CAN1_RX = PA_11, - - CAN2_TX = PB_13, - CAN2_RX = PB_12, - - CAN_TX = CAN1_TX, - CAN_RX = CAN1_RX, - - SERIAL_TX = STDIO_UART_TX, - SERIAL_RX = STDIO_UART_RX, - - USBTX = STDIO_UART_TX, - USBRX = STDIO_UART_RX, - - TEMP_MOIST_I2C_SCL = PA_8, - TEMP_MOIST_I2C_SDA = PC_9, - - /**** OSCILLATOR pins ****/ - RCC_OSC_IN = PH_0, - RCC_OSC_OUT = PH_1, - - /**** DEBUG pins ****/ - SYS_JTCK_SWCLK = PA_14, - SYS_JTDI = PA_15, - SYS_JTDO_SWO = PB_3, - SYS_JTMS_SWDIO = PA_13 + /**** UI ****/ + LED1 = PC_0, + LED_R = PC_1, + LED_G = PC_2, + LED_B = PC_3, + + BUTTON_1 = PA_2, + + /**** Servo Pins *****/ + SRVO_PWM_SHVL = PB_2, + SRVO_PWM_LID = PB_10, + + /**** Actuator Pins ****/ + MTR_PWM_ELVTR = PA_6, + MTR_DIR_ELVTR = PC_5, + MTR_PWM_CENTFGE = PA_7, + MTR_DIR_CENTFGE = PC_4, + + /**** Limit Switch Pins ****/ + LIM_SW_CENTFGE_DN = PB_8, + LIM_SW_CENTFGE_UP = PC_13, + LIM_SW_ELVTR_DN = PC_14, + LIM_SW_ELVTR_UP = PC_15, + + /**** Encoder Pins ****/ + ENC_A_LIFT = PB_6, + ENC_B_LIFT = PB_7, + ENC_MISO_CENTFGE = PB_4, + ENC_SCK_CENTFGE = PA_5, + ENC_CS_CENTFGE = PA_4, + + /**** Serial Interface Pins ****/ + CAN1_TX = PA_12, + CAN1_RX = PA_11, + + CAN2_TX = PB_13, + CAN2_RX = PB_12, + + CAN_TX = CAN1_TX, + CAN_RX = CAN1_RX, + + SERIAL_TX = STDIO_UART_TX, + SERIAL_RX = STDIO_UART_RX, + + USBTX = STDIO_UART_TX, + USBRX = STDIO_UART_RX, + + TEMP_MOIST_I2C_SCL = PA_8, + TEMP_MOIST_I2C_SDA = PC_9, + + /**** OSCILLATOR pins ****/ + RCC_OSC_IN = PH_0, + RCC_OSC_OUT = PH_1, + + /**** DEBUG pins ****/ + SYS_JTCK_SWCLK = PA_14, + SYS_JTDI = PA_15, + SYS_JTDO_SWO = PB_3, + SYS_JTMS_SWDIO = PA_13, + + /**** POLLING SENSOR pins ****/ + /* TODO: CHANGE THE PIN NUMBERS ONCE SCHEMATIC IS READY*/ + MOISTURE_IN = PC_7, + CO2_IN = PC_8, } PinName; #ifdef __cplusplus From 756ae60ee9dd480d005bc553c28bd9da1203aeec Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 20:40:20 -0500 Subject: [PATCH 04/14] smal fix --- libs/sensors/src/PollingSensors.cpp | 34 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp index 3ff34dfd..7e05b674 100644 --- a/libs/sensors/src/PollingSensors.cpp +++ b/libs/sensors/src/PollingSensors.cpp @@ -2,29 +2,31 @@ #include "Logger.h" +using namespace Sensor; + PollingSensors::PollingSensors() : moisture_in_adc(MOISTURE_IN), CO2_in_adc(CO2_IN) {} // The function currently logs a status message. Can be changed to return just a float indicating the sensor value float moisture_monitoring() { - float moisture_reading = (moisture_in_adc.read_voltage() * 5.0) / 1023.0; + float moisture_reading = (moisture_in_adc.read_voltage() * 5.0) / 1023.0; - if (moisture_reading < 0 && moisture_reading > 900) { - Utility::logger << "!!! MOISTURE FAULT:" << moisture_reading << "\n"; - return -1; - } - return moisture_reading; + if (moisture_reading < 0 && moisture_reading > 900) { + Utility::logger << "!!! MOISTURE FAULT:" << moisture_reading << "\n"; + return -1; + } + return moisture_reading; } float C02_monitoring() { - float CO2_reading = CO2_in_adc.read_voltage() * 1000; + float CO2_reading = CO2_in_adc.read_voltage() * 1000; - if (CO2_reading <= 0) { - Utility::logger << "!!! CO2 FAULT:" << CO2_reading << "\n"; - return -1; - } else if (CO2_reading < 400) { - Utility::logger << "!!! CO2 PREHEATING:" << CO2_reading << "\n"; - return 0; - } - float concentration = ((CO2_reading - 400) * 50.0) / 16.0; - return concentration; + if (CO2_reading <= 0) { + Utility::logger << "!!! CO2 FAULT:" << CO2_reading << "\n"; + return -1; + } else if (CO2_reading < 400) { + Utility::logger << "!!! CO2 PREHEATING:" << CO2_reading << "\n"; + return 0; + } + float concentration = ((CO2_reading - 400) * 50.0) / 16.0; + return concentration; } From ba7099d440d26841417fc07704999b422619c018 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 20:59:14 -0500 Subject: [PATCH 05/14] clan --- .../include/PinNames.h | 352 +++++++++--------- 1 file changed, 175 insertions(+), 177 deletions(-) diff --git a/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h b/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h index fd96d79e..098cd651 100644 --- a/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h +++ b/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h @@ -37,193 +37,191 @@ extern "C" { #endif -typedef enum { - ALT0 = 0x100, ALT1 = 0x200, ALT2 = 0x300, ALT3 = 0x400 -} ALTx; +typedef enum { ALT0 = 0x100, ALT1 = 0x200, ALT2 = 0x300, ALT3 = 0x400 } ALTx; typedef enum { - PA_0 = 0x00, - PA_0_ALT0 = PA_0 | ALT0, - PA_0_ALT1 = PA_0 | ALT1, - PA_1 = 0x01, - PA_1_ALT0 = PA_1 | ALT0, - PA_1_ALT1 = PA_1 | ALT1, - PA_2 = 0x02, - PA_3 = 0x03, - PA_4 = 0x04, - PA_4_ALT0 = PA_4 | ALT0, - PA_5 = 0x05, - PA_5_ALT0 = PA_5 | ALT0, - PA_6 = 0x06, - PA_6_ALT0 = PA_6 | ALT0, - PA_7 = 0x07, - PA_7_ALT0 = PA_7 | ALT0, - PA_7_ALT1 = PA_7 | ALT1, - PA_7_ALT2 = PA_7 | ALT2, - PA_8 = 0x08, - PA_9 = 0x09, - PA_10 = 0x0A, - PA_11 = 0x0B, - PA_12 = 0x0C, - PA_13 = 0x0D, - PA_14 = 0x0E, - PA_15 = 0x0F, - PA_15_ALT0 = PA_15 | ALT0, - - PB_0 = 0x10, - PB_0_ALT0 = PB_0 | ALT0, - PB_0_ALT1 = PB_0 | ALT1, - PB_1 = 0x11, - PB_1_ALT0 = PB_1 | ALT0, - PB_1_ALT1 = PB_1 | ALT1, - PB_2 = 0x12, - PB_3 = 0x13, - PB_3_ALT0 = PB_3 | ALT0, - PB_4 = 0x14, - PB_4_ALT0 = PB_4 | ALT0, - PB_4_ALT1 = PB_4 | ALT1, - PB_5 = 0x15, - PB_5_ALT0 = PB_5 | ALT0, - PB_5_ALT1 = PB_5 | ALT1, - PB_6 = 0x16, - PB_7 = 0x17, - PB_8 = 0x18, - PB_8_ALT0 = PB_8 | ALT0, - PB_8_ALT1 = PB_8 | ALT1, - PB_9 = 0x19, - PB_9_ALT0 = PB_9 | ALT0, - PB_9_ALT1 = PB_9 | ALT1, - PB_10 = 0x1A, - PB_12 = 0x1C, - PB_13 = 0x1D, - PB_14 = 0x1E, - PB_14_ALT0 = PB_14 | ALT0, - PB_14_ALT1 = PB_14 | ALT1, - PB_15 = 0x1F, - PB_15_ALT0 = PB_15 | ALT0, - PB_15_ALT1 = PB_15 | ALT1, - - PC_0 = 0x20, - PC_0_ALT0 = PC_0 | ALT0, - PC_0_ALT1 = PC_0 | ALT1, - PC_1 = 0x21, - PC_1_ALT0 = PC_1 | ALT0, - PC_1_ALT1 = PC_1 | ALT1, - PC_2 = 0x22, - PC_2_ALT0 = PC_2 | ALT0, - PC_2_ALT1 = PC_2 | ALT1, - PC_3 = 0x23, - PC_3_ALT0 = PC_3 | ALT0, - PC_3_ALT1 = PC_3 | ALT1, - PC_4 = 0x24, - PC_4_ALT0 = PC_4 | ALT0, - PC_5 = 0x25, - PC_5_ALT0 = PC_5 | ALT0, - PC_6 = 0x26, - PC_6_ALT0 = PC_6 | ALT0, - PC_7 = 0x27, - PC_7_ALT0 = PC_7 | ALT0, - PC_8 = 0x28, - PC_8_ALT0 = PC_8 | ALT0, - PC_9 = 0x29, - PC_9_ALT0 = PC_9 | ALT0, - PC_10 = 0x2A, - PC_10_ALT0 = PC_10 | ALT0, - PC_11 = 0x2B, - PC_11_ALT0 = PC_11 | ALT0, - PC_12 = 0x2C, - PC_13 = 0x2D, - PC_14 = 0x2E, - PC_15 = 0x2F, - - PD_2 = 0x32, - - PH_0 = 0x70, - PH_1 = 0x71, - - // ADC internal channels - ADC_TEMP = 0xF0, - ADC_VREF = 0xF1, - ADC_VBAT = 0xF2, - - // Not connected - NC = (int) 0xFFFFFFFF, + PA_0 = 0x00, + PA_0_ALT0 = PA_0 | ALT0, + PA_0_ALT1 = PA_0 | ALT1, + PA_1 = 0x01, + PA_1_ALT0 = PA_1 | ALT0, + PA_1_ALT1 = PA_1 | ALT1, + PA_2 = 0x02, + PA_3 = 0x03, + PA_4 = 0x04, + PA_4_ALT0 = PA_4 | ALT0, + PA_5 = 0x05, + PA_5_ALT0 = PA_5 | ALT0, + PA_6 = 0x06, + PA_6_ALT0 = PA_6 | ALT0, + PA_7 = 0x07, + PA_7_ALT0 = PA_7 | ALT0, + PA_7_ALT1 = PA_7 | ALT1, + PA_7_ALT2 = PA_7 | ALT2, + PA_8 = 0x08, + PA_9 = 0x09, + PA_10 = 0x0A, + PA_11 = 0x0B, + PA_12 = 0x0C, + PA_13 = 0x0D, + PA_14 = 0x0E, + PA_15 = 0x0F, + PA_15_ALT0 = PA_15 | ALT0, + + PB_0 = 0x10, + PB_0_ALT0 = PB_0 | ALT0, + PB_0_ALT1 = PB_0 | ALT1, + PB_1 = 0x11, + PB_1_ALT0 = PB_1 | ALT0, + PB_1_ALT1 = PB_1 | ALT1, + PB_2 = 0x12, + PB_3 = 0x13, + PB_3_ALT0 = PB_3 | ALT0, + PB_4 = 0x14, + PB_4_ALT0 = PB_4 | ALT0, + PB_4_ALT1 = PB_4 | ALT1, + PB_5 = 0x15, + PB_5_ALT0 = PB_5 | ALT0, + PB_5_ALT1 = PB_5 | ALT1, + PB_6 = 0x16, + PB_7 = 0x17, + PB_8 = 0x18, + PB_8_ALT0 = PB_8 | ALT0, + PB_8_ALT1 = PB_8 | ALT1, + PB_9 = 0x19, + PB_9_ALT0 = PB_9 | ALT0, + PB_9_ALT1 = PB_9 | ALT1, + PB_10 = 0x1A, + PB_12 = 0x1C, + PB_13 = 0x1D, + PB_14 = 0x1E, + PB_14_ALT0 = PB_14 | ALT0, + PB_14_ALT1 = PB_14 | ALT1, + PB_15 = 0x1F, + PB_15_ALT0 = PB_15 | ALT0, + PB_15_ALT1 = PB_15 | ALT1, + + PC_0 = 0x20, + PC_0_ALT0 = PC_0 | ALT0, + PC_0_ALT1 = PC_0 | ALT1, + PC_1 = 0x21, + PC_1_ALT0 = PC_1 | ALT0, + PC_1_ALT1 = PC_1 | ALT1, + PC_2 = 0x22, + PC_2_ALT0 = PC_2 | ALT0, + PC_2_ALT1 = PC_2 | ALT1, + PC_3 = 0x23, + PC_3_ALT0 = PC_3 | ALT0, + PC_3_ALT1 = PC_3 | ALT1, + PC_4 = 0x24, + PC_4_ALT0 = PC_4 | ALT0, + PC_5 = 0x25, + PC_5_ALT0 = PC_5 | ALT0, + PC_6 = 0x26, + PC_6_ALT0 = PC_6 | ALT0, + PC_7 = 0x27, + PC_7_ALT0 = PC_7 | ALT0, + PC_8 = 0x28, + PC_8_ALT0 = PC_8 | ALT0, + PC_9 = 0x29, + PC_9_ALT0 = PC_9 | ALT0, + PC_10 = 0x2A, + PC_10_ALT0 = PC_10 | ALT0, + PC_11 = 0x2B, + PC_11_ALT0 = PC_11 | ALT0, + PC_12 = 0x2C, + PC_13 = 0x2D, + PC_14 = 0x2E, + PC_15 = 0x2F, + + PD_2 = 0x32, + + PH_0 = 0x70, + PH_1 = 0x71, + + // ADC internal channels + ADC_TEMP = 0xF0, + ADC_VREF = 0xF1, + ADC_VBAT = 0xF2, + + // Not connected + NC = (int)0xFFFFFFFF, #ifdef MBED_CONF_TARGET_STDIO_UART_TX - STDIO_UART_TX = NC, + STDIO_UART_TX = NC, #else - STDIO_UART_TX = NC, + STDIO_UART_TX = NC, #endif #ifdef MBED_CONF_TARGET_STDIO_UART_RX - STDIO_UART_RX = NC, + STDIO_UART_RX = NC, #else - STDIO_UART_RX = NC, + STDIO_UART_RX = NC, #endif - /**** UI ****/ - LED1 = PC_0, - LED_R = PC_1, - LED_G = PC_2, - LED_B = PC_3, - - BUTTON_1 = PA_2, - - /**** Servo Pins *****/ - SRVO_PWM_SHVL = PB_2, - SRVO_PWM_LID = PB_10, - - /**** Actuator Pins ****/ - MTR_PWM_ELVTR = PA_6, - MTR_DIR_ELVTR = PC_5, - MTR_PWM_CENTFGE = PA_7, - MTR_DIR_CENTFGE = PC_4, - - /**** Limit Switch Pins ****/ - LIM_SW_CENTFGE_DN = PB_8, - LIM_SW_CENTFGE_UP = PC_13, - LIM_SW_ELVTR_DN = PC_14, - LIM_SW_ELVTR_UP = PC_15, - - /**** Encoder Pins ****/ - ENC_A_LIFT = PB_6, - ENC_B_LIFT = PB_7, - ENC_MISO_CENTFGE = PB_4, - ENC_SCK_CENTFGE = PA_5, - ENC_CS_CENTFGE = PA_4, - - /**** Serial Interface Pins ****/ - CAN1_TX = PA_12, - CAN1_RX = PA_11, - - CAN2_TX = PB_13, - CAN2_RX = PB_12, - - CAN_TX = CAN1_TX, - CAN_RX = CAN1_RX, - - SERIAL_TX = STDIO_UART_TX, - SERIAL_RX = STDIO_UART_RX, - - USBTX = STDIO_UART_TX, - USBRX = STDIO_UART_RX, - - TEMP_MOIST_I2C_SCL = PA_8, - TEMP_MOIST_I2C_SDA = PC_9, - - /**** OSCILLATOR pins ****/ - RCC_OSC_IN = PH_0, - RCC_OSC_OUT = PH_1, - - /**** DEBUG pins ****/ - SYS_JTCK_SWCLK = PA_14, - SYS_JTDI = PA_15, - SYS_JTDO_SWO = PB_3, - SYS_JTMS_SWDIO = PA_13, - - /**** POLLING SENSOR pins ****/ - /* TODO: CHANGE THE PIN NUMBERS ONCE SCHEMATIC IS READY*/ - MOISTURE_IN = PC_7, - CO2_IN = PC_8, + /**** UI ****/ + LED1 = PC_0, + LED_R = PC_1, + LED_G = PC_2, + LED_B = PC_3, + + BUTTON_1 = PA_2, + + /**** Servo Pins *****/ + SRVO_PWM_SHVL = PB_2, + SRVO_PWM_LID = PB_10, + + /**** Actuator Pins ****/ + MTR_PWM_ELVTR = PA_6, + MTR_DIR_ELVTR = PC_5, + MTR_PWM_CENTFGE = PA_7, + MTR_DIR_CENTFGE = PC_4, + + /**** Limit Switch Pins ****/ + LIM_SW_CENTFGE_DN = PB_8, + LIM_SW_CENTFGE_UP = PC_13, + LIM_SW_ELVTR_DN = PC_14, + LIM_SW_ELVTR_UP = PC_15, + + /**** Encoder Pins ****/ + ENC_A_LIFT = PB_6, + ENC_B_LIFT = PB_7, + ENC_MISO_CENTFGE = PB_4, + ENC_SCK_CENTFGE = PA_5, + ENC_CS_CENTFGE = PA_4, + + /**** Serial Interface Pins ****/ + CAN1_TX = PA_12, + CAN1_RX = PA_11, + + CAN2_TX = PB_13, + CAN2_RX = PB_12, + + CAN_TX = CAN1_TX, + CAN_RX = CAN1_RX, + + SERIAL_TX = STDIO_UART_TX, + SERIAL_RX = STDIO_UART_RX, + + USBTX = STDIO_UART_TX, + USBRX = STDIO_UART_RX, + + TEMP_MOIST_I2C_SCL = PA_8, + TEMP_MOIST_I2C_SDA = PC_9, + + /**** OSCILLATOR pins ****/ + RCC_OSC_IN = PH_0, + RCC_OSC_OUT = PH_1, + + /**** DEBUG pins ****/ + SYS_JTCK_SWCLK = PA_14, + SYS_JTDI = PA_15, + SYS_JTDO_SWO = PB_3, + SYS_JTMS_SWDIO = PA_13, + + /**** POLLING SENSOR pins ****/ + /* TODO: CHANGE THE PIN NUMBERS ONCE SCHEMATIC IS READY*/ + MOISTURE_IN = PC_7, + CO2_IN = PC_8, } PinName; #ifdef __cplusplus From 82fd81474e01d2231acce8b8541eff8e0d1cc40d Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 21:06:34 -0500 Subject: [PATCH 06/14] clang fix --- libs/sensors/include/PollingSensors.h | 74 +++++++++++++-------------- libs/sensors/src/PollingSensors.cpp | 32 ++++++------ 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/libs/sensors/include/PollingSensors.h b/libs/sensors/include/PollingSensors.h index 8721e273..ac5c2d5a 100644 --- a/libs/sensors/include/PollingSensors.h +++ b/libs/sensors/include/PollingSensors.h @@ -4,40 +4,40 @@ #include "mbed.h" namespace Sensor { - class PollingSensors final : Sensor { - public: - PollingSensors(); - -// float read() override; -// -// float alternateRead() override; -// -// bool getStatus() const override; -// -// [[nodiscard]] bool reset() override; -// -// [[nodiscard]] bool update() override; - - /* Functions specific to sensor modules*/ - - /* This function returns Moisture sensor value - * 0-300 - dry - * 300-700 - humid - * 700-900 - wet - * Returns -1 for fault - * */ - float moisture_monitoring(); - - /* This function returns CO2 sensor value in ppm\ - * Returns -1 for fault and 0 for preheating - * */ - float C02_monitoring(); - - private: - /*Pins configuration for moisture sensing*/ - AnalogIn moisture_in_adc; - - /*Pins configuration for CO2 sensing*/ - AnalogIn CO2_in_adc; - }; -} \ No newline at end of file +class PollingSensors final : Sensor { + public: + PollingSensors(); + + // float read() override; + // + // float alternateRead() override; + // + // bool getStatus() const override; + // + // [[nodiscard]] bool reset() override; + // + // [[nodiscard]] bool update() override; + + /* Functions specific to sensor modules*/ + + /* This function returns Moisture sensor value + * 0-300 - dry + * 300-700 - humid + * 700-900 - wet + * Returns -1 for fault + * */ + float moisture_monitoring(); + + /* This function returns CO2 sensor value in ppm\ + * Returns -1 for fault and 0 for preheating + * */ + float C02_monitoring(); + + private: + /*Pins configuration for moisture sensing*/ + AnalogIn moisture_in_adc; + + /*Pins configuration for CO2 sensing*/ + AnalogIn CO2_in_adc; +}; +} // namespace Sensor \ No newline at end of file diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp index 7e05b674..5e04f656 100644 --- a/libs/sensors/src/PollingSensors.cpp +++ b/libs/sensors/src/PollingSensors.cpp @@ -8,25 +8,25 @@ PollingSensors::PollingSensors() : moisture_in_adc(MOISTURE_IN), CO2_in_adc(CO2_ // The function currently logs a status message. Can be changed to return just a float indicating the sensor value float moisture_monitoring() { - float moisture_reading = (moisture_in_adc.read_voltage() * 5.0) / 1023.0; + float moisture_reading = (moisture_in_adc.read_voltage() * 5.0) / 1023.0; - if (moisture_reading < 0 && moisture_reading > 900) { - Utility::logger << "!!! MOISTURE FAULT:" << moisture_reading << "\n"; - return -1; - } - return moisture_reading; + if (moisture_reading < 0 && moisture_reading > 900) { + Utility::logger << "!!! MOISTURE FAULT:" << moisture_reading << "\n"; + return -1; + } + return moisture_reading; } float C02_monitoring() { - float CO2_reading = CO2_in_adc.read_voltage() * 1000; + float CO2_reading = CO2_in_adc.read_voltage() * 1000; - if (CO2_reading <= 0) { - Utility::logger << "!!! CO2 FAULT:" << CO2_reading << "\n"; - return -1; - } else if (CO2_reading < 400) { - Utility::logger << "!!! CO2 PREHEATING:" << CO2_reading << "\n"; - return 0; - } - float concentration = ((CO2_reading - 400) * 50.0) / 16.0; - return concentration; + if (CO2_reading <= 0) { + Utility::logger << "!!! CO2 FAULT:" << CO2_reading << "\n"; + return -1; + } else if (CO2_reading < 400) { + Utility::logger << "!!! CO2 PREHEATING:" << CO2_reading << "\n"; + return 0; + } + float concentration = ((CO2_reading - 400) * 50.0) / 16.0; + return concentration; } From bd38049c7a2b327d4b8584324e3053df6c9fdb7b Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 21:27:39 -0500 Subject: [PATCH 07/14] scope fix --- libs/sensors/include/PollingSensors.h | 2 +- libs/sensors/src/PollingSensors.cpp | 5 ++++- targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h | 7 +------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libs/sensors/include/PollingSensors.h b/libs/sensors/include/PollingSensors.h index ac5c2d5a..8c0d691b 100644 --- a/libs/sensors/include/PollingSensors.h +++ b/libs/sensors/include/PollingSensors.h @@ -6,7 +6,7 @@ namespace Sensor { class PollingSensors final : Sensor { public: - PollingSensors(); + PollingSensors(PinName moisture_in, PinName co2_in); // float read() override; // diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp index 5e04f656..878d1033 100644 --- a/libs/sensors/src/PollingSensors.cpp +++ b/libs/sensors/src/PollingSensors.cpp @@ -4,7 +4,10 @@ using namespace Sensor; -PollingSensors::PollingSensors() : moisture_in_adc(MOISTURE_IN), CO2_in_adc(CO2_IN) {} +PollingSensors::PollingSensors(PinName moisture_in, PinName co2_in) { + moisture_in_adc = MOISTURE_IN; + CO2_in_adc = CO2_IN; +} // The function currently logs a status message. Can be changed to return just a float indicating the sensor value float moisture_monitoring() { diff --git a/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h b/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h index 098cd651..5edb3c5a 100644 --- a/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h +++ b/targets/TARGET_SCIENCE_REV2_2021/include/PinNames.h @@ -216,12 +216,7 @@ typedef enum { SYS_JTCK_SWCLK = PA_14, SYS_JTDI = PA_15, SYS_JTDO_SWO = PB_3, - SYS_JTMS_SWDIO = PA_13, - - /**** POLLING SENSOR pins ****/ - /* TODO: CHANGE THE PIN NUMBERS ONCE SCHEMATIC IS READY*/ - MOISTURE_IN = PC_7, - CO2_IN = PC_8, + SYS_JTMS_SWDIO = PA_13 } PinName; #ifdef __cplusplus From 2d7124e78a0074d2a9a987f6a8334ae5b45644f9 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 22:21:07 -0500 Subject: [PATCH 08/14] constructor fix --- libs/sensors/src/PollingSensors.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp index 878d1033..e1e23298 100644 --- a/libs/sensors/src/PollingSensors.cpp +++ b/libs/sensors/src/PollingSensors.cpp @@ -4,10 +4,7 @@ using namespace Sensor; -PollingSensors::PollingSensors(PinName moisture_in, PinName co2_in) { - moisture_in_adc = MOISTURE_IN; - CO2_in_adc = CO2_IN; -} +PollingSensors::PollingSensors() : moisture_in_adc(moisture_in), CO2_in_adc(co2_in) {} // The function currently logs a status message. Can be changed to return just a float indicating the sensor value float moisture_monitoring() { From 696b6887b11e497b7f1ca6a5d80b6f8ad2142010 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 22:29:33 -0500 Subject: [PATCH 09/14] constructor fix --- libs/sensors/src/PollingSensors.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp index e1e23298..1cd95dc2 100644 --- a/libs/sensors/src/PollingSensors.cpp +++ b/libs/sensors/src/PollingSensors.cpp @@ -4,7 +4,8 @@ using namespace Sensor; -PollingSensors::PollingSensors() : moisture_in_adc(moisture_in), CO2_in_adc(co2_in) {} +PollingSensors::PollingSensors(PinName moisture_in, PinName co2_in) + : moisture_in_adc(moisture_in), CO2_in_adc(co2_in) {} // The function currently logs a status message. Can be changed to return just a float indicating the sensor value float moisture_monitoring() { From bcb278f3d076989c3c7f706d4203dae1cc906500 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 28 Feb 2022 22:43:57 -0500 Subject: [PATCH 10/14] function fix --- libs/sensors/src/PollingSensors.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp index 1cd95dc2..7cce7f78 100644 --- a/libs/sensors/src/PollingSensors.cpp +++ b/libs/sensors/src/PollingSensors.cpp @@ -8,7 +8,7 @@ PollingSensors::PollingSensors(PinName moisture_in, PinName co2_in) : moisture_in_adc(moisture_in), CO2_in_adc(co2_in) {} // The function currently logs a status message. Can be changed to return just a float indicating the sensor value -float moisture_monitoring() { +float PollingSensors::moisture_monitoring() { float moisture_reading = (moisture_in_adc.read_voltage() * 5.0) / 1023.0; if (moisture_reading < 0 && moisture_reading > 900) { @@ -18,7 +18,7 @@ float moisture_monitoring() { return moisture_reading; } -float C02_monitoring() { +float PollingSensors::C02_monitoring() { float CO2_reading = CO2_in_adc.read_voltage() * 1000; if (CO2_reading <= 0) { From 6081e5641ca8a036b3239ae16f1b223c2efa69f8 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Thu, 10 Mar 2022 12:13:36 -0500 Subject: [PATCH 11/14] overrride --- libs/sensors/include/PollingSensors.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/sensors/include/PollingSensors.h b/libs/sensors/include/PollingSensors.h index 8c0d691b..5c086dbe 100644 --- a/libs/sensors/include/PollingSensors.h +++ b/libs/sensors/include/PollingSensors.h @@ -8,15 +8,15 @@ class PollingSensors final : Sensor { public: PollingSensors(PinName moisture_in, PinName co2_in); - // float read() override; - // - // float alternateRead() override; - // - // bool getStatus() const override; - // - // [[nodiscard]] bool reset() override; - // - // [[nodiscard]] bool update() override; + float read() override {} + + float alternateRead() override {} + + bool getStatus() const override {} + + [[nodiscard]] bool reset() override {} + + [[nodiscard]] bool update() override {} /* Functions specific to sensor modules*/ From 399319ba69e5fb6c6f42350b1ebe56cf63299380 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Fri, 11 Mar 2022 10:15:58 -0500 Subject: [PATCH 12/14] fixes --- libs/sensors/include/PollingSensors.h | 4 ++-- libs/sensors/src/PollingSensors.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libs/sensors/include/PollingSensors.h b/libs/sensors/include/PollingSensors.h index 5c086dbe..a2374ca6 100644 --- a/libs/sensors/include/PollingSensors.h +++ b/libs/sensors/include/PollingSensors.h @@ -35,9 +35,9 @@ class PollingSensors final : Sensor { private: /*Pins configuration for moisture sensing*/ - AnalogIn moisture_in_adc; + AnalogIn m_moisture_in_adc; /*Pins configuration for CO2 sensing*/ - AnalogIn CO2_in_adc; + AnalogIn m_CO2_in_adc; }; } // namespace Sensor \ No newline at end of file diff --git a/libs/sensors/src/PollingSensors.cpp b/libs/sensors/src/PollingSensors.cpp index 7cce7f78..56a0208e 100644 --- a/libs/sensors/src/PollingSensors.cpp +++ b/libs/sensors/src/PollingSensors.cpp @@ -5,21 +5,22 @@ using namespace Sensor; PollingSensors::PollingSensors(PinName moisture_in, PinName co2_in) - : moisture_in_adc(moisture_in), CO2_in_adc(co2_in) {} + : m_moisture_in_adc(moisture_in), m_CO2_in_adc(co2_in) {} -// The function currently logs a status message. Can be changed to return just a float indicating the sensor value +/*https://www.dfrobot.com/product-599.html*/ float PollingSensors::moisture_monitoring() { - float moisture_reading = (moisture_in_adc.read_voltage() * 5.0) / 1023.0; + float moisture_reading = (m_moisture_in_adc.read_voltage() * 950) / 4.2; - if (moisture_reading < 0 && moisture_reading > 900) { + if (moisture_reading < 0 && moisture_reading > 950) { Utility::logger << "!!! MOISTURE FAULT:" << moisture_reading << "\n"; return -1; } return moisture_reading; } +/*https://www.dfrobot.com/product-1549.html*/ float PollingSensors::C02_monitoring() { - float CO2_reading = CO2_in_adc.read_voltage() * 1000; + float CO2_reading = m_CO2_in_adc.read_voltage() * 1000; if (CO2_reading <= 0) { Utility::logger << "!!! CO2 FAULT:" << CO2_reading << "\n"; From 827f80cc9881cb1e11b0d0b668b5721e5d4ae714 Mon Sep 17 00:00:00 2001 From: Jahnavi Date: Mon, 11 Jul 2022 19:44:41 -0400 Subject: [PATCH 13/14] Test apps --- CMakeLists.txt | 2 ++ rover-apps/arm_2021/src/main.cpp | 2 +- supported_build_configurations.yaml | 8 ++++++++ test-apps/test-CO2-sensor/CMakeLists.txt | 4 ++++ test-apps/test-CO2-sensor/src/main.cpp | 20 +++++++++++++++++++ test-apps/test-moisture-sensor/CMakeLists.txt | 4 ++++ test-apps/test-moisture-sensor/src/main.cpp | 20 +++++++++++++++++++ 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test-apps/test-CO2-sensor/CMakeLists.txt create mode 100644 test-apps/test-CO2-sensor/src/main.cpp create mode 100644 test-apps/test-moisture-sensor/CMakeLists.txt create mode 100644 test-apps/test-moisture-sensor/src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a747dc2..a5ab067e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,8 @@ add_app_subdirectory(${TEST_APPS_DIR}/test-quadrature64cpr) add_app_subdirectory(${TEST_APPS_DIR}/test-stress-can) add_app_subdirectory(${TEST_APPS_DIR}/test-units) add_app_subdirectory(${TEST_APPS_DIR}/test-watchdog) +add_app_subdirectory(${TEST_APPS_DIR}/test-CO2-sensor) +add_app_subdirectory(${TEST_APPS_DIR}/test-moisture-sensor) # Ensure APP was specified if ("$ENV{APP}" STREQUAL "") diff --git a/rover-apps/arm_2021/src/main.cpp b/rover-apps/arm_2021/src/main.cpp index aa8a9c0a..0b263b4e 100644 --- a/rover-apps/arm_2021/src/main.cpp +++ b/rover-apps/arm_2021/src/main.cpp @@ -10,7 +10,7 @@ #include "TurntableConfig.h" #include "WristConfig.h" -CANInterface can(CANConfig::config); +CANInterface can(CANConfig::config) ; // Convert degrees to radians static inline float DEG_TO_RAD(float deg) { diff --git a/supported_build_configurations.yaml b/supported_build_configurations.yaml index 0a385884..2668f03c 100644 --- a/supported_build_configurations.yaml +++ b/supported_build_configurations.yaml @@ -105,5 +105,13 @@ test-stress-can: - ARM_REV2_2021 - GIMBAL_REV2_2021 - PDB_REV2_2021 + - SCIENCE_REV2_2021 + - UWRT_NUCLEO + +test-moisture-sensor: + - SCIENCE_REV2_2021 + - UWRT_NUCLEO + +test-CO2-sensor: - SCIENCE_REV2_2021 - UWRT_NUCLEO \ No newline at end of file diff --git a/test-apps/test-CO2-sensor/CMakeLists.txt b/test-apps/test-CO2-sensor/CMakeLists.txt new file mode 100644 index 00000000..85178bb9 --- /dev/null +++ b/test-apps/test-CO2-sensor/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(test-CO2-sensor) +target_sources(test-CO2-sensor PRIVATE src/main.cpp) +target_link_libraries(test-CO2-sensor PRIVATE PollingSensors Logger) +mbed_set_post_build(test-CO2-sensor) diff --git a/test-apps/test-CO2-sensor/src/main.cpp b/test-apps/test-CO2-sensor/src/main.cpp new file mode 100644 index 00000000..be46e436 --- /dev/null +++ b/test-apps/test-CO2-sensor/src/main.cpp @@ -0,0 +1,20 @@ +#include "PollingSensors.h" +#include "PinNames.h" +#include "Logger.h" + +DigitalOut led1(LED1); + +int main() { + Sensor::PollingSensors CO2_sensor(PA_0,PA_1); + + while (1) { + + printf("\r\nReading CO2 Levels...\r\n"); + + Utility::logger << "CO2: " << ((unsigned int) CO2_sensor.C02_monitoring()) << "\r\n"; + + printf("\r\n-----------------------------\r\n"); + + ThisThread::sleep_for(100ms); + } +} diff --git a/test-apps/test-moisture-sensor/CMakeLists.txt b/test-apps/test-moisture-sensor/CMakeLists.txt new file mode 100644 index 00000000..bf396ddb --- /dev/null +++ b/test-apps/test-moisture-sensor/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(test-moisture-sensor) +target_sources(test-moisture-sensor PRIVATE src/main.cpp) +target_link_libraries(test-moisture-sensor PRIVATE PollingSensors Logger) +mbed_set_post_build(test-moisture-sensor) diff --git a/test-apps/test-moisture-sensor/src/main.cpp b/test-apps/test-moisture-sensor/src/main.cpp new file mode 100644 index 00000000..10402263 --- /dev/null +++ b/test-apps/test-moisture-sensor/src/main.cpp @@ -0,0 +1,20 @@ +#include "PollingSensors.h" +#include "PinNames.h" +#include "Logger.h" + +DigitalOut led1(LED1); + +int main() { + Sensor::PollingSensors moisture_sensor(PA_0, PA_1); + + while (1) { + + printf("\r\nReading moisture Levels...\r\n"); + + Utility::logger << "Moisture: " << ((unsigned int) moisture_sensor.moisture_monitoring()) << "\r\n"; + + printf("\r\n-----------------------------\r\n"); + + ThisThread::sleep_for(100ms); + } +} From aa47fd8821da55081426b60cafd5614226c61ff9 Mon Sep 17 00:00:00 2001 From: jahnavithota2011 <34670246+jahnavithota2011@users.noreply.github.com> Date: Mon, 11 Jul 2022 19:46:49 -0400 Subject: [PATCH 14/14] small fix --- rover-apps/arm_2021/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rover-apps/arm_2021/src/main.cpp b/rover-apps/arm_2021/src/main.cpp index 0b263b4e..aa8a9c0a 100644 --- a/rover-apps/arm_2021/src/main.cpp +++ b/rover-apps/arm_2021/src/main.cpp @@ -10,7 +10,7 @@ #include "TurntableConfig.h" #include "WristConfig.h" -CANInterface can(CANConfig::config) ; +CANInterface can(CANConfig::config); // Convert degrees to radians static inline float DEG_TO_RAD(float deg) {