#pragma once

#include <Automaton.h>
// #include <TeensyStep.h>
#include <AccelStepper.h>
class Atm_stepper: public Machine {

 public:
  enum { IDLE, READY, RUNNING, STOPPING }; // STATES
  enum { EVT_IDLE_TIMER, EVT_ON_TARGET, EVT_GOTO, ELSE }; // EVENTS
  Atm_stepper( void ) : Machine()  {};
  Atm_stepper& begin( int setpPin, int dirPin ) ;
  Atm_stepper& trace( Stream & stream );
  Atm_stepper& trigger( int event );
  int state( void );
  Atm_stepper& onOnchange( Machine& machine, int event = 0 );
  Atm_stepper& onOnchange( atm_cb_push_t callback, int idx = 0 );
  Atm_stepper& gotoStep( long int targetStep );

 private:
  AccelStepper _motor;
  // Stepper *_motor;       // STEP pin: 2, DIR pin: 3
  // StepControl _controller;
  enum { ENT_IDLE, ENT_READY, ENT_RUNNING, LP_RUNNING, ENT_STOPPING, EXT_STOPPING }; // ACTIONS
  enum { ON_ONCHANGE, CONN_MAX }; // CONNECTORS
  atm_connector connectors[CONN_MAX];
  int event( int id );
  void action( int id );

};

/*
Automaton::ATML::begin - Automaton Markup Language

<?xml version="1.0" encoding="UTF-8"?>
<machines>
  <machine name="Atm_stepper">
    <states>
      <IDLE index="0" on_enter="ENT_IDLE">
        <EVT_GOTO>RUNNING</EVT_GOTO>
      </IDLE>
      <READY index="1" on_enter="ENT_READY">
        <EVT_IDLE_TIMER>IDLE</EVT_IDLE_TIMER>
        <EVT_GOTO>RUNNING</EVT_GOTO>
      </READY>
      <RUNNING index="2" on_enter="ENT_RUNNING" on_loop="LP_RUNNING">
        <EVT_ON_TARGET>STOPPING</EVT_ON_TARGET>
        <EVT_GOTO>RUNNING</EVT_GOTO>
      </RUNNING>
      <STOPPING index="3" on_enter="ENT_STOPPING" on_exit="EXT_STOPPING">
        <EVT_ON_TARGET>READY</EVT_ON_TARGET>
      </STOPPING>
    </states>
    <events>
      <EVT_IDLE_TIMER index="0" access="PRIVATE"/>
      <EVT_ON_TARGET index="1" access="PRIVATE"/>
      <EVT_GOTO index="2" access="PUBLIC"/>
    </events>
    <connectors>
      <ONCHANGE autostore="0" broadcast="0" dir="PUSH" slots="1"/>
    </connectors>
    <methods>
    </methods>
  </machine>
</machines>

Automaton::ATML::end
*/
