main_screen.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. * main_screen.c
  3. *
  4. * Created on: Jan 12, 2021
  5. * Author: David Original work by Jose (PTDreamer), 2017
  6. */
  7. #include "main_screen.h"
  8. #include "oled.h"
  9. #include "gui.h"
  10. //-------------------------------------------------------------------------------------------------------------------------------
  11. // Main screen variables
  12. //-------------------------------------------------------------------------------------------------------------------------------
  13. static uint16_t plotData[100];
  14. static uint8_t plot_Index;
  15. static uint32_t plotTime;
  16. static bool plotUpdate;
  17. static uint32_t barTime;
  18. static uint8_t sleepWidth;
  19. static uint8_t sleepHeigh;
  20. static uint32_t sleepTim=0;
  21. static uint8_t Slp_xpos=30, Slp_ypos=14;
  22. static int8_t Slp_xadd=1, Slp_yadd=1;
  23. static int32_t temp;
  24. static char *tipName[TipSize];
  25. enum mode{ main_irontemp=0, main_disabled, main_ironstatus, main_setpoint, main_tipselect, main_setMode};
  26. enum{ status_running=0x20, status_standby, status_sleep, status_error };
  27. enum { temp_numeric, temp_graph };
  28. const uint8_t shakeXBM[] ={
  29. 9, 9,
  30. 0x70, 0x00, 0x80, 0x00, 0x30, 0x01, 0x40, 0x01, 0x45, 0x01, 0x05, 0x00,
  31. 0x19, 0x00, 0x02, 0x00, 0x1C, 0x00, };
  32. const uint8_t tempXBM[] ={
  33. 10, 13,
  34. 0x70, 0x00, 0x8B, 0x00, 0x88, 0x00, 0xAB, 0x00, 0xA8, 0x00, 0xAB, 0x00,
  35. 0xA8, 0x00, 0x24, 0x01, 0x72, 0x02, 0x72, 0x02, 0x72, 0x02, 0x04, 0x01,
  36. 0xF8, 0x00, };
  37. #ifdef USE_VIN
  38. const uint8_t voltXBM[] ={
  39. 6, 9,
  40. 0x30, 0x18, 0x0C, 0x06, 0x1F, 0x18, 0x0C, 0x06, 0x01, };
  41. #endif
  42. const uint8_t warningXBM[] ={
  43. 13, 13,
  44. 0x40, 0x00, 0xA0, 0x00, 0xA0, 0x00, 0x10, 0x01, 0x10, 0x01, 0x48, 0x02,
  45. 0x48, 0x02, 0x44, 0x04, 0x44, 0x04, 0x02, 0x08, 0x42, 0x08, 0x01, 0x10,
  46. 0xFF, 0x1F, };
  47. //-------------------------------------------------------------------------------------------------------------------------------
  48. // Main screen widgets
  49. //-------------------------------------------------------------------------------------------------------------------------------
  50. screen_t Screen_main;
  51. #ifdef USE_NTC
  52. static widget_t Widget_AmbTemp;
  53. static displayOnly_widget_t display_AmbTemp;
  54. #endif
  55. #ifdef USE_VIN
  56. static widget_t Widget_Vsupply;
  57. static displayOnly_widget_t display_Vsupply;
  58. #endif
  59. static widget_t Widget_IronTemp;
  60. static displayOnly_widget_t display_IronTemp;
  61. static widget_t Widget_TipSelect;
  62. static editable_widget_t editable_TipSelect;
  63. static widget_t Widget_SetPoint;
  64. static editable_widget_t editable_SetPoint;
  65. static struct{
  66. uint32_t updateTick;
  67. bool update;
  68. uint16_t lastTip;
  69. uint8_t lastPwr;
  70. #ifdef USE_NTC
  71. int16_t lastAmb;
  72. #endif
  73. #ifdef USE_VIN
  74. uint16_t lastVin;
  75. #endif
  76. uint32_t drawTick;
  77. uint32_t idleTick;
  78. uint32_t enteredSleep;
  79. bool idle;
  80. bool ActivityOn;
  81. uint8_t ironStatus;
  82. uint8_t prevIronStatus;
  83. uint8_t setMode;
  84. uint8_t currentMode;
  85. bool displayMode;
  86. uint8_t menuPos;
  87. widget_t* Selected;
  88. }mainScr;
  89. //-------------------------------------------------------------------------------------------------------------------------------
  90. // Main screen widgets functions
  91. //-------------------------------------------------------------------------------------------------------------------------------
  92. static void setTemp(uint16_t *val) {
  93. setUserTemperature(*val);
  94. }
  95. static void * getTemp() {
  96. temp = getUserTemperature();
  97. return &temp;
  98. }
  99. static void setTip(uint8_t *val) {
  100. if(systemSettings.Profile.currentTip != *val){ // Tip temp uses huge font that partially overlaps other widgets
  101. systemSettings.Profile.currentTip = *val;
  102. setCurrentTip(*val);
  103. Screen_main.refresh=screenRefresh_eraseNow; // So, we must redraw the screen. Tip temp is drawed first, then the rest go on top.
  104. }
  105. }
  106. static void * getTip() {
  107. temp = systemSettings.Profile.currentTip;
  108. return &temp;
  109. }
  110. static void * main_screen_getIronTemp() {
  111. if(mainScr.update){
  112. mainScr.lastTip=readTipTemperatureCompensated(stored_reading,read_Avg);
  113. }
  114. temp=mainScr.lastTip;
  115. return &temp;
  116. }
  117. #ifdef USE_VIN
  118. static void * main_screen_getVin() {
  119. if(mainScr.update){
  120. mainScr.lastVin = getSupplyVoltage_v_x10();
  121. }
  122. temp=mainScr.lastVin;
  123. return &temp;
  124. }
  125. #endif
  126. #ifdef USE_NTC
  127. static void * main_screen_getAmbTemp() {
  128. if(mainScr.update){
  129. mainScr.lastAmb = readColdJunctionSensorTemp_x10(systemSettings.settings.tempUnit);
  130. }
  131. temp=mainScr.lastAmb;
  132. return &temp;
  133. }
  134. #endif
  135. static void updateIronPower() {
  136. static uint32_t stored=0;
  137. static uint32_t updateTim;
  138. if((HAL_GetTick()-updateTim)>19){
  139. updateTim = HAL_GetTick();
  140. int32_t tmpPwr = getCurrentPower();
  141. if(tmpPwr < 0){
  142. tmpPwr = 0 ;
  143. }
  144. tmpPwr = tmpPwr<<12;
  145. stored = ( ((stored<<3)-stored)+tmpPwr+(1<<11))>>3 ;
  146. tmpPwr = stored>>12;
  147. mainScr.lastPwr=tmpPwr;
  148. }
  149. }
  150. static void setMainWidget(widget_t* w){
  151. selectable_widget_t* sel =extractSelectablePartFromWidget(w);
  152. mainScr.drawTick=HAL_GetTick();
  153. Screen_main.refresh=screenRefresh_eraseNow;
  154. widgetDisable(mainScr.Selected);
  155. mainScr.Selected=w;
  156. widgetEnable(w);
  157. Screen_main.current_widget=w;
  158. if(sel){
  159. sel->state=widget_edit;
  160. sel->previous_state=widget_selected;
  161. }
  162. }
  163. void clearActivityIcon(void){
  164. if(mainScr.ActivityOn){
  165. u8g2_SetDrawColor(&u8g2, BLACK);
  166. u8g2_DrawBox(&u8g2, 0,OledHeight-shakeXBM[1], shakeXBM[0], shakeXBM[1]);
  167. mainScr.ActivityOn=0;
  168. Iron.newActivity=0;
  169. }
  170. }
  171. //-------------------------------------------------------------------------------------------------------------------------------
  172. // Main screen functions
  173. //-------------------------------------------------------------------------------------------------------------------------------
  174. static void setMainScrTempUnit(void) {
  175. if(systemSettings.settings.tempUnit==mode_Farenheit){
  176. display_IronTemp.endString="\260F";
  177. #ifdef USE_NTC
  178. display_AmbTemp.endString="F";
  179. #endif
  180. editable_SetPoint.inputData.endString="\260F";
  181. }
  182. else{
  183. display_IronTemp.endString="\260C"; // \260 = ASCII dec. 176(°) in octal representation
  184. #ifdef USE_NTC
  185. display_AmbTemp.endString="C";
  186. #endif
  187. editable_SetPoint.inputData.endString="\260C";
  188. }
  189. }
  190. static void main_screen_init(screen_t *scr) {
  191. default_init(scr);
  192. mainScr.currentMode = main_irontemp;
  193. setMainWidget(&Widget_IronTemp);
  194. if(mainScr.displayMode==temp_graph){
  195. widgetDisable(&Widget_IronTemp);
  196. }
  197. editable_TipSelect.numberOfOptions = systemSettings.Profile.currentNumberOfTips;
  198. editable_SetPoint.step = systemSettings.settings.tempStep;
  199. editable_SetPoint.big_step = systemSettings.settings.tempStep;
  200. editable_SetPoint.max_value = systemSettings.Profile.MaxSetTemperature;
  201. editable_SetPoint.min_value = systemSettings.Profile.MinSetTemperature;
  202. setMainScrTempUnit();
  203. mainScr.idleTick=HAL_GetTick();
  204. }
  205. int main_screenProcessInput(screen_t * scr, RE_Rotation_t input, RE_State_t *state) {
  206. updateIronPower();
  207. uint32_t currentTime = HAL_GetTick();
  208. uint8_t error = GetIronError();
  209. if(mainScr.update){ // This was set on a previous pass. We reset the flag now.
  210. mainScr.update = 0;
  211. }
  212. if((HAL_GetTick()-mainScr.updateTick)>systemSettings.settings.guiUpdateDelay){
  213. mainScr.update=1; // Update realtime readings slower than the rest of the GUI
  214. mainScr.updateTick=currentTime;
  215. }
  216. uint8_t current_mode = getCurrentMode();
  217. if(error){
  218. if(!(mainScr.ironStatus == status_sleep && error==1)){
  219. mainScr.ironStatus = status_error;
  220. }
  221. }
  222. else if(current_mode==mode_sleep){
  223. mainScr.ironStatus = status_sleep;
  224. clearActivityIcon();
  225. }
  226. else{
  227. mainScr.ironStatus = status_running;
  228. if(current_mode==mode_standby){
  229. clearActivityIcon();
  230. }
  231. else if(Iron.newActivity && !mainScr.ActivityOn && mainScr.currentMode==main_irontemp){
  232. mainScr.ActivityOn=1;
  233. }
  234. }
  235. if(mainScr.ActivityOn && (currentTime-Iron.lastActivityTime)>50){
  236. clearActivityIcon();
  237. }
  238. if(input!=Rotate_Nothing){
  239. mainScr.idleTick=currentTime;
  240. }
  241. // Check for click input and wake iron. Disable button wake for 500mS after manually entering sleep mode
  242. if(input==Click && ((mainScr.currentMode==main_irontemp) || (mainScr.currentMode==main_disabled)) && (currentTime - mainScr.enteredSleep) >500 ){
  243. IronWake(source_wakeButton);
  244. }
  245. switch(mainScr.currentMode){
  246. case main_irontemp:
  247. if(mainScr.ironStatus!=status_running){ // When the screen goes to disable state
  248. memset(plotData,0,sizeof(plotData)); // Clear plotdata
  249. plot_Index=0; // Reset X
  250. mainScr.setMode=main_disabled;
  251. mainScr.currentMode=main_setMode;
  252. break;
  253. }
  254. if((input==LongClick)){
  255. return screen_settingsmenu;
  256. }
  257. else if((input==Rotate_Increment_while_click)){
  258. mainScr.setMode=main_tipselect;
  259. mainScr.currentMode=main_setMode;
  260. }
  261. else if((input==Rotate_Decrement_while_click)){
  262. mainScr.enteredSleep = currentTime;
  263. if(Iron.CurrentMode==mode_run){
  264. setCurrentMode(mode_standby);
  265. }
  266. else if(Iron.CurrentMode==mode_standby){
  267. setCurrentMode(mode_sleep);
  268. }
  269. }
  270. else if((input==Rotate_Increment)||(input==Rotate_Decrement)){
  271. mainScr.setMode=main_setpoint;
  272. mainScr.currentMode=main_setMode;
  273. if(current_mode==mode_standby){
  274. IronWake(source_wakeButton);
  275. }
  276. }
  277. else if(input==Click){
  278. mainScr.update=1;
  279. scr->refresh=screenRefresh_eraseNow;
  280. if(mainScr.displayMode==temp_numeric){
  281. mainScr.displayMode=temp_graph;
  282. widgetDisable(&Widget_IronTemp);
  283. }
  284. else if(mainScr.displayMode==temp_graph){
  285. mainScr.displayMode=temp_numeric;
  286. widgetEnable(&Widget_IronTemp);
  287. }
  288. }
  289. break;
  290. case main_disabled:
  291. {
  292. enum{ dim_idle, dim_down, dim_up };
  293. static uint8_t dimDisplay=dim_idle;
  294. static uint32_t dimTimer=0;
  295. uint8_t contrast = getContrast();
  296. if((currentTime-mainScr.idleTick)>15000 && contrast>5){
  297. dimDisplay=dim_down;
  298. }
  299. if((input==Rotate_Decrement) || (input==Rotate_Increment)){
  300. dimDisplay=dim_up;
  301. }
  302. else if(input!=Rotate_Nothing){
  303. dimDisplay = dim_idle;
  304. setContrast(systemSettings.settings.contrast);
  305. }
  306. if(dimDisplay!=dim_idle){
  307. if(systemSettings.settings.screenDimming && currentTime-dimTimer>9){
  308. dimTimer = currentTime;
  309. mainScr.idleTick = currentTime;
  310. if(dimDisplay==dim_down){
  311. if(contrast>5){
  312. dimTimer=currentTime;
  313. setContrast(contrast-5);
  314. }
  315. else{
  316. dimDisplay=dim_idle;
  317. }
  318. }
  319. else{
  320. if(systemSettings.settings.contrast>(contrast+5)){
  321. setContrast(contrast+5);
  322. }
  323. else{
  324. setContrast(systemSettings.settings.contrast);
  325. dimDisplay=dim_idle;
  326. }
  327. }
  328. }
  329. }
  330. if((input==LongClick)){
  331. return screen_settingsmenu;
  332. }
  333. else if((input==Rotate_Increment_while_click)){
  334. mainScr.setMode=main_tipselect;
  335. mainScr.currentMode=main_setMode;
  336. }
  337. if(mainScr.ironStatus==status_running){
  338. setContrast(systemSettings.settings.contrast);
  339. mainScr.setMode=main_irontemp;
  340. mainScr.currentMode=main_setMode;
  341. }
  342. break;
  343. }
  344. case main_tipselect:
  345. if(input==LongClick){
  346. return screen_edit_tip_settings;
  347. }
  348. case main_setpoint:
  349. switch((uint8_t)input){
  350. case LongClick:
  351. return -1;
  352. case Rotate_Nothing:
  353. if( (mainScr.currentMode==main_setpoint && currentTime-mainScr.idleTick > 1000) || (mainScr.currentMode!=main_setpoint && currentTime-mainScr.idleTick > 5000)){
  354. case Click:
  355. mainScr.currentMode=main_setMode;
  356. mainScr.setMode=main_irontemp;
  357. return -1;
  358. }
  359. break;
  360. default:
  361. if(input==Rotate_Increment_while_click){
  362. input=Rotate_Increment;
  363. }
  364. if(input==Rotate_Decrement_while_click){
  365. input=Rotate_Decrement;
  366. }
  367. break;
  368. }
  369. default:
  370. break;
  371. }
  372. if(mainScr.currentMode==main_setMode){
  373. mainScr.update=1;
  374. mainScr.idleTick=currentTime;
  375. scr->refresh=screenRefresh_eraseNow;
  376. mainScr.currentMode=mainScr.setMode;
  377. switch(mainScr.currentMode){
  378. case main_disabled:
  379. widgetDisable(&Widget_IronTemp);
  380. break;
  381. case main_irontemp:
  382. setMainWidget(&Widget_IronTemp);
  383. if(mainScr.displayMode==temp_graph){
  384. widgetDisable(&Widget_IronTemp);
  385. }
  386. break;
  387. case main_setpoint:
  388. setMainWidget(&Widget_SetPoint);
  389. break;
  390. case main_tipselect:
  391. setMainWidget(&Widget_TipSelect);
  392. break;
  393. default:
  394. break;
  395. }
  396. return -1;
  397. }
  398. return default_screenProcessInput(scr, input, state);
  399. }
  400. void main_screen_draw(screen_t *scr){
  401. uint8_t scr_refresh;
  402. static uint32_t lastState = 0;
  403. uint32_t currentState = (uint32_t)Iron.Error.Flags<<24 | (uint32_t)mainScr.ironStatus<<16 | mainScr.currentMode; // Simple method to detect changes
  404. uint16_t plot_t = (systemSettings.Profile.pwmPeriod+1)/100; // Update at the same rate as the system pwm
  405. if(plot_t<20){ plot_t = 20; }
  406. if(mainScr.currentMode!=main_disabled && (HAL_GetTick()-plotTime)>plot_t){ // Only store values if running
  407. plotUpdate=1;
  408. plotTime=HAL_GetTick();
  409. int16_t t = readTipTemperatureCompensated(stored_reading,read_Avg);
  410. if(systemSettings.settings.tempUnit==mode_Farenheit){
  411. t = TempConversion(t, mode_Celsius, 0);
  412. }
  413. if (t<20) t = 20;
  414. if (t>500) t = 500;
  415. plotData[plot_Index] = t;
  416. if(++plot_Index>99){
  417. plot_Index=0;
  418. }
  419. }
  420. if((lastState!=currentState) || Widget_SetPoint.refresh || Widget_IronTemp.refresh || plotUpdate){
  421. lastState=currentState;
  422. scr->refresh=screenRefresh_eraseNow;
  423. }
  424. if(mainScr.ironStatus==status_sleep && mainScr.currentMode==main_disabled){
  425. if((HAL_GetTick()-sleepTim)>50){
  426. sleepTim=HAL_GetTick();
  427. scr->refresh=screenRefresh_eraseNow;
  428. Slp_xpos += Slp_xadd;
  429. Slp_ypos += Slp_yadd;
  430. if((Slp_xpos+sleepWidth)>OledWidth){
  431. Slp_xadd = -1;
  432. }
  433. else if(Slp_xpos==0){
  434. Slp_xadd = 1;
  435. }
  436. if(Slp_ypos+sleepHeigh>OledHeight){
  437. Slp_yadd = -1;
  438. }
  439. else if(Slp_ypos<16){
  440. Slp_yadd = 1;
  441. }
  442. }
  443. }
  444. /*
  445. if(scr->refresh==screenRefresh_eraseNow){
  446. FillBuffer(BLACK,fill_dma);
  447. scr->refresh=screenRefresh_alreadyErased;
  448. // Screen is erased now, draw anything here before main screen draws
  449. }
  450. */
  451. scr_refresh=scr->refresh;
  452. default_screenDraw(scr);
  453. if(scr_refresh){
  454. u8g2_SetDrawColor(&u8g2, WHITE);
  455. #ifdef USE_NTC
  456. u8g2_DrawXBMP(&u8g2, Widget_AmbTemp.posX-tempXBM[0]-2, 0, tempXBM[0], tempXBM[1], &tempXBM[2]);
  457. #endif
  458. #ifdef USE_VIN
  459. u8g2_DrawXBMP(&u8g2, 0, 2, voltXBM[0], voltXBM[1], &voltXBM[2]);
  460. #endif
  461. if(mainScr.currentMode==main_disabled){
  462. u8g2_SetFont(&u8g2, u8g2_font_mainBig);
  463. if(mainScr.ironStatus==status_error){
  464. uint8_t Err_ypos = 14;
  465. if(Iron.Error.Flags==0x81){ // 0x81 = Only "No iron detected". Don't show error just for it
  466. u8g2_SetFont(&u8g2, u8g2_font_mainBig);
  467. putStrAligned("NO IRON", 26, align_center);
  468. }
  469. else{
  470. char errStr[16];
  471. sprintf(errStr, "ERROR %X",Iron.Error.Flags);
  472. u8g2_SetFont(&u8g2, u8g2_font_t0_16_tr);
  473. putStrAligned(errStr, Err_ypos, align_center);
  474. Err_ypos+=13;
  475. if(Iron.Error.failState){
  476. putStrAligned("Internal failure", Err_ypos, align_center);
  477. Err_ypos+=13;
  478. }
  479. if(Iron.Error.V_low){
  480. putStrAligned("Voltage low!", Err_ypos, align_center);
  481. Err_ypos+=13;
  482. }
  483. if(Iron.Error.noIron){
  484. putStrAligned("No iron detected", Err_ypos, align_center);
  485. Err_ypos+=13;
  486. }
  487. if(Iron.Error.NTC_high){
  488. putStrAligned("NTC read high!", Err_ypos, align_center);
  489. Err_ypos+=13;
  490. }
  491. else if(Iron.Error.NTC_low){
  492. putStrAligned("NTC read low!", Err_ypos, align_center);
  493. Err_ypos+=13;
  494. }
  495. }
  496. }
  497. else if(mainScr.ironStatus==status_sleep){
  498. u8g2_DrawStr(&u8g2, Slp_xpos, Slp_ypos, "SLEEP");
  499. u8g2_SetFont(&u8g2, u8g2_font_labels);
  500. if(!Iron.Error.Flags && readTipTemperatureCompensated(0,0)>120){
  501. u8g2_DrawXBMP(&u8g2, 42,0, warningXBM[0], warningXBM[1], &warningXBM[2]);
  502. u8g2_DrawStr(&u8g2, 55, 2, "HOT!");
  503. }
  504. }
  505. }
  506. else{
  507. if(mainScr.currentMode==main_tipselect){
  508. u8g2_SetFont(&u8g2, u8g2_font_t0_16_tr);
  509. putStrAligned("TIP SELECTION", 16, align_center);
  510. }
  511. if(mainScr.ActivityOn){
  512. u8g2_DrawXBMP(&u8g2, 57, 2, shakeXBM[0], shakeXBM[1], &shakeXBM[2]);
  513. }
  514. }
  515. }
  516. if(mainScr.ironStatus==status_running){
  517. if(scr_refresh && getCurrentMode()==mode_standby){
  518. u8g2_SetFont(&u8g2, u8g2_font_labels);
  519. u8g2_DrawStr(&u8g2, 47, 2, "STBY");
  520. }
  521. if( scr_refresh || (HAL_GetTick()-barTime)>9){ // Update every 10mS or if screen was erased
  522. if(scr_refresh<screenRefresh_eraseNow){ // If screen not erased
  523. u8g2_SetDrawColor(&u8g2,BLACK); // Draw a black square to wipe old widget data
  524. u8g2_DrawBox(&u8g2, 13 , OledHeight-6, 100, 5);
  525. }
  526. u8g2_SetDrawColor(&u8g2,WHITE);
  527. u8g2_DrawBox(&u8g2, 13, OledHeight-5, mainScr.lastPwr, 3);
  528. u8g2_DrawRFrame(&u8g2, 13, OledHeight-6, 100, 5, 2);
  529. }
  530. if((scr_refresh || plotUpdate) && mainScr.currentMode==main_irontemp && mainScr.displayMode==temp_graph){ //Update every 100mS or if screen is erased
  531. plotUpdate=0;
  532. uint8_t set;
  533. int16_t t = Iron.CurrentSetTemperature;
  534. bool magnify = true; // for future, to support both graph types
  535. if(systemSettings.settings.tempUnit==mode_Farenheit){
  536. t = TempConversion(t, mode_Celsius, 0);
  537. }
  538. // plot is 16-56 V, 14-113 H ?
  539. u8g2_DrawVLine(&u8g2, 11, 16, 41); // left scale
  540. if (magnify) { // graphing magnified
  541. for(uint8_t y=16; y<57; y+=10){
  542. u8g2_DrawHLine(&u8g2, 7, y, 4); // left ticks
  543. }
  544. for(uint8_t x=0; x<100; x++){
  545. uint8_t pos=plot_Index+x;
  546. if(pos>99){ pos-=100; } // Reset index if > 99
  547. uint16_t plotV = plotData[pos];
  548. if (plotV < t-20) plotV = 0;
  549. else if (plotV >= t+20) plotV = 40;
  550. else plotV = (plotV-t+20) ; // relative to t, +-20C
  551. u8g2_DrawVLine(&u8g2, x+13, 56-plotV, plotV); // data points
  552. }
  553. set= 36;
  554. } else { // graphing full range
  555. for(uint8_t y=16; y<57; y+=13){
  556. u8g2_DrawHLine(&u8g2, 7, y, 4); // left ticks
  557. }
  558. for(uint8_t x=0; x<100; x++){
  559. uint8_t pos=plot_Index+x;
  560. if(pos>99) pos-=100;
  561. uint16_t plotV = plotData[pos];
  562. if (plotV<180) plotV = 0;
  563. else plotV = (plotV-180) >> 3; // divide by 8, (500-180)/8=40
  564. u8g2_DrawVLine(&u8g2, x+13, 56-plotV, plotV); // data points
  565. }
  566. if(t<188){ set = 1; }
  567. else {
  568. set=(t-180)>>3;
  569. }
  570. set= 56-set;
  571. }
  572. u8g2_DrawTriangle(&u8g2, 122, set-4, 122, set+4, 115, set); // set temp marker
  573. }
  574. }
  575. }
  576. //-------------------------------------------------------------------------------------------------------------------------------
  577. // Main screen setup
  578. //-------------------------------------------------------------------------------------------------------------------------------
  579. void main_screen_setup(screen_t *scr) {
  580. //
  581. for(int x = 0; x < TipSize; x++) {
  582. tipName[x] = systemSettings.Profile.tip[x].name;
  583. }
  584. screen_setDefaults(scr);
  585. scr->draw = &main_screen_draw;
  586. scr->init = &main_screen_init;
  587. scr->processInput = &main_screenProcessInput;
  588. widget_t *w;
  589. displayOnly_widget_t* dis;
  590. editable_widget_t* edit;
  591. //iron tip temperature display
  592. w=&Widget_IronTemp;
  593. screen_addWidget(w,scr);
  594. widgetDefaultsInit(w, widget_display, &display_IronTemp);
  595. dis=extractDisplayPartFromWidget(w);
  596. edit=extractEditablePartFromWidget(w);
  597. dis->reservedChars=5;
  598. dis->textAlign=align_center;
  599. dis->dispAlign=align_center;
  600. dis->font=u8g2_font_iron;
  601. w->posY = 17;
  602. dis->getData = &main_screen_getIronTemp;
  603. // Tip temperature setpoint
  604. w=&Widget_SetPoint;
  605. screen_addWidget(w,scr);
  606. widgetDefaultsInit(w, widget_editable, &editable_SetPoint);
  607. dis=extractDisplayPartFromWidget(w);
  608. edit=extractEditablePartFromWidget(w);
  609. dis->reservedChars=5;
  610. w->posY = Widget_IronTemp.posY-2;
  611. dis->getData = &getTemp;
  612. dis->dispAlign=align_center;
  613. dis->textAlign=align_center;
  614. dis->font=display_IronTemp.font;
  615. edit->selectable.tab = 1;
  616. edit->setData = (void (*)(void *))&setTemp;
  617. w->frameType=frame_solid;
  618. w->radius=0;
  619. w->enabled=0;
  620. #ifdef USE_VIN
  621. //V input display
  622. w = &Widget_Vsupply;
  623. screen_addWidget(w, scr);
  624. widgetDefaultsInit(w, widget_display, &display_Vsupply);
  625. dis=extractDisplayPartFromWidget(w);
  626. edit=extractEditablePartFromWidget(w);
  627. dis->endString="V";
  628. dis->reservedChars=5;
  629. dis->textAlign=align_center;
  630. dis->number_of_dec=1;
  631. dis->font=u8g2_font_labels;
  632. w->posX = voltXBM[0]+2;
  633. w->posY= 2;
  634. dis->getData = &main_screen_getVin;
  635. //w->width = 40;
  636. #endif
  637. #ifdef USE_NTC
  638. //Ambient temperature display
  639. w=&Widget_AmbTemp;
  640. screen_addWidget(w,scr);
  641. widgetDefaultsInit(w, widget_display, &display_AmbTemp);
  642. dis=extractDisplayPartFromWidget(w);
  643. edit=extractEditablePartFromWidget(w);
  644. dis->reservedChars=7;
  645. dis->dispAlign=align_right;
  646. dis->textAlign=align_center;
  647. w->posY= 2;
  648. dis->number_of_dec=1;
  649. dis->font=u8g2_font_labels;
  650. dis->getData = &main_screen_getAmbTemp;
  651. #endif
  652. // Tips
  653. w=&Widget_TipSelect;
  654. screen_addWidget(w,scr);
  655. widgetDefaultsInit(w, widget_multi_option, &editable_TipSelect);
  656. dis=extractDisplayPartFromWidget(w);
  657. edit=extractEditablePartFromWidget(w);
  658. dis->reservedChars=TipCharSize-1;
  659. w->posY = 32;
  660. dis->dispAlign=align_center;
  661. dis->textAlign=align_center;
  662. edit->inputData.getData = &getTip;
  663. edit->inputData.number_of_dec = 0;
  664. edit->big_step = 0;
  665. edit->step = 0;
  666. edit->selectable.tab = 2;
  667. edit->setData = (void (*)(void *))&setTip;
  668. edit->options = tipName;
  669. w->enabled=0;
  670. w->frameType=frame_disabled;
  671. setMainWidget(&Widget_IronTemp);
  672. u8g2_SetFont(&u8g2,u8g2_font_mainBig);
  673. sleepWidth=u8g2_GetStrWidth(&u8g2, "SLEEP")+2;
  674. sleepHeigh= u8g2_GetMaxCharHeight(&u8g2)+3;
  675. }