Skip to content

Commit

Permalink
Simplify #29 and #50 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
abukhalaf committed Jul 2, 2020
1 parent 47c7caf commit 152e899
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 41 deletions.
16 changes: 11 additions & 5 deletions Alarms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ void AlarmManager::begin() {
}

void AlarmManager::update() {
displ_->setAlarmText(getHeaderText(), getFooterText(), beeper_.getRemainingSnoozeTime());
displ_->setAlarmText(getGeneralAlarmText());
displ_->setUnconfirmedKnobAlarmText(getUnconfirmedKnobText());
displ_->setSnoozeText(beeper_.getRemainingSnoozeTime());
AlarmLevel highest_level = getHighestLevel();
beeper_.update(highest_level);
if (highest_level > NO_ALARM) {
Expand Down Expand Up @@ -210,7 +212,9 @@ int AlarmManager::numON_Confirm() const {
for (int i = 0; i < NUM_ALARMS; i++) {
aConfirmAlarm = (i==NOT_CONFIRM_TV || i==NOT_CONFIRM_RR ||
i==NOT_CONFIRM_IE || i==NOT_CONFIRM_AC);
num += (int)alarms_[i].isON();
if(aConfirmAlarm) {
num += (int)alarms_[i].isON();
}
}
return num;
}
Expand All @@ -221,12 +225,14 @@ int AlarmManager::numON_NonConfirm() const {
for (int i = 0; i < NUM_ALARMS; i++) {
aConfirmAlarm = (i==NOT_CONFIRM_TV || i==NOT_CONFIRM_RR ||
i==NOT_CONFIRM_IE || i==NOT_CONFIRM_AC);
num += (int)alarms_[i].isON();
if(!aConfirmAlarm) {
num += (int)alarms_[i].isON();
}
}
return num;
}

String AlarmManager::getHeaderText() const {
String AlarmManager::getGeneralAlarmText() const {
const int num_on = numON_NonConfirm();
String text = "";
if (num_on > 0) {
Expand All @@ -247,7 +253,7 @@ String AlarmManager::getHeaderText() const {
return text;
}

String AlarmManager::getFooterText() const {
String AlarmManager::getUnconfirmedKnobText() const {
const int num_on = numON_Confirm();
String text = "";
if (num_on > 0) {
Expand Down
15 changes: 9 additions & 6 deletions Alarms.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ class AlarmManager {
NUM_ALARMS
};

// Number of NOT_CONFIRM_XX alarms
static const int numConfirmKnob = 4;

public:
AlarmManager(const int& beeper_pin, const int& snooze_pin, const int& led_pin,
Display* displ, unsigned long const* cycle_count):
Expand Down Expand Up @@ -335,8 +338,8 @@ class AlarmManager {
int led_pin_;
utils::Pulse led_pulse_;
Alarm alarms_[NUM_ALARMS];
Alarm alarmsHeader_[NUM_ALARMS-4];
Alarm alarmsFooter_[4];
Alarm alarmsHeader_[NUM_ALARMS-numConfirmKnob];
Alarm alarmsFooter_[numConfirmKnob];
unsigned long const* cycle_count_;

// Get number of alarms that are ON
Expand All @@ -348,11 +351,11 @@ class AlarmManager {
// Get number of nonconfirm alarms that are ON
int numON_NonConfirm() const;

// Get header text to display
String getHeaderText() const;
// Get general alarm text to display
String getGeneralAlarmText() const;

// Get footer text to display
String getFooterText() const;
// Get unconfirmed knob alarm text to display
String getUnconfirmedKnobText() const;

// Get highest priority level of the alarms that are ON
AlarmLevel getHighestLevel() const;
Expand Down
52 changes: 34 additions & 18 deletions Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Display::begin() {
void Display::addCustomCharacters() {
lcd_->createChar(0, patientIcon);
lcd_->createChar(1, timeIcon);
lcd_->createChar(2, peekIcon);
lcd_->createChar(2, peakIcon);
lcd_->createChar(3, plateauIcon);
lcd_->createChar(4, peepIcon);
lcd_->createChar(5, ieiIcon);
Expand All @@ -58,13 +58,19 @@ void Display::update() {
writeFooter();
}

void Display::setAlarmText(const String& alarmH, const String& alarmF, const int& countdown) {
if (animation_.text() != alarmH) {
animation_.reset(alarmH);
void Display::setAlarmText(const String& alarm) {
if (animation_.text() != alarm) {
animation_.reset(alarm);
}
if (animationfooter_.text() != alarmF) {
animationfooter_.reset(alarmF);
}

void Display::setUnconfirmedKnobAlarmText(const String& alarm) {
if (animationfooter_.text() != alarm) {
animationfooter_.reset(alarm);
}
}

void Display::setSnoozeText(const int& countdown) {
snoozecountdown_ = countdown;
}

Expand Down Expand Up @@ -128,10 +134,10 @@ void Display::writeHeader() {
void Display::writeFooter() {
if (!alarmsON()) {
writeBlank(FOOTER);
hideIcon(3,0);
hideBellIcon();
}
else {
showBellIcon(3, 0);
showBellIcon();
const String line = animationfooter_.getLine();
if (line.length() > 0) {
write(elements_[FOOTER].row, elements_[FOOTER].col, line);
Expand Down Expand Up @@ -195,7 +201,7 @@ void Display::writeACTrigger(const float& ac_trigger) {

void Display::writePeakP(const int& peak) {
const int peak_c = constrain(peak, -9, 99);
showPeekIcon(elements_[PEAK_PRES].row, elements_[PEAK_PRES].col);
showPeakIcon(elements_[PEAK_PRES].row, elements_[PEAK_PRES].col);
char buff[3];
sprintf(buff, "%2s", toString(PEAK_PRES, peak_c).c_str());
write(elements_[PEAK_PRES].row, elements_[PEAK_PRES].col+1, buff);
Expand Down Expand Up @@ -243,30 +249,35 @@ String Display::toString(const DisplayKey& key, const T& value) const {
}

// This displays a patient icon
void Display::showPatientIcon(const int& row, const int& col) {
lcd_->setCursor(col, row);
void Display::showPatientIcon() {
lcd_->setCursor(elements_[BREATHING].col, elements_[BREATHING].row);
lcd_->write(byte(0));
}

// This displays a time icon
void Display::showTimeIcon(const int& row, const int& col) {
lcd_->setCursor(col, row);
void Display::showTimeIcon() {
lcd_->setCursor(elements_[BREATHING].col, elements_[BREATHING].row);
lcd_->write(byte(1));
}

// This hides a time-patient icon
void Display::hideTimePatientIcon() {
hideIcon(elements_[BREATHING].row, elements_[BREATHING].col);
}

// Hides icon
void Display::hideIcon(const int& row, const int& col) {
lcd_->setCursor(col, row);
lcd_->write(byte(32));
}

// This displays the peek icon
void Display::showPeekIcon(const int& row, const int& col) {
// This displays the PIP icon
void Display::showPeakIcon(const int& row, const int& col) {
lcd_->setCursor(col, row);
lcd_->write(byte(2));
}

// This displays a plateau icon
// This displays a plateau pressure icon
void Display::showPlateauIcon(const int& row, const int& col) {
lcd_->setCursor(col, row);
lcd_->write(byte(3));
Expand All @@ -291,11 +302,16 @@ void Display::showIE1Icon(const int& row, const int& col) {
}

// This displays a bell icon
void Display::showBellIcon(const int& row, const int& col) {
lcd_->setCursor(col, row);
void Display::showBellIcon() {
lcd_->setCursor(elements_[BELL].col, elements_[BELL].row);
lcd_->write(byte(7));
}

// This hides the bell icon
void Display::hideBellIcon() {
hideIcon(elements_[BELL].row, elements_[BELL].col);
}

template <typename T>
void Display::write(const int& row, const int& col, const T& printable) {
lcd_->setCursor(col, row);
Expand Down
30 changes: 23 additions & 7 deletions Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TextAnimation {

enum DisplayKey {
HEADER,
BREATHING,
VOLUME,
BPM,
IE_RATIO,
Expand All @@ -85,6 +86,7 @@ enum DisplayKey {
PLATEAU_PRES,
PEEP_PRES,
SNOOZE,
BELL,
FOOTER,
NUM_KEYS
};
Expand Down Expand Up @@ -129,6 +131,7 @@ class Display {
animationfooter_(1000, 0.5),
snoozecountdown_(0) {
elements_[HEADER] = Element{0, 0, kHeaderLength};
elements_[BREATHING] = Element{0, 19, 1};
elements_[VOLUME] = Element{1, 0, 4, "TV"};
elements_[BPM] = Element{1, 4, 3, "RR"};
elements_[IE_RATIO] = Element{1, 7, 5, "IE"};
Expand All @@ -137,6 +140,7 @@ class Display {
elements_[PLATEAU_PRES] = Element{2, 17, 3, "plat"};
elements_[PEEP_PRES] = Element{3, 17, 3, "PEEP"};
elements_[SNOOZE] = Element{3, 1, 3};
elements_[BELL] = Element{3, 0, 1};
elements_[FOOTER] = Element{3, 7, kFooterLength};
}

Expand All @@ -149,8 +153,14 @@ class Display {
// Update during arduino loop()
void update();

// Write arbitrary alarm in the header and footer
void setAlarmText(const String& alarmH, const String& alarmF, const int& countdown);
// Set arbitrary alarm text
void setAlarmText(const String& alarm);

// Set unconfirmed knob alarm text
void setUnconfirmedKnobAlarmText(const String& alarm);

// Set snooze time text
void setSnoozeText(const int& countdown);

// Write value corresponding to key'ed element
template <typename T>
Expand Down Expand Up @@ -190,16 +200,19 @@ class Display {
void writePEEP(const int& peep);

// This displays a patient icon
void showPatientIcon(const int& row, const int& col);
void showPatientIcon();

// This displays a time icon
void showTimeIcon(const int& row, const int& col);
void showTimeIcon();

// Hide time-patient icon
void hideTimePatientIcon();

// Hides icon
void hideIcon(const int& row, const int& col);

// This displays the peek icon
void showPeekIcon(const int& row, const int& col);
// This displays the PIP icon
void showPeakIcon(const int& row, const int& col);

// This displays a plateau icon
void showPlateauIcon(const int& row, const int& col);
Expand All @@ -214,7 +227,10 @@ class Display {
void showIE1Icon(const int& row, const int& col);

// This displays a bell icon
void showBellIcon(const int& row, const int& col);
void showBellIcon();

// Hide bell icon
void hideBellIcon();

// Convert value e.g. RR from numeric to string for displaying.
template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions Indicators.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static const byte timeIcon[8] = {
B11111,
B11111};

static const byte peekIcon[8] = {
static const byte peakIcon[8] = {
B01111,
B10000,
B10000,
Expand Down Expand Up @@ -114,4 +114,4 @@ static const byte bellIcon[8] = {
B00100,
B00000};

#endif
#endif
6 changes: 3 additions & 3 deletions e-vent.ino
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void loop() {
if (enteringState) {
enteringState = false;
goToPositionByDur(roboclaw, BAG_CLEAR_POS, motorPosition, tEx - (now() - tCycleTimer));
displ.hideIcon(0,19);
displ.hideTimePatientIcon();
}

if (abs(motorPosition - BAG_CLEAR_POS) < BAG_CLEAR_TOL) {
Expand Down Expand Up @@ -271,9 +271,9 @@ void loop() {

// An indicator that shows patient-triggered or time-triggered cycles
if(patientTriggered) {
displ.showPatientIcon(0,19);
displ.showPatientIcon();
} else {
displ.showTimeIcon(0,19);
displ.showTimeIcon();
}
}
break;
Expand Down

0 comments on commit 152e899

Please sign in to comment.