state-handler: create eKey fucntionality
This commit introduces buttonHandling of esp-vent within the StateHandler class and main().
This commit is contained in:
parent
736d8aa1b7
commit
acb1b73b9a
@ -1,5 +1,5 @@
|
||||
#MCUXpresso IDE
|
||||
#Wed Sep 14 11:02:46 EEST 2022
|
||||
#Fri Oct 14 12:50:11 EEST 2022
|
||||
product.name=MCUXpresso IDE v11.5.0 [Build 7232] [2022-01-11]
|
||||
product.version=11.5.0
|
||||
product.build=7232
|
||||
|
||||
@ -23,10 +23,10 @@ class Event {
|
||||
/** Time event */
|
||||
eTick
|
||||
};
|
||||
Event(eventType e = eTick, int b = 0, int t = 0)
|
||||
Event(eventType e = eTick, uint8_t b = 0, int t = 0)
|
||||
: type(e), button(b), temp(t){};
|
||||
eventType type;
|
||||
int button;
|
||||
uint8_t button;
|
||||
int temp;
|
||||
};
|
||||
|
||||
|
||||
@ -96,7 +96,7 @@ private:
|
||||
* @param newstate new state to be set to current
|
||||
*/
|
||||
void SetState (state_pointer newstate);
|
||||
uint8_t current_mode;
|
||||
bool current_mode;
|
||||
Counter value[2] = { { 0, 100 }, { 0, 120 } };
|
||||
LiquidCrystal *_lcd;
|
||||
|
||||
|
||||
@ -10,7 +10,9 @@
|
||||
StateHandler::StateHandler (LiquidCrystal *lcd)
|
||||
{
|
||||
this->_lcd = lcd;
|
||||
// TODO
|
||||
current = &StateHandler::stateInit;
|
||||
(this->*current) (Event (Event::eEnter));
|
||||
current_mode = MANUAL;
|
||||
}
|
||||
|
||||
StateHandler::~StateHandler ()
|
||||
@ -40,8 +42,8 @@ StateHandler::displaySet (unsigned int value1, unsigned int value2)
|
||||
/*
|
||||
* AUTO MODE:
|
||||
* ----------------
|
||||
* PRESSURE SET: 35Pa
|
||||
* PRESSURE CUR: XXPa
|
||||
* P. SET: 35Pa
|
||||
* P. CURR: XXPa
|
||||
* ----------------
|
||||
*/
|
||||
case AUTO:
|
||||
@ -85,15 +87,43 @@ StateHandler::SetState (state_pointer newstate)
|
||||
}
|
||||
|
||||
void
|
||||
stateInit (const Event &event)
|
||||
StateHandler::stateInit (const Event &event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Event::eEnter:
|
||||
break;
|
||||
case Event::eExit:
|
||||
_lcd->clear ();
|
||||
break;
|
||||
case Event::eKey:
|
||||
handleControlButtons (event.button);
|
||||
break;
|
||||
case Event::eTick:
|
||||
if (current_mode == MANUAL)
|
||||
{
|
||||
SetState (&StateHandler::stateManual);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetState (&StateHandler::stateAuto);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StateHandler::stateManual (const Event &event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Event::eEnter:
|
||||
break;
|
||||
case Event::eExit:
|
||||
_lcd->clear ();
|
||||
break;
|
||||
case Event::eKey:
|
||||
handleControlButtons (event.button);
|
||||
break;
|
||||
case Event::eTick:
|
||||
break;
|
||||
@ -101,15 +131,17 @@ stateInit (const Event &event)
|
||||
}
|
||||
|
||||
void
|
||||
stateManual (const Event &event)
|
||||
StateHandler::stateAuto (const Event &event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Event::eEnter:
|
||||
break;
|
||||
case Event::eExit:
|
||||
_lcd->clear ();
|
||||
break;
|
||||
case Event::eKey:
|
||||
handleControlButtons (event.button);
|
||||
break;
|
||||
case Event::eTick:
|
||||
break;
|
||||
@ -117,36 +149,21 @@ stateManual (const Event &event)
|
||||
}
|
||||
|
||||
void
|
||||
stateAuto (const Event &event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Event::eEnter:
|
||||
break;
|
||||
case Event::eExit:
|
||||
break;
|
||||
case Event::eKey:
|
||||
break;
|
||||
case Event::eTick:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handleControlButtons (uint8_t button)
|
||||
StateHandler::handleControlButtons (uint8_t button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case BUTTON_CONTROL_DOWN:
|
||||
/* code */
|
||||
this->value[(current_mode) ? AUTO : MANUAL].dec ();
|
||||
break;
|
||||
case BUTTON_CONTROL_UP:
|
||||
/* code */
|
||||
this->value[(current_mode) ? AUTO : MANUAL].inc ();
|
||||
break;
|
||||
case BUTTON_CONTROL_TOG_MODE:
|
||||
/* code */
|
||||
current_mode = !current_mode;
|
||||
SetState (&StateHandler::stateInit);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/inc}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.cpp.misc.dialect.1893636131" name="Language standard" superClass="com.crt.advproject.cpp.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.c++11" valueType="enumerated"/>
|
||||
<inputType id="com.crt.advproject.compiler.cpp.input.1024506123" superClass="com.crt.advproject.compiler.cpp.input"/>
|
||||
@ -71,6 +72,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/inc}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.c.misc.dialect.1885316467" name="Language standard" superClass="com.crt.advproject.c.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.c11" valueType="enumerated"/>
|
||||
<inputType id="com.crt.advproject.compiler.input.1491212950" superClass="com.crt.advproject.compiler.input"/>
|
||||
@ -88,6 +90,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/inc}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.486566022" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
<inputType id="com.crt.advproject.assembler.input.255980151" name="Additional Assembly Source Files" superClass="com.crt.advproject.assembler.input"/>
|
||||
@ -118,6 +121,7 @@
|
||||
<listOptionValue builtIn="false" value="DigitalIoPin"/>
|
||||
<listOptionValue builtIn="false" value="LiquidCrystal"/>
|
||||
<listOptionValue builtIn="false" value="I2C"/>
|
||||
<listOptionValue builtIn="false" value="StateHandler"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.paths.804461696" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/Debug}""/>
|
||||
@ -125,6 +129,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/Debug}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/Debug}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/Debug}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/Debug}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.link.cpp.crpenable.8641361" name="Enable automatic placement of Code Read Protection field in image" superClass="com.crt.advproject.link.cpp.crpenable"/>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.849613399" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
@ -188,6 +193,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/inc}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.cpp.misc.dialect.1640449237" name="Language standard" superClass="com.crt.advproject.cpp.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.c++11" valueType="enumerated"/>
|
||||
<inputType id="com.crt.advproject.compiler.cpp.input.812988440" superClass="com.crt.advproject.compiler.cpp.input"/>
|
||||
@ -215,6 +221,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/inc}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.c.misc.dialect.1383624929" name="Language standard" superClass="com.crt.advproject.c.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.c11" valueType="enumerated"/>
|
||||
<inputType id="com.crt.advproject.compiler.input.391538574" superClass="com.crt.advproject.compiler.input"/>
|
||||
@ -232,6 +239,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/inc}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1169670567" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
<inputType id="com.crt.advproject.assembler.input.956763731" name="Additional Assembly Source Files" superClass="com.crt.advproject.assembler.input"/>
|
||||
@ -262,6 +270,7 @@
|
||||
<listOptionValue builtIn="false" value="DigitalIoPin"/>
|
||||
<listOptionValue builtIn="false" value="LiquidCrystal"/>
|
||||
<listOptionValue builtIn="false" value="I2C"/>
|
||||
<listOptionValue builtIn="false" value="StateHandler"/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.paths.245096214" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/Release}""/>
|
||||
@ -269,6 +278,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/Release}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/Release}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/Release}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/Release}""/>
|
||||
</option>
|
||||
<option id="com.crt.advproject.link.cpp.crpenable.209534913" name="Enable automatic placement of Code Read Protection field in image" superClass="com.crt.advproject.link.cpp.crpenable"/>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1513506142" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
<project>DigitalIoPin</project>
|
||||
<project>LiquidCrystal</project>
|
||||
<project>I2C</project>
|
||||
<project>StateHandler</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
|
||||
@ -16,6 +16,9 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "DigitalIoPin.h"
|
||||
#include "StateHandler.h"
|
||||
|
||||
#include <cr_section_macros.h>
|
||||
|
||||
// TODO: insert other include files here
|
||||
@ -30,7 +33,7 @@ main (void)
|
||||
// Read clock settings and update SystemCoreClock variable
|
||||
SystemCoreClockUpdate ();
|
||||
#if !defined(NO_BOARD_LIB)
|
||||
// Set up and initialize all required blocks and
|
||||
// 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"
|
||||
@ -38,8 +41,43 @@ main (void)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
DigitalIoPin b_up ();
|
||||
DigitalIoPin b_down ();
|
||||
DigitalIoPin b_toggle ();
|
||||
bool b_up_state = false, b_down_state = false, b_toggle_state = false;
|
||||
|
||||
StateHandler ventMachine;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (b_up.read ())
|
||||
b_up_state = true;
|
||||
if (!b_up.read () && b_up_state)
|
||||
{
|
||||
ventMachine.HandleState (Event (Event::eKey, BUTTON_CONTROL_UP));
|
||||
b_up_state = false;
|
||||
}
|
||||
if (b_down.read ())
|
||||
b_down_state = true;
|
||||
if (!b_down.read () && b_down_state)
|
||||
{
|
||||
ventMachine.HandleState (Event (Event::eKey, BUTTON_CONTROL_DOWN));
|
||||
b_down_state = false;
|
||||
}
|
||||
if (b_toggle.read ())
|
||||
b_toggle_state = true;
|
||||
if (!b_toggle.read () && b_toggle_state)
|
||||
{
|
||||
ventMachine.HandleState (
|
||||
Event (Event::eKey, BUTTON_CONTROL_TOG_MODE));
|
||||
b_toggle_state = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* - Update current pressure to eTick
|
||||
*/
|
||||
ventMachine.HandleState (Event (Event::eTick));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user