diff --git a/.mcuxpressoide_packages_support/info.properties b/.mcuxpressoide_packages_support/info.properties index 0eacd38..2d68962 100644 --- a/.mcuxpressoide_packages_support/info.properties +++ b/.mcuxpressoide_packages_support/info.properties @@ -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 diff --git a/StateHandler/inc/Counter.h b/StateHandler/inc/Counter.h index b402f32..8e38df4 100644 --- a/StateHandler/inc/Counter.h +++ b/StateHandler/inc/Counter.h @@ -8,19 +8,19 @@ #ifndef COUNTER_H_ #define COUNTER_H_ -class Counter { +class Counter +{ public: - Counter(int i, int up); - void inc(); - void dec(); - int getCurrent(); - void setInit(int i); - ~Counter() = default; + Counter (int i, int up); + void inc (); + void dec (); + int getCurrent (); + void setInit (int i); + ~Counter () = default; private: - int init; - int up_lim; - + int init; + int up_lim; }; #endif /* COUNTER_H_ */ diff --git a/StateHandler/inc/Event.h b/StateHandler/inc/Event.h index 6785bad..9bf7e45 100644 --- a/StateHandler/inc/Event.h +++ b/StateHandler/inc/Event.h @@ -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; }; diff --git a/StateHandler/inc/StateHandler.h b/StateHandler/inc/StateHandler.h index d22a914..bd38137 100644 --- a/StateHandler/inc/StateHandler.h +++ b/StateHandler/inc/StateHandler.h @@ -124,6 +124,12 @@ private: * @param event */ void stateAuto (const Event &event); + + /** Hnadle button presses + * + * @param button current button + */ + void handleControlButtons (uint8_t button); }; #endif /* STATE_HANDLER_H_ */ diff --git a/StateHandler/src/Counter.cpp b/StateHandler/src/Counter.cpp index 0b53145..ff60011 100644 --- a/StateHandler/src/Counter.cpp +++ b/StateHandler/src/Counter.cpp @@ -7,39 +7,49 @@ #include "Counter.h" -void Counter::inc() { - if(init >= up_lim){ - init = 0; - } else{ - ++init; +void +Counter::inc () +{ + if (init < up_lim) + { + ++init; } } -void Counter::dec() { - if(init <= 0){ - init = up_lim; - } else{ - --init; +void +Counter::dec () +{ + if (init - 1 > 0) + { + --init; } } - -int Counter::getCurrent(){ +int +Counter::getCurrent () +{ return this->init; } -Counter::Counter(int i, int up) { - up_lim = up; - if(i > up){ - init = up; - }else if(i < 0){ - init = 0; - }else{ - init = i; +Counter::Counter (int i, int up) +{ + up_lim = up; + if (i > up) + { + init = up; + } + else if (i < 0) + { + init = 0; + } + else + { + init = i; } - } -void Counter::setInit(int i){ +void +Counter::setInit (int i) +{ init = i; } diff --git a/StateHandler/src/StateHandler.cpp b/StateHandler/src/StateHandler.cpp index a4518c7..9186236 100644 --- a/StateHandler/src/StateHandler.cpp +++ b/StateHandler/src/StateHandler.cpp @@ -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 () @@ -21,19 +23,41 @@ StateHandler::~StateHandler () void StateHandler::displaySet (unsigned int value1, unsigned int value2) { - // TODO - /** - * MANUAL MODE: - * ---------------- - * SPEED: 20% - * PRESSURE: XXPa - * ---------------- - * AUTO MODE: - * ---------------- - * PRESSURE SET: 35Pa - * PRESSURE CUR: XXPa - * ---------------- - */ + char line_up[16] = { 0 }; + char line_down[16] = { 0 }; + + switch (current_mode) + { + /* + * MANUAL MODE: + * ---------------- + * SPEED: 20% + * PRESSURE: XXPa + * ---------------- + */ + case MANUAL: + snprintf (line_up, 16, "SPEED: %02d%", value1); + snprintf (line_down, 16, "PRESSURE: %02dPa", value2); + break; + /* + * AUTO MODE: + * ---------------- + * P. SET: 35Pa + * P. CURR: XXPa + * ---------------- + */ + case AUTO: + snprintf (line_up, 16, "P. SET: %02dPa", value1); + snprintf (line_down, 16, "P. CURR: %02dPa", value2); + break; + default: + break; + } + _lcd->clear (); + _lcd->setCursor (0, 0); + _lcd->print (line_up); + _lcd->setCursor (0, 1); + _lcd->print (line_down); } unsigned int @@ -63,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; @@ -79,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; @@ -95,17 +149,21 @@ stateManual (const Event &event) } void -stateAuto (const Event &event) +StateHandler::handleControlButtons (uint8_t button) { - switch (event.type) + switch (button) { - case Event::eEnter: + case BUTTON_CONTROL_DOWN: + this->value[(current_mode) ? AUTO : MANUAL].dec (); break; - case Event::eExit: + case BUTTON_CONTROL_UP: + this->value[(current_mode) ? AUTO : MANUAL].inc (); break; - case Event::eKey: + case BUTTON_CONTROL_TOG_MODE: + current_mode = !current_mode; + SetState (&StateHandler::stateInit); break; - case Event::eTick: + default: break; } -} \ No newline at end of file +} diff --git a/Timer/.cproject b/Timer/.cproject new file mode 100644 index 0000000..8855f43 --- /dev/null +++ b/Timer/.cproject @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <?xml version="1.0" encoding="UTF-8"?> +<TargetConfig> +<Properties property_2="LPC15xx_256K.cfx" property_3="NXP" property_4="LPC1549" property_count="5" version="100300"/> +<infoList vendor="NXP"> +<info chip="LPC1549" connectscript="LPC15RunBootRomConnect.scp" flash_driver="LPC15xx_256K.cfx" match_id="0x0" name="LPC1549" resetscript="LPC15RunBootRomReset.scp" stub="crt_emu_cm3_gen"> +<chip> +<name>LPC1549</name> +<family>LPC15xx</family> +<vendor>NXP (formerly Philips)</vendor> +<reset board="None" core="Real" sys="Real"/> +<clock changeable="TRUE" freq="12MHz" is_accurate="TRUE"/> +<memory can_program="true" id="Flash" is_ro="true" type="Flash"/> +<memory id="RAM" type="RAM"/> +<memory id="Periph" is_volatile="true" type="Peripheral"/> +<memoryInstance derived_from="Flash" id="MFlash256" location="0x0" size="0x40000"/> +<memoryInstance derived_from="RAM" id="Ram0_16" location="0x2000000" size="0x4000"/> +<memoryInstance derived_from="RAM" id="Ram1_16" location="0x2004000" size="0x4000"/> +<memoryInstance derived_from="RAM" id="Ram2_4" location="0x2008000" size="0x1000"/> +</chip> +<processor> +<name gcc_name="cortex-m3">Cortex-M3</name> +<family>Cortex-M</family> +</processor> +</info> +</infoList> +</TargetConfig> + + + LPCXpresso1549 + + \ No newline at end of file diff --git a/Timer/.project b/Timer/.project new file mode 100644 index 0000000..db5b0e9 --- /dev/null +++ b/Timer/.project @@ -0,0 +1,28 @@ + + + Timer + + + lpc_chip_15xx + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Timer/inc/Timer.h b/Timer/inc/Timer.h new file mode 100644 index 0000000..55ca9a1 --- /dev/null +++ b/Timer/inc/Timer.h @@ -0,0 +1,76 @@ +/* + * Timer.h + * + * Created on: Oct 14, 2022 + * Author: tylen + */ + +#ifndef TIMER_H_ +#define TIMER_H_ + +#include "board.h" +#include +#include + +extern "C" +{ + /** + * @brief Handle interrupt from SysTick timer + * @return Nothing + */ + void SysTick_Handler (void); +} + +class Timer +{ +public: + /** + * @brief Initalize the systick configuration with your frequency + * + */ + Timer (uint32_t freq = 1000); + virtual ~Timer (); + + /** + * @brief Tick the counter. + * + * Counter is incremented by one every tick, + * if it gets over the INT_MAX (see limits.h), + * the counter rolls up back to zero and starts + * over. + * + * + * @param ms Counter ticking frequency is provided in milliseconds + */ + void tickCounter (int ms); + + /** + * @brief Get the current counter value + * + * @return int counter value + */ + int getCounter (); + + /** + * @brief Set counter to 0. + * + */ + void resetCounter (); + + /** + * @brief Sleep for amount of time + * + * Time is either in ms or in sec, defined + * by systickInit_xx() + * + * @param ms milliseconds + */ + void Sleep (int ms); + +private: + volatile std::atomic_int counter; + volatile std::atomic_int timer; + uint32_t freq; +}; + +#endif /* TIMER_H_ */ diff --git a/Timer/liblinks.xml b/Timer/liblinks.xml new file mode 100644 index 0000000..1dc1803 --- /dev/null +++ b/Timer/liblinks.xml @@ -0,0 +1,32 @@ + + + + + ${MacroStart}workspace_loc:/${ProjName}/inc${MacroEnd} + + + ${MacroStart}workspace_loc:/${ProjName}/inc${MacroEnd} + + + ${ProjName} + + + ${MacroStart}workspace_loc:/${ProjName}/Debug${MacroEnd} + + + ${MacroStart}workspace_loc:/${ProjName}/Release${MacroEnd} + + + ${ProjName} + + + diff --git a/Timer/src/Timer.cpp b/Timer/src/Timer.cpp new file mode 100644 index 0000000..e41a10d --- /dev/null +++ b/Timer/src/Timer.cpp @@ -0,0 +1,65 @@ +/* + * Timer.cpp + * + * Created on: Oct 14, 2022 + * Author: tylen + */ + +#include + +extern "C" +{ + void + SysTick_Handler (void) + { + if (timer > 0) + timer--; + } +} + +Timer::Timer (uint32_t freq) : freq (freq) +{ + Chip_Clock_SetSysTickClockDiv (1); + uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate (); + SysTick_Config (sysTickRate / freq); + counter = 0; + timer = 0; +} + +Timer::~Timer () +{ + // TODO Auto-generated destructor stub +} + +void +Timer::tickCounter (int ms) +{ + if (counter >= INT_MAX) + { + counter = 0; + } + counter++; + Sleep (ms); +} + +void +Timer::Sleep (int ms) +{ + timer = ms; + while (timer > 0) + { + __WFI (); + } +} + +int +Timer::getCounter () +{ + return counter; +} + +void +Timer::resetCounter () +{ + counter = 0; +} diff --git a/esp-vent-main/.cproject b/esp-vent-main/.cproject index 56d571c..424e11a 100644 --- a/esp-vent-main/.cproject +++ b/esp-vent-main/.cproject @@ -44,6 +44,7 @@ + @@ -118,6 +121,7 @@ + @@ -262,6 +270,7 @@ +