Skip to content

Commit

Permalink
Merge pull request #197 from makers-for-life/fix-blower-telemetry
Browse files Browse the repository at this point in the history
Fix blower telemetry & use consistent types
  • Loading branch information
dsferruzza committed Apr 27, 2020
2 parents 9f02b90 + cb0e71f commit 7cfbeb1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/software/firmware/includes/blower.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ class Blower {
* Run the Blower to a speed
* @param p_speed speed between MIN_BLOWER_SPEED and MAX_BLOWER_SPEED.
*/
void runSpeed(int16_t p_speed);
void runSpeed(uint16_t p_speed);

/// Stops the blower
void stop();

/// Get speed value
int getSpeed() const;
uint16_t getSpeed() const;

private:
HardwareTimer* actuator;
uint16_t timerChannel;
uint16_t blowerPin;
int16_t m_speed;
uint16_t m_speed;
bool m_stopped;
};
6 changes: 3 additions & 3 deletions src/software/firmware/includes/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ static const int32_t PID_PATIENT_SAFETY_PEEP_OFFSET = 0;
* @name Blower
*/
///@{
#define MIN_BLOWER_SPEED 950
#define MAX_BLOWER_SPEED 1800
#define DEFAULT_BLOWER_SPEED 1300
#define MIN_BLOWER_SPEED 950u
#define MAX_BLOWER_SPEED 1800u
#define DEFAULT_BLOWER_SPEED 1300u
///@}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/software/firmware/srcs/blower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Blower::setup() {
actuator->resume();
}

void Blower::runSpeed(int16_t p_speed) {
void Blower::runSpeed(uint16_t p_speed) {
if ((p_speed > MIN_BLOWER_SPEED) && (p_speed < MAX_BLOWER_SPEED)) {
// do not forcefully set the capture compare again and again if speed do not change
if (m_stopped || (m_speed != p_speed)) {
Expand All @@ -57,7 +57,7 @@ void Blower::runSpeed(int16_t p_speed) {
}
}

int Blower::getSpeed() const { return m_speed; }
uint16_t Blower::getSpeed() const { return m_speed; }

void Blower::stop() {
actuator->setCaptureCompare(timerChannel, BlowerSpeed2MicroSeconds(0), MICROSEC_COMPARE_FORMAT);
Expand Down
16 changes: 14 additions & 2 deletions src/software/firmware/srcs/pressure_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,18 @@ void PressureController::initRespiratoryCycle() {
m_maxPlateauPressure = m_maxPlateauPressureCommand;

// Apply blower ramp-up
m_blower->runSpeed(m_blower->getSpeed() + m_blower_increment);
if (m_blower_increment >= 0) {
m_blower->runSpeed(m_blower->getSpeed() + static_cast<uint16_t>(abs(m_blower_increment)));
} else {
// When blower increment is negative, we need to check that it is less than current speed
// If not, it would result in an overflow
if (static_cast<uint16_t>(abs(m_blower_increment)) < m_blower->getSpeed()) {
m_blower->runSpeed(m_blower->getSpeed()
- static_cast<uint16_t>(abs(m_blower_increment)));
} else {
m_blower->runSpeed(MIN_BLOWER_SPEED);
}
}
m_blower_increment = 0;

for (uint8_t i = 0; i < MAX_PRESSURE_SAMPLES; i++) {
Expand Down Expand Up @@ -255,7 +266,7 @@ void PressureController::compute(uint16_t p_centiSec) {
#if HARDWARE_VERSION == 2
m_alarmController->updateCoreData(p_centiSec, m_pressure, m_phase, m_subPhase, m_cycleNb);
sendDataSnapshot(p_centiSec, m_pressure, m_phase, m_subPhase, m_blower_valve.position,
m_patient_valve.position, m_blower->getSpeed(), getBatteryLevel());
m_patient_valve.position, m_blower->getSpeed() / 10u, getBatteryLevel());
#endif

executeCommands();
Expand Down Expand Up @@ -452,6 +463,7 @@ void PressureController::updatePeakPressure() {

if (abs(plateauDelta) > 20) {
m_maxPeakPressureCommand =
// cppcheck-suppress misra-c2012-12.3
min((min(m_peakPressure, m_maxPeakPressureCommand) + plateauDelta),
static_cast<int>(CONST_MAX_PEAK_PRESSURE));
} else if ((abs(plateauDelta) < 20) && (abs(plateauDelta) > 5)) {
Expand Down

0 comments on commit 7cfbeb1

Please sign in to comment.