debug_screen.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * debug_screen.c
  3. *
  4. * Created on: Jan 12, 2021
  5. * Author: David Original work by Jose (PTDreamer), 2017
  6. */
  7. #include "debug_screen.h"
  8. #include "oled.h"
  9. #include "gui.h"
  10. #ifdef ENABLE_DEBUG_SCREEN
  11. //-------------------------------------------------------------------------------------------------------------------------------
  12. // Debug screen variables
  13. //-------------------------------------------------------------------------------------------------------------------------------
  14. int32_t temp;
  15. int32_t debugTemperature = 0;
  16. //-------------------------------------------------------------------------------------------------------------------------------
  17. // Debug screen widgets
  18. //-------------------------------------------------------------------------------------------------------------------------------
  19. screen_t Screen_debug;
  20. screen_t Screen_debug2;
  21. static widget_t widget_Debug_ADC_Val;
  22. static displayOnly_widget_t display_Debug_ADC_Val;
  23. static widget_t widget_Debug_ADC_ValRaw;
  24. static displayOnly_widget_t display_Debug_ADC_ValRaw;
  25. static widget_t widget_Debug_SetPoint;
  26. static editable_widget_t editable_Debug_SetPoint;
  27. static widget_t widget_Debug_Cal250;
  28. static editable_widget_t editable_Debug_Cal250;
  29. static widget_t widget_Debug_Cal350;
  30. static editable_widget_t editable_Debug_Cal350;
  31. static widget_t widget_Debug_Cal450;
  32. static editable_widget_t editable_Debug_Cal450;
  33. static widget_t widget_Debug_Power;
  34. static displayOnly_widget_t display_Debug_Power;
  35. //-------------------------------------------------------------------------------------------------------------------------------
  36. // Debug screen widgets functions
  37. //-------------------------------------------------------------------------------------------------------------------------------
  38. static void * debug_screen_getADC1() {
  39. temp = TIP.last_avg;
  40. return &temp;
  41. }
  42. static void * debug_screen_getADC1_raw() {
  43. temp = TIP.last_raw;
  44. return &temp;
  45. }
  46. static void * debug_screen_getIronPower() {
  47. //if(UpdateReadings){
  48. temp = getCurrentPower();
  49. //}
  50. return &temp;
  51. }
  52. static void * getDebugTemperature() {
  53. return &debugTemperature;
  54. }
  55. static void setDebugTemperature(uint16_t *val) {
  56. debugTemperature = *val;
  57. resetPID();
  58. setDebugTemp(debugTemperature);
  59. }
  60. static void * getCalcAt250() {
  61. temp = getCurrentTip()->calADC_At_250;
  62. return &temp;
  63. }
  64. static void setCalcAt250(uint16_t *val) {
  65. getCurrentTip()->calADC_At_250 = *val;
  66. }
  67. static void * getCalcAt350() {
  68. temp = getCurrentTip()->calADC_At_350;
  69. return &temp;
  70. }
  71. static void setCalcAt350(uint16_t *val) {
  72. getCurrentTip()->calADC_At_350 = *val;
  73. }
  74. static void * getCalcAt450() {
  75. temp = getCurrentTip()->calADC_At_450;
  76. return &temp;
  77. }
  78. static void setCalcAt450(uint16_t *val) {
  79. getCurrentTip()->calADC_At_450 = *val;
  80. }
  81. //-------------------------------------------------------------------------------------------------------------------------------
  82. // Debug screen functions
  83. //-------------------------------------------------------------------------------------------------------------------------------
  84. int debug_screenProcessInput(screen_t * scr, RE_Rotation_t input, RE_State_t *state) {
  85. if(input==LongClick){
  86. return screen_debug2;
  87. }
  88. return (default_screenProcessInput(scr, input, state));
  89. }
  90. int debug2_screenProcessInput(screen_t * scr, RE_Rotation_t input, RE_State_t *state) {
  91. if(input==LongClick){
  92. return screen_main;
  93. }
  94. return (default_screenProcessInput(scr, input, state));
  95. }
  96. //-------------------------------------------------------------------------------------------------------------------------------
  97. // Debug screen functions
  98. //-------------------------------------------------------------------------------------------------------------------------------
  99. void debug_screenDraw(screen_t *scr){
  100. static uint32_t time=0;
  101. if(HAL_GetTick()-time > systemSettings.settings.guiUpdateDelay){
  102. char str[16];
  103. time = HAL_GetTick();
  104. u8g2_SetFont(&u8g2,default_font );
  105. u8g2_SetDrawColor(&u8g2, WHITE);
  106. FillBuffer(BLACK,fill_dma);
  107. sprintf(str, "ADC %u", TIP.last_avg);
  108. u8g2_DrawStr(&u8g2,65,0,str);
  109. sprintf(str, "RAW %u", TIP.last_raw);
  110. u8g2_DrawStr(&u8g2,65,16,str);
  111. sprintf(str, "PWM %u", Iron.Pwm_Out);
  112. u8g2_DrawStr(&u8g2,60,50,str);
  113. sprintf(str, "ERR %ld", (int32_t)getPID_Error());
  114. u8g2_DrawStr(&u8g2,65,33,str);
  115. sprintf(str, "P %ld", (int32_t)(getPID_P()* 1000));
  116. u8g2_DrawStr(&u8g2,0,0,str);
  117. sprintf(str, "I %ld", (int32_t)(getPID_I()* 1000));
  118. u8g2_DrawStr(&u8g2,0,16,str);
  119. sprintf(str, "D %04ld", (int32_t)(getPID_D()* 1000));
  120. u8g2_DrawStr(&u8g2,0,33,str);
  121. }
  122. }
  123. //-------------------------------------------------------------------------------------------------------------------------------
  124. // Debug2 screen functions
  125. //-------------------------------------------------------------------------------------------------------------------------------
  126. static void debug2_onExit(screen_t *scr) {
  127. setDebugMode(RESET);
  128. }
  129. static void debug2_onEnter(screen_t *scr) {
  130. setDebugMode(SET);
  131. u8g2_SetFont(&u8g2,default_font );
  132. u8g2_SetDrawColor(&u8g2, WHITE);
  133. u8g2_DrawStr(&u8g2,0,2,"SetP");
  134. u8g2_DrawStr(&u8g2,0,18,"C250");
  135. u8g2_DrawStr(&u8g2,0,34,"C350");
  136. u8g2_DrawStr(&u8g2,0,50,"C450");
  137. }
  138. //-------------------------------------------------------------------------------------------------------------------------------
  139. // Debug screen setup
  140. //-------------------------------------------------------------------------------------------------------------------------------
  141. void debug_screen_setup(screen_t *scr) {
  142. screen_setDefaults(scr);
  143. scr->processInput = &debug_screenProcessInput;
  144. scr->draw = &debug_screenDraw;
  145. }
  146. //-------------------------------------------------------------------------------------------------------------------------------
  147. // Debug2 screen setup
  148. //-------------------------------------------------------------------------------------------------------------------------------
  149. void debug2_screen_setup(screen_t *scr) {
  150. screen_setDefaults(scr);
  151. scr->processInput = &debug2_screenProcessInput;
  152. scr->onEnter = &debug2_onEnter;
  153. scr->onExit = &debug2_onExit;
  154. widget_t *w;
  155. displayOnly_widget_t* dis;
  156. editable_widget_t* edit;
  157. //power display
  158. w=&widget_Debug_Power;
  159. screen_addWidget(w,scr);
  160. widgetDefaultsInit(w, widget_display, &display_Debug_Power);
  161. dis=extractDisplayPartFromWidget(w);
  162. edit=extractEditablePartFromWidget(w);
  163. dis->endString="%";
  164. dis->reservedChars=4;
  165. w->posX = 92;
  166. w->posY = 50;
  167. w->width = 32;
  168. dis->getData = &debug_screen_getIronPower;
  169. dis->textAlign = align_right;
  170. //ADC1 display, filtered
  171. w = &widget_Debug_ADC_Val;
  172. screen_addWidget(w, scr);
  173. widgetDefaultsInit(w, widget_display, &display_Debug_ADC_Val);
  174. dis=extractDisplayPartFromWidget(w);
  175. edit=extractEditablePartFromWidget(w);
  176. dis->reservedChars=4;
  177. w->posX = 92;
  178. w->posY = 0;
  179. w->width = 32;
  180. dis->getData = &debug_screen_getADC1;
  181. dis->textAlign = align_right;
  182. //ADC1 display, unfiltered
  183. w = &widget_Debug_ADC_ValRaw;
  184. screen_addWidget(w, scr);
  185. widgetDefaultsInit(w, widget_display, &display_Debug_ADC_ValRaw);
  186. dis=extractDisplayPartFromWidget(w);
  187. edit=extractEditablePartFromWidget(w);
  188. dis->reservedChars=4;
  189. w->posX = 92;
  190. w->posY = 16;
  191. w->width = 32;
  192. dis->getData = &debug_screen_getADC1_raw;
  193. dis->textAlign = align_right;
  194. //Debug setpoint
  195. w = &widget_Debug_SetPoint;
  196. screen_addWidget(w, scr);
  197. widgetDefaultsInit(w, widget_editable, &editable_Debug_SetPoint);
  198. dis=extractDisplayPartFromWidget(w);
  199. edit=extractEditablePartFromWidget(w);
  200. dis->reservedChars=4;
  201. w->posX = 36;
  202. w->posY = 0;
  203. w->width = 40;
  204. dis->getData = &getDebugTemperature;
  205. edit->big_step = 200;
  206. edit->step = 20;
  207. edit->max_value = 4095;
  208. edit->selectable.tab = 0;
  209. edit->setData = (void (*)(void *))&setDebugTemperature;
  210. // Cal at 250
  211. w = &widget_Debug_Cal250;
  212. screen_addWidget(w, scr);
  213. widgetDefaultsInit(w, widget_editable, &editable_Debug_Cal250);
  214. dis=extractDisplayPartFromWidget(w);edit=extractEditablePartFromWidget(w);
  215. dis->reservedChars=4;
  216. w->posX = 36;
  217. w->posY = 16;
  218. w->width = 40;
  219. dis->getData = &getCalcAt250;
  220. edit->big_step = 200;
  221. edit->step = 20;
  222. edit->max_value = 4095;
  223. edit->selectable.tab = 1;
  224. edit->setData = (void (*)(void *))&setCalcAt250;
  225. // Cal at 350
  226. w = &widget_Debug_Cal350;
  227. screen_addWidget(w, scr);
  228. widgetDefaultsInit(w, widget_editable, &editable_Debug_Cal350);
  229. dis=extractDisplayPartFromWidget(w);
  230. edit=extractEditablePartFromWidget(w);
  231. dis->reservedChars=4;
  232. w->posX = 36;
  233. w->posY = 32;
  234. w->width = 40;
  235. dis->getData = &getCalcAt350;
  236. edit->big_step = 200;
  237. edit->step = 20;
  238. edit->max_value = 4095;
  239. edit->selectable.tab = 2;
  240. edit->setData = (void (*)(void *))&setCalcAt350;
  241. // Cal at 450
  242. w = &widget_Debug_Cal450;
  243. screen_addWidget(w, scr);
  244. widgetDefaultsInit(w, widget_editable, &editable_Debug_Cal450);
  245. dis=extractDisplayPartFromWidget(w);
  246. edit=extractEditablePartFromWidget(w);
  247. dis->reservedChars=4;
  248. w->posX = 36;
  249. w->posY = 48;
  250. w->width=40;
  251. dis->getData = &getCalcAt450;
  252. edit->big_step = 200;
  253. edit->step = 20;
  254. edit->max_value = 4095;
  255. edit->selectable.tab = 3;
  256. edit->setData = (void (*)(void *))&setCalcAt450;
  257. }
  258. #endif