Atm_sweep.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <Automaton.h>
  2. #include "Atm_sweep.h"
  3. Atm_sweep & Atm_sweep::begin( int p0, int p1, int p2, int p3, int p4, int p5 ) {
  4. const static state_t state_table[] PROGMEM = {
  5. /* ON_ENTER ON_LOOP ON_EXIT EVT_TIMER EVT_START EVT_STOP EVT_TOGGLE, ELSE */
  6. /* IDLE */ ENT_OFF, ATM_SLEEP, -1, -1, U0, IDLE, U0, -1,
  7. /* U0 */ ENT_L0, -1, ENT_OFF, U1, -1, IDLE, IDLE, -1,
  8. /* U1 */ ENT_L1, -1, ENT_OFF, U2, -1, IDLE, IDLE, -1,
  9. /* U2 */ ENT_L2, -1, ENT_OFF, U3, -1, IDLE, IDLE, -1,
  10. /* U3 */ ENT_L3, -1, ENT_OFF, U4, -1, IDLE, IDLE, -1,
  11. /* U4 */ ENT_L4, -1, ENT_OFF, U5, -1, IDLE, IDLE, -1,
  12. /* U5 */ ENT_L5, -1, ENT_OFF, D4, -1, IDLE, IDLE, -1,
  13. /* D4 */ ENT_L4, -1, ENT_OFF, D3, -1, IDLE, IDLE, -1,
  14. /* D3 */ ENT_L3, -1, ENT_OFF, D2, -1, IDLE, IDLE, -1,
  15. /* D2 */ ENT_L2, -1, ENT_OFF, D1, -1, IDLE, IDLE, -1,
  16. /* D1 */ ENT_L1, -1, ENT_OFF, D0, -1, IDLE, IDLE, -1,
  17. /* D0 */ ENT_L0, -1, ENT_OFF, U0, -1, IDLE, IDLE, -1,
  18. };
  19. Machine::begin( state_table, ELSE );
  20. pin[0] = p0; pin[1] = p1; pin[2] = p2;
  21. pin[3] = p3; pin[4] = p4; pin[5] = p5;
  22. timer.set( 200 );
  23. for ( uint8_t i = 0; i <= 5; i++ ) {
  24. pinMode( pin[i], OUTPUT );
  25. }
  26. return *this;
  27. }
  28. Atm_sweep & Atm_sweep::speed( uint32_t v ) {
  29. timer.set( v );
  30. return *this;
  31. }
  32. int Atm_sweep::event( int id ) {
  33. switch ( id ) {
  34. case EVT_TIMER :
  35. return timer.expired( this );
  36. }
  37. return 0;
  38. }
  39. void Atm_sweep::action( int id ) {
  40. switch ( id ) {
  41. case ENT_L0 : return digitalWrite( pin[0], HIGH );
  42. case ENT_L1 : return digitalWrite( pin[1], HIGH );
  43. case ENT_L2 : return digitalWrite( pin[2], HIGH );
  44. case ENT_L3 : return digitalWrite( pin[3], HIGH );
  45. case ENT_L4 : return digitalWrite( pin[4], HIGH );
  46. case ENT_L5 : return digitalWrite( pin[5], HIGH );
  47. case ENT_OFF :
  48. for ( uint8_t i = 0; i <= 5; i++ ) {
  49. digitalWrite( pin[i], LOW );
  50. }
  51. return;
  52. }
  53. }
  54. Atm_sweep & Atm_sweep::trace( Stream & stream ) {
  55. Machine::setTrace( &stream, atm_serial_debug::trace,
  56. "SWEEP\0EVT_TIMER\0EVT_START\0EVT_STOP\0ELSE\0"
  57. "IDLE\0U0\0U1\0U2\0U3\0U4\0U5\0D4\0D3\0D2\0D1\0D0" );
  58. return *this;
  59. }