Atm_digital.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <Automaton.h>
  3. // Digital pin with a minimum duration in ms
  4. // On detection another machine is messaged or a callback is fired
  5. class Atm_digital : public Machine {
  6. public:
  7. enum { IDLE, WAITH, VHIGH, WAITL, VLOW }; // STATES
  8. enum { EVT_TIMER, EVT_HIGH, EVT_LOW, ELSE }; // EVENTS
  9. Atm_digital( void ) : Machine(){};
  10. Atm_digital& begin( int pin, int debounce = 20, bool activeLow = false, bool pullUp = false );
  11. int state( void );
  12. Atm_digital& onChange( bool status, atm_cb_push_t callback, int idx = 0 );
  13. Atm_digital& onChange( bool status, Machine& machine, int event = 0 );
  14. Atm_digital& onChange( atm_cb_push_t callback, int idx = 0 );
  15. Atm_digital& onChange( Machine& machine, int event = 0 );
  16. Atm_digital& led( int led, bool activeLow = false );
  17. Atm_digital& trace( Stream& stream );
  18. private:
  19. enum { ENT_HIGH, ENT_LOW }; // ACTIONS
  20. enum { ON_CHANGE_FALSE, ON_CHANGE_TRUE, _CONN_SIZE_ }; // CONNECTORS
  21. short pin;
  22. atm_timer_millis timer;
  23. bool activeLow;
  24. atm_connector connection[_CONN_SIZE_];
  25. int8_t indicator;
  26. bool indicatorActiveLow;
  27. int event( int id );
  28. void action( int id );
  29. };