Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

states.cpp 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <Arduino.h>
  2. #include "config.h"
  3. #include "config_pins.h"
  4. #include "common.h"
  5. #include "lcd.h"
  6. #include "steppers.h"
  7. #include "statemachine.h"
  8. #include "states.h"
  9. // --------------------------------------
  10. StateText sm_ask_homing = StateText();
  11. StateText sm_do_homing = StateText(&sm_ask_homing);
  12. StateMenu sm_menu = StateMenu(&sm_do_homing);
  13. StateMenu sm_auto = StateMenu(&sm_menu);
  14. StateMenu sm_config = StateMenu(&sm_menu);
  15. // --------------------------------------
  16. State *current_state = NULL;
  17. void states_init(void) {
  18. // ----------------------------------
  19. sm_ask_homing.setHeading("Homing Required!");
  20. sm_ask_homing.setText("Click to home all four axes.");
  21. // ----------------------------------
  22. sm_do_homing.setTitle("Home all axes");
  23. sm_do_homing.setHeading("Homing");
  24. sm_do_homing.onEnter([]() {
  25. steppers_start_homing();
  26. });
  27. sm_do_homing.whenIn([](StateMachineInput smi) {
  28. if (smi.motors_done) {
  29. if (steppers_homed()) {
  30. async_beep(100, 2000);
  31. states_go_to(&sm_menu);
  32. }
  33. }
  34. // TODO update text with current axis
  35. });
  36. // ----------------------------------
  37. sm_menu.setTitle("Main Menu");
  38. sm_menu.addChild(&sm_do_homing, 1);
  39. // ----------------------------------
  40. sm_auto.setTitle("Filling Menu");
  41. sm_auto.setChild(&sm_menu);
  42. // ----------------------------------
  43. sm_config.setTitle("Configuration");
  44. sm_auto.setChild(&sm_menu);
  45. // ----------------------------------
  46. states_go_to(&sm_ask_homing);
  47. }
  48. void states_run(StateMachineInput smi) {
  49. if (current_state != NULL) {
  50. current_state->inState(smi);
  51. }
  52. }
  53. State *states_get(void) {
  54. return current_state;
  55. }
  56. void states_go_to(State *state) {
  57. current_state = state;
  58. if (current_state != NULL) {
  59. current_state->enterState();
  60. }
  61. }