state-handler: format code and document
This commit is contained in:
parent
42251f7ed7
commit
cd06e2b3ba
@ -104,15 +104,11 @@ public:
|
|||||||
* MANUAL MODE: SPEED: XX% PRESSURE: XXPa
|
* MANUAL MODE: SPEED: XX% PRESSURE: XXPa
|
||||||
*
|
*
|
||||||
* AUTO MODE: P. SET: XXPa P. CURR: XXPa
|
* AUTO MODE: P. SET: XXPa P. CURR: XXPa
|
||||||
|
*
|
||||||
|
* @param sensors the current printing mode
|
||||||
*/
|
*/
|
||||||
void displaySet (bool sensors);
|
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
|
/** Handle the given event of the current state
|
||||||
*
|
*
|
||||||
* @param event event to be handled in the current state
|
* @param event event to be handled in the current state
|
||||||
@ -127,14 +123,19 @@ private:
|
|||||||
void SetState (state_pointer newstate);
|
void SetState (state_pointer newstate);
|
||||||
bool current_mode;
|
bool current_mode;
|
||||||
Counter value[2] = { { 0, 100 }, { 0, 120 } };
|
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
|
* weigh of fan, so voltage within range of 0-89 is not
|
||||||
* sufficient to start motor.
|
* 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 };
|
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 integral = 0;
|
||||||
|
|
||||||
int saved_set_value[2] = { 0, 0 };
|
int saved_set_value[2] = { 0, 0 };
|
||||||
int saved_curr_value[2] = { 0, 0 };
|
int saved_curr_value[2] = { 0, 0 };
|
||||||
int sensors_data[4] = { 0 };
|
int sensors_data[4] = { 0 };
|
||||||
@ -143,6 +144,7 @@ private:
|
|||||||
PressureWrapper *pressure;
|
PressureWrapper *pressure;
|
||||||
bool pressure_status;
|
bool pressure_status;
|
||||||
Timer *state_timer;
|
Timer *state_timer;
|
||||||
|
|
||||||
/* CO2 sensor object */
|
/* CO2 sensor object */
|
||||||
GMP252 co2;
|
GMP252 co2;
|
||||||
|
|
||||||
|
|||||||
@ -31,20 +31,24 @@ StateHandler::displaySet (bool sensors)
|
|||||||
char line_up[16] = { 0 };
|
char line_up[16] = { 0 };
|
||||||
char line_down[16] = { 0 };
|
char line_down[16] = { 0 };
|
||||||
|
|
||||||
if(sensors) {
|
if (sensors)
|
||||||
|
{
|
||||||
snprintf (line_up, 16, "PRE:%02d TEM:%02d", sensors_data[PRESSUREDAT],
|
snprintf (line_up, 16, "PRE:%02d TEM:%02d", sensors_data[PRESSUREDAT],
|
||||||
sensors_data[TEMPERATURE]);
|
sensors_data[TEMPERATURE]);
|
||||||
snprintf (line_down, 16, "HUM:%02d CO2:%02d", sensors_data[HUMIDITY],
|
snprintf (line_down, 16, "HUM:%02d CO2:%02d", sensors_data[HUMIDITY],
|
||||||
sensors_data[CO2]);
|
sensors_data[CO2]);
|
||||||
|
}
|
||||||
} else if (current_mode == MANUAL)
|
else if (current_mode == MANUAL)
|
||||||
{
|
{
|
||||||
snprintf (line_up, 16, "SPEED: %02d%", saved_set_value[current_mode]);
|
snprintf (line_up, 16, "SPEED: %02d%", saved_set_value[current_mode]);
|
||||||
snprintf (line_down, 16, "PRESSURE: %02dPa", saved_curr_value[current_mode]);
|
snprintf (line_down, 16, "PRESSURE: %02dPa",
|
||||||
} else if(current_mode == AUTO)
|
saved_curr_value[current_mode]);
|
||||||
|
}
|
||||||
|
else if (current_mode == AUTO)
|
||||||
{
|
{
|
||||||
snprintf (line_up, 16, "P. SET: %02dPa", saved_set_value[current_mode]);
|
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 ();
|
_lcd->clear ();
|
||||||
@ -53,11 +57,6 @@ StateHandler::displaySet (bool sensors)
|
|||||||
_lcd->setCursor (0, 1);
|
_lcd->setCursor (0, 1);
|
||||||
_lcd->print (line_down);
|
_lcd->print (line_down);
|
||||||
}
|
}
|
||||||
void
|
|
||||||
StateHandler::displaySens ()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
StateHandler::getSetPressure ()
|
StateHandler::getSetPressure ()
|
||||||
@ -125,7 +124,8 @@ StateHandler::stateManual (const Event &event)
|
|||||||
handleControlButtons (event.value);
|
handleControlButtons (event.value);
|
||||||
break;
|
break;
|
||||||
case Event::eTick:
|
case Event::eTick:
|
||||||
if(event.value % 5000 == 0) {
|
if (event.value % 5000 == 0)
|
||||||
|
{
|
||||||
SetState (&StateHandler::stateSensors);
|
SetState (&StateHandler::stateSensors);
|
||||||
displaySet (SENSORS);
|
displaySet (SENSORS);
|
||||||
}
|
}
|
||||||
@ -155,7 +155,8 @@ StateHandler::stateAuto (const Event &event)
|
|||||||
{
|
{
|
||||||
SetState (&StateHandler::stateGetPressure);
|
SetState (&StateHandler::stateGetPressure);
|
||||||
}
|
}
|
||||||
if(event.value % 150 == 0) {
|
if (event.value % 150 == 0)
|
||||||
|
{
|
||||||
SetState (&StateHandler::stateSensors);
|
SetState (&StateHandler::stateSensors);
|
||||||
// displaySens ();
|
// displaySens ();
|
||||||
}
|
}
|
||||||
@ -183,7 +184,8 @@ StateHandler::stateSensors (const Event &event)
|
|||||||
handleControlButtons (event.value);
|
handleControlButtons (event.value);
|
||||||
break;
|
break;
|
||||||
case Event::eTick:
|
case Event::eTick:
|
||||||
// save (pressure->getPressure (), ((current_mode) ? AUTO : MANUAL));
|
// save (pressure->getPressure (), ((current_mode) ? AUTO :
|
||||||
|
// MANUAL));
|
||||||
SetState (current_mode ? &StateHandler::stateAuto
|
SetState (current_mode ? &StateHandler::stateAuto
|
||||||
: &StateHandler::stateManual);
|
: &StateHandler::stateManual);
|
||||||
break;
|
break;
|
||||||
@ -250,7 +252,8 @@ StateHandler::save (int eventValue, size_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
StateHandler::fan_speed_normalized() {
|
StateHandler::fan_speed_normalized ()
|
||||||
|
{
|
||||||
int speed = value[MANUAL].getCurrent ();
|
int speed = value[MANUAL].getCurrent ();
|
||||||
if (speed <= 92)
|
if (speed <= 92)
|
||||||
speed += 8;
|
speed += 8;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user