diff --git a/esp-vent-main/inc/StateHandler/StateHandler.h b/esp-vent-main/inc/StateHandler/StateHandler.h index cb6aa69..d0cb3c1 100644 --- a/esp-vent-main/inc/StateHandler/StateHandler.h +++ b/esp-vent-main/inc/StateHandler/StateHandler.h @@ -104,15 +104,11 @@ public: * MANUAL MODE: SPEED: XX% PRESSURE: XXPa * * AUTO MODE: P. SET: XXPa P. CURR: XXPa + * + * @param sensors the current printing mode */ void displaySet (bool sensors); - /** Display values of sensors readings on LCD - * needed only for Debug purposes - * can be removed in production - */ - void displaySens (); - /** Handle the given event of the current state * * @param event event to be handled in the current state @@ -127,14 +123,19 @@ private: void SetState (state_pointer newstate); bool current_mode; Counter value[2] = { { 0, 100 }, { 0, 120 } }; - /* motor of fan starts at value 90. probably because of some + + /* Motor of fan starts at value 90. probably because of some * weigh of fan, so voltage within range of 0-89 is not * sufficient to start motor. - * TODO: Value 89 should be scaled to 0 at some point */ + * TODO: Value 89 should be scaled to 0 at some point + */ Counter fan_speed = { 80, 1000 }; - /*integral controller for PID. should be global, since it - * accumulates error signals encountered since startup*/ + + /* Integral controller for PID. should be global, since it + * accumulates error signals encountered since startup + */ int integral = 0; + int saved_set_value[2] = { 0, 0 }; int saved_curr_value[2] = { 0, 0 }; int sensors_data[4] = { 0 }; @@ -143,6 +144,7 @@ private: PressureWrapper *pressure; bool pressure_status; Timer *state_timer; + /* CO2 sensor object */ GMP252 co2; @@ -208,7 +210,7 @@ private: */ void pid (); - int fan_speed_normalized(); + int fan_speed_normalized (); }; #endif /* STATE_HANDLER_H_ */ diff --git a/esp-vent-main/src/StateHandler/StateHandler.cpp b/esp-vent-main/src/StateHandler/StateHandler.cpp index 3e58cc7..8f99777 100644 --- a/esp-vent-main/src/StateHandler/StateHandler.cpp +++ b/esp-vent-main/src/StateHandler/StateHandler.cpp @@ -31,20 +31,24 @@ StateHandler::displaySet (bool sensors) char line_up[16] = { 0 }; char line_down[16] = { 0 }; - if(sensors) { - snprintf (line_up, 16, "PRE:%02d TEM:%02d", sensors_data[PRESSUREDAT], - sensors_data[TEMPERATURE]); - snprintf (line_down, 16, "HUM:%02d CO2:%02d", sensors_data[HUMIDITY], - sensors_data[CO2]); - - } else if (current_mode == MANUAL) + if (sensors) + { + snprintf (line_up, 16, "PRE:%02d TEM:%02d", sensors_data[PRESSUREDAT], + sensors_data[TEMPERATURE]); + snprintf (line_down, 16, "HUM:%02d CO2:%02d", sensors_data[HUMIDITY], + sensors_data[CO2]); + } + else if (current_mode == MANUAL) { snprintf (line_up, 16, "SPEED: %02d%", saved_set_value[current_mode]); - snprintf (line_down, 16, "PRESSURE: %02dPa", saved_curr_value[current_mode]); - } else if(current_mode == AUTO) + snprintf (line_down, 16, "PRESSURE: %02dPa", + saved_curr_value[current_mode]); + } + else if (current_mode == AUTO) { snprintf (line_up, 16, "P. SET: %02dPa", saved_set_value[current_mode]); - snprintf (line_down, 16, "P. CURR: %02dPa", saved_curr_value[current_mode]); + snprintf (line_down, 16, "P. CURR: %02dPa", + saved_curr_value[current_mode]); } _lcd->clear (); @@ -53,11 +57,6 @@ StateHandler::displaySet (bool sensors) _lcd->setCursor (0, 1); _lcd->print (line_down); } -void -StateHandler::displaySens () -{ - -} unsigned int StateHandler::getSetPressure () @@ -117,7 +116,7 @@ StateHandler::stateManual (const Event &event) switch (event.type) { case Event::eEnter: - this->A01->write (fan_speed_normalized()); + this->A01->write (fan_speed_normalized ()); break; case Event::eExit: break; @@ -125,10 +124,11 @@ StateHandler::stateManual (const Event &event) handleControlButtons (event.value); break; case Event::eTick: - if(event.value % 5000 == 0) { - SetState(&StateHandler::stateSensors); - displaySet(SENSORS); - } + if (event.value % 5000 == 0) + { + SetState (&StateHandler::stateSensors); + displaySet (SENSORS); + } if (event.value % 500 == 0) { SetState (&StateHandler::stateGetPressure); @@ -143,7 +143,7 @@ StateHandler::stateAuto (const Event &event) switch (event.type) { case Event::eEnter: - this->A01->write (fan_speed.getCurrent ()); + this->A01->write (fan_speed.getCurrent ()); break; case Event::eExit: break; @@ -152,15 +152,16 @@ StateHandler::stateAuto (const Event &event) break; case Event::eTick: if (event.value % 2 == 0) - { - SetState (&StateHandler::stateGetPressure); - } - if(event.value % 150 == 0) { - SetState(&StateHandler::stateSensors); -// displaySens (); - } - pid(); - this->A01->write (fan_speed.getCurrent ()); + { + SetState (&StateHandler::stateGetPressure); + } + if (event.value % 150 == 0) + { + SetState (&StateHandler::stateSensors); + // displaySens (); + } + pid (); + this->A01->write (fan_speed.getCurrent ()); break; } } @@ -175,15 +176,16 @@ StateHandler::stateSensors (const Event &event) sensors_data[TEMPERATURE] = humidity.readT (); sensors_data[HUMIDITY] = humidity.readRH (); sensors_data[CO2] = co2.read (); -// displaySens (); + // displaySens (); break; case Event::eExit: break; case Event::eKey: - handleControlButtons (event.value); + handleControlButtons (event.value); break; case Event::eTick: -// save (pressure->getPressure (), ((current_mode) ? AUTO : MANUAL)); + // save (pressure->getPressure (), ((current_mode) ? AUTO : + // MANUAL)); SetState (current_mode ? &StateHandler::stateAuto : &StateHandler::stateManual); break; @@ -250,11 +252,12 @@ StateHandler::save (int eventValue, size_t mode) } int -StateHandler::fan_speed_normalized() { - int speed = value[MANUAL].getCurrent(); - if(speed <=92) - speed += 8; - return speed * 10; +StateHandler::fan_speed_normalized () +{ + int speed = value[MANUAL].getCurrent (); + if (speed <= 92) + speed += 8; + return speed * 10; } void