esp-vent-main: main cleanup and doc
- Delete unnused stuff in main - Create common values header - Minor fix
This commit is contained in:
@@ -27,30 +27,32 @@ StateHandler::~StateHandler ()
|
||||
void
|
||||
StateHandler::displaySet (size_t mode)
|
||||
{
|
||||
char line_up[16] = { 0 };
|
||||
char line_down[16] = { 0 };
|
||||
char line_up[LCD_SIZE] = { 0 };
|
||||
char line_down[LCD_SIZE] = { 0 };
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case MANUAL:
|
||||
snprintf (line_up, 16, "SPEED: %02d%", saved_set_value[current_mode]);
|
||||
snprintf (line_down, 16, "PRESSURE: %02dPa",
|
||||
snprintf (line_up, LCD_SIZE, "SPEED: %02d%",
|
||||
saved_set_value[current_mode]);
|
||||
snprintf (line_down, LCD_SIZE, "PRESSURE: %02dPa",
|
||||
saved_curr_value[current_mode]);
|
||||
break;
|
||||
case AUTO:
|
||||
snprintf (line_up, 16, "P. SET: %02dPa", saved_set_value[current_mode]);
|
||||
snprintf (line_down, 16, "P. CURR: %02dPa",
|
||||
snprintf (line_up, LCD_SIZE, "P. SET: %02dPa",
|
||||
saved_set_value[current_mode]);
|
||||
snprintf (line_down, LCD_SIZE, "P. CURR: %02dPa",
|
||||
saved_curr_value[current_mode]);
|
||||
break;
|
||||
case 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]);
|
||||
snprintf (line_up, LCD_SIZE, "PRE:%02d TEM:%02d",
|
||||
sensors_data[PRESSUREDAT], sensors_data[TEMPERATURE]);
|
||||
snprintf (line_down, LCD_SIZE, "HUM:%02d CO2:%02d",
|
||||
sensors_data[HUMIDITY], sensors_data[CO2]);
|
||||
break;
|
||||
case ERROR_TIMEOUT:
|
||||
snprintf (line_up, 16, " FORCE STOP ");
|
||||
snprintf (line_down, 16, "REASON: TIMEOUT");
|
||||
snprintf (line_up, LCD_SIZE, " FORCE STOP ");
|
||||
snprintf (line_down, LCD_SIZE, "REASON: TIMEOUT");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -203,16 +205,16 @@ StateHandler::handleControlButtons (uint8_t button)
|
||||
void
|
||||
StateHandler::handleTickValue (int value)
|
||||
{
|
||||
if (value % 5000 == 0)
|
||||
if (value % TIMER_SENSORS_TIMEOUT == 0)
|
||||
{
|
||||
updateSensorValues ();
|
||||
displaySet (SENSORS);
|
||||
}
|
||||
if (value % 500 == 0)
|
||||
if (value % TIMER_PRESSURE_TIMEOUT == 0)
|
||||
{
|
||||
SetState (&StateHandler::stateGetPressure);
|
||||
}
|
||||
if (value < 0)
|
||||
if (value == TIMER_ERROR_VALUE)
|
||||
{
|
||||
displaySet (ERROR_TIMEOUT);
|
||||
this->fan_speed.setInit (0);
|
||||
|
||||
@@ -8,14 +8,6 @@
|
||||
===============================================================================
|
||||
*/
|
||||
|
||||
#if defined(__USE_LPCOPEN)
|
||||
#if defined(NO_BOARD_LIB)
|
||||
#include "chip.h"
|
||||
#else
|
||||
#include "board.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "DigitalIoPin.h"
|
||||
#include "Fan.h"
|
||||
#include "LiquidCrystal.h"
|
||||
@@ -23,32 +15,20 @@
|
||||
#include "StateHandler/StateHandler.h"
|
||||
#include "SwitchController.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "chip.h"
|
||||
#include "common_control_values.h"
|
||||
#include <cr_section_macros.h>
|
||||
|
||||
// TODO: insert other include files here
|
||||
|
||||
// TODO: insert other definitions and declarations here
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
|
||||
#if defined(__USE_LPCOPEN)
|
||||
// Read clock settings and update SystemCoreClock variable
|
||||
/* Board init */
|
||||
SystemCoreClockUpdate ();
|
||||
#if !defined(NO_BOARD_LIB)
|
||||
// Set b_up_state and initialize all required blocks and
|
||||
// functions related to the board hardware
|
||||
Board_Init ();
|
||||
// Set the LED to the state of "On"
|
||||
Board_LED_Set (0, true);
|
||||
#endif
|
||||
#endif
|
||||
/** Lcd & stateHandler */
|
||||
|
||||
/** LCD setup */
|
||||
Chip_RIT_Init (LPC_RITIMER);
|
||||
Timer glob_time;
|
||||
Timer switch_time (false);
|
||||
DigitalIoPin rs (0, 29, false, true, false);
|
||||
DigitalIoPin en (0, 9, false, true, false);
|
||||
DigitalIoPin d4 (0, 10, false, true, false);
|
||||
@@ -56,20 +36,26 @@ main (void)
|
||||
DigitalIoPin d6 (1, 3, false, true, false);
|
||||
DigitalIoPin d7 (0, 0, false, true, false);
|
||||
LiquidCrystal lcd (&rs, &en, &d4, &d5, &d6, &d7);
|
||||
//
|
||||
lcd.setCursor (0, 0);
|
||||
lcd.print ("Vent-Machine");
|
||||
|
||||
/* FAN object */
|
||||
/* Timers */
|
||||
Timer glob_time;
|
||||
Timer switch_time (false);
|
||||
|
||||
/* Modbus Fan setup */
|
||||
ModbusMaster fan (1);
|
||||
fan.begin (9600);
|
||||
Fan propeller (new ModbusRegister (&fan, 0));
|
||||
|
||||
/* Pressure sensor setup */
|
||||
PressureWrapper sens;
|
||||
glob_time.Sleep (1000);
|
||||
|
||||
/* State Machine */
|
||||
StateHandler ventMachine (&lcd, &propeller, &sens, &glob_time);
|
||||
/** Common pins */
|
||||
|
||||
/** Control switches */
|
||||
DigitalIoPin b_up (0, 7, true, true, true); // A5
|
||||
SwitchController sw_up (&b_up, &ventMachine, BUTTON_CONTROL_UP);
|
||||
|
||||
@@ -79,14 +65,16 @@ main (void)
|
||||
DigitalIoPin b_toggle (0, 5, true, true, true); // A3
|
||||
SwitchController sw_toggle (&b_toggle, &ventMachine,
|
||||
BUTTON_CONTROL_TOG_MODE);
|
||||
int getcounterValue = 0;
|
||||
/* Other declarations */
|
||||
int getcounterValue;
|
||||
|
||||
while (1)
|
||||
{
|
||||
getcounterValue = glob_time.getCounter ();
|
||||
if (getcounterValue > 15000)
|
||||
if (getcounterValue > TIMER_GLOBAL_TIMEOUT)
|
||||
{
|
||||
glob_time.resetCounter ();
|
||||
ventMachine.HandleState (Event (Event::eTick, -1));
|
||||
ventMachine.HandleState (Event (Event::eTick, TIMER_ERROR_VALUE));
|
||||
}
|
||||
sw_up.listen ();
|
||||
sw_down.listen ();
|
||||
|
||||
Reference in New Issue
Block a user