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 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..b0ada3ac --- /dev/null +++ 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