boot_screen.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * boot_screen.c
  3. *
  4. * Created on: Jan 12, 2021
  5. * Author: David Original work by Jose (PTDreamer), 2017
  6. */
  7. #include "boot_screen.h"
  8. #include "oled.h"
  9. #include "gui.h"
  10. #define SPLASH_TIMEOUT 1000
  11. //-------------------------------------------------------------------------------------------------------------------------------
  12. // Boot Screen variables
  13. //-------------------------------------------------------------------------------------------------------------------------------
  14. int32_t profile;
  15. uint8_t status;
  16. uint32_t splash_time;
  17. //-------------------------------------------------------------------------------------------------------------------------------
  18. // Boot Screen widgets
  19. //-------------------------------------------------------------------------------------------------------------------------------
  20. screen_t Screen_boot;
  21. static widget_t Widget_profile_edit;
  22. static editable_widget_t editable_Profile_edit;
  23. static widget_t Widget_profile_OK;
  24. static button_widget_t button_Profile_OK;
  25. static uint8_t boot_step=0;
  26. //-------------------------------------------------------------------------------------------------------------------------------
  27. // Boot Screen widget functions
  28. //-------------------------------------------------------------------------------------------------------------------------------
  29. static void * getProfile() {
  30. return &profile;
  31. }
  32. static void setProfile(int32_t *val) {
  33. profile = *val;
  34. }
  35. static int profile_OK(widget_t *w) {
  36. loadProfile((uint8_t)profile); // Load profile
  37. saveSettings(saveKeepingProfiles); // Save
  38. systemSettings.setupMode=setup_Off; // Reset setup mode
  39. SetFailState(noError); // Enable normal operation
  40. return screen_main;
  41. }
  42. // Credits: Jesus Vallejo https://github.com/jesusvallejo/
  43. const uint8_t splashXBM[] = {
  44. 128, 64,
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x54, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x0F, 0x00, 0x00, 0xF2, 0x03,
  48. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF,
  49. 0x00, 0xC0, 0xF3, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0xFE, 0xFF, 0x0F, 0x00, 0xF0, 0xF3, 0xFF, 0x00, 0x00, 0x00, 0x00,
  51. 0x00, 0x00, 0x00, 0x00, 0xC0, 0x83, 0x20, 0x39, 0x00, 0xFC, 0xF3, 0xFF,
  52. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFA, 0x3B, 0x09,
  53. 0x00, 0xCC, 0xF3, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0xF8, 0x83, 0xBB, 0xFA, 0x00, 0x87, 0xF3, 0xFF, 0x0F, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xBB, 0x0B, 0x80, 0x03, 0x00, 0xF8,
  56. 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x83, 0xBB, 0x1B,
  57. 0xC0, 0x07, 0x00, 0xF0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x00, 0xFE, 0xFF, 0x0F, 0xC0, 0xCF, 0xFF, 0xE3, 0x3F, 0xF0, 0x33, 0xF3,
  59. 0x03, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x3F, 0xE0, 0xFF, 0xFF, 0x07,
  60. 0x00, 0xF0, 0x33, 0xF3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x7E, 0xCC, 0x0F,
  61. 0xF0, 0xFF, 0x07, 0x0C, 0x00, 0xC0, 0x30, 0x33, 0x00, 0x00, 0x00, 0x00,
  62. 0xE0, 0xFF, 0xBB, 0xFF, 0xF0, 0xFF, 0x00, 0xF8, 0xFF, 0xC0, 0xF0, 0xF3,
  63. 0x01, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xDC, 0x0F, 0xF0, 0x7F, 0x00, 0xE0,
  64. 0xF9, 0xC0, 0xF0, 0xF3, 0x01, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xEB, 0xFF,
  65. 0xF8, 0x3F, 0x00, 0xC0, 0xF0, 0xC1, 0x30, 0x33, 0x00, 0x00, 0x00, 0x00,
  66. 0x00, 0x7E, 0x8C, 0x0F, 0xF8, 0x3F, 0x00, 0x40, 0xE0, 0xC1, 0x30, 0xF3,
  67. 0x03, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x7F, 0x00, 0x1E, 0x60, 0x80,
  68. 0xF0, 0xC1, 0x30, 0xF3, 0x03, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x0F,
  69. 0x00, 0x1E, 0xF8, 0x81, 0xF9, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0x00, 0x54, 0x55, 0x05, 0x7C, 0x0E, 0xF8, 0x01, 0xF9, 0x03, 0x00, 0x00,
  71. 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x54, 0x01, 0x7C, 0x0E, 0xFC, 0x03,
  72. 0xF9, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x01,
  73. 0x7C, 0x0E, 0xFC, 0x03, 0xF9, 0xF3, 0xF3, 0x33, 0xF0, 0xF3, 0xF3, 0xF3,
  74. 0x33, 0xF3, 0x43, 0x00, 0x7C, 0x0E, 0xF8, 0x01, 0xF9, 0xF3, 0xF3, 0x33,
  75. 0x70, 0xF2, 0xF3, 0xF3, 0x73, 0xF3, 0x43, 0x00, 0x7C, 0x1E, 0xF8, 0x81,
  76. 0x19, 0x33, 0x30, 0x33, 0x70, 0x32, 0x30, 0xC2, 0xF0, 0x33, 0x00, 0x00,
  77. 0x7C, 0x1E, 0x60, 0x80, 0x09, 0xF0, 0x33, 0x33, 0x70, 0xF2, 0xF1, 0xC3,
  78. 0xF0, 0xB3, 0x03, 0x00, 0x7C, 0x1E, 0x00, 0x80, 0x09, 0xF0, 0x33, 0x33,
  79. 0x70, 0xF2, 0xB1, 0xC0, 0xB0, 0xB3, 0x03, 0x00, 0x7C, 0x1E, 0x60, 0x80,
  80. 0x19, 0x03, 0x33, 0x33, 0x70, 0x32, 0xB0, 0xC1, 0x30, 0x33, 0x03, 0x00,
  81. 0x3C, 0x3C, 0x60, 0xC0, 0xF9, 0xF3, 0xF3, 0xF3, 0x73, 0xF2, 0x33, 0xF3,
  82. 0x33, 0xF3, 0x03, 0x00, 0x18, 0x78, 0x60, 0x00, 0xF8, 0xF1, 0xF3, 0xF3,
  83. 0xF3, 0xF3, 0x33, 0xF3, 0x33, 0xF3, 0x03, 0x00, 0x18, 0xF8, 0x60, 0x00,
  84. 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85. 0x30, 0xFC, 0x60, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  86. 0x00, 0x00, 0x00, 0x00, 0x70, 0xFE, 0x60, 0xF8, 0xFF, 0x00, 0x00, 0x00,
  87. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x7F, 0x60, 0xF0,
  88. 0x7F, 0xF0, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0x33, 0x03, 0x00, 0x00, 0x00,
  89. 0xC0, 0x3F, 0x60, 0xE0, 0x3F, 0xF0, 0xF3, 0xF3, 0xF3, 0xF3, 0xF3, 0x73,
  90. 0x03, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x60, 0xC0, 0x1F, 0x30, 0xC0, 0x30,
  91. 0xC3, 0xC0, 0x30, 0xF3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x60, 0xC0,
  92. 0x0F, 0xF0, 0xC3, 0xF0, 0xC3, 0xC0, 0x30, 0xB3, 0x03, 0x00, 0x00, 0x00,
  93. 0x00, 0x1E, 0x60, 0x80, 0x07, 0xF0, 0xC3, 0xF0, 0xC3, 0xC0, 0x30, 0x33,
  94. 0x03, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x03, 0x00, 0xC3, 0x30,
  95. 0xC3, 0xC0, 0x30, 0x33, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  96. 0x00, 0xF0, 0xC3, 0x30, 0xC3, 0xF0, 0xF3, 0x33, 0x03, 0x00, 0x00, 0x00,
  97. 0x00, 0x00, 0x60, 0x00, 0x00, 0xF0, 0xC3, 0x30, 0xC3, 0xF0, 0xF3, 0x33,
  98. 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
  99. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  100. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  101. 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
  103. 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00,
  105. 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14,
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
  107. 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  108. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
  109. 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28,
  110. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
  111. 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
  112. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
  113. 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
  114. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
  115. 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01,
  116. 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0x1D, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
  117. 0x00, 0x00, 0x80, 0x03, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1D, 0x00, 0x00,
  118. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xEF, 0xFF, 0xFF, 0xFF,
  119. 0xFF, 0xDD, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E,
  120. 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDD, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00,
  121. 0x00, 0x00, 0x00, 0x00, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1D, 0x00, 0x00,
  122. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF,
  123. 0xFF, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  124. 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  125. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  126. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  127. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  128. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  130. 0x00, 0x00, 0x00, 0x00, };
  131. void boot_screen_draw(screen_t *scr){
  132. if(boot_step==1){
  133. boot_step=2;
  134. default_screenDraw(scr);
  135. u8g2_SetFont(&u8g2,default_font );
  136. u8g2_SetDrawColor(&u8g2, WHITE);
  137. putStrAligned("First boot!", 0, align_center);
  138. putStrAligned("Select profile", 16, align_center);
  139. u8g2_DrawHLine(&u8g2, 0, 32, OledWidth);
  140. return;
  141. }
  142. default_screenDraw(scr);
  143. }
  144. int boot_screen_processInput(screen_t * scr, RE_Rotation_t input, RE_State_t *state) {
  145. if(HAL_GetTick() - splash_time > SPLASH_TIMEOUT){ // After splash timeout
  146. if(!systemSettings.setupMode){
  147. return screen_main;
  148. }
  149. else if(boot_step==0){
  150. boot_step=1;
  151. widgetEnable(&Widget_profile_edit);
  152. widgetEnable(&Widget_profile_OK);
  153. scr->refresh = screenRefresh_eraseNow;
  154. }
  155. }
  156. else{
  157. return -1;
  158. }
  159. return default_screenProcessInput(scr, input, state);
  160. }
  161. void boot_screen_init(screen_t * scr){
  162. profile=systemSettings.settings.currentProfile;
  163. if( (systemSettings.settings.NotInitialized!=initialized) || (systemSettings.settings.currentProfile>profile_C210) ){
  164. profile=profile_C210; // For safety, set C210 profile by default, has the lowest Output TC
  165. systemSettings.setupMode=setup_On; // (Failure state is set in the iron routine when unknown iron profile is detected)
  166. }
  167. default_init(scr);
  168. splash_time = HAL_GetTick();
  169. u8g2_SetDrawColor(&u8g2,WHITE);
  170. u8g2_DrawXBMP(&u8g2, 0, 0, splashXBM[0], splashXBM[1], &splashXBM[2]);
  171. }
  172. void boot_screen_setup(screen_t *scr) {
  173. widget_t* w;
  174. displayOnly_widget_t* dis;
  175. editable_widget_t* edit;
  176. screen_setDefaults(scr);
  177. scr->draw = &boot_screen_draw;
  178. scr->processInput = &boot_screen_processInput;
  179. scr->init = &boot_screen_init;
  180. // Profile select
  181. //
  182. w = &Widget_profile_edit;
  183. screen_addWidget(w,scr);
  184. widgetDefaultsInit(w, widget_multi_option, &editable_Profile_edit);
  185. dis=extractDisplayPartFromWidget(w);
  186. edit=extractEditablePartFromWidget(w);
  187. dis->reservedChars=4;
  188. w->posX = 12;
  189. w->posY = 40;
  190. w->width = 48;
  191. dis->getData = &getProfile;
  192. edit->big_step = 1;
  193. edit->step = 1;
  194. edit->selectable.tab = 0;
  195. edit->setData = (void (*)(void *))&setProfile;
  196. edit->max_value = ProfileSize-1;
  197. edit->options = profileStr;
  198. edit->numberOfOptions = ProfileSize;
  199. w->enabled=0;
  200. // OK Button
  201. //
  202. w = &Widget_profile_OK;
  203. screen_addWidget(w,scr);
  204. widgetDefaultsInit(w, widget_button, &button_Profile_OK);
  205. button_Profile_OK.displayString="OK";
  206. button_Profile_OK.selectable.tab = 1;
  207. button_Profile_OK.action = &profile_OK;
  208. w->posX = 95;
  209. w->posY = 40;
  210. w->width = 32;
  211. w->enabled=0;
  212. }