Atm_timer.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <Automaton.h>
  3. class Atm_timer : public Machine {
  4. public:
  5. enum { IDLE, START, WAITD, WAITMS, TRIGGER, FINISH };
  6. enum { EVT_DAYCNT, EVT_DAYTIMER, EVT_MSTIMER, EVT_REPCNT, EVT_STOP, EVT_START, EVT_TOGGLE, ELSE }; // EVT_PAUSE, EVT_RESUME
  7. Atm_timer( void ) : Machine(){};
  8. Atm_timer& begin( uint32_t ms = 0, uint16_t repeats = 1 );
  9. Atm_timer& trace( Stream& stream );
  10. Atm_timer& onTimer( atm_cb_push_t callback, int idx = 0 );
  11. Atm_timer& onTimer( Machine& machine, int event = 0 );
  12. Atm_timer& onFinish( atm_cb_push_t callback, int idx = 0 );
  13. Atm_timer& onFinish( Machine& machine, int event = 0 );
  14. Atm_timer& interval_seconds( uint32_t v );
  15. Atm_timer& interval_millis( uint32_t v );
  16. Atm_timer& interval( uint32_t v );
  17. uint32_t left();
  18. Atm_timer& repeat( uint16_t v = ATM_COUNTER_OFF );
  19. Atm_timer& start( void );
  20. Atm_timer& stop( void );
  21. Atm_timer& toggle( void );
  22. // Atm_timer& pause( void ); TODO
  23. // Atm_timer& resume( void );
  24. private:
  25. enum { ENT_START, ENT_TRIGGER, EXT_WAITD, ENT_FINISH };
  26. atm_timer_millis daytimer, mstimer;
  27. atm_counter daycounter, repcounter;
  28. uint32_t abscounter;
  29. uint16_t days;
  30. uint16_t repeat_cnt;
  31. atm_connector ontimer, onfinish;
  32. int event( int id );
  33. void action( int id );
  34. };