1 #platform "uOLED-32028-PMD3T"
3 // Note that 4DGL has built in sine table, this is just for #DATA access example.
5 #inherit "4DGL_16bitColours.fnc"
7 //*********************************************************************************************
8 //*********************************************************************************************
9 //*********************************************************************************************
10 //*********************************************************************************************
15 V_TAB 4 //number of rectangles
20 VOLT_WIDTH 59// width for voltage color field
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
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 '-', '|', '/', '-', '\\', '|'
89 var RX_buffer[200];//var work_buffer[200];
96 var act_fsm_state[20];
97 var move_fsm_state[20];
98 var main_fsm_state[20];
107 var firstState, firstCtrl;
108 var keyval, page; // - 1 if no key pressed else 0-15
113 var buffer[100];//[30];
121 //*********************************************************************************************
122 //*********************************************************************************************
123 //*********************************************************************************************
124 //*********************************************************************************************
130 voltages[idx] := 'x';
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';
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';
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';
176 comp_state[idx] := (idx+1) & 0x0f;
184 //*********************************************************************************************
185 //*********************************************************************************************
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;
192 gfx_Set(PEN_SIZE, 1);
194 gfx_Rectangle(0, 0, MAX_WIDTH, 18, WHITE);//table
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
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:");
210 //*********************************************************************************************
211 //*********************************************************************************************
212 func redraw_voltage()//(var voltage)
214 gfx_Set(PEN_SIZE, 0);
215 txt_Set(TEXT_COLOUR, BLACK);
217 if((voltages[0] & 0x08) != 0x08)
220 gfx_Rectangle(1, 19, 58, 47, color);//table
222 print([CHR]voltages[1], [CHR]voltages[2],".", [CHR]voltages[3],[CHR]voltages[4], "\n");
224 if((voltages[0] & 0x04) != 0x04)
227 gfx_Rectangle(61,19,118,47, color);//table
229 print([CHR]voltages[5], [CHR]voltages[6],".", [CHR]voltages[7],[CHR]voltages[8], "\n");
231 if((voltages[0] & 0x02) != 0x02)
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");
238 if((voltages[0] & 0x01) != 0x01)
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");
246 //*********************************************************************************************
247 //*********************************************************************************************
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);
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]);
270 //*********************************************************************************************
271 //*********************************************************************************************
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);
282 //*********************************************************************************************
283 //*********************************************************************************************
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)
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;
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;
307 //*********************************************************************************************
308 //*********************************************************************************************
310 func paint_comp_states(var select)
311 var cntX,cntY,x,y, v_tab, row;
316 gfx_Set(PEN_SIZE, 1);
317 //draw table for components
318 gfx_Rectangle(0, rec_pos_Y[cntY], MAX_WIDTH, 66, WHITE);//table
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
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
334 txt_MoveCursor(Text_row[STATE],0);
335 txt_Set(TEXT_COLOUR, GRAY);
336 print("Component indicator:")
339 //*********************************************************************************************
340 //*********************************************************************************************
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);
352 //*********************************************************************************************
353 //*********************************************************************************************
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
362 //*********************************************************************************************
363 //*********************************************************************************************
365 func redraw_move_state()
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);
377 putch(move_fsm_state[idx]);
379 until(move_fsm_state[idx] == '\0');
381 //*********************************************************************************************
382 //*********************************************************************************************
384 func redraw_act_state()
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);
396 putch(act_fsm_state[idx]);
398 until(act_fsm_state[idx] == '\0');
401 //*********************************************************************************************
402 //*********************************************************************************************
404 func redraw_main_state()
407 gfx_Rectangle(0, 127, 178, 158, BLACK);//table
409 txt_Set(TEXT_COLOUR, TEAL);
410 gfx_Set(PEN_SIZE, 0);//table
416 putch(main_fsm_state[idx]);
418 until(main_fsm_state[idx] == '\0');
421 //*********************************************************************************************
422 //*********************************************************************************************
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
430 //*********************************************************************************************
431 //*********************************************************************************************
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");
445 //*********************************************************************************************
446 //*********************************************************************************************
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]);
457 //*********************************************************************************************
458 //*********************************************************************************************
461 if(keyval == 8)//||(keyval == 8))//do nothing
465 gfx_Button(BT_state[keyval], 3, dY[keyval], collor[keyval], BLACK, FONT2, 2, 2, BT_text[keyval]);
469 //*********************************************************************************************
470 //*********************************************************************************************
472 if(keyval == 8)//do nothing
477 putch(commands[keyval]);
481 //*********************************************************************************************
482 //*********************************************************************************************
487 y := y / (BUTTONHEIGHT+1);
494 //*********************************************************************************************
495 //*********************************************************************************************
499 gfx_Rectangle(0,0,MAX_WIDTH,MAX_HEIGHT,BLACK);
502 //*********************************************************************************************
503 //*********************************************************************************************
504 // function for debugging only
508 txt_MoveCursor(16,1);
510 to(COM0),print("\n");
511 to(COM0),print(keyval);
512 to(COM0),print("\n");
516 //*********************************************************************************************
517 //*********************************************************************************************
518 //*********************************************************************************************
519 //*********************************************************************************************
520 //*********************************************************************************************
521 //*********************************************************************************************
522 //*********************************************************************************************
523 //*********************************************************************************************
524 //*********************************************************************************************
525 //*********************************************************************************************
533 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
534 if((rx_ch & 0x80) == 0x80)
538 sys_SetTimer(0,3000);// 3 seconds
545 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
546 if (index < 100) // 100 is buffer capacity
547 RX_buffer[index] := rx_ch;
552 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
553 if(id == COMPS && index == 1)
554 redraw_comp_state(RX_buffer[0]);//draw_status();
558 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
559 if(id == CORNS)// && index == 1)
560 corns := RX_buffer[0];
561 redraw_corns();//draw_status();
565 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
566 if(id == ACT_FSM && rx_ch == '\0')
569 act_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
571 until(RX_buffer[cnt_idx] == '\0')
572 act_fsm_state[cnt_idx] := '\0';
577 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
578 if(id == MOVE_FSM && rx_ch == '\0')
581 move_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
583 until(RX_buffer[cnt_idx] == '\0')
584 move_fsm_state[cnt_idx] := '\0';
588 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
589 if(id == MAIN_FSM && rx_ch == '\0')
592 main_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
594 until(RX_buffer[cnt_idx] == '\0')
595 main_fsm_state[cnt_idx] := '\0';
600 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
601 if (id == VOLTAGES && index == 17)
604 voltages[cnt_idx] := RX_buffer[cnt_idx];
611 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
612 if(id == LOCATION && index == 9)
615 position[cnt_idx] := RX_buffer[cnt_idx];
622 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
623 if(id == DRESS && index == 1)
624 if(RX_buffer[0] == 1)
625 dress_color := YELLOW;
627 if(RX_buffer[0] == 0)
634 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
638 //*********************************************************************************************
639 //*********************************************************************************************
640 //*********************************************************************************************
641 //*********************************************************************************************
642 //*********************************************************************************************
643 //*********************************************************************************************
644 //*********************************************************************************************
645 //*********************************************************************************************
646 //*********************************************************************************************
647 //*********************************************************************************************
650 var state, cnt,idx1,tmr;
651 sys_SetTimer(0,3000);
655 paint_comp_states(0);
657 com_Init(buffer,100,0);
658 cnt := 0; //draw states for all components
660 redraw_comp_state(comp_state[cnt]);
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);
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 ");
679 if(state == TOUCH_RELEASE)
680 gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");
685 if(sys_GetTimer(0) == 0)
689 comp_state[idx1] := idx1;
691 cnt := 0; //draw states for all components
693 redraw_comp_state(comp_state[cnt]);
700 //*********************************************************************************************
701 //*********************************************************************************************
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 //*********************************************************************************************
720 BT_state[n] := UP; //set state for all buttons
721 BT_OLDstate[n] := DOWN;
723 //*********************************************************************************************
726 sys_SetTimer(0,3000);
727 state := touch_Get(TOUCH_STATUS);
728 if(state == TOUCH_PRESS)
730 // send_axis(); //debugging only
732 if(keyval == 10 || keyval == 9)
734 gfx_Button(BT_state[8], 3, dY[8], collor[8], BLUE, FONT1, 2, 2, BT_text[8]);// misto redraw();
736 BT_state[keyval] := DOWN; // set that button is pushed
741 if(state == TOUCH_RELEASE)
743 BT_state[keyval] := UP; //button was released
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();
757 //*********************************************************************************************
758 //*********************************************************************************************
759 //*********************************************************************************************
760 //*********************************************************************************************
768 voltages[0]:=0xff;// voltage color initate
772 if(!page)// view state page
775 else// view ctrl page