From 7fcca75bb7686b00f433d7d2337fe29f34c788ef Mon Sep 17 00:00:00 2001 From: Meghdeep Basu Date: Tue, 5 Apr 2022 20:16:59 +0100 Subject: [PATCH 1/3] suspension_temperature_sensor --- src/sensors/temperature_amb.cpp | 36 +++++++++++++++++++++ src/sensors/temperature_amb.hpp | 55 ++++++++++++++++++++++++++++++++ src/sensors/temperature_susp.cpp | 36 +++++++++++++++++++++ src/sensors/temperature_susp.hpp | 0 4 files changed, 127 insertions(+) create mode 100644 src/sensors/temperature_amb.cpp create mode 100644 src/sensors/temperature_amb.hpp create mode 100644 src/sensors/temperature_susp.cpp create mode 100644 src/sensors/temperature_susp.hpp diff --git a/src/sensors/temperature_amb.cpp b/src/sensors/temperature_amb.cpp new file mode 100644 index 00000000..dae6917e --- /dev/null +++ b/src/sensors/temperature_amb.cpp @@ -0,0 +1,36 @@ +#include "temperature.hpp" + +#include + +#include + +namespace hyped::sensors { + +Temperature::Temperature(const uint8_t pin) + : pin_(pin), + log_("TEMPERATURE", utils::System::getSystem().config_.log_level_sensors) +{ +} + +void Temperature::run() +{ + uint16_t raw_value = pin_.read(); + log_.debug("raw value: %d", raw_value); + temperature_data_.temperature = scaleData(raw_value); + log_.debug("scaled value: %d", temperature_data_.temperature); + temperature_data_.operational = true; +} + +int8_t Temperature::scaleData(const uint8_t raw_value) +{ + // convert to degrees C + double temp = static_cast(raw_value) / 4095; + temp = (temp * 175) - 50; + return static_cast(temp); +} + +uint8_t Temperature::getData() const +{ + return temperature_data_.temperature; +} +} // namespace hyped::sensors diff --git a/src/sensors/temperature_amb.hpp b/src/sensors/temperature_amb.hpp new file mode 100644 index 00000000..933e716d --- /dev/null +++ b/src/sensors/temperature_amb.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include "interface.hpp" + +#include + +#include +#include +#include +namespace hyped::sensors { + +class Temperature : public ITemperature { + public: + /** + * @brief Construct a new Temperature object + * + * @param pin for specific ADC pin + */ + Temperature(const uint8_t pin); + ~Temperature() {} + + /** + * @brief + * + * @return int to set to data struct in sensors main + */ + uint8_t getData() const override; + + /** + * @brief one interation of checking sensors + */ + void run() override; + + private: + /** + * @brief scale raw digital data to output in degrees C + * + * @param raw_value input voltage + * @return int representation of temperature + */ + static int8_t scaleData(uint8_t raw_value); + + /** + * @brief ADC pin + */ + utils::io::ADC pin_; + utils::Logger log_; + + /** + * @brief int from data structs + */ + data::TemperatureData temperature_data_; +}; + +} // namespace hyped::sensors diff --git a/src/sensors/temperature_susp.cpp b/src/sensors/temperature_susp.cpp new file mode 100644 index 00000000..fdd935ea --- /dev/null +++ b/src/sensors/temperature_susp.cpp @@ -0,0 +1,36 @@ +#include "temperature.hpp" + +#include + +#include + +namespace hyped::sensors { + +Temperature_susp::Temperature_susp(const uint8_t pin) + : pin_(pin), + log_("TEMPERATURE", utils::System::getSystem().config_.log_level_sensors) +{ +} + +void Temperature_susp::run() +{ + uint16_t raw_value = pin_.read(); + log_.debug("raw value: %d", raw_value); + temperature_susp_data_.temperature_susp = scaleData(raw_value); + log_.debug("scaled value: %d", temperature_susp_data_.temperature_susp); + temperature_susp_data_.operational = true; +} + +int8_t Temperature_susp::scaleData(const uint8_t raw_value) +{ + // convert to degrees C + double temp = static_cast(raw_value) / 4095; + temp = ((temp * 175) - 50)/(4*20*0.001); + return static_cast(temp); +} + +uint8_t Temperature_susp::getData() const +{ + return temperature_data_.temperature; +} +} // namespace hyped::sensors \ No newline at end of file diff --git a/src/sensors/temperature_susp.hpp b/src/sensors/temperature_susp.hpp new file mode 100644 index 00000000..e69de29b From 6ac5f76a7c7730f84f7ef1d33f44d6cde2ec55f6 Mon Sep 17 00:00:00 2001 From: Meghdeep Basu Date: Tue, 5 Apr 2022 20:22:59 +0100 Subject: [PATCH 2/3] suspension_temperature_sensor --- src/sensors/temperature_susp.hpp | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/sensors/temperature_susp.hpp b/src/sensors/temperature_susp.hpp index e69de29b..b0ada3ac 100644 --- a/src/sensors/temperature_susp.hpp +++ b/src/sensors/temperature_susp.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include "interface.hpp" + +#include + +#include +#include +#include +namespace hyped::sensors { + +class Temperature_susp : public ITemperature_susp { + public: + /** + * @brief Construct a new Temperature_susp object + * + * @param pin for specific ADC pin + */ + Temperature_susp(const uint8_t pin); + ~Temperature_susp() {} + + /** + * @brief + * + * @return int to set to data struct in sensors main + */ + uint8_t getData() const override; + + /** + * @brief one interation of checking sensors + */ + void run() override; + + private: + /** + * @brief scale raw digital data to output in degrees C + * + * @param raw_value input voltage + * @return int representation of temperature_susp + */ + static int8_t scaleData(uint8_t raw_value); + + /** + * @brief ADC pin + */ + utils::io::ADC pin_; + utils::Logger log_; + + /** + * @brief int from data structs + */ + data::Temperature_suspData temperature_susp_data_; +}; + +} // namespace hyped::sensors From 3a790e3ce5d5cb6534915af6341ff3c7d8864455 Mon Sep 17 00:00:00 2001 From: Meghdeep Basu Date: Fri, 8 Apr 2022 14:09:54 +0100 Subject: [PATCH 3/3] suspension_temperature_sensor --- src/sensors/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sensors/main.cpp b/src/sensors/main.cpp index 481ffc11..031ec91b 100644 --- a/src/sensors/main.cpp +++ b/src/sensors/main.cpp @@ -132,6 +132,19 @@ void Main::checkTemperature() } } +void Main::checkSuspensionTemperature() +{ + Temperature_susp_->run(); // not a thread + + const auto temperature_susp = temperature_susp_->getData(); // *C + if (temperature_susp > 85) { + log_.info("Suspension Temperature (%u) exceeds maximum value (%d)", temperature_susp, 85); + auto sensors_data = data_.getSensorsData(); + sensors_data.module_status = data::ModuleStatus::kCriticalFailure; + data_.setSensorsData(sensors_data); + } +} + void Main::checkAmbientPressure() { ambient_pressure_->run(); // not a thread