Atm_encoder.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <Automaton.h>
  3. class Atm_encoder : public Machine {
  4. public:
  5. enum { IDLE, UP, DOWN }; // STATES
  6. enum { EVT_UP, EVT_DOWN, ELSE }; // EVENTS
  7. Atm_encoder( void ) : Machine(){};
  8. Atm_encoder& begin( int pin1, int pin2, int divider = 1 );
  9. Atm_encoder& trace( Stream& stream );
  10. Atm_encoder& onChange( Machine& machine, int event = 0 );
  11. Atm_encoder& onChange( atm_cb_push_t callback, int idx = 0 );
  12. Atm_encoder& onChange( bool status, Machine& machine, int event = 0 );
  13. Atm_encoder& onChange( bool status, atm_cb_push_t callback, int idx = 0 );
  14. int state( void );
  15. Atm_encoder& range( int min, int max, bool wrap = false );
  16. Atm_encoder& set( int value );
  17. private:
  18. enum { LP_IDLE, ENT_UP, ENT_DOWN }; // ACTIONS
  19. short pin1, pin2;
  20. const static char enc_states[];
  21. uint8_t enc_bits;
  22. int8_t enc_counter;
  23. int8_t enc_direction;
  24. int divider;
  25. int value, min, max;
  26. bool wrap, range_invert;
  27. atm_connector onup, ondown;
  28. bool count( int direction );
  29. int event( int id );
  30. void action( int id );
  31. };