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
*
*/
Timer (uint32_t freq = 1000);
Timer (uint32_t freq = 1000, bool mode = true);
Timer (bool mode);
virtual ~Timer ();
/**

View File

@ -13,6 +13,8 @@
#define BROKER_IP "192.168.1.254"
#define BROKER_PORT 1883
#define ONE_K_HZ 1000
enum _global_values
{
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);
uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate ();
SysTick_Config (sysTickRate / freq);
resetCounter ();
timer = 0;
systicks.store (0, std::memory_order_relaxed);
}
Timer::Timer (bool mode)
{
this->mode = false;
}
resetCounter ();
timer = 0;
systicks.store (0, std::memory_order_relaxed);

View File

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