state-handler: fix auto mode
This commit is contained in:
parent
58dbbf0f06
commit
fa8734a9a8
@ -75,8 +75,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
volatile std::atomic_int counter;
|
volatile std::atomic_int counter;
|
||||||
|
volatile std::atomic_int prev_ticks;
|
||||||
uint32_t freq;
|
uint32_t freq;
|
||||||
bool mode;
|
bool mode;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TIMER_H_ */
|
#endif /* TIMER_H_ */
|
||||||
|
|||||||
@ -18,9 +18,9 @@
|
|||||||
enum _global_values
|
enum _global_values
|
||||||
{
|
{
|
||||||
LCD_SIZE = 16,
|
LCD_SIZE = 16,
|
||||||
TIMER_GLOBAL_TIMEOUT = 15000,
|
TIMER_GLOBAL_TIMEOUT = 120000,
|
||||||
TIMER_SENSORS_TIMEOUT = 5000,
|
TIMER_SENSORS_TIMEOUT = 5000,
|
||||||
TIMER_PRESSURE_TIMEOUT = 500,
|
TIMER_PRESSURE_TIMEOUT = 250,
|
||||||
TIMER_ERROR_VALUE = -255,
|
TIMER_ERROR_VALUE = -255,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -150,8 +150,8 @@ StateHandler::stateAuto (const Event &event)
|
|||||||
break;
|
break;
|
||||||
case Event::eTick:
|
case Event::eTick:
|
||||||
handleTickValue (event.value);
|
handleTickValue (event.value);
|
||||||
pid ();
|
pid ();
|
||||||
this->_propeller->spin (fan_speed.getCurrent ());
|
this->_propeller->spin (fan_speed.getCurrent ());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,13 +190,16 @@ StateHandler::handleControlButtons (uint8_t button)
|
|||||||
{
|
{
|
||||||
case BUTTON_CONTROL_DOWN:
|
case BUTTON_CONTROL_DOWN:
|
||||||
this->value[(current_mode)].dec ();
|
this->value[(current_mode)].dec ();
|
||||||
|
state_timer->resetCounter();
|
||||||
break;
|
break;
|
||||||
case BUTTON_CONTROL_UP:
|
case BUTTON_CONTROL_UP:
|
||||||
this->value[(current_mode)].inc ();
|
this->value[(current_mode)].inc ();
|
||||||
|
state_timer->resetCounter();
|
||||||
break;
|
break;
|
||||||
case BUTTON_CONTROL_TOG_MODE:
|
case BUTTON_CONTROL_TOG_MODE:
|
||||||
current_mode = !current_mode;
|
current_mode = !current_mode;
|
||||||
SetState (&StateHandler::stateInit);
|
SetState (&StateHandler::stateInit);
|
||||||
|
state_timer->resetCounter();
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -220,9 +223,10 @@ StateHandler::handleTickValue (int value)
|
|||||||
updateSensorValues ();
|
updateSensorValues ();
|
||||||
// displaySet (SENSORS);
|
// displaySet (SENSORS);
|
||||||
}
|
}
|
||||||
if (value % TIMER_PRESSURE_TIMEOUT == 0)
|
if (value > TIMER_PRESSURE_TIMEOUT)
|
||||||
{
|
{
|
||||||
SetState (&StateHandler::stateGetPressure);
|
SetState (&StateHandler::stateGetPressure);
|
||||||
|
state_timer->resetCounter();
|
||||||
}
|
}
|
||||||
if (value == TIMER_ERROR_VALUE)
|
if (value == TIMER_ERROR_VALUE)
|
||||||
{
|
{
|
||||||
@ -282,7 +286,7 @@ StateHandler::updateSensorValues ()
|
|||||||
{
|
{
|
||||||
|
|
||||||
sensors_data[TEMPERATURE] = humidity.readT ();
|
sensors_data[TEMPERATURE] = humidity.readT ();
|
||||||
sensors_data[PRESSUREDAT] = _pressure->getPressure ();
|
// sensors_data[PRESSUREDAT] = _pressure->getPressure ();
|
||||||
sensors_data[CO2] = co2.read ();
|
sensors_data[CO2] = co2.read ();
|
||||||
state_timer->tickCounter (5);
|
state_timer->tickCounter (5);
|
||||||
sensors_data[HUMIDITY] = humidity.readRH ();
|
sensors_data[HUMIDITY] = humidity.readRH ();
|
||||||
|
|||||||
@ -28,6 +28,7 @@ Timer::Timer (uint32_t freq, bool setup) : freq (freq), mode (setup)
|
|||||||
}
|
}
|
||||||
resetCounter ();
|
resetCounter ();
|
||||||
timer = 0;
|
timer = 0;
|
||||||
|
prev_ticks = 0;
|
||||||
systicks.store (0, std::memory_order_relaxed);
|
systicks.store (0, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,8 +44,9 @@ Timer::tickCounter (int ms)
|
|||||||
{
|
{
|
||||||
resetCounter ();
|
resetCounter ();
|
||||||
}
|
}
|
||||||
counter.fetch_add (ms, std::memory_order_relaxed);
|
|
||||||
Sleep (ms);
|
Sleep (ms);
|
||||||
|
counter += (systicks - prev_ticks);
|
||||||
|
prev_ticks = systicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@ -71,8 +71,21 @@ main (void)
|
|||||||
/* Other declarations */
|
/* Other declarations */
|
||||||
int getcounterValue;
|
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)
|
while (1)
|
||||||
{
|
{
|
||||||
|
i1 = DWT->CYCCNT;
|
||||||
|
|
||||||
getcounterValue = glob_time.getCounter ();
|
getcounterValue = glob_time.getCounter ();
|
||||||
if (getcounterValue > TIMER_GLOBAL_TIMEOUT)
|
if (getcounterValue > TIMER_GLOBAL_TIMEOUT)
|
||||||
{
|
{
|
||||||
@ -84,6 +97,12 @@ main (void)
|
|||||||
sw_toggle.listen ();
|
sw_toggle.listen ();
|
||||||
ventMachine.HandleState (Event (Event::eTick, getcounterValue));
|
ventMachine.HandleState (Event (Event::eTick, getcounterValue));
|
||||||
glob_time.tickCounter (1);
|
glob_time.tickCounter (1);
|
||||||
|
|
||||||
|
// i2 = DWT->CYCCNT;
|
||||||
|
// sleep_Arr[i] = (i2 - i1) / 72;
|
||||||
|
// ++i;
|
||||||
|
// if (i == 100)
|
||||||
|
// while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user