Atm_AccelStepper.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. #include "Atm_AccelStepper.h"
  2. /* Add optional parameters for the state machine to begin()
  3. * Add extra initialization code
  4. */
  5. Atm_AccelStepper& Atm_AccelStepper::begin(int step_pin, int dir_pin) {
  6. // clang-format off
  7. const static state_t state_table[] PROGMEM = {
  8. /* ON_ENTER ON_LOOP ON_EXIT EVT_DISABLE EVT_ENABLE EVT_ENABLED_TIMEOUT EVT_MOVE EVT_STOP EVT_EMERGENCY_STOP EVT_ON_LIMIT_LOW EVT_ON_LIMIT_HIGH EVT_ON_TARGET EVT_HOMING_LOW EVT_HOMING_HIGH ELSE */
  9. /* DISABLE */ ENT_DISABLED, -1, -1, -1, ENABLED, -1, RUNNING, -1, -1, -1, -1, -1, HOMING_LOW, HOMING_HIGH, -1,
  10. /* ENABLED */ ENT_ENABLED, -1, -1, DISABLE, -1, DISABLE, RUNNING, STOP, STOP, LIMIT_LOW, LIMIT_HIGH, -1, HOMING_LOW, HOMING_HIGH, -1,
  11. /* RUNNING */ ENT_RUNNING, LP_RUNNING, -1, DISABLE, -1, -1, RUNNING, STOP, STOP, LIMIT_LOW, LIMIT_HIGH, ENABLED, -1, -1, -1,
  12. /* STOP */ ENT_STOP, LP_STOP, -1, DISABLE, -1, -1, RUNNING, -1, -1, -1, -1, ENABLED, -1, -1, -1,
  13. /* HOMING_LOW */ ENT_HOMING_LOW, LP_HOMING_LOW, EXT_HOMING_LOW, DISABLE, -1, -1, -1, STOP, STOP, LIMIT_LOW, LIMIT_HIGH, -1, -1, -1, -1,
  14. /* HOMING_HIGH */ ENT_HOMING_HIGH, LP_HOMING_HIGH, EXT_HOMING_HIGH, DISABLE, -1, -1, -1, STOP, STOP, LIMIT_LOW, LIMIT_HIGH, -1, -1, -1, -1,
  15. /* LIMIT_LOW */ ENT_LIMIT_LOW, LP_LIMIT_LOW, -1, -1, -1, -1, RUNNING, STOP, STOP, LIMIT_LOW, -1, -1, -1, -1, -1,
  16. /* LIMIT_HIGH */ ENT_LIMIT_HIGH, LP_LIMIT_HIGH, -1, -1, -1, -1, RUNNING, STOP, STOP, -1, LIMIT_HIGH, -1, -1, -1, -1
  17. };
  18. // clang-format on
  19. Machine::begin( state_table, ELSE );
  20. stepper = new AccelStepper(1, step_pin, dir_pin);
  21. stepper->setMaxSpeed(max_speed);
  22. stepper->setAcceleration(acceleration);
  23. idle_timer.set(ATM_TIMER_OFF);
  24. position_timer.set(POSITION_SEND_TIMER);
  25. return *this;
  26. }
  27. /* Add C++ code for each internally handled event (input)
  28. * The code must return 1 to trigger the event
  29. */
  30. int Atm_AccelStepper::event( int id ) {
  31. //updateLimitSwitch();
  32. switch ( id ) {
  33. case EVT_DISABLE:
  34. return 0;
  35. case EVT_ENABLE:
  36. return 0;
  37. case EVT_ENABLED_TIMEOUT:
  38. return 0;
  39. case EVT_MOVE:
  40. return 0;
  41. case EVT_STOP:
  42. return 0;
  43. case EVT_EMERGENCY_STOP:
  44. return 0;
  45. case EVT_ON_LIMIT_LOW:
  46. previous_state = limitLow_State;
  47. switch(_limitLow_Mode) {
  48. case 0:
  49. return 0;
  50. case 1: //digital INPUT
  51. // Serial.println("digital");
  52. limitLow_State = digitalRead(_limitLow_Pin);
  53. limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
  54. return limitLow_State != previous_state;
  55. case 2:
  56. int analogTemp = analogRead(_limitLow_Pin);
  57. limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
  58. limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
  59. if(limitLow_State){analogTemp = analogRead(_limitLow_Pin);
  60. limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
  61. limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;}
  62. return limitLow_State != previous_state;
  63. }
  64. case EVT_ON_LIMIT_HIGH:
  65. previous_state = limitHigh_State;
  66. switch(_limitHigh_Mode) {
  67. case 0:
  68. return 0;
  69. case 1: //digital INPUT
  70. limitHigh_State = digitalRead(_limitHigh_Pin);
  71. limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
  72. return limitHigh_State != previous_state;
  73. case 2:
  74. //Serial.println("analog");
  75. int analogTemp = analogRead(_limitHigh_Pin);
  76. limitHigh_State = (_limitHigh_Thresholds[0] < analogTemp) && (analogTemp < _limitHigh_Thresholds[1]);
  77. limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
  78. return limitHigh_State != previous_state;
  79. }
  80. case EVT_ON_TARGET:
  81. return runMode ? 0 : _currentStep == _targetStep;
  82. case EVT_HOMING_LOW:
  83. return 0;
  84. case EVT_HOMING_HIGH:
  85. return 0;
  86. }
  87. return 0;
  88. }
  89. /* Add C++ code for each action
  90. * This generates the 'output' for the state machine
  91. *
  92. * Available connectors:
  93. * push( connectors, ON_CHANGEPOSITION, 0, <v>, <up> );
  94. * push( connectors, ON_CHANGESTATE, 0, <v>, <up> );
  95. * push( connectors, ON_ONLIMITHIGH, 0, <v>, <up> );
  96. * push( connectors, ON_ONLIMITLOW, 0, <v>, <up> );
  97. * push( connectors, ON_ONTARGET, 0, <v>, <up> );
  98. * push( connectors, ON_STOP, 0, <v>, <up> );
  99. */
  100. void Atm_AccelStepper::action( int id ) {
  101. switch ( id ) {
  102. case ENT_DISABLED:
  103. push(connectors, ON_CHANGESTATE, 0, state(), 0);
  104. enabled = _enableReversed ? HIGH : LOW;
  105. digitalWrite(_enablePin, enabled);
  106. return;
  107. case ENT_ENABLED:
  108. _isHoming = 0 ;
  109. if(last_trigger == EVT_ON_TARGET){push( connectors, ON_ONTARGET, 0, _currentStep, 0 );};
  110. push(connectors, ON_CHANGESTATE, 0, state(), 0);
  111. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  112. enabled = _enableReversed ? LOW : HIGH ;
  113. digitalWrite(_enablePin, enabled);
  114. return;
  115. case ENT_RUNNING:
  116. push(connectors, ON_CHANGESTATE, 0, state(), 0);
  117. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  118. _isHoming = 0;
  119. //reset limit state so that they trigger again if we're stopped on it
  120. // limitLow_State = 0;
  121. // limitHigh_State = 0;
  122. Serial.print("target ");
  123. Serial.println(_targetStep);
  124. stepper->moveTo(_targetStep);
  125. // stepper->computeNewSpeed();
  126. //stepper_update();
  127. //push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  128. position_timer.setFromNow(this, POSITION_SEND_TIMER);
  129. return;
  130. case LP_RUNNING:
  131. stepper_update();
  132. if(stepper->speed() == 0.) {trigger(EVT_ON_TARGET);}
  133. return;
  134. case ENT_STOP:
  135. push(connectors, ON_CHANGESTATE, 0, state(), 0);
  136. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  137. if (last_trigger == EVT_STOP) {
  138. // runMode = 0 ;
  139. stepper->stop();
  140. _targetStep = stepper->targetPosition();
  141. push( connectors, ON_STOP, 0, 0, 0 );
  142. }
  143. if (last_trigger == EVT_EMERGENCY_STOP) {
  144. stepper->setSpeed(0);
  145. _currentStep = stepper->currentPosition();
  146. _targetStep = _currentStep ;
  147. stepper->moveTo(_targetStep);
  148. push( connectors, ON_STOP, 0, 1, 0 );
  149. }
  150. return;
  151. case LP_STOP:
  152. stepper_update();
  153. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  154. if(stepper->speed() == 0.) {trigger(EVT_ON_TARGET);}
  155. // _currentStep = stepper->currentPosition();
  156. return;
  157. case ENT_HOMING_LOW:
  158. push(connectors, ON_CHANGESTATE, 0, state(), 0);
  159. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  160. runMode = 1;
  161. _isHoming = 1 ;
  162. stepper->setSpeed(-1*homing_speed);
  163. return;
  164. case LP_HOMING_LOW:
  165. stepper_update();
  166. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  167. return;
  168. case EXT_HOMING_LOW:
  169. runMode = 0;
  170. _isHoming = 0;
  171. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  172. if(last_trigger == EVT_ON_LIMIT_LOW) {
  173. stepper->setCurrentPosition(0);
  174. _currentStep = 0;
  175. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  176. Serial.println("homing low done");
  177. }
  178. else{Serial.println("homing low failed");}
  179. trigger(EVT_EMERGENCY_STOP);
  180. return;
  181. case ENT_HOMING_HIGH:
  182. push(connectors, ON_CHANGESTATE, 0, state(), 0);
  183. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  184. runMode = 1;
  185. _isHoming = 2 ;
  186. stepper->setSpeed(homing_speed);
  187. return;
  188. case LP_HOMING_HIGH:
  189. stepper_update();
  190. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  191. return;
  192. case EXT_HOMING_HIGH:
  193. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  194. runMode = 0;
  195. _isHoming = 0;
  196. trigger(EVT_EMERGENCY_STOP);
  197. if(last_trigger == EVT_ON_LIMIT_HIGH) {
  198. _maxStep = stepper->currentPosition();
  199. _currentStep = _maxStep;
  200. Serial.println("homing high done");
  201. }
  202. else{Serial.println("homing high failed");}
  203. _targetStep = _currentStep;
  204. return;
  205. case ENT_LIMIT_LOW:
  206. /*triggered by a change in limit state
  207. if state is 0, we may leave this state for running
  208. if state is 1 we stay in limit state loop, where moves are allowed only in
  209. the free direction, until a trigger comes with state 0
  210. */
  211. push( connectors, ON_ONLIMITLOW, 0, limitLow_State, 0 );
  212. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  213. if (!limitLow_State){trigger(EVT_MOVE);}
  214. return;
  215. case LP_LIMIT_LOW:
  216. //stop motor if going down, allow going up
  217. if(_limitLow_Hard && (_targetStep < _currentStep)) {
  218. // Serial.println("youpi");
  219. _currentStep = stepper->currentPosition();
  220. stepper->moveTo(_currentStep);
  221. _targetStep = _currentStep;
  222. stepper->setSpeed(0);
  223. }
  224. stepper_update();
  225. //else{} // _isHoming ? trigger(EVT_STOP):
  226. return;
  227. case ENT_LIMIT_HIGH:
  228. push( connectors, ON_ONLIMITHIGH, 0, limitHigh_State, 0 );
  229. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  230. if (!limitHigh_State){trigger(EVT_MOVE);};
  231. return;
  232. case LP_LIMIT_HIGH:
  233. //stop motor if going down, allow going up
  234. if(_limitHigh_Hard && (_targetStep > _currentStep)) {
  235. // Serial.println("youpi");
  236. _currentStep = stepper->currentPosition();
  237. stepper->moveTo(_currentStep);
  238. _targetStep = _currentStep;
  239. stepper->setSpeed(0);
  240. }
  241. stepper_update();
  242. // else{}
  243. return;
  244. }
  245. }
  246. /* Optionally override the default trigger() method
  247. * Control how your machine processes triggers
  248. */
  249. Atm_AccelStepper& Atm_AccelStepper::trigger( int event ) {
  250. Machine::trigger( event );
  251. return *this;
  252. }
  253. /* Optionally override the default state() method
  254. * Control what the machine returns when another process requests its state
  255. */
  256. int Atm_AccelStepper::state( void ) {
  257. return Machine::state();
  258. }
  259. /* Nothing customizable below this line
  260. ************************************************************************************************
  261. */
  262. /* Still I'll customize a little just here
  263. */
  264. void Atm_AccelStepper::stepper_update(void) {
  265. switch (runMode) {
  266. case 0: //positional modae
  267. stepper->run();
  268. break;
  269. case 1: // speed mode
  270. stepper->runSpeed();
  271. break;
  272. }
  273. // Serial.print("update ");
  274. // Serial.println(stepper->speed());
  275. long int tempStep = stepper->currentPosition();
  276. if (tempStep != _currentStep){
  277. _currentStep = tempStep;
  278. //Serial.println(stepper->currentPosition());
  279. if (position_timer.expired(this)){
  280. push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
  281. position_timer.setFromNow(this, POSITION_SEND_TIMER);
  282. }
  283. }
  284. }
  285. Atm_AccelStepper& Atm_AccelStepper::setMaxSpeed( long int maxSpeed){
  286. max_speed = maxSpeed ;
  287. stepper->setMaxSpeed(max_speed);
  288. return *this ;
  289. }
  290. Atm_AccelStepper& Atm_AccelStepper::setHomingSpeed(long int homingSpeed){
  291. homing_speed = homingSpeed ;
  292. return *this ;
  293. }
  294. Atm_AccelStepper& Atm_AccelStepper::setAcceleration(long int acc){
  295. acceleration = acc ;
  296. stepper->setAcceleration(acceleration);
  297. return *this ;
  298. }
  299. Atm_AccelStepper& Atm_AccelStepper::setPosition(long int position){
  300. stepper->setCurrentPosition(position);
  301. _currentStep = position ;
  302. return *this ;
  303. }
  304. long int Atm_AccelStepper::getPosition(){
  305. return stepper->currentPosition();;
  306. }
  307. long int Atm_AccelStepper::distanceToGo(){
  308. return stepper->distanceToGo();;
  309. }
  310. bool Atm_AccelStepper::isRunning(){
  311. return stepper->isRunning();
  312. }
  313. float Atm_AccelStepper::getSpeed(){
  314. return stepper->speed();
  315. }
  316. Atm_AccelStepper& Atm_AccelStepper::position_refresh(long int refresh_ms){
  317. POSITION_SEND_TIMER = refresh_ms ;
  318. return *this ;
  319. }
  320. Atm_AccelStepper& Atm_AccelStepper::move( long int stepRel) {
  321. _targetStep = _currentStep + stepRel;
  322. runMode = 0;
  323. _isHoming = 0;
  324. //Serial.println(_targetStep);
  325. stepper->moveTo(_targetStep);
  326. enable();
  327. trigger( EVT_MOVE );
  328. return *this;
  329. }
  330. Atm_AccelStepper& Atm_AccelStepper::moveTo( long int stepAbs) {
  331. _targetStep = stepAbs;
  332. _isHoming = 0 ;
  333. runMode = 0;
  334. stepper->moveTo(_targetStep);
  335. enable();
  336. trigger( EVT_MOVE );
  337. return *this;
  338. }
  339. Atm_AccelStepper& Atm_AccelStepper::rotate( long int speed) {
  340. runMode = 1;
  341. _isHoming = 0 ;
  342. stepper->setSpeed( speed);
  343. enable();
  344. trigger( EVT_MOVE );
  345. return *this;
  346. }
  347. Atm_AccelStepper& Atm_AccelStepper::homing( bool direction ){
  348. enable();
  349. direction == 1 ? _isHoming = 2 : _isHoming = 1;
  350. direction == 1 ? this->trigger(EVT_HOMING_HIGH) : this->trigger(EVT_HOMING_LOW);
  351. return *this;
  352. }
  353. // Atm_AccelStepper& Atm_AccelStepper::rotationReversed(bool reversed){
  354. // _rotationReversed = reversed ? -1 : 1 ;
  355. // }
  356. Atm_AccelStepper& Atm_AccelStepper::setEnablePin( int enablePin ){
  357. _enablePin = enablePin ;
  358. pinMode(_enablePin, OUTPUT);
  359. return *this;
  360. }
  361. Atm_AccelStepper& Atm_AccelStepper::pinReversed( bool directionInvert,
  362. bool stepInvert, bool enableInvert){
  363. stepper->setPinsInverted(directionInvert, stepInvert, enableInvert);
  364. return *this;
  365. }
  366. Atm_AccelStepper& Atm_AccelStepper::limitLow_set(int mode, int pin, int reversed){
  367. _limitLow_Mode = mode ;
  368. _limitLow_Pin = pin ;
  369. _limitLow_Reversed = reversed ;
  370. if (_limitLow_Mode==1) {pinMode(_limitLow_Pin, INPUT_PULLUP);}
  371. if (_limitLow_Mode==2) {pinMode(_limitLow_Pin, INPUT);}
  372. return *this;
  373. }
  374. Atm_AccelStepper& Atm_AccelStepper::limitLow_isHard(bool hardlimit){
  375. _limitLow_Hard = hardlimit;
  376. return *this;
  377. }
  378. Atm_AccelStepper& Atm_AccelStepper::limitLow_setThresholds (int threshold_low, int threshold_high){
  379. _limitLow_Thresholds[0] = threshold_low ;
  380. _limitLow_Thresholds[1] = threshold_high ;
  381. return *this;
  382. }
  383. Atm_AccelStepper& Atm_AccelStepper::limitHigh_set(int mode, int pin, int reversed){
  384. _limitHigh_Mode = mode ;
  385. _limitHigh_Pin = pin ;
  386. _limitHigh_Reversed = reversed ;
  387. if (_limitHigh_Mode==1) {pinMode(_limitHigh_Pin, INPUT_PULLUP);}
  388. if (_limitHigh_Mode==2) {pinMode(_limitHigh_Pin, INPUT);}
  389. return *this;
  390. }
  391. Atm_AccelStepper& Atm_AccelStepper::limitHigh_isHard(bool hardlimit){
  392. _limitHigh_Hard = hardlimit;
  393. return *this;
  394. }
  395. Atm_AccelStepper& Atm_AccelStepper::limitHigh_setThresholds (int threshold_low, int threshold_high){
  396. _limitHigh_Thresholds[0] = threshold_low ;
  397. _limitHigh_Thresholds[1] = threshold_high ;
  398. return *this;
  399. }
  400. /* Public event methods
  401. *
  402. */
  403. Atm_AccelStepper& Atm_AccelStepper::disable() {
  404. trigger( EVT_DISABLE );
  405. return *this;
  406. }
  407. Atm_AccelStepper& Atm_AccelStepper::enable() {
  408. trigger( EVT_ENABLE );
  409. return *this;
  410. }
  411. // Atm_AccelStepper& Atm_AccelStepper::move() {
  412. // trigger( EVT_MOVE );
  413. // return *this;
  414. // }
  415. Atm_AccelStepper& Atm_AccelStepper::stop() {
  416. trigger( EVT_STOP );
  417. return *this;
  418. }
  419. Atm_AccelStepper& Atm_AccelStepper::emergency_stop() {
  420. trigger( EVT_EMERGENCY_STOP );
  421. return *this;
  422. }
  423. Atm_AccelStepper& Atm_AccelStepper::on_limit_low() {
  424. trigger( EVT_ON_LIMIT_LOW );
  425. return *this;
  426. }
  427. Atm_AccelStepper& Atm_AccelStepper::on_limit_high() {
  428. trigger( EVT_ON_LIMIT_HIGH );
  429. return *this;
  430. }
  431. Atm_AccelStepper& Atm_AccelStepper::on_target() {
  432. trigger( EVT_ON_TARGET );
  433. return *this;
  434. }
  435. /*
  436. * onChangeposition() push connector variants ( slots 1, autostore 0, broadcast 0 )
  437. */
  438. Atm_AccelStepper& Atm_AccelStepper::onChangeposition( Machine& machine, int event ) {
  439. onPush( connectors, ON_CHANGEPOSITION, 0, 1, 1, machine, event );
  440. return *this;
  441. }
  442. Atm_AccelStepper& Atm_AccelStepper::onChangeposition( atm_cb_push_t callback, int idx ) {
  443. onPush( connectors, ON_CHANGEPOSITION, 0, 1, 1, callback, idx );
  444. return *this;
  445. }
  446. /*
  447. * onChangestate() push connector variants ( slots 1, autostore 0, broadcast 0 )
  448. */
  449. Atm_AccelStepper& Atm_AccelStepper::onChangestate( Machine& machine, int event ) {
  450. onPush( connectors, ON_CHANGESTATE, 0, 1, 1, machine, event );
  451. return *this;
  452. }
  453. Atm_AccelStepper& Atm_AccelStepper::onChangestate( atm_cb_push_t callback, int idx ) {
  454. onPush( connectors, ON_CHANGESTATE, 0, 1, 1, callback, idx );
  455. return *this;
  456. }
  457. /*
  458. * onOnlimithigh() push connector variants ( slots 1, autostore 0, broadcast 0 )
  459. */
  460. Atm_AccelStepper& Atm_AccelStepper::onOnlimithigh( Machine& machine, int event ) {
  461. onPush( connectors, ON_ONLIMITHIGH, 0, 1, 1, machine, event );
  462. return *this;
  463. }
  464. Atm_AccelStepper& Atm_AccelStepper::onOnlimithigh( atm_cb_push_t callback, int idx ) {
  465. onPush( connectors, ON_ONLIMITHIGH, 0, 1, 1, callback, idx );
  466. return *this;
  467. }
  468. /*
  469. * onOnlimitlow() push connector variants ( slots 1, autostore 0, broadcast 0 )
  470. */
  471. Atm_AccelStepper& Atm_AccelStepper::onOnlimitlow( Machine& machine, int event ) {
  472. onPush( connectors, ON_ONLIMITLOW, 0, 1, 1, machine, event );
  473. return *this;
  474. }
  475. Atm_AccelStepper& Atm_AccelStepper::onOnlimitlow( atm_cb_push_t callback, int idx ) {
  476. onPush( connectors, ON_ONLIMITLOW, 0, 1, 1, callback, idx );
  477. return *this;
  478. }
  479. /*
  480. * onOntarget() push connector variants ( slots 1, autostore 0, broadcast 0 )
  481. */
  482. Atm_AccelStepper& Atm_AccelStepper::onOntarget( Machine& machine, int event ) {
  483. onPush( connectors, ON_ONTARGET, 0, 1, 1, machine, event );
  484. return *this;
  485. }
  486. Atm_AccelStepper& Atm_AccelStepper::onOntarget( atm_cb_push_t callback, int idx ) {
  487. onPush( connectors, ON_ONTARGET, 0, 1, 1, callback, idx );
  488. return *this;
  489. }
  490. /*
  491. * onStop() push connector variants ( slots 1, autostore 0, broadcast 0 )
  492. */
  493. Atm_AccelStepper& Atm_AccelStepper::onStop( Machine& machine, int event ) {
  494. onPush( connectors, ON_STOP, 0, 1, 1, machine, event );
  495. return *this;
  496. }
  497. Atm_AccelStepper& Atm_AccelStepper::onStop( atm_cb_push_t callback, int idx ) {
  498. onPush( connectors, ON_STOP, 0, 1, 1, callback, idx );
  499. return *this;
  500. }
  501. Atm_AccelStepper& Atm_AccelStepper::onOnhominglow( Machine& machine, int event ) {
  502. onPush( connectors, ON_ONTARGET, 0, 1, 1, machine, event );
  503. return *this;
  504. }
  505. Atm_AccelStepper& Atm_AccelStepper::onOnhominglow( atm_cb_push_t callback, int idx ) {
  506. onPush( connectors, ON_ONTARGET, 0, 1, 1, callback, idx );
  507. return *this;
  508. }
  509. Atm_AccelStepper& Atm_AccelStepper::onOnhominghigh( Machine& machine, int event ) {
  510. onPush( connectors, ON_ONTARGET, 0, 1, 1, machine, event );
  511. return *this;
  512. }
  513. Atm_AccelStepper& Atm_AccelStepper::onOnhominghigh( atm_cb_push_t callback, int idx ) {
  514. onPush( connectors, ON_ONTARGET, 0, 1, 1, callback, idx );
  515. return *this;
  516. }
  517. /* State trace method
  518. * Sets the symbol table and the default logging method for serial monitoring
  519. */
  520. Atm_AccelStepper& Atm_AccelStepper::trace( Stream & stream ) {
  521. Machine::setTrace( &stream, atm_serial_debug::trace,
  522. "ACCELSTEPPER\0EVT_DISABLE\0EVT_ENABLE\0EVT_ENABLED_TIMEOUT\0EVT_MOVE\0EVT_STOP\0EVT_EMERGENCY_STOP\0EVT_ON_LIMIT_LOW\0EVT_ON_LIMIT_HIGH\0EVT_ON_TARGET\0EVT_HOMING_LOW\0EVT_HOMING_HIGH\0ELSE\0DISABLED\0ENABLED\0RUNNING\0STOP\0HOMING_LOW\0HOMING_HIGH\0LIMIT_LOW\0LIMIT_HIGH" );
  523. return *this;
  524. }