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.

base_screen.cpp 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*******************
  2. * base_screen.cpp *
  3. *******************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  7. * *
  8. * This program is free software: you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation, either version 3 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <https://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. #include "../screens.h"
  23. #ifdef FTDI_BASE_SCREEN
  24. using namespace FTDI;
  25. using namespace Theme;
  26. void BaseScreen::onEntry() {
  27. CommandProcessor cmd;
  28. cmd.set_button_style_callback(buttonStyleCallback);
  29. reset_menu_timeout();
  30. UIScreen::onEntry();
  31. }
  32. bool BaseScreen::buttonIsPressed(uint8_t tag) {
  33. return tag != 0 && EventLoop::get_pressed_tag() == tag;
  34. }
  35. bool BaseScreen::buttonStyleCallback(CommandProcessor &cmd, uint8_t tag, uint8_t &style, uint16_t &options, bool post) {
  36. if (post) {
  37. cmd.colors(normal_btn);
  38. return false;
  39. }
  40. #if HAS_SCREEN_TIMEOUT
  41. if (EventLoop::get_pressed_tag() != 0) {
  42. #if ENABLED(TOUCH_UI_DEBUG)
  43. SERIAL_ECHO_MSG("buttonStyleCallback, resetting timeout");
  44. #endif
  45. reset_menu_timeout();
  46. }
  47. #endif
  48. if (buttonIsPressed(tag)) options = OPT_FLAT;
  49. if (style & cmd.STYLE_DISABLED) {
  50. cmd.tag(0);
  51. style &= ~cmd.STYLE_DISABLED;
  52. cmd.colors(disabled_btn);
  53. return true; // Call me again to reset the colors
  54. }
  55. return false;
  56. }
  57. void BaseScreen::onIdle() {
  58. #if HAS_SCREEN_TIMEOUT
  59. if (EventLoop::get_pressed_tag() != 0)
  60. reset_menu_timeout();
  61. if ((millis() - last_interaction) > LCD_TIMEOUT_TO_STATUS) {
  62. reset_menu_timeout();
  63. #if ENABLED(TOUCH_UI_DEBUG)
  64. SERIAL_ECHO_MSG("Returning to status due to menu timeout");
  65. #endif
  66. GOTO_SCREEN(StatusScreen);
  67. }
  68. #endif
  69. }
  70. void BaseScreen::reset_menu_timeout() {
  71. TERN_(HAS_SCREEN_TIMEOUT, last_interaction = millis());
  72. }
  73. #if HAS_SCREEN_TIMEOUT
  74. uint32_t BaseScreen::last_interaction;
  75. #endif
  76. #endif // FTDI_BASE_SCREEN