state-handler: fix auto mode

This commit is contained in:
Evgenii Meshcheriakov 2022-10-27 16:33:36 +03:00
parent 58dbbf0f06
commit fa8734a9a8
5 changed files with 34 additions and 7 deletions

View File

@ -75,8 +75,10 @@ public:
private:
volatile std::atomic_int counter;
volatile std::atomic_int prev_ticks;
uint32_t freq;
bool mode;
};
#endif /* TIMER_H_ */

View File

@ -18,9 +18,9 @@
enum _global_values
{
LCD_SIZE = 16,
TIMER_GLOBAL_TIMEOUT = 15000,
TIMER_GLOBAL_TIMEOUT = 120000,
TIMER_SENSORS_TIMEOUT = 5000,
TIMER_PRESSURE_TIMEOUT = 500,
TIMER_PRESSURE_TIMEOUT = 250,
TIMER_ERROR_VALUE = -255,
};

View File

@ -150,8 +150,8 @@ StateHandler::stateAuto (const Event &event)
break;
case Event::eTick:
handleTickValue (event.value);
pid ();
this->_propeller->spin (fan_speed.getCurrent ());
pid ();
this->_propeller->spin (fan_speed.getCurrent ());
break;
}
}
@ -190,13 +190,16 @@ StateHandler::handleControlButtons (uint8_t button)
{
case BUTTON_CONTROL_DOWN:
this->value[(current_mode)].dec ();
state_timer->resetCounter();
break;
case BUTTON_CONTROL_UP:
this->value[(current_mode)].inc ();
state_timer->resetCounter();
break;
case BUTTON_CONTROL_TOG_MODE:
current_mode = !current_mode;
SetState (&StateHandler::stateInit);
state_timer->resetCounter();
return;
break;
default:
@ -220,9 +223,10 @@ StateHandler::handleTickValue (int value)
updateSensorValues ();
// displaySet (SENSORS);
}
if (value % TIMER_PRESSURE_TIMEOUT == 0)
if (value > TIMER_PRESSURE_TIMEOUT)
{
SetState (&StateHandler::stateGetPressure);
state_timer->resetCounter();
}
if (value == TIMER_ERROR_VALUE)
{
@ -282,7 +286,7 @@ StateHandler::updateSensorValues ()
{
sensors_data[TEMPERATURE] = humidity.readT ();
sensors_data[PRESSUREDAT] = _pressure->getPressure ();
// sensors_data[PRESSUREDAT] = _pressure->getPressure ();
sensors_data[CO2] = co2.read ();
state_timer->tickCounter (5);
sensors_data[HUMIDITY] = humidity.readRH ();

View File

@ -28,6 +28,7 @@ Timer::Timer (uint32_t freq, bool setup) : freq (freq), mode (setup)
}
resetCounter ();
timer = 0;
prev_ticks = 0;
systicks.store (0, std::memory_order_relaxed);
}
@ -43,8 +44,9 @@ Timer::tickCounter (int ms)
{
resetCounter ();
}
counter.fetch_add (ms, std::memory_order_relaxed);
Sleep (ms);
counter += (systicks - prev_ticks);
prev_ticks = systicks;
}
void

View File

@ -71,8 +71,21 @@ main (void)
/* Other declarations */
int getcounterValue;
uint32_t sleep_Arr[100] = {0};
CoreDebug->DEMCR |= 1 << 24;
DWT->CTRL |= 1;
volatile static int i1 = 0 ;
volatile static int i2 = 0 ;
volatile static int i = 0 ;
while (1)
{
i1 = DWT->CYCCNT;
getcounterValue = glob_time.getCounter ();
if (getcounterValue > TIMER_GLOBAL_TIMEOUT)
{
@ -84,6 +97,12 @@ main (void)
sw_toggle.listen ();
ventMachine.HandleState (Event (Event::eTick, getcounterValue));
glob_time.tickCounter (1);
// i2 = DWT->CYCCNT;
// sleep_Arr[i] = (i2 - i1) / 72;
// ++i;
// if (i == 100)
// while(1);
}
return 0;