Atm_AccelStepper.cpp 21 KB

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