timer: modify class to have one common constructor

This commit is contained in:
Vasily Davydov 2022-10-27 09:55:50 +03:00
parent 8f54fe85aa
commit 9492081fbb
4 changed files with 15 additions and 17 deletions

View File

@ -33,9 +33,8 @@ public:
* @brief Initalize the systick configuration with your frequency * @brief Initalize the systick configuration with your frequency
* *
*/ */
Timer (uint32_t freq = 1000); Timer (uint32_t freq = 1000, bool mode = true);
Timer (bool mode);
virtual ~Timer (); virtual ~Timer ();
/** /**

View File

@ -13,6 +13,8 @@
#define BROKER_IP "192.168.1.254" #define BROKER_IP "192.168.1.254"
#define BROKER_PORT 1883 #define BROKER_PORT 1883
#define ONE_K_HZ 1000
enum _global_values enum _global_values
{ {
LCD_SIZE = 16, LCD_SIZE = 16,

View File

@ -18,20 +18,14 @@ extern "C"
} }
} }
Timer::Timer (uint32_t freq) : freq (freq) Timer::Timer (uint32_t freq, bool setup) : freq (freq), mode (setup)
{ {
mode = true; if (mode)
{
Chip_Clock_SetSysTickClockDiv (1); Chip_Clock_SetSysTickClockDiv (1);
uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate (); uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate ();
SysTick_Config (sysTickRate / freq); SysTick_Config (sysTickRate / freq);
resetCounter (); }
timer = 0;
systicks.store (0, std::memory_order_relaxed);
}
Timer::Timer (bool mode)
{
this->mode = false;
resetCounter (); resetCounter ();
timer = 0; timer = 0;
systicks.store (0, std::memory_order_relaxed); systicks.store (0, std::memory_order_relaxed);

View File

@ -40,8 +40,11 @@ main (void)
lcd.print ("Vent-Machine"); lcd.print ("Vent-Machine");
/* Timers */ /* Timers */
Timer glob_time; Timer glob_time (ONE_K_HZ, true);
Timer switch_time (false); /* Currently not used, but if we have time left,
* quick button increment is needed
* Timer switch_time (ONE_K_HZ, false);
*/
/* Modbus Fan setup */ /* Modbus Fan setup */
ModbusMaster fan (1); ModbusMaster fan (1);