Atm_comparator.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <Automaton.h>
  3. class Atm_comparator : public Machine {
  4. public:
  5. enum { IDLE, SAMPLE, SEND }; // STATES
  6. enum { EVT_TRIGGER, EVT_TIMER, ELSE }; // EVENTS
  7. Atm_comparator( void ) : Machine(){};
  8. Atm_comparator& begin( int attached_pin, int sampleRate = 50 );
  9. Atm_comparator& threshold( uint16_t* v, uint16_t size, bool catchUp = false );
  10. Atm_comparator& average( uint16_t* v, uint16_t size );
  11. Atm_comparator& skip();
  12. Atm_comparator& onChange( atm_cb_push_t callback, int idx = 0 );
  13. Atm_comparator& onChange( Machine& machine, int event = 0 );
  14. Atm_comparator& onChange( bool status, atm_cb_push_t callback, int idx = 0 );
  15. Atm_comparator& onChange( bool status, Machine& machine, int event = 0 );
  16. int state( void );
  17. virtual int read_sample();
  18. Atm_comparator& trace( Stream& stream );
  19. private:
  20. enum { ENT_SAMPLE, ENT_SEND }; // ACTIONS
  21. short pin;
  22. atm_timer_millis timer;
  23. int v_sample, v_threshold, v_previous;
  24. uint64_t bitmap_sample, bitmap_previous, bitmap_diff;
  25. uint16_t* p_threshold; // Max 64 values
  26. uint16_t p_threshold_size;
  27. uint16_t* avg_buf;
  28. uint16_t avg_buf_size;
  29. uint16_t avg_buf_head;
  30. uint32_t avg_buf_total;
  31. atm_connector onup, ondown;
  32. int skip_mode;
  33. int avg();
  34. Atm_comparator& bitmap( uint16_t v );
  35. int sample();
  36. int event( int id );
  37. void action( int id );
  38. };