]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/disp-4dgl/Display2010.4dg
Remove all openembedded modules
[eurobot/public.git] / src / disp-4dgl / Display2010.4dg
1 #platform "uOLED-32028-PMD3T"
2
3 // Note that 4DGL has built in sine table, this is just for #DATA access example.
4
5 #inherit "4DGL_16bitColours.fnc"
6
7 //*********************************************************************************************
8 //*********************************************************************************************
9 //*********************************************************************************************
10 //*********************************************************************************************
11 #CONST                                          
12     LEFT 15
13     TOP  15
14     // tables
15     V_TAB   4   //number of rectangles
16     MAX_WIDTH   239
17     MAX_HEIGHT  319
18     LAST_ROW    19
19     VOLT_HEIGHT 30
20     VOLT_WIDTH  59// width for voltage color field
21     BUTTONWIDTH 60 
22     BUTTONHEIGHT 30
23
24     // positions
25     VOLT    0
26     VOLT1   1
27     STATE   2
28     NMB_BT  8
29 #END
30
31
32 #CONST
33     NO               0
34     YES              1
35     Y                2
36     X                1   
37 #END
38
39
40 #DATA
41     // button Y positions for control page
42     word dY 3,33,63,93,123,153,183,213,293
43     word colors RED,GREEN,ORANGE
44     word collor BLUE,BLUE,CRIMSON,CRIMSON,YELLOW,YELLOW,GREEN,INDIGO,GRAY
45     byte commands 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88
46     byte Text_row 0,2,3
47     byte Text_col 1,0
48     byte Text_pos 1,6,11,16,1,6,11,16
49     byte rec_pos_X 0,60,120,180 
50     byte rec_pos_Y 18,48,66,96
51     byte rec_X 1,61,121,181,1,61,121,181 
52     byte rec_Y 67,67,67,67,97,97,97,97
53     byte comm_chars '-', '|', '/', '-', '\\', '|'
54 #END
55
56 #CONST
57    COMPS       0x81
58    VOLTAGES    0x82
59    MAIN_FSM    0x83
60    MOVE_FSM    0x84
61    ACT_FSM     0x85
62    LOCATION    0x86
63    KEEPALIVE   0x87
64    CORNS       0x88 
65    DRESS       0x89
66 #END
67
68
69 #CONST
70     MOT     0
71     ODO     1
72     CAM     2
73     PWR     3
74     HOK     4
75     APP     5
76     VID     6
77     STA     7
78 #END
79
80
81 #CONST
82     VOLT33      0
83     VOLT50      1
84     VOLT80      2
85     VOLT_BAT    3
86 #END
87
88
89 var RX_buffer[200];//var work_buffer[200];
90 // voltage strings 
91 var voltage_3V3[4];
92 var voltage_5V0[4];
93 var voltage_8V0[4];
94 var voltage_BAT[5];
95 // states strings
96 var act_fsm_state[20];
97 var move_fsm_state[20];
98 var main_fsm_state[20];
99 // pozition
100 var position[9];
101 var voltages[17];
102 var comp_state[10];
103 //
104
105
106
107 var firstState, firstCtrl;
108 var keyval, page;        // - 1 if no key pressed else 0-15
109 var BT_text[10];
110 var BT_state[10];
111 var BT_OLDstate[10];
112 var names[8];
113 var buffer[100];//[30];
114 var comp_collor;
115 var volt_state;
116 var corns;
117 var states;
118 var rx_ch,index,id;
119 var comm_idx;
120 var dress_color;
121 //*********************************************************************************************
122 //*********************************************************************************************
123 //*********************************************************************************************
124 //*********************************************************************************************
125
126 func data_init()
127    var idx;
128    idx := 0;
129    repeat 
130       voltages[idx] := 'x';
131       idx++;
132    until(idx == 17);
133  
134   
135    position[0] := 'x';
136    position[1] := 'x';
137    position[2] := 'x';
138    position[3] := 'y';
139    position[4] := 'y';
140    position[5] := 'y';
141    position[6] := 'a';
142    position[7] := 'a';
143    position[8] := 'a';
144    
145     
146 // component names array
147       act_fsm_state[0] := 'I';
148       act_fsm_state[1] := 'n';
149       act_fsm_state[2] := 'i';
150       act_fsm_state[3] := 't';
151       act_fsm_state[4] := '\0';
152
153       move_fsm_state[0] := 'I';
154       move_fsm_state[1] := 'n';
155       move_fsm_state[2] := 'i';
156       move_fsm_state[3] := 't';
157       move_fsm_state[4] := '\0';
158
159       main_fsm_state[0] := 'I';
160       main_fsm_state[1] := 'n';
161       main_fsm_state[2] := 'i';
162       main_fsm_state[3] := 't';
163       main_fsm_state[4] := '\0';
164       
165       names[0] := "MOT";
166       names[1] := "ODO";
167       names[2] := "CAM";
168       names[3] := "PWR";
169       names[4] := "HOK";
170       names[5] := "APP";
171       names[6] := "VID";
172       names[7] := "STA";
173
174     idx := 0;
175     repeat
176         comp_state[idx] := (idx+1) & 0x0f;
177         idx++;    
178     until(idx==8);
179     corns := 0;
180   
181     dress_color := BLUE;
182 endfunc
183
184 //*********************************************************************************************
185 //*********************************************************************************************
186
187 func paint_voltage()//select variable is chooseing which voltage will be rewrite. CAN BE VALUE 0, to 5. 5 is ALL
188     var cntX, cntY, x, y, v_tab, idx;
189     cntX:=0;
190     cntY:=0;    
191     v_tab:=4;
192     gfx_Set(PEN_SIZE, 1);     
193     //draw table
194     gfx_Rectangle(0, 0, MAX_WIDTH, 18, WHITE);//table
195     while(cntX < v_tab)
196         x := rec_pos_X[cntX];
197         y := rec_pos_Y[cntY];  
198         gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
199         cntX++;
200     wend
201     //write legend
202     gfx_Set(PEN_SIZE, 0);     
203     txt_Set(FONT_SIZE, 3);
204     txt_Set(TEXT_COLOUR, GRAY);
205     txt_Set(TEXT_OPACITY, 0); 
206     txt_MoveCursor(Text_row[VOLT],0);
207     print ("Voltage indicator:");
208 endfunc
209
210 //*********************************************************************************************
211 //*********************************************************************************************
212 func redraw_voltage()//(var voltage)
213     var idx, color; 
214     gfx_Set(PEN_SIZE, 0);   
215     txt_Set(TEXT_COLOUR, BLACK);
216     color := RED;
217     if((voltages[0] & 0x08) != 0x08)
218         color := GREEN;
219     endif    
220     gfx_Rectangle(1, 19, 58, 47, color);//table
221     txt_MoveCursor(2,0);
222     print([CHR]voltages[1], [CHR]voltages[2],".", [CHR]voltages[3],[CHR]voltages[4], "\n");
223     color := RED;    
224     if((voltages[0] & 0x04) != 0x04)
225         color := GREEN;
226     endif
227     gfx_Rectangle(61,19,118,47, color);//table
228     txt_MoveCursor(2,5);
229     print([CHR]voltages[5], [CHR]voltages[6],".", [CHR]voltages[7],[CHR]voltages[8], "\n");
230     color := RED;    
231     if((voltages[0] & 0x02) != 0x02)
232         color := GREEN; 
233     endif
234     gfx_Rectangle(121, 19, 178,47, color);//table
235     txt_MoveCursor(2,10);
236     print([CHR]voltages[9], [CHR]voltages[10], ".",[CHR]voltages[11],[CHR]voltages[12], "\n");
237     color := RED;    
238     if((voltages[0] & 0x01) != 0x01)
239         color := GREEN;
240     endif
241     gfx_Rectangle(181,19,238, 47, color);//table
242     txt_MoveCursor(2,15);
243     print([CHR]voltages[13],[CHR]voltages[14], ".",[CHR]voltages[15],[CHR]voltages[16], "\n");
244     paint_voltage();
245 endfunc
246 //*********************************************************************************************
247 //*********************************************************************************************
248
249 func paint_comm()
250    gfx_Set(PEN_SIZE, 1);//table     
251    gfx_Rectangle(180, 174, 239, 192, WHITE);//table
252    txt_MoveCursor(11,15);
253    txt_Set(TEXT_COLOUR, GRAY);
254    print("Comm:");
255 endfunc
256
257
258
259 func redraw_comm()
260    if(comm_idx >= 6)
261         comm_idx := 0;
262    endif      
263    gfx_Set(PEN_SIZE, 0);//solid rec     
264    gfx_Rectangle(181, 191, 238, 221, GREEN);//table
265    txt_MoveCursor(13,17);
266    txt_Set(TEXT_COLOUR, BLACK);
267    print([CHR]comm_chars[comm_idx]);
268 endfunc
269
270 //*********************************************************************************************
271 //*********************************************************************************************
272    
273 func draw_error()
274    sys_SetTimer(0,3000);
275    gfx_Set(PEN_SIZE, 0);//solid rec     
276    gfx_Rectangle(181, 191, 238, 221, BLACK);//table
277    txt_MoveCursor(13,16);
278    txt_Set(TEXT_COLOUR, RED);
279    print("ERR");
280 endfunc
281
282 //*********************************************************************************************
283 //*********************************************************************************************
284
285 func redraw_comp_state(var data)
286     var Y_axes, X_axes,X_end, Y_end, comp_nmb, col_idx, text_Y;
287     comp_nmb := ((data & 0x1f)-1);   
288     col_idx := (data & 0x60) >> 5;
289     if((comp_nmb >7)||(col_idx > 2) ||comp_nmb<0)
290         return;
291     endif
292     Y_axes := rec_Y[comp_nmb];
293     X_axes := rec_X[comp_nmb];
294     X_end := X_axes + 57;
295     Y_end := Y_axes + 28;
296     text_Y := 5;
297     if(comp_nmb >3)
298         text_Y := 7;
299     endif    
300     gfx_Set(PEN_SIZE, 0);//solid rectangle     
301     gfx_Rectangle(X_axes, Y_axes, X_end, Y_end, colors[col_idx]);//table
302     txt_MoveCursor(text_Y,Text_pos[comp_nmb]); 
303     txt_Set(TEXT_COLOUR, BLACK);   
304     print([STR]names[comp_nmb]);
305     comp_state[comp_nmb] := data;
306 endfunc
307 //*********************************************************************************************
308 //*********************************************************************************************
309
310 func paint_comp_states(var select)
311     var cntX,cntY,x,y, v_tab, row;
312     cntX := 0;
313     cntY := 1;
314     row := 0;
315     v_tab:=4;
316     gfx_Set(PEN_SIZE, 1);     
317     //draw table for components
318     gfx_Rectangle(0, rec_pos_Y[cntY], MAX_WIDTH, 66, WHITE);//table
319     cntY++;    
320       while(cntX < v_tab)
321          x := rec_pos_X[cntX];
322          y := rec_pos_Y[cntY];  
323          gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
324          cntX++;
325       wend
326       cntY := 3;
327       cntX := 0;
328       while(cntX < v_tab)
329          x := rec_pos_X[cntX];
330          y := rec_pos_Y[cntY];  
331          gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
332          cntX++;
333       wend
334     txt_MoveCursor(Text_row[STATE],0);
335     txt_Set(TEXT_COLOUR, GRAY);
336     print("Component indicator:")
337 endfunc
338
339 //*********************************************************************************************
340 //*********************************************************************************************
341
342 func paint_corn()
343     gfx_Set(PEN_SIZE, 1);//table     
344     gfx_Rectangle(180, 126, 239, 222, WHITE);//table
345     gfx_Rectangle(180, 126, 239, 144, WHITE);//table
346     gfx_Rectangle(179, 126, 239, 222, WHITE);//table
347     txt_MoveCursor(8,15);
348     txt_Set(TEXT_COLOUR, GRAY);
349     print("Corn:")
350 endfunc
351
352 //*********************************************************************************************
353 //*********************************************************************************************
354
355 func redraw_corns()    
356     txt_MoveCursor(10,17);
357     txt_Set(TEXT_COLOUR, BLACK);
358     gfx_Set(PEN_SIZE, 0);//solid rectangle     
359     gfx_Rectangle(181, 145, 237, 173, dress_color);//table
360     print(corns&0x0f);
361 endfunc
362 //*********************************************************************************************
363 //*********************************************************************************************
364
365 func redraw_move_state()    
366     var idx;    
367     gfx_Set(PEN_SIZE, 0);//table     
368     gfx_Rectangle(0, 159, 178, 190, BLACK);//table
369     txt_MoveCursor(10,0);
370     txt_Set(TEXT_COLOUR, OLIVE);
371     idx :=0;
372     print("MO:");    
373     repeat
374        if(idx == 11)
375             print("-\n   ");
376        endif
377        putch(move_fsm_state[idx]);
378        idx++;
379     until(move_fsm_state[idx] == '\0');    
380 endfunc
381 //*********************************************************************************************
382 //*********************************************************************************************
383
384 func redraw_act_state()
385     var idx;
386     gfx_Set(PEN_SIZE, 0);//table     
387     gfx_Rectangle(0, 191, 178, 221, BLACK);//table
388     txt_MoveCursor(12,0);
389     txt_Set(TEXT_COLOUR, BROWN);
390     idx :=0;
391     print("AC:");    
392     repeat
393        if(idx == 11)
394             print("-\n   ");
395        endif
396        putch(act_fsm_state[idx]);
397        idx++;
398     until(act_fsm_state[idx] == '\0');    
399 endfunc
400
401 //*********************************************************************************************
402 //*********************************************************************************************
403
404 func redraw_main_state()
405     var idx;
406     idx :=0;
407     gfx_Rectangle(0, 127, 178, 158, BLACK);//table
408     txt_MoveCursor(8,0);
409     txt_Set(TEXT_COLOUR, TEAL);
410     gfx_Set(PEN_SIZE, 0);//table     
411     print("MA:");    
412     repeat
413        if(idx == 11)
414             print("-\n   ");
415        endif
416        putch(main_fsm_state[idx]);
417        idx++;
418     until(main_fsm_state[idx] == '\0');    
419 endfunc
420
421 //*********************************************************************************************
422 //*********************************************************************************************
423
424 func paint_position()
425     gfx_Set(PEN_SIZE, 0);//solid rectangle     
426     gfx_Rectangle(0, 223, 239, 255, MAGENTA);//table
427     gfx_Rectangle(0, 256, 239, 291, MAGENTA);//table
428 endfunc
429
430 //*********************************************************************************************
431 //*********************************************************************************************
432
433 func redraw_position()
434     gfx_Set(PEN_SIZE, 0);//solid rectangle     
435     gfx_Rectangle(60, 239, 110, 255, MAGENTA);//table
436     gfx_Rectangle(160, 239, 220, 255,MAGENTA);//table
437     gfx_Rectangle(0, 272, 47, 286, MAGENTA);//table
438     txt_MoveCursor(14,0); 
439     txt_Set(TEXT_COLOUR, BLACK);   
440     print("Position:\n X = ", [CHR]position[0],".",[CHR]position[1],[CHR]position[2]);
441     print(" Y = ", [CHR]position[3],".",[CHR]position[4], [CHR]position[5], "\n");
442     print("Angle: ","\n"," ", [CHR]position[6],[CHR]position[7],[CHR]position[8]," Deg \n");
443 endfunc
444
445 //*********************************************************************************************
446 //*********************************************************************************************
447
448 func draw_keys()
449     var i;
450     i:=0;
451     repeat
452       gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT2, 2, 2, BT_text[i]);
453     until(++i == NMB_BT);
454     gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT1, 2, 2, BT_text[i]);
455 endfunc
456
457 //*********************************************************************************************
458 //*********************************************************************************************
459
460 func redraw()
461    if(keyval == 8)//||(keyval == 8))//do nothing
462       return; 
463    endif
464    if(keyval < 9)
465       gfx_Button(BT_state[keyval], 3, dY[keyval], collor[keyval], BLACK, FONT2, 2, 2, BT_text[keyval]);
466    endif
467 endfunc
468
469 //*********************************************************************************************
470 //*********************************************************************************************
471 func send_cmd()
472    if(keyval == 8)//do nothing
473       return; 
474    endif
475    if(keyval < 9)
476       to(COM0);
477       putch(commands[keyval]);
478       to(TEXT);
479    endif
480 endfunc
481 //*********************************************************************************************
482 //*********************************************************************************************
483
484 func read_key()
485     var x, y;
486     y := touch_Get(Y);
487     y := y / (BUTTONHEIGHT+1);
488     keyval := y;
489     if(keyval == 8)
490         keyval := -1;
491     endif
492 endfunc
493
494 //*********************************************************************************************
495 //*********************************************************************************************
496
497 func clear_page()
498     gfx_Set(0,0);
499     gfx_Rectangle(0,0,MAX_WIDTH,MAX_HEIGHT,BLACK);
500 endfunc
501
502 //*********************************************************************************************
503 //*********************************************************************************************
504 // function for debugging only
505 func send_axis()
506     var y;
507     y := touch_Get(Y);
508     txt_MoveCursor(16,1);
509     to(COM0),print(y);
510     to(COM0),print("\n"); 
511     to(COM0),print(keyval);
512     to(COM0),print("\n"); 
513 endfunc
514
515
516 //*********************************************************************************************
517 //*********************************************************************************************
518 //*********************************************************************************************
519 //*********************************************************************************************
520 //*********************************************************************************************
521 //*********************************************************************************************
522 //*********************************************************************************************
523 //*********************************************************************************************
524 //*********************************************************************************************
525 //*********************************************************************************************
526
527 func read_serial()
528       var cnt_idx;  
529       rx_ch := serin();
530       if(rx_ch < 0)
531           goto out;
532       endif
533 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
534       if((rx_ch & 0x80) == 0x80)
535           id := rx_ch;
536           index:=0;
537       if (id == KEEPALIVE)
538           sys_SetTimer(0,3000);// 3 seconds  
539           comm_idx++;  
540           redraw_comm();
541           id:=0;
542       endif;
543           goto out;//return;
544       endif
545 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
546       if (index < 100)    // 100 is buffer capacity
547           RX_buffer[index] := rx_ch;
548           index++;
549       else
550           index := 0;
551       endif
552 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
553       if(id == COMPS && index == 1)
554           redraw_comp_state(RX_buffer[0]);//draw_status();
555           id:=0;
556           goto out;//return;
557       endif
558 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
559       if(id == CORNS)// && index == 1)
560           corns := RX_buffer[0];  
561           redraw_corns();//draw_status();
562           id:=0;
563           goto out;//return;
564       endif
565 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
566       if(id == ACT_FSM && rx_ch == '\0')
567           cnt_idx := 0;
568           repeat    
569              act_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
570              cnt_idx++;
571           until(RX_buffer[cnt_idx] == '\0')
572           act_fsm_state[cnt_idx] := '\0';
573           redraw_act_state();
574           id:=0;
575           goto out;//return;
576       endif
577 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
578       if(id == MOVE_FSM && rx_ch == '\0')
579           cnt_idx := 0;
580           repeat    
581              move_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
582              cnt_idx++;
583           until(RX_buffer[cnt_idx] == '\0')
584           move_fsm_state[cnt_idx] := '\0';
585           redraw_move_state();
586           goto out;//return;
587       endif
588 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
589       if(id == MAIN_FSM && rx_ch == '\0')
590           cnt_idx := 0;
591           repeat    
592              main_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
593              cnt_idx++;
594           until(RX_buffer[cnt_idx] == '\0')
595           main_fsm_state[cnt_idx] := '\0';
596           redraw_main_state();
597           id:=0;
598           goto out;//return;
599       endif
600 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
601       if (id == VOLTAGES && index == 17)
602          cnt_idx :=0;   
603          repeat    
604             voltages[cnt_idx] := RX_buffer[cnt_idx];
605             cnt_idx++;
606          until(cnt_idx == 17)
607          redraw_voltage();
608          id:=0;
609          goto out;//return;
610       endif
611 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
612       if(id == LOCATION && index == 9)
613           cnt_idx := 0;
614           repeat
615               position[cnt_idx] := RX_buffer[cnt_idx];
616               cnt_idx++;
617           until(cnt_idx == 9)          
618           redraw_position();
619           id:=0;
620           goto out;//return;
621       endif
622 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
623       if(id == DRESS && index == 1)
624           if(RX_buffer[0] == 1)  
625               dress_color := YELLOW;
626           endif
627           if(RX_buffer[0] == 0)  
628               dress_color := BLUE;
629           endif
630               redraw_corns();
631               id:=0;
632           goto out;//return;
633       endif
634 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
635 out:
636 endfunc
637
638 //*********************************************************************************************
639 //*********************************************************************************************
640 //*********************************************************************************************
641 //*********************************************************************************************
642 //*********************************************************************************************
643 //*********************************************************************************************
644 //*********************************************************************************************
645 //*********************************************************************************************
646 //*********************************************************************************************
647 //*********************************************************************************************
648
649 func STATE_page()
650     var state, cnt,idx1,tmr;
651     sys_SetTimer(0,3000);
652     paint_voltage();
653     cnt:=0;
654     redraw_voltage();
655     paint_comp_states(0);
656     paint_corn();
657     com_Init(buffer,100,0);
658     cnt := 0;                   //draw states for all components
659     repeat
660         redraw_comp_state(comp_state[cnt]);
661     until(cnt++ == 8)
662     paint_position();
663     redraw_position();
664     redraw_corns();
665     redraw_main_state();
666     redraw_move_state();
667     redraw_act_state();
668     paint_comm();
669     redraw_comm();
670
671     gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLACK,FONT1,2,2, " To control screen ");
672     touch_DetectRegion(0, MAX_HEIGHT-30, MAX_WIDTH, MAX_HEIGHT);
673     touch_Set(TOUCH_ENABLE);
674     repeat
675         state := touch_Get(TOUCH_STATUS);
676         if(state == TOUCH_PRESS)
677             gfx_Button(DOWN,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");
678         endif
679         if(state == TOUCH_RELEASE)
680             gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");
681             page := 1;
682             break;
683         endif
684         read_serial(); 
685         if(sys_GetTimer(0) == 0)
686             idx1 := 0;
687             repeat
688                 idx1++;  
689                 comp_state[idx1] := idx1;  
690             until(idx1==8);
691             cnt := 0;                   //draw states for all components
692             repeat
693                 redraw_comp_state(comp_state[cnt]);
694             until(cnt++ == 8)
695             draw_error();
696         endif
697     forever
698 endfunc
699
700 //*********************************************************************************************
701 //*********************************************************************************************
702
703 func CTRL_page()
704     var n, state, x;
705     n :=0;
706     keyval := -1;  // initate key value
707     BT_text[0] := "  FORK DOWN   ";    //set texts for all buttons
708     BT_text[1] := "  FORK UP     ";
709     BT_text[2] := "  DOOR OPEN   ";
710     BT_text[3] := "  DOOR CLOSE  ";
711     BT_text[4] := "  START ROLL  ";
712     BT_text[5] := "  STOP ROLL   ";
713     BT_text[6] := "SEND ALL STATE";
714     BT_text[7] := " SWITCH COLOR ";
715     BT_text[8] := "  To state screen  ";
716     touch_Set(TOUCH_ENABLE);          // enable the touch screen                
717     touch_DetectRegion(0, 0, MAX_WIDTH, MAX_HEIGHT);
718 //*********************************************************************************************
719     repeat  
720        BT_state[n] := UP;           //set state for all buttons
721        BT_OLDstate[n] := DOWN;
722     until(++n == 9);   
723 //*********************************************************************************************
724     draw_keys();
725     repeat 
726     sys_SetTimer(0,3000);
727         state := touch_Get(TOUCH_STATUS);
728         if(state == TOUCH_PRESS)
729            read_key();
730         //   send_axis();     //debugging only   
731            if(keyval != -1)
732               if(keyval == 10 || keyval == 9)
733                   BT_state[8] := DOWN;
734                   gfx_Button(BT_state[8], 3, dY[8], collor[8], BLUE, FONT1, 2, 2, BT_text[8]);// misto redraw();
735               else    
736                  BT_state[keyval] := DOWN; // set that button is pushed
737                  redraw();
738               endif;    
739            endif
740         endif
741         if(state == TOUCH_RELEASE)
742             if(keyval != -1)
743                 BT_state[keyval] := UP; //button was released
744                 page := 0;
745                 redraw();
746                 if(keyval == 10 || keyval == 9)
747                     gfx_Button(BT_state[8], 3, dY[8], collor[8], BLACK, FONT1, 2, 2, BT_text[8]);// misto redraw();
748                     keyval := -1;
749                     break;
750                 endif;    
751                 send_cmd();
752             endif
753         endif
754     forever
755 endfunc
756
757 //*********************************************************************************************
758 //*********************************************************************************************
759 //*********************************************************************************************
760 //*********************************************************************************************
761
762 func main()
763     page := 0;
764     firstState := 0;
765     firstCtrl := 0;
766     comp_collor := RED;
767     data_init();
768     voltages[0]:=0xff;// voltage color initate
769     comm_idx := 3;
770
771     repeat
772         if(!page)// view state page
773             clear_page();    
774             STATE_page();
775         else// view ctrl page
776             clear_page();            
777             CTRL_page();
778         endif    
779     forever        
780 endfunc
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807