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.

interface_sounds_screen.cpp 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*******************************
  2. * interface_sounds_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: <http://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. #if ENABLED(TOUCH_UI_FTDI_EVE)
  23. #include "screens.h"
  24. #include "screen_data.h"
  25. using namespace FTDI;
  26. using namespace Theme;
  27. using namespace ExtUI;
  28. uint8_t InterfaceSoundsScreen::event_sounds[];
  29. const char* InterfaceSoundsScreen::getSoundSelection(event_t event) {
  30. return SoundList::name(event_sounds[event]);
  31. }
  32. void InterfaceSoundsScreen::toggleSoundSelection(event_t event) {
  33. event_sounds[event] = (event_sounds[event]+1) % SoundList::n;
  34. playEventSound(event);
  35. }
  36. void InterfaceSoundsScreen::setSoundSelection(event_t event, const SoundPlayer::sound_t* sound) {
  37. for(uint8_t i = 0; i < SoundList::n; i++)
  38. if (SoundList::data(i) == sound)
  39. event_sounds[event] = i;
  40. }
  41. void InterfaceSoundsScreen::playEventSound(event_t event, play_mode_t mode) {
  42. sound.play(SoundList::data(event_sounds[event]), mode);
  43. }
  44. void InterfaceSoundsScreen::defaultSettings() {
  45. setSoundSelection(PRINTING_STARTED, twinkle);
  46. setSoundSelection(PRINTING_FINISHED, fanfare);
  47. setSoundSelection(PRINTING_FAILED, sad_trombone);
  48. }
  49. void InterfaceSoundsScreen::onRedraw(draw_mode_t what) {
  50. CommandProcessor cmd;
  51. if (what & BACKGROUND) {
  52. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  53. .cmd(CLEAR(true,true,true))
  54. .cmd(COLOR_RGB(bg_text_enabled))
  55. .tag(0)
  56. #define GRID_COLS 4
  57. #define GRID_ROWS 9
  58. .font(font_medium)
  59. .text(BTN_POS(1,1), BTN_SIZE(4,1), GET_TEXT_F(MSG_INTERFACE_SOUNDS))
  60. #undef EDGE_R
  61. #define EDGE_R 30
  62. .font(font_small)
  63. .tag(0).text (BTN_POS(1,2), BTN_SIZE(2,1), GET_TEXT_F(MSG_SOUND_VOLUME), OPT_RIGHTX | OPT_CENTERY)
  64. .text (BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_CLICK_SOUNDS), OPT_RIGHTX | OPT_CENTERY)
  65. .text (BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_STARTING), OPT_RIGHTX | OPT_CENTERY)
  66. .text (BTN_POS(1,6), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_FINISHED), OPT_RIGHTX | OPT_CENTERY)
  67. .text (BTN_POS(1,7), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_ERROR), OPT_RIGHTX | OPT_CENTERY);
  68. #undef EDGE_R
  69. }
  70. if (what & FOREGROUND) {
  71. #ifdef TOUCH_UI_PORTRAIT
  72. constexpr uint8_t w = 2;
  73. #else
  74. constexpr uint8_t w = 1;
  75. #endif
  76. cmd.font(font_medium)
  77. .colors(ui_slider)
  78. #define EDGE_R 30
  79. .tag(2).slider (BTN_POS(3,2), BTN_SIZE(2,1), screen_data.InterfaceSettingsScreen.volume, 0xFF)
  80. .colors(ui_toggle)
  81. .tag(3).toggle2 (BTN_POS(3,3), BTN_SIZE(w,1), GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), UIData::touch_sounds_enabled())
  82. #undef EDGE_R
  83. .colors(normal_btn)
  84. #define EDGE_R 0
  85. .tag(4).button (BTN_POS(3,5), BTN_SIZE(2,1), getSoundSelection(PRINTING_STARTED))
  86. .tag(5).button (BTN_POS(3,6), BTN_SIZE(2,1), getSoundSelection(PRINTING_FINISHED))
  87. .tag(6).button (BTN_POS(3,7), BTN_SIZE(2,1), getSoundSelection(PRINTING_FAILED))
  88. .colors(action_btn)
  89. .tag(1).button (BTN_POS(1,9), BTN_SIZE(4,1), GET_TEXT_F(MSG_BACK));
  90. }
  91. }
  92. void InterfaceSoundsScreen::onEntry() {
  93. screen_data.InterfaceSettingsScreen.volume = SoundPlayer::get_volume();
  94. BaseScreen::onEntry();
  95. }
  96. bool InterfaceSoundsScreen::onTouchEnd(uint8_t tag) {
  97. switch (tag) {
  98. case 1: GOTO_PREVIOUS(); return true;
  99. case 3: UIData::enable_touch_sounds(!UIData::touch_sounds_enabled()); break;
  100. case 4: toggleSoundSelection(PRINTING_STARTED); break;
  101. case 5: toggleSoundSelection(PRINTING_FINISHED); break;
  102. case 6: toggleSoundSelection(PRINTING_FAILED); break;
  103. default:
  104. return false;
  105. }
  106. SaveSettingsDialogBox::settingsChanged();
  107. return true;
  108. }
  109. bool InterfaceSoundsScreen::onTouchStart(uint8_t tag) {
  110. CommandProcessor cmd;
  111. #undef EDGE_R
  112. #define EDGE_R 30
  113. switch (tag) {
  114. case 2: cmd.track_linear(BTN_POS(3,2), BTN_SIZE(2,1), 2).execute(); break;
  115. default: break;
  116. }
  117. return true;
  118. }
  119. void InterfaceSoundsScreen::onIdle() {
  120. if (refresh_timer.elapsed(TOUCH_UPDATE_INTERVAL)) {
  121. refresh_timer.start();
  122. uint16_t value;
  123. CommandProcessor cmd;
  124. switch (cmd.track_tag(value)) {
  125. case 2:
  126. screen_data.InterfaceSettingsScreen.volume = value >> 8;
  127. SoundPlayer::set_volume(screen_data.InterfaceSettingsScreen.volume);
  128. SaveSettingsDialogBox::settingsChanged();
  129. break;
  130. default:
  131. return;
  132. }
  133. onRefresh();
  134. }
  135. BaseScreen::onIdle();
  136. }
  137. #endif // TOUCH_UI_FTDI_EVE