]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/disp-4dgl/status_screen.4dg
8902ff4af140028a259d9f94d863710769e67282
[eurobot/public.git] / src / disp-4dgl / status_screen.4dg
1 #platform "uOLED-32028-PMD3T"
2
3 #inherit "4DGL_16bitColours.fnc"\r
4 //#inherit "4DGL-System.fnc"
5 \r
6 #constant MSG_TERM '~'\r
7 #constant MSG_BUFF_LEN 103\r
8 #constant MSG_POWER 'V'\r
9 #constant MSG_POSITION 'P'\r
10 #constant MSG_FSM_STATE 'F'\r
11 #constant MSG_MOVE_FSM_STATE 'M'\r
12 \r
13 #constant MSG_START 150\r
14 #constant MSG_TERM_LF 10\r
15 \r
16 #constant MSG_SWITCH_TO_STATUS_DONE 185\r
17 \r
18 #constant MSG_STATUS 'S'\r
19
20 // Indices to the voltage_status array
21 #constant VOLTAGE33 0
22 #constant VOLTAGE50 1
23 #constant VOLTAGE80 2
24 #constant VOLTAGE_BAT 3
25
26 /*Voltage branch OK indication*/
27 #constant VOLTAGE_OK 1\r
28 \r
29 #constant HW_STATUS_OK 1\r
30 #constant HW_STATUS_WARN 2\r
31 \r
32 #constant MSG_CONTROL_REQ 184\r
33 #constant MSG_SWITCH_REP 200\r
34 \r
35 #constant HW1 1\r
36 #constant HW2 2\r
37 #constant HW3 3\r
38 #constant HW4 4\r
39 #constant HW5 5\r
40 #constant HW6 6\r
41
42 var msg_buff[MSG_BUFF_LEN]; // serial RX buffer\r
43 var msg_rcvd[MSG_BUFF_LEN]; // serial RX buffer\r
44 var out_buff[3];
45
46 var voltage33[4];
47 var voltage50[4];
48 var voltage80[4];
49 var voltageBAT[5];
50
51 var voltage_status[4]; // status of individual voltage branches
52
53 var position[8];
54 var game_color;
55
56 var fsm_state[20];
57 var fsm_state_len;\r
58 var move_fsm_state[20];\r
59 var move_fsm_state_len;\r
60 \r
61 var lift_pos[4];\r
62 var pucks_nr;\r
63 var game_conf;\r
64 \r
65 var hw_status[8];\r
66
67 func init()\r
68     var idx;\r
69     \r
70     game_color:=BLACK;\r
71     \r
72     idx:=0;\r
73     repeat\r
74         position[idx]:=' ';\r
75         idx++;\r
76     until(idx == 8);\r
77     idx:=0;\r
78     repeat\r
79         voltage33[idx]:=' ';\r
80         idx++;\r
81     until(idx == 4);\r
82     idx:=0;\r
83     repeat\r
84         voltage50[idx]:=' ';\r
85         idx++;\r
86     until(idx == 4);\r
87     idx:=0;\r
88     repeat\r
89         voltage80[idx]:=' ';\r
90         idx++;\r
91     until(idx == 4);\r
92     idx:=0;\r
93     repeat\r
94         voltageBAT[idx]:=' ';\r
95         idx++;\r
96     until(idx == 5);\r
97     \r
98     lift_pos[0]:='0';\r
99     lift_pos[1]:='0';\r
100     lift_pos[2]:='0';\r
101     lift_pos[3]:='0';\r
102     pucks_nr:='0';\r
103     game_conf:='1';\r
104 endfunc\r
105 \r
106
107 func clear_screen()
108     gfx_Rectangle(0, 0, 239, 319, BLACK);   
109     return 0;
110 endfunc\r
111 \r
112 func bt_control(var state)\r
113     gfx_Button(state, 2, 290, GRAY, WHITE, FONT3, 1, 1, "           CONTROL          ");\r
114 endfunc 
115
116 func draw_voltage33() // draw the 3.3 V voltage status indicator
117     var col_rect;
118
119     if(voltage_status[VOLTAGE33]==VOLTAGE_OK)
120         col_rect := RED;
121     else
122         col_rect := GREEN;
123     endif
124
125     gfx_Rectangle(0,10,60,50,col_rect);
126     gfx_Line(59, 10, 59, 50, BLACK);
127     txt_Set(TEXT_COLOUR, WHITE);
128     txt_Set(FONT_SIZE, FONT3);
129     txt_MoveCursor(1,1);
130     putstr("3,30V");
131     txt_Set(FONT_SIZE, FONT4);
132     txt_MoveCursor(2,0);
133     putch(voltage33[0]);
134     putch(voltage33[1]);
135     putch(voltage33[2]);
136     putch(voltage33[3]);
137     return 0;
138 endfunc
139
140 func draw_voltage50()
141     var col_rect;
142
143     if(voltage_status[VOLTAGE50]==VOLTAGE_OK)
144         col_rect := RED;
145     else
146         col_rect := GREEN;
147     endif
148
149     gfx_Rectangle(60,10,120,50,col_rect);
150     gfx_Line(119, 10, 119, 50, BLACK);
151     txt_Set(TEXT_COLOUR, WHITE);
152     txt_Set(FONT_SIZE, FONT3);
153     txt_MoveCursor(1,9);
154     putstr("5,00V");
155     txt_Set(FONT_SIZE, FONT4);
156     txt_MoveCursor(2,5);
157     putch(voltage50[0]);
158     putch(voltage50[1]);
159     putch(voltage50[2]);
160     putch(voltage50[3]);
161     return 0;
162 endfunc
163
164 func draw_voltage80()
165     var col_rect;
166
167     if(voltage_status[VOLTAGE80]==VOLTAGE_OK)
168         col_rect := RED;
169     else
170         col_rect := GREEN;
171     endif
172
173     gfx_Rectangle(120,10,180,50,col_rect);
174     gfx_Line(179, 10, 179, 50, BLACK);
175     txt_Set(TEXT_COLOUR, WHITE);
176     txt_Set(FONT_SIZE, FONT3);
177     txt_MoveCursor(1,17);
178     putstr("8,00V");
179     txt_Set(FONT_SIZE, FONT4);
180     txt_MoveCursor(2,10);
181     putch(voltage80[0]);
182     putch(voltage80[1]);
183     putch(voltage80[2]);
184     putch(voltage80[3]);
185     return 0;
186 endfunc
187
188 func draw_voltageBAT()
189     var col_rect;
190
191     if(voltage_status[VOLTAGE_BAT]==VOLTAGE_OK)
192         col_rect := RED;
193     else
194         col_rect := GREEN;
195     endif
196
197     gfx_Rectangle(180,10,240,50,col_rect);
198     txt_Set(TEXT_COLOUR, WHITE);
199     txt_Set(FONT_SIZE, FONT3);
200     txt_MoveCursor(1,25);
201     putstr("BATT");
202     txt_Set(FONT_SIZE, FONT4);
203     txt_MoveCursor(2,15);
204     putch(voltageBAT[0]);
205     putch(voltageBAT[1]);
206     putch(voltageBAT[2]);
207     putch(voltageBAT[3]);
208     putch(voltageBAT[4]);
209     return 0;
210 endfunc
211
212 func draw_voltage()
213     putstr("VOLTAGE");
214     draw_voltage33();
215     draw_voltage50();
216     draw_voltage80();
217     draw_voltageBAT();
218 endfunc
219
220 func draw_position()
221     txt_Set(FONT_SIZE, FONT3);
222     txt_MoveCursor(21, 6);     
223     txt_Set(TEXT_COLOUR, GRAY);
224     
225     putstr("POSITION AND COLOR");
226
227     gfx_Rectangle(0,266,239,289,game_color);
228     txt_Set(FONT_SIZE, FONT4);
229     txt_Set(TEXT_COLOUR, WHITE);
230     txt_MoveCursor(17,0);
231     putstr("X,Y: ");
232     putch(position[0]);
233     putch(position[1]);
234     putch(position[2]);
235     putch(position[3]);
236     putch(' ');
237     putch(position[4]);
238     putch(position[5]);
239     putch(position[6]);
240     putch(position[7]);
241     putstr(" [m]");
242     return 0;
243 endfunc\r
244
245 func draw_fsm_state()
246     var idx;
247     txt_Set(FONT_SIZE, FONT3);
248     txt_MoveCursor(5, 6);           // move the cursor to line 4, column 5
249     txt_Set(TEXT_COLOUR, GRAY);
250     
251     putstr("CURRENT FSM STATE");
252     return 0;
253 endfunc
254
255 func update_fsm_state()
256     var idx;
257     gfx_Rectangle(0, 70, 239, 99, BLACK);
258     txt_Set(FONT_SIZE, FONT4);
259     txt_MoveCursor(5, 0);           // move the cursor to line 4, column 5
260     txt_Set(TEXT_COLOUR, WHITE);
261     idx:=0;
262     repeat
263         putch(fsm_state[idx]);
264         idx++;
265     until(idx==20)
266     return 0;
267 endfunc
268
269 func update_move_fsm_state()\r
270     var idx;\r
271     gfx_Rectangle(0, 99, 239, 112, BLACK);\r
272     txt_Set(FONT_SIZE, FONT4);\r
273     txt_MoveCursor(6, 0);           // move the cursor to line 4, column 5\r
274     txt_Set(TEXT_COLOUR, WHITE);\r
275     idx:=0;\r
276     repeat\r
277         putch(move_fsm_state[idx]);\r
278         idx++;\r
279     until(idx==20)\r
280     return 0;\r
281 endfunc\r
282 \r
283 func draw_hw1(var status)\r
284     txt_Set(FONT_SIZE, FONT3);\r
285     txt_Set(TEXT_COLOUR, WHITE);\r
286     \r
287     if(status==HW_STATUS_OK)\r
288         gfx_Rectangle(0,193,59,218,GREEN);\r
289     else\r
290         if(status==HW_STATUS_WARN)
291             gfx_Rectangle(0,193,59,218,ORANGE);\r
292         else
293             gfx_Rectangle(0,193,59,218,RED);\r
294         endif
295     endif\r
296 \r
297     txt_MoveCursor(17,3);\r
298     putstr("MOT");\r
299 endfunc\r
300 \r
301 func draw_hw2(var status)\r
302     txt_Set(FONT_SIZE, FONT3);\r
303     txt_Set(TEXT_COLOUR, WHITE);\r
304     \r
305     if(status==HW_STATUS_OK)\r
306         gfx_Rectangle(61,193,120,218,GREEN);\r
307     else\r
308             if(status==HW_STATUS_WARN)
309             gfx_Rectangle(61,193,120,218,ORANGE);\r
310             else
311             gfx_Rectangle(61,193,120,218,RED);\r
312             endif
313     endif\r
314     txt_MoveCursor(17,10);\r
315     putstr("UZV");\r
316 endfunc\r
317 \r
318 func draw_hw3(var status)\r
319     txt_Set(FONT_SIZE, FONT3);\r
320     txt_Set(TEXT_COLOUR, WHITE);\r
321     \r
322     if(status==HW_STATUS_OK)\r
323         gfx_Rectangle(122,193,181,218,GREEN);\r
324     else\r
325             if(status==HW_STATUS_WARN)
326             gfx_Rectangle(122,193,181,218,ORANGE);\r
327             else
328             gfx_Rectangle(122,193,181,218,RED);\r
329             endif
330     endif\r
331 \r
332     txt_MoveCursor(17,17);\r
333     putstr("LFT");\r
334 endfunc\r
335 \r
336 func draw_hw3a(var status)\r
337     txt_Set(FONT_SIZE, FONT3);\r
338     txt_Set(TEXT_COLOUR, WHITE);\r
339     \r
340     if(status==HW_STATUS_OK)\r
341         gfx_Rectangle(183,193,239,218,GREEN);\r
342     else\r
343             if(status==HW_STATUS_WARN)
344             gfx_Rectangle(183,193,239,218,ORANGE);\r
345             else
346             gfx_Rectangle(183,193,239,218,RED);\r
347             endif
348     endif\r
349 \r
350     txt_MoveCursor(17,25);\r
351     putstr("CHE");\r
352 endfunc\r
353 \r
354 func draw_hw4(var status)\r
355     txt_Set(FONT_SIZE, FONT3);\r
356     txt_Set(TEXT_COLOUR, WHITE);\r
357     \r
358     if(status==HW_STATUS_OK)\r
359         gfx_Rectangle(0,220,59,245,GREEN);\r
360     else\r
361             if(status==HW_STATUS_WARN)
362             gfx_Rectangle(0,220,59,245,ORANGE);\r
363             else
364             gfx_Rectangle(0,220,59,245,RED);\r
365             endif
366     endif\r
367     \r
368     txt_MoveCursor(19,3);\r
369     putstr("CAM");\r
370 endfunc\r
371 \r
372 func draw_hw5(var status)\r
373     txt_Set(FONT_SIZE, FONT3);\r
374     txt_Set(TEXT_COLOUR, WHITE);\r
375     \r
376     if(status==HW_STATUS_OK)\r
377         gfx_Rectangle(61,220,120,245,GREEN);\r
378     else\r
379             if(status==HW_STATUS_WARN)
380             gfx_Rectangle(61,220,120,245,ORANGE);\r
381             else
382             gfx_Rectangle(61,220,120,245,RED);\r
383             endif
384     endif\r
385     \r
386     txt_MoveCursor(19,10);\r
387     putstr("HOK");\r
388 endfunc\r
389 \r
390 func draw_hw6(var status)\r
391     txt_Set(FONT_SIZE, FONT3);\r
392     txt_Set(TEXT_COLOUR, WHITE);\r
393     \r
394     if(status==HW_STATUS_OK)\r
395         gfx_Rectangle(122,220,181,245,GREEN);\r
396     else\r
397             if(status==HW_STATUS_WARN)
398             gfx_Rectangle(122,220,181,245,ORANGE);\r
399             else
400             gfx_Rectangle(122,220,181,245,RED);\r
401             endif
402     endif\r
403     \r
404     txt_MoveCursor(19,17);\r
405     putstr("PWR");\r
406 endfunc\r
407 \r
408 func draw_hw6a(var status)\r
409     txt_Set(FONT_SIZE, FONT3);\r
410     txt_Set(TEXT_COLOUR, WHITE);\r
411     \r
412     if(status==HW_STATUS_OK)\r
413         gfx_Rectangle(183,220,239,245,GREEN);\r
414     else\r
415         if(status==HW_STATUS_WARN)\r
416             gfx_Rectangle(183,220,239,245,ORANGE);\r
417         else\r
418             gfx_Rectangle(183,220,239,245,RED);\r
419         endif\r
420     endif\r
421     \r
422     txt_MoveCursor(19,25);\r
423     putstr("STA");\r
424 endfunc\r
425 \r
426 func draw_hw()\r
427     txt_Set(FONT_SIZE, FONT3);\r
428     txt_MoveCursor(15, 10);           // move the cursor to line 4, column 5\r
429     txt_Set(TEXT_COLOUR, GRAY);\r
430     \r
431     putstr("HW STATUS");\r
432     \r
433     txt_Set(TEXT_COLOUR, WHITE);\r
434 \r
435     draw_hw1(HW_STATUS_OK);\r
436     draw_hw2(HW_STATUS_OK);\r
437     draw_hw3(HW_STATUS_OK);\r
438     draw_hw3a(HW_STATUS_OK);\r
439     draw_hw4(HW_STATUS_OK);\r
440     draw_hw5(HW_STATUS_OK);\r
441     draw_hw6(HW_STATUS_OK);\r
442     draw_hw6a(HW_STATUS_OK);\r
443     return 0;\r
444 endfunc\r
445 \r
446 func update_pucks()\r
447     gfx_Rectangle(0, 142, 50, 170, BLACK);\r
448     txt_Set(FONT_SIZE, FONT4);\r
449     txt_MoveCursor(9, 3);           // move the cursor to line 4, column 5\r
450     txt_Set(TEXT_COLOUR, LEMONCHIFFON);\r
451     putch(pucks_nr);\r
452 endfunc\r
453 \r
454 func draw_pucks()\r
455     txt_Set(FONT_SIZE, FONT3);\r
456     txt_MoveCursor(10, 1);           // move the cursor to line 4, column 5\r
457     txt_Set(TEXT_COLOUR, GRAY);\r
458     \r
459     putstr("PUCKS nr.");\r
460     update_pucks();\r
461 endfunc\r
462 \r
463 func update_lift()\r
464     gfx_Rectangle(170, 142, 239, 170, BLACK);\r
465     txt_Set(FONT_SIZE, FONT4);\r
466     txt_MoveCursor(9, 15);           // move the cursor to line 4, column 5\r
467     txt_Set(TEXT_COLOUR, LEMONCHIFFON);\r
468     putch(lift_pos[0]);\r
469     putch(lift_pos[1]);\r
470     putch(lift_pos[2]);\r
471     putch(lift_pos[3]);\r
472 endfunc\r
473 \r
474 func draw_lift()\r
475     txt_Set(FONT_SIZE, FONT3);\r
476     txt_MoveCursor(10, 20);           // move the cursor to line 4, column 5\r
477     txt_Set(TEXT_COLOUR, GRAY);\r
478     \r
479     putstr("LIFT pos.");\r
480     update_lift();\r
481 endfunc\r
482 \r
483 func update_conf()\r
484     gfx_Rectangle(70, 142, 140, 170, BLACK);\r
485     txt_Set(FONT_SIZE, FONT4);\r
486     txt_MoveCursor(9, 9);           // move the cursor to line 4, column 5\r
487     txt_Set(TEXT_COLOUR, LEMONCHIFFON);\r
488     putch(game_conf);\r
489 endfunc\r
490 \r
491 func draw_conf()\r
492     txt_Set(FONT_SIZE, FONT3);\r
493     txt_MoveCursor(10, 10);           // move the cursor to line 4, column 5\r
494     txt_Set(TEXT_COLOUR, GRAY);\r
495     \r
496     putstr("GAME conf.");\r
497     update_conf();\r
498 endfunc\r
499     
500 func draw_status() 
501     clear_screen();
502     txt_Set(FONT_SIZE, FONT3);
503     txt_MoveCursor(0, 12);           // move the cursor to line 4, column 5
504     txt_Set(TEXT_COLOUR, GRAY);
505     draw_voltage(); \r
506     draw_fsm_state(); \r
507     draw_pucks();\r
508     draw_lift();
509     draw_position();\r
510     draw_hw();\r
511     draw_conf();\r
512     bt_control(UP);
513     return 0;
514 endfunc\r
515 \r
516 func update_hw()\r
517     draw_hw1(hw_status[0]);\r
518     draw_hw2(hw_status[1]);\r
519     draw_hw3(hw_status[2]);\r
520     draw_hw3a(hw_status[3]);\r
521     draw_hw4(hw_status[4]);\r
522     draw_hw5(hw_status[5]);\r
523     draw_hw6(hw_status[6]);\r
524     draw_hw6a(hw_status[7]);\r
525 endfunc\r
526 \r
527 func load_control()\r
528     clear_screen();\r
529     file_Run("CTRL.4XE",0);\r
530 endfunc
531
532 /*Process the message received on serial line*/
533 func process_msg()\r
534     var idx;\r
535     if(msg_rcvd[0]==MSG_STATUS)\r
536         mem_Copy(msg_rcvd+2, voltage33, 8);\r
537         mem_Copy(msg_rcvd+6, voltage50, 8);\r
538         mem_Copy(msg_rcvd+10, voltage80, 8);\r
539         mem_Copy(msg_rcvd+14, voltageBAT, 10);\r
540         \r
541         mem_Copy(msg_rcvd+21, position, 16);\r
542         \r
543         mem_Copy(msg_rcvd+35, fsm_state, 40);\r
544         mem_Copy(msg_rcvd+57, move_fsm_state, 40);\r
545         \r
546         if(msg_rcvd[79]==0)\r
547             game_color := GREEN;\r
548         else\r
549             game_color := RED;\r
550         endif\r
551         \r
552         mem_Copy(msg_rcvd+82, lift_pos, 8);\r
553         pucks_nr := msg_rcvd[88];\r
554         \r
555         mem_Copy(msg_rcvd+91, hw_status, 16);\r
556         //mem_Copy(msg_rcvd+101, game_conf, 2);\r
557         game_conf:=msg_rcvd[101];\r
558         \r
559         draw_voltage33();\r
560         draw_voltage50();\r
561         draw_voltage80();\r
562         draw_voltageBAT();\r
563         draw_position();\r
564         update_fsm_state();\r
565         update_move_fsm_state();\r
566         update_lift();\r
567         update_pucks();\r
568         update_conf();\r
569         update_hw();\r
570         \r
571         \r
572     endif\r
573     if(msg_rcvd[0]==200)\r
574         if(msg_rcvd[2]==2)\r
575             load_control();\r
576         endif\r
577     endif\r
578         
579 endfunc
580
581 func get_msg()
582     var in, idx, bad, msg_len;
583
584     idx:=0;
585     bad:=0;    
586     in:=serin();
587     
588     repeat
589         in:=serin();
590         if(in!=-1)
591             msg_rcvd[idx] := in;
592             idx++;
593         else
594             break;
595         endif\r
596     forever
597 \r
598     msg_len := idx;\r
599     com_Init(msg_buff, MSG_BUFF_LEN, ':');
600
601     process_msg();
602     return 0;
603 endfunc    \r
604 \r
605 func act_control()    \r
606     var idx;\r
607     \r
608     out_buff[0]:=MSG_START;\r
609     out_buff[1]:=MSG_CONTROL_REQ;\r
610     out_buff[2]:=MSG_TERM_LF;\r
611     \r
612     idx:=0;\r
613     repeat\r
614         serout(out_buff[idx]);\r
615         idx++;\r
616     until(idx==3)    \r
617 endfunc
618 \r
619 func touchscreen() \r
620     var col, state, x, y;\r
621     state := touch_Get(TOUCH_STATUS);               // get touchscreen status\r
622         \r
623         if(state == NOTOUCH)\r
624             return;\r
625         endif\r
626         //-----------------------------------------------------------------------------------------\r
627         if(state == TOUCH_PRESS)                        // if there's a press\r
628             x := touch_Get(TOUCH_GETX);                          \r
629             y := touch_Get(TOUCH_GETY);\r
630             if(y>290)\r
631                 bt_control(DOWN);\r
632             endif\r
633         endif\r
634         if(state == TOUCH_RELEASE)                        // if there's a press\r
635             x := touch_Get(TOUCH_GETX);                          \r
636             y := touch_Get(TOUCH_GETY);\r
637             if(y>290)\r
638                 bt_control(UP);\r
639                 act_control();\r
640             endif\r
641         endif\r
642             \r
643 endfunc\r
644
645 func main()\r
646     var idx;
647     setbaud(8); // 19200 baud
648     com_Init(msg_buff, MSG_BUFF_LEN, ':');\r
649     \r
650     out_buff[0]:=MSG_START;\r
651     out_buff[1]:=MSG_SWITCH_TO_STATUS_DONE;\r
652     out_buff[2]:=MSG_TERM_LF;\r
653     idx:=0;\r
654     repeat\r
655         serout(out_buff[idx]);\r
656         idx++;\r
657     until(idx==3)  \r
658
659
660     touch_Set(TOUCH_ENABLE); // enable TS
661     touch_Set(TOUCH_REGIONDEFAULT); // reset touch area to fullscreen\r
662     \r
663     init();\r
664     \r
665     draw_status();
666     repeat // the main application loop
667         touchscreen();\r
668         if(com_Full()==1)\r
669             get_msg();\r
670         endif
671     forever
672 endfunc
673 \r
674 \r
675 \r
676 \r
677 \r
678 \r
679 \r
680 \r
681 \r
682 \r
683 \r
684 \r
685 \r
686 \r
687 \r
688 \r
689 \r
690 \r
691 \r
692 \r