-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sns susptemp #143
base: master
Are you sure you want to change the base?
Sns susptemp #143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,19 @@ void Main::checkTemperature() | |
} | ||
} | ||
|
||
void Main::checkSuspensionTemperature() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also needs to be defined in main.hpp |
||
{ | ||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "temperature.hpp" | ||
|
||
#include <stdio.h> | ||
|
||
#include <utils/system.hpp> | ||
|
||
namespace hyped::sensors { | ||
|
||
Temperature::Temperature(const uint8_t pin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AmbientTemperature as class name and ambient_temperature.cpp for file name is probably better |
||
: pin_(pin), | ||
log_("TEMPERATURE", utils::System::getSystem().config_.log_level_sensors) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Ambient Temperature" |
||
{ | ||
} | ||
|
||
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<double>(raw_value) / 4095; | ||
temp = (temp * 175) - 50; | ||
return static_cast<int8_t>(temp); | ||
} | ||
|
||
uint8_t Temperature::getData() const | ||
{ | ||
return temperature_data_.temperature; | ||
} | ||
} // namespace hyped::sensors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include "interface.hpp" | ||
|
||
#include <cstdint> | ||
|
||
#include <data/data.hpp> | ||
#include <utils/io/adc.hpp> | ||
#include <utils/logger.hpp> | ||
namespace hyped::sensors { | ||
|
||
class Temperature : public ITemperature { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AmbientTemperature ambient_temperature.hpp |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "temperature.hpp" | ||
|
||
#include <stdio.h> | ||
|
||
#include <utils/system.hpp> | ||
|
||
namespace hyped::sensors { | ||
|
||
Temperature_susp::Temperature_susp(const uint8_t pin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BrakeAndSuspenionTemperature for class? brake_and_suspension_temperature.cpp for file? Open to ideas on this, but the current naming isn't ideal |
||
: pin_(pin), | ||
log_("TEMPERATURE", utils::System::getSystem().config_.log_level_sensors) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Brakes and Suspension Temperature" |
||
{ | ||
} | ||
|
||
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<double>(raw_value) / 4095; | ||
temp = ((temp * 175) - 50)/(4*20*0.001); | ||
return static_cast<int8_t>(temp); | ||
} | ||
|
||
uint8_t Temperature_susp::getData() const | ||
{ | ||
return temperature_data_.temperature; | ||
} | ||
} // namespace hyped::sensors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include "interface.hpp" | ||
|
||
#include <cstdint> | ||
|
||
#include <data/data.hpp> | ||
#include <utils/io/adc.hpp> | ||
#include <utils/logger.hpp> | ||
namespace hyped::sensors { | ||
|
||
class Temperature_susp : public ITemperature_susp { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ITemperature_susp isn't defined anywhere + define the interface within the header instead of interface.hpp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also same naming comment from the other file applies here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think both types of temperature managers could be using the same interface |
||
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_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can probably just keep data::TemperatureData and even then you'd need to define it within data |
||
}; | ||
|
||
} // namespace hyped::sensors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've defined this but you aren't calling it anywhere yet