My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

screen_types.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /******************
  2. * screen_types.h *
  3. ******************/
  4. /****************************************************************************
  5. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  6. * *
  7. * This program is free software: you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * To view a copy of the GNU General Public License, go to the following *
  18. * location: <https://www.gnu.org/licenses/>. *
  19. ****************************************************************************/
  20. #include "ftdi_extended.h"
  21. #if ENABLED(FTDI_EXTENDED)
  22. /********************** VIRTUAL DISPATCH DATA TYPE ******************************/
  23. uint8_t ScreenRef::lookupScreen(onRedraw_func_t onRedraw_ptr) {
  24. for (uint8_t type = 0; type < tableSize(); type++) {
  25. if (GET_METHOD(type, onRedraw) == onRedraw_ptr) {
  26. return type;
  27. }
  28. }
  29. #if ENABLED(TOUCH_UI_DEBUG)
  30. SERIAL_ECHO_START();
  31. SERIAL_ECHOPAIR("Screen not found: ", (uintptr_t) onRedraw_ptr);
  32. #endif
  33. return 0xFF;
  34. }
  35. void ScreenRef::setScreen(onRedraw_func_t onRedraw_ptr) {
  36. uint8_t type = lookupScreen(onRedraw_ptr);
  37. if (type != 0xFF) {
  38. setType(type);
  39. #if ENABLED(TOUCH_UI_DEBUG)
  40. SERIAL_ECHO_MSG("New screen: ", type);
  41. #endif
  42. }
  43. }
  44. void ScreenRef::initializeAll() {
  45. for (uint8_t type = 0; type < tableSize(); type++)
  46. GET_METHOD(type, onStartup)();
  47. }
  48. /********************** SCREEN STACK ******************************/
  49. void ScreenStack::start() {
  50. initializeAll();
  51. onEntry();
  52. }
  53. void ScreenStack::push(onRedraw_func_t onRedraw_ptr) {
  54. stack[3] = stack[2];
  55. stack[2] = stack[1];
  56. stack[1] = stack[0];
  57. stack[0] = lookupScreen(onRedraw_ptr);
  58. }
  59. void ScreenStack::push() {
  60. stack[3] = stack[2];
  61. stack[2] = stack[1];
  62. stack[1] = stack[0];
  63. stack[0] = getType();
  64. }
  65. void ScreenStack::pop() {
  66. setType(stack[0]);
  67. forget();
  68. }
  69. void ScreenStack::forget() {
  70. stack[0] = stack[1];
  71. stack[1] = stack[2];
  72. stack[2] = stack[3];
  73. stack[3] = 0;
  74. }
  75. void ScreenStack::goTo(onRedraw_func_t s) {
  76. push();
  77. onExit();
  78. setScreen(s);
  79. onEntry();
  80. }
  81. void ScreenStack::goBack() {
  82. onExit();
  83. pop();
  84. onEntry();
  85. }
  86. ScreenStack current_screen;
  87. #endif // FTDI_EXTENDED