-#platform "uOLED-32028-PMD3T"\r
-\r
-// Note that 4DGL has built in sine table, this is just for #DATA access example.\r
-\r
-#inherit "4DGL_16bitColours.fnc"\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-#CONST \r
- LEFT 15\r
- TOP 15\r
- // tables\r
- V_TAB 4 //number of rectangles\r
- MAX_WIDTH 239\r
- MAX_HEIGHT 319\r
- LAST_ROW 19\r
- VOLT_HEIGHT 30\r
- VOLT_WIDTH 59// width for voltage color field\r
- BUTTONWIDTH 60 \r
- BUTTONHEIGHT 30\r
-\r
- // positions\r
- VOLT 0\r
- VOLT1 1\r
- STATE 2\r
- NMB_BT 8\r
-#END\r
-\r
-\r
-#CONST\r
- NO 0\r
- YES 1\r
- Y 2\r
- X 1 \r
-#END\r
-\r
-\r
-#DATA\r
- // button Y positions for control page\r
- word dY 3,33,63,93,123,153,183,213,293\r
- word colors RED,GREEN,ORANGE\r
- word collor BLUE,BLUE,CRIMSON,CRIMSON,YELLOW,YELLOW,GREEN,INDIGO,GRAY\r
- byte commands 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88\r
- byte Text_row 0,2,3\r
- byte Text_col 1,0\r
- byte Text_pos 1,6,11,16,1,6,11,16\r
- byte rec_pos_X 0,60,120,180 \r
- byte rec_pos_Y 18,48,66,96\r
- byte rec_X 1,61,121,181,1,61,121,181 \r
- byte rec_Y 67,67,67,67,97,97,97,97\r
- byte comm_chars '-', '|', '/', '-', '\\', '|'\r
-#END\r
-\r
-#CONST\r
- COMPS 0x81\r
- VOLTAGES 0x82\r
- MAIN_FSM 0x83\r
- MOVE_FSM 0x84\r
- ACT_FSM 0x85\r
- LOCATION 0x86\r
- KEEPALIVE 0x87\r
- CORNS 0x88 \r
- COLOR 0x89\r
-#END\r
-\r
-\r
-#CONST\r
- MOT 0\r
- ODO 1\r
- CAM 2\r
- PWR 3\r
- HOK 4\r
- APP 5\r
- VID 6\r
- STA 7\r
-#END\r
-\r
-\r
-#CONST\r
- VOLT33 0\r
- VOLT50 1\r
- VOLT80 2\r
- VOLT_BAT 3\r
-#END\r
-\r
-\r
-var RX_buffer[200];//var work_buffer[200];\r
-// voltage strings \r
-var voltage_3V3[4];\r
-var voltage_5V0[4];\r
-var voltage_8V0[4];\r
-var voltage_BAT[5];\r
-// states strings\r
-var act_fsm_state[20];\r
-var move_fsm_state[20];\r
-var main_fsm_state[20];\r
-// pozition\r
-var position[9];\r
-var voltages[17];\r
-var comp_state[10];\r
-//\r
-\r
-\r
-\r
-var firstState, firstCtrl;\r
-var keyval, page; // - 1 if no key pressed else 0-15\r
-var BT_text[10];\r
-var BT_state[10];\r
-var BT_OLDstate[10];\r
-var names[8];\r
-var buffer[100];//[30];\r
-var comp_collor;\r
-var volt_state;\r
-var corns[2];\r
-var states;\r
-var rx_ch,index,id;\r
-var comm_idx;\r
-var dress_color;\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func data_init()\r
- var idx;\r
- idx := 0;\r
- repeat \r
- voltages[idx] := 'x';\r
- idx++;\r
- until(idx == 17);\r
- \r
- \r
- position[0] := 'x';\r
- position[1] := 'x';\r
- position[2] := 'x';\r
- position[3] := 'y';\r
- position[4] := 'y';\r
- position[5] := 'y';\r
- position[6] := 'a';\r
- position[7] := 'a';\r
- position[8] := 'a';\r
- \r
- \r
-// component names array\r
- act_fsm_state[0] := 'I';\r
- act_fsm_state[1] := 'n';\r
- act_fsm_state[2] := 'i';\r
- act_fsm_state[3] := 't';\r
- act_fsm_state[4] := '\0';\r
-\r
- move_fsm_state[0] := 'I';\r
- move_fsm_state[1] := 'n';\r
- move_fsm_state[2] := 'i';\r
- move_fsm_state[3] := 't';\r
- move_fsm_state[4] := '\0';\r
-\r
- main_fsm_state[0] := 'I';\r
- main_fsm_state[1] := 'n';\r
- main_fsm_state[2] := 'i';\r
- main_fsm_state[3] := 't';\r
- main_fsm_state[4] := '\0';\r
- \r
- names[0] := "MOT";\r
- names[1] := "ODO";\r
- names[2] := "CAM";\r
- names[3] := "PWR";\r
- names[4] := "HOK";\r
- names[5] := "APP";\r
- names[6] := "VID";\r
- names[7] := "STA";\r
-\r
- idx := 0;\r
- repeat\r
- comp_state[idx] := (idx+1) & 0x0f;\r
- idx++; \r
- until(idx==8);\r
- corns[0] = '-';\r
- corns[1] = '-';\r
- \r
- dress_color := BLUE;\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func paint_voltage()//select variable is chooseing which voltage will be rewrite. CAN BE VALUE 0, to 5. 5 is ALL\r
- var cntX, cntY, x, y, v_tab, idx;\r
- cntX:=0;\r
- cntY:=0; \r
- v_tab:=4;\r
- gfx_Set(PEN_SIZE, 1); \r
- //draw table\r
- gfx_Rectangle(0, 0, MAX_WIDTH, 18, WHITE);//table\r
- while(cntX < v_tab)\r
- x := rec_pos_X[cntX];\r
- y := rec_pos_Y[cntY]; \r
- gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table\r
- cntX++;\r
- wend\r
- //write legend\r
- gfx_Set(PEN_SIZE, 0); \r
- txt_Set(FONT_SIZE, 3);\r
- txt_Set(TEXT_COLOUR, GRAY);\r
- txt_Set(TEXT_OPACITY, 0); \r
- txt_MoveCursor(Text_row[VOLT],0);\r
- print ("Voltage indicator:");\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-func redraw_voltage()//(var voltage)\r
- var idx, color; \r
- gfx_Set(PEN_SIZE, 0); \r
- txt_Set(TEXT_COLOUR, BLACK);\r
- color := RED;\r
- if((voltages[0] & 0x08) != 0x08)\r
- color := GREEN;\r
- endif \r
- gfx_Rectangle(1, 19, 58, 47, color);//table\r
- txt_MoveCursor(2,0);\r
- print([CHR]voltages[1], [CHR]voltages[2],".", [CHR]voltages[3],[CHR]voltages[4], "\n");\r
- color := RED; \r
- if((voltages[0] & 0x04) != 0x04)\r
- color := GREEN;\r
- endif\r
- gfx_Rectangle(61,19,118,47, color);//table\r
- txt_MoveCursor(2,5);\r
- print([CHR]voltages[5], [CHR]voltages[6],".", [CHR]voltages[7],[CHR]voltages[8], "\n");\r
- color := RED; \r
- if((voltages[0] & 0x02) != 0x02)\r
- color := GREEN; \r
- endif\r
- gfx_Rectangle(121, 19, 178,47, color);//table\r
- txt_MoveCursor(2,10);\r
- print([CHR]voltages[9], [CHR]voltages[10], ".",[CHR]voltages[11],[CHR]voltages[12], "\n");\r
- color := RED; \r
- if((voltages[0] & 0x01) != 0x01)\r
- color := GREEN;\r
- endif\r
- gfx_Rectangle(181,19,238, 47, color);//table\r
- txt_MoveCursor(2,15);\r
- print([CHR]voltages[13],[CHR]voltages[14], ".",[CHR]voltages[15],[CHR]voltages[16], "\n");\r
- paint_voltage();\r
-endfunc\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func paint_comm()\r
- gfx_Set(PEN_SIZE, 1);//table \r
- gfx_Rectangle(180, 174, 239, 192, WHITE);//table\r
- txt_MoveCursor(11,15);\r
- txt_Set(TEXT_COLOUR, GRAY);\r
- print("Comm:");\r
-endfunc\r
-\r
-\r
-\r
-func redraw_comm()\r
- if(comm_idx >= 6)\r
- comm_idx := 0;\r
- endif \r
- gfx_Set(PEN_SIZE, 0);//solid rec \r
- gfx_Rectangle(181, 191, 238, 221, GREEN);//table\r
- txt_MoveCursor(13,17);\r
- txt_Set(TEXT_COLOUR, BLACK);\r
- print([CHR]comm_chars[comm_idx]);\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
- \r
-func draw_error()\r
- sys_SetTimer(0,3000);\r
- gfx_Set(PEN_SIZE, 0);//solid rec \r
- gfx_Rectangle(181, 191, 238, 221, BLACK);//table\r
- txt_MoveCursor(13,16);\r
- txt_Set(TEXT_COLOUR, RED);\r
- print("ERR");\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func redraw_comp_state(var data)\r
- var Y_axes, X_axes,X_end, Y_end, comp_nmb, col_idx, text_Y;\r
- comp_nmb := ((data & 0x1f)-1); \r
- col_idx := (data & 0x60) >> 5;\r
- if((comp_nmb >7)||(col_idx > 2) ||comp_nmb<0)\r
- return;\r
- endif\r
- Y_axes := rec_Y[comp_nmb];\r
- X_axes := rec_X[comp_nmb];\r
- X_end := X_axes + 57;\r
- Y_end := Y_axes + 28;\r
- text_Y := 5;\r
- if(comp_nmb >3)\r
- text_Y := 7;\r
- endif \r
- gfx_Set(PEN_SIZE, 0);//solid rectangle \r
- gfx_Rectangle(X_axes, Y_axes, X_end, Y_end, colors[col_idx]);//table\r
- txt_MoveCursor(text_Y,Text_pos[comp_nmb]); \r
- txt_Set(TEXT_COLOUR, BLACK); \r
- print([STR]names[comp_nmb]);\r
- comp_state[comp_nmb] := data;\r
-endfunc\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func paint_comp_states(var select)\r
- var cntX,cntY,x,y, v_tab, row;\r
- cntX := 0;\r
- cntY := 1;\r
- row := 0;\r
- v_tab:=4;\r
- gfx_Set(PEN_SIZE, 1); \r
- //draw table for components\r
- gfx_Rectangle(0, rec_pos_Y[cntY], MAX_WIDTH, 66, WHITE);//table\r
- cntY++; \r
- while(cntX < v_tab)\r
- x := rec_pos_X[cntX];\r
- y := rec_pos_Y[cntY]; \r
- gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table\r
- cntX++;\r
- wend\r
- cntY := 3;\r
- cntX := 0;\r
- while(cntX < v_tab)\r
- x := rec_pos_X[cntX];\r
- y := rec_pos_Y[cntY]; \r
- gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table\r
- cntX++;\r
- wend\r
- txt_MoveCursor(Text_row[STATE],0);\r
- txt_Set(TEXT_COLOUR, GRAY);\r
- print("Component indicator:")\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func paint_corn()\r
- gfx_Set(PEN_SIZE, 1);//table \r
- gfx_Rectangle(180, 126, 239, 222, WHITE);//table\r
- gfx_Rectangle(180, 126, 239, 144, WHITE);//table\r
- gfx_Rectangle(179, 126, 239, 222, WHITE);//table\r
- txt_MoveCursor(8,15);\r
- txt_Set(TEXT_COLOUR, GRAY);\r
- print("Corn:")\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func redraw_corns() \r
- txt_MoveCursor(10,17);\r
- txt_Set(TEXT_COLOUR, BLACK);\r
- gfx_Set(PEN_SIZE, 0);//solid rectangle \r
- gfx_Rectangle(181, 145, 237, 173, dress_color);//table\r
- print(corns[0], corns[1]);\r
-endfunc\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func redraw_move_state() \r
- var idx; \r
- gfx_Set(PEN_SIZE, 0);//table \r
- gfx_Rectangle(0, 159, 178, 190, BLACK);//table\r
- txt_MoveCursor(10,0);\r
- txt_Set(TEXT_COLOUR, OLIVE);\r
- idx :=0;\r
- print("MO:"); \r
- repeat\r
- if(idx == 11)\r
- print("-\n ");\r
- endif\r
- putch(move_fsm_state[idx]);\r
- idx++;\r
- until(move_fsm_state[idx] == '\0'); \r
-endfunc\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func redraw_act_state()\r
- var idx;\r
- gfx_Set(PEN_SIZE, 0);//table \r
- gfx_Rectangle(0, 191, 178, 221, BLACK);//table\r
- txt_MoveCursor(12,0);\r
- txt_Set(TEXT_COLOUR, BROWN);\r
- idx :=0;\r
- print("AC:"); \r
- repeat\r
- if(idx == 11)\r
- print("-\n ");\r
- endif\r
- putch(act_fsm_state[idx]);\r
- idx++;\r
- until(act_fsm_state[idx] == '\0'); \r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func redraw_main_state()\r
- var idx;\r
- idx :=0;\r
- gfx_Rectangle(0, 127, 178, 158, BLACK);//table\r
- txt_MoveCursor(8,0);\r
- txt_Set(TEXT_COLOUR, TEAL);\r
- gfx_Set(PEN_SIZE, 0);//table \r
- print("MA:"); \r
- repeat\r
- if(idx == 11)\r
- print("-\n ");\r
- endif\r
- putch(main_fsm_state[idx]);\r
- idx++;\r
- until(main_fsm_state[idx] == '\0'); \r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func paint_position()\r
- gfx_Set(PEN_SIZE, 0);//solid rectangle \r
- gfx_Rectangle(0, 223, 239, 255, MAGENTA);//table\r
- gfx_Rectangle(0, 256, 239, 291, MAGENTA);//table\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func redraw_position()\r
- gfx_Set(PEN_SIZE, 0);//solid rectangle \r
- gfx_Rectangle(60, 239, 110, 255, MAGENTA);//table\r
- gfx_Rectangle(160, 239, 220, 255,MAGENTA);//table\r
- gfx_Rectangle(0, 272, 47, 286, MAGENTA);//table\r
- txt_MoveCursor(14,0); \r
- txt_Set(TEXT_COLOUR, BLACK); \r
- print("Position:\n X = ", [CHR]position[0],".",[CHR]position[1],[CHR]position[2]);\r
- print(" Y = ", [CHR]position[3],".",[CHR]position[4], [CHR]position[5], "\n");\r
- print("Angle: ","\n"," ", [CHR]position[6],[CHR]position[7],[CHR]position[8]," Deg \n");\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func draw_keys()\r
- var i;\r
- i:=0;\r
- repeat\r
- gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT2, 2, 2, BT_text[i]);\r
- until(++i == NMB_BT);\r
- gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT1, 2, 2, BT_text[i]);\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func redraw()\r
- if(keyval == 8)//||(keyval == 8))//do nothing\r
- return; \r
- endif\r
- if(keyval < 9)\r
- gfx_Button(BT_state[keyval], 3, dY[keyval], collor[keyval], BLACK, FONT2, 2, 2, BT_text[keyval]);\r
- endif\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-func send_cmd()\r
- if(keyval == 8)//do nothing\r
- return; \r
- endif\r
- if(keyval < 8)\r
- to(COM0);\r
- putch(commands[keyval]);\r
- to(TEXT);\r
- endif\r
-endfunc\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func read_key()\r
- var x, y;\r
- y := touch_Get(Y);\r
- y := y / (BUTTONHEIGHT+1);\r
- keyval := y;\r
- if(keyval == 9)\r
- keyval := -1;\r
- endif\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func clear_page()\r
- gfx_Set(0,0);\r
- gfx_Rectangle(0,0,MAX_WIDTH,MAX_HEIGHT,BLACK);\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-// function for debugging only\r
-func send_axis()\r
- var y;\r
- y := touch_Get(Y);\r
- txt_MoveCursor(16,1);\r
- to(COM0),print(y);\r
- to(COM0),print("\n"); \r
- to(COM0),print(keyval);\r
- to(COM0),print("\n"); \r
-endfunc\r
-\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func read_serial()\r
- var cnt_idx; \r
- rx_ch := serin();\r
- if(rx_ch < 0)\r
- goto out;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if((rx_ch & 0x80) == 0x80)\r
- id := rx_ch;\r
- index:=0;\r
- if (id == KEEPALIVE)\r
- sys_SetTimer(0,3000);// 3 seconds \r
- comm_idx++; \r
- redraw_comm();\r
- id:=0;\r
- endif;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if (index < 100) // 100 is buffer capacity\r
- RX_buffer[index] := rx_ch;\r
- index++;\r
- else\r
- index := 0;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if(id == COMPS && index == 1)\r
- redraw_comp_state(RX_buffer[0]);//draw_status();\r
- id:=0;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if(id == CORNS && index == 2)\r
- corns[0] := RX_buffer[0]; \r
- corns[1] := RX_buffer[1]; \r
- redraw_corns();//draw_status();\r
- id:=0;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if(id == ACT_FSM && rx_ch == '\0')\r
- cnt_idx := 0;\r
- repeat \r
- act_fsm_state[cnt_idx] := RX_buffer[cnt_idx];\r
- cnt_idx++;\r
- until(RX_buffer[cnt_idx] == '\0')\r
- act_fsm_state[cnt_idx] := '\0';\r
- redraw_act_state();\r
- id:=0;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if(id == MOVE_FSM && rx_ch == '\0')\r
- cnt_idx := 0;\r
- repeat \r
- move_fsm_state[cnt_idx] := RX_buffer[cnt_idx];\r
- cnt_idx++;\r
- until(RX_buffer[cnt_idx] == '\0')\r
- move_fsm_state[cnt_idx] := '\0';\r
- redraw_move_state();\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if(id == MAIN_FSM && rx_ch == '\0')\r
- cnt_idx := 0;\r
- repeat \r
- main_fsm_state[cnt_idx] := RX_buffer[cnt_idx];\r
- cnt_idx++;\r
- until(RX_buffer[cnt_idx] == '\0')\r
- main_fsm_state[cnt_idx] := '\0';\r
- redraw_main_state();\r
- id:=0;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if (id == VOLTAGES && index == 17)\r
- cnt_idx :=0; \r
- repeat \r
- voltages[cnt_idx] := RX_buffer[cnt_idx];\r
- cnt_idx++;\r
- until(cnt_idx == 17)\r
- redraw_voltage();\r
- id:=0;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if(id == LOCATION && index == 9)\r
- cnt_idx := 0;\r
- repeat\r
- position[cnt_idx] := RX_buffer[cnt_idx];\r
- cnt_idx++;\r
- until(cnt_idx == 9) \r
- redraw_position();\r
- id:=0;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
- if(id == COLOR && index == 1)\r
- if(RX_buffer[0] == 1) \r
- dress_color := YELLOW;\r
- endif\r
- if(RX_buffer[0] == 0) \r
- dress_color := BLUE;\r
- endif\r
- redraw_corns();\r
- id:=0;\r
- goto out;//return;\r
- endif\r
-//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`\r
-out:\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func STATE_page()\r
- var state, cnt,idx1,tmr;\r
- sys_SetTimer(0,3000);\r
- paint_voltage();\r
- cnt:=0;\r
- redraw_voltage();\r
- paint_comp_states(0);\r
- paint_corn();\r
- com_Init(buffer,100,0);\r
- cnt := 0; //draw states for all components\r
- repeat\r
- redraw_comp_state(comp_state[cnt]);\r
- until(cnt++ == 8)\r
- paint_position();\r
- redraw_position();\r
- redraw_corns();\r
- redraw_main_state();\r
- redraw_move_state();\r
- redraw_act_state();\r
- paint_comm();\r
- redraw_comm();\r
-\r
- gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLACK,FONT1,2,2, " To control screen ");\r
- touch_DetectRegion(0, MAX_HEIGHT-30, MAX_WIDTH, MAX_HEIGHT);\r
- touch_Set(TOUCH_ENABLE);\r
- repeat\r
- state := touch_Get(TOUCH_STATUS);\r
- if(state == TOUCH_PRESS)\r
- gfx_Button(DOWN,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");\r
- endif\r
- if(state == TOUCH_RELEASE)\r
- gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");\r
- page := 1;\r
- break;\r
- endif\r
- read_serial(); \r
- if(sys_GetTimer(0) == 0)\r
- idx1 := 0;\r
- repeat\r
- idx1++; \r
- comp_state[idx1] := idx1; \r
- until(idx1==8);\r
- cnt := 0; //draw states for all components\r
- repeat\r
- redraw_comp_state(comp_state[cnt]);\r
- until(cnt++ == 8)\r
- draw_error();\r
- endif\r
- forever\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func CTRL_page()\r
- var n, state, x;\r
- n :=0;\r
- keyval := -1; // initate key value\r
- BT_text[0] := " FORK DOWN "; //set texts for all buttons\r
- BT_text[1] := " FORK UP ";\r
- BT_text[2] := " DOOR OPEN ";\r
- BT_text[3] := " DOOR CLOSE ";\r
- BT_text[4] := " START ROLL ";\r
- BT_text[5] := " STOP ROLL ";\r
- BT_text[6] := "SEND ALL STATE";\r
- BT_text[7] := " SWITCH COLOR ";\r
- BT_text[8] := " To state screen ";\r
- touch_Set(TOUCH_ENABLE); // enable the touch screen \r
- touch_DetectRegion(0, 0, MAX_WIDTH, MAX_HEIGHT);\r
-//*********************************************************************************************\r
- repeat \r
- BT_state[n] := UP; //set state for all buttons\r
- BT_OLDstate[n] := DOWN;\r
- until(++n == 9); \r
-//*********************************************************************************************\r
- draw_keys();\r
- repeat \r
- sys_SetTimer(0,3000);\r
- state := touch_Get(TOUCH_STATUS);\r
- if(state == TOUCH_PRESS)\r
- read_key();\r
- send_axis(); //debugging only \r
- if(keyval != -1)\r
- if(keyval == 10 || keyval == 9)\r
- BT_state[8] := DOWN;\r
- gfx_Button(BT_state[8], 3, dY[8], collor[8], BLUE, FONT1, 2, 2, BT_text[8]);// misto redraw();\r
- else \r
- BT_state[keyval] := DOWN; // set that button is pushed\r
- redraw();\r
- endif; \r
- endif\r
- endif\r
- if(state == TOUCH_RELEASE)\r
- if(keyval != -1)\r
- BT_state[keyval] := UP; //button was released\r
- redraw();\r
- page := 0;\r
- if(keyval == 10 || keyval == 9)\r
- gfx_Button(BT_state[8], 3, dY[8], collor[8], BLACK, FONT1, 2, 2, BT_text[8]);// misto redraw();\r
- keyval := -1;\r
- break;\r
- endif; \r
- send_cmd();\r
- endif\r
- endif\r
- forever\r
-endfunc\r
-\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-//*********************************************************************************************\r
-\r
-func main()\r
- page := 0;\r
- firstState := 0;\r
- firstCtrl := 0;\r
- comp_collor := RED;\r
- data_init();\r
- voltages[0]:=0xff;// voltage color initate\r
- comm_idx := 3;\r
-\r
- repeat\r
- if(!page)// view state page\r
- clear_page(); \r
- STATE_page();\r
- else// view ctrl page\r
- clear_page(); \r
- CTRL_page();\r
- endif \r
- forever \r
-endfunc\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+#platform "uOLED-32028-PMD3T"
+
+// Note that 4DGL has built in sine table, this is just for #DATA access example.
+
+#inherit "4DGL_16bitColours.fnc"
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+#CONST
+ LEFT 15
+ TOP 15
+ // tables
+ V_TAB 4 //number of rectangles
+ MAX_WIDTH 239
+ MAX_HEIGHT 319
+ LAST_ROW 19
+ VOLT_HEIGHT 30
+ VOLT_WIDTH 59// width for voltage color field
+ BUTTONWIDTH 60
+ BUTTONHEIGHT 30
+
+ // positions
+ VOLT 0
+ VOLT1 1
+ STATE 2
+ NMB_BT 8
+#END
+
+
+#CONST
+ NO 0
+ YES 1
+ Y 2
+ X 1
+#END
+
+
+#DATA
+ // button Y positions for control page
+ word dY 3,33,63,93,123,153,183,213,293
+ word colors RED,GREEN,ORANGE
+ word collor BLUE,BLUE,CRIMSON,CRIMSON,YELLOW,YELLOW,GREEN,INDIGO,GRAY
+ byte commands 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88
+ byte Text_row 0,2,3
+ byte Text_col 1,0
+ byte Text_pos 1,6,11,16,1,6,11,16
+ byte rec_pos_X 0,60,120,180
+ byte rec_pos_Y 18,48,66,96
+ byte rec_X 1,61,121,181,1,61,121,181
+ byte rec_Y 67,67,67,67,97,97,97,97
+ byte comm_chars '-', '|', '/', '-', '\\', '|'
+#END
+
+#CONST
+ COMPS 0x81
+ VOLTAGES 0x82
+ MAIN_FSM 0x83
+ MOVE_FSM 0x84
+ ACT_FSM 0x85
+ LOCATION 0x86
+ KEEPALIVE 0x87
+ CORNS 0x88
+ COLOR 0x89
+#END
+
+
+#CONST
+ MOT 0
+ ODO 1
+ CAM 2
+ PWR 3
+ HOK 4
+ APP 5
+ VID 6
+ STA 7
+#END
+
+
+#CONST
+ VOLT33 0
+ VOLT50 1
+ VOLT80 2
+ VOLT_BAT 3
+#END
+
+
+var RX_buffer[200];//var work_buffer[200];
+// voltage strings
+var voltage_3V3[4];
+var voltage_5V0[4];
+var voltage_8V0[4];
+var voltage_BAT[5];
+// states strings
+var act_fsm_state[20];
+var move_fsm_state[20];
+var main_fsm_state[20];
+// pozition
+var position[9];
+var voltages[17];
+var comp_state[10];
+//
+
+
+
+var firstState, firstCtrl;
+var keyval, page; // - 1 if no key pressed else 0-15
+var BT_text[10];
+var BT_state[10];
+var BT_OLDstate[10];
+var names[8];
+var buffer[100];//[30];
+var comp_collor;
+var volt_state;
+var corns[2];
+var states;
+var rx_ch,index,id;
+var comm_idx;
+var dress_color;
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func data_init()
+ var idx;
+ idx := 0;
+ repeat
+ voltages[idx] := 'x';
+ idx++;
+ until(idx == 17);
+
+
+ position[0] := 'x';
+ position[1] := 'x';
+ position[2] := 'x';
+ position[3] := 'y';
+ position[4] := 'y';
+ position[5] := 'y';
+ position[6] := 'a';
+ position[7] := 'a';
+ position[8] := 'a';
+
+
+// component names array
+ act_fsm_state[0] := 'I';
+ act_fsm_state[1] := 'n';
+ act_fsm_state[2] := 'i';
+ act_fsm_state[3] := 't';
+ act_fsm_state[4] := '\0';
+
+ move_fsm_state[0] := 'I';
+ move_fsm_state[1] := 'n';
+ move_fsm_state[2] := 'i';
+ move_fsm_state[3] := 't';
+ move_fsm_state[4] := '\0';
+
+ main_fsm_state[0] := 'I';
+ main_fsm_state[1] := 'n';
+ main_fsm_state[2] := 'i';
+ main_fsm_state[3] := 't';
+ main_fsm_state[4] := '\0';
+
+ names[0] := "MOT";
+ names[1] := "ODO";
+ names[2] := "CAM";
+ names[3] := "PWR";
+ names[4] := "HOK";
+ names[5] := "APP";
+ names[6] := "VID";
+ names[7] := "STA";
+
+ idx := 0;
+ repeat
+ comp_state[idx] := (idx+1) & 0x0f;
+ idx++;
+ until(idx==8);
+ corns[0] := '-';
+ corns[1] := '-';
+
+ dress_color := BLUE;
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_voltage()//select variable is chooseing which voltage will be rewrite. CAN BE VALUE 0, to 5. 5 is ALL
+ var cntX, cntY, x, y, v_tab, idx;
+ cntX:=0;
+ cntY:=0;
+ v_tab:=4;
+ gfx_Set(PEN_SIZE, 1);
+ //draw table
+ gfx_Rectangle(0, 0, MAX_WIDTH, 18, WHITE);//table
+ while(cntX < v_tab)
+ x := rec_pos_X[cntX];
+ y := rec_pos_Y[cntY];
+ gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
+ cntX++;
+ wend
+ //write legend
+ gfx_Set(PEN_SIZE, 0);
+ txt_Set(FONT_SIZE, 3);
+ txt_Set(TEXT_COLOUR, GRAY);
+ txt_Set(TEXT_OPACITY, 0);
+ txt_MoveCursor(Text_row[VOLT],0);
+ print ("Voltage indicator:");
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+func redraw_voltage()//(var voltage)
+ var idx, color;
+ gfx_Set(PEN_SIZE, 0);
+ txt_Set(TEXT_COLOUR, BLACK);
+ color := RED;
+ if((voltages[0] & 0x08) != 0x08)
+ color := GREEN;
+ endif
+ gfx_Rectangle(1, 19, 58, 47, color);//table
+ txt_MoveCursor(2,0);
+ print([CHR]voltages[1], [CHR]voltages[2],".", [CHR]voltages[3],[CHR]voltages[4], "\n");
+ color := RED;
+ if((voltages[0] & 0x04) != 0x04)
+ color := GREEN;
+ endif
+ gfx_Rectangle(61,19,118,47, color);//table
+ txt_MoveCursor(2,5);
+ print([CHR]voltages[5], [CHR]voltages[6],".", [CHR]voltages[7],[CHR]voltages[8], "\n");
+ color := RED;
+ if((voltages[0] & 0x02) != 0x02)
+ color := GREEN;
+ endif
+ gfx_Rectangle(121, 19, 178,47, color);//table
+ txt_MoveCursor(2,10);
+ print([CHR]voltages[9], [CHR]voltages[10], ".",[CHR]voltages[11],[CHR]voltages[12], "\n");
+ color := RED;
+ if((voltages[0] & 0x01) != 0x01)
+ color := GREEN;
+ endif
+ gfx_Rectangle(181,19,238, 47, color);//table
+ txt_MoveCursor(2,15);
+ print([CHR]voltages[13],[CHR]voltages[14], ".",[CHR]voltages[15],[CHR]voltages[16], "\n");
+ paint_voltage();
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_comm()
+ gfx_Set(PEN_SIZE, 1);//table
+ gfx_Rectangle(180, 174, 239, 192, WHITE);//table
+ txt_MoveCursor(11,15);
+ txt_Set(TEXT_COLOUR, GRAY);
+ print("Comm:");
+endfunc
+
+
+
+func redraw_comm()
+ if(comm_idx >= 6)
+ comm_idx := 0;
+ endif
+ gfx_Set(PEN_SIZE, 0);//solid rec
+ gfx_Rectangle(181, 191, 238, 221, GREEN);//table
+ txt_MoveCursor(13,17);
+ txt_Set(TEXT_COLOUR, BLACK);
+ print([CHR]comm_chars[comm_idx]);
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func draw_error()
+ sys_SetTimer(0,3000);
+ gfx_Set(PEN_SIZE, 0);//solid rec
+ gfx_Rectangle(181, 191, 238, 221, BLACK);//table
+ txt_MoveCursor(13,16);
+ txt_Set(TEXT_COLOUR, RED);
+ print("ERR");
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_comp_state(var data)
+ var Y_axes, X_axes,X_end, Y_end, comp_nmb, col_idx, text_Y;
+ comp_nmb := ((data & 0x1f)-1);
+ col_idx := (data & 0x60) >> 5;
+ if((comp_nmb >7)||(col_idx > 2) ||comp_nmb<0)
+ return;
+ endif
+ Y_axes := rec_Y[comp_nmb];
+ X_axes := rec_X[comp_nmb];
+ X_end := X_axes + 57;
+ Y_end := Y_axes + 28;
+ text_Y := 5;
+ if(comp_nmb >3)
+ text_Y := 7;
+ endif
+ gfx_Set(PEN_SIZE, 0);//solid rectangle
+ gfx_Rectangle(X_axes, Y_axes, X_end, Y_end, colors[col_idx]);//table
+ txt_MoveCursor(text_Y,Text_pos[comp_nmb]);
+ txt_Set(TEXT_COLOUR, BLACK);
+ print([STR]names[comp_nmb]);
+ comp_state[comp_nmb] := data;
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_comp_states(var select)
+ var cntX,cntY,x,y, v_tab, row;
+ cntX := 0;
+ cntY := 1;
+ row := 0;
+ v_tab:=4;
+ gfx_Set(PEN_SIZE, 1);
+ //draw table for components
+ gfx_Rectangle(0, rec_pos_Y[cntY], MAX_WIDTH, 66, WHITE);//table
+ cntY++;
+ while(cntX < v_tab)
+ x := rec_pos_X[cntX];
+ y := rec_pos_Y[cntY];
+ gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
+ cntX++;
+ wend
+ cntY := 3;
+ cntX := 0;
+ while(cntX < v_tab)
+ x := rec_pos_X[cntX];
+ y := rec_pos_Y[cntY];
+ gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
+ cntX++;
+ wend
+ txt_MoveCursor(Text_row[STATE],0);
+ txt_Set(TEXT_COLOUR, GRAY);
+ print("Component indicator:")
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_corn()
+ gfx_Set(PEN_SIZE, 1);//table
+ gfx_Rectangle(180, 126, 239, 222, WHITE);//table
+ gfx_Rectangle(180, 126, 239, 144, WHITE);//table
+ gfx_Rectangle(179, 126, 239, 222, WHITE);//table
+ txt_MoveCursor(8,15);
+ txt_Set(TEXT_COLOUR, GRAY);
+ print("Corn:")
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_corns()
+ txt_MoveCursor(10,16);
+ txt_Set(TEXT_COLOUR, BLACK);
+ gfx_Set(PEN_SIZE, 0);//solid rectangle
+ gfx_Rectangle(181, 145, 237, 173, dress_color);//table
+ print([CHR]corns[0]," ",[CHR]corns[1]);
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_move_state()
+ var idx;
+ gfx_Set(PEN_SIZE, 0);//table
+ gfx_Rectangle(0, 159, 178, 190, BLACK);//table
+ txt_MoveCursor(10,0);
+ txt_Set(TEXT_COLOUR, OLIVE);
+ idx :=0;
+ print("MO:");
+ repeat
+ if(idx == 11)
+ print("-\n ");
+ endif
+ putch(move_fsm_state[idx]);
+ idx++;
+ until(move_fsm_state[idx] == '\0');
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_act_state()
+ var idx;
+ gfx_Set(PEN_SIZE, 0);//table
+ gfx_Rectangle(0, 191, 178, 221, BLACK);//table
+ txt_MoveCursor(12,0);
+ txt_Set(TEXT_COLOUR, BROWN);
+ idx :=0;
+ print("AC:");
+ repeat
+ if(idx == 11)
+ print("-\n ");
+ endif
+ putch(act_fsm_state[idx]);
+ idx++;
+ until(act_fsm_state[idx] == '\0');
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_main_state()
+ var idx;
+ idx :=0;
+ gfx_Rectangle(0, 127, 178, 158, BLACK);//table
+ txt_MoveCursor(8,0);
+ txt_Set(TEXT_COLOUR, TEAL);
+ gfx_Set(PEN_SIZE, 0);//table
+ print("MA:");
+ repeat
+ if(idx == 11)
+ print("-\n ");
+ endif
+ putch(main_fsm_state[idx]);
+ idx++;
+ until(main_fsm_state[idx] == '\0');
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_position()
+ gfx_Set(PEN_SIZE, 0);//solid rectangle
+ gfx_Rectangle(0, 223, 239, 255, MAGENTA);//table
+ gfx_Rectangle(0, 256, 239, 291, MAGENTA);//table
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_position()
+ gfx_Set(PEN_SIZE, 0);//solid rectangle
+ gfx_Rectangle(60, 239, 110, 255, MAGENTA);//table
+ gfx_Rectangle(160, 239, 220, 255,MAGENTA);//table
+ gfx_Rectangle(0, 272, 47, 286, MAGENTA);//table
+ txt_MoveCursor(14,0);
+ txt_Set(TEXT_COLOUR, BLACK);
+ print("Position:\n X = ", [CHR]position[0],".",[CHR]position[1],[CHR]position[2]);
+ print(" Y = ", [CHR]position[3],".",[CHR]position[4], [CHR]position[5], "\n");
+ print("Angle: ","\n"," ", [CHR]position[6],[CHR]position[7],[CHR]position[8]," Deg \n");
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func draw_keys()
+ var i;
+ i:=0;
+ repeat
+ gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT2, 2, 2, BT_text[i]);
+ until(++i == NMB_BT);
+ gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT1, 2, 2, BT_text[i]);
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw()
+ if(keyval == 8)//||(keyval == 8))//do nothing
+ return;
+ endif
+ if(keyval < 9)
+ gfx_Button(BT_state[keyval], 3, dY[keyval], collor[keyval], BLACK, FONT2, 2, 2, BT_text[keyval]);
+ endif
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+func send_cmd()
+ if(keyval == 8)//do nothing
+ return;
+ endif
+ if(keyval < 8)
+ to(COM0);
+ putch(commands[keyval]);
+ to(TEXT);
+ endif
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func read_key()
+ var x, y;
+ y := touch_Get(Y);
+ y := y / (BUTTONHEIGHT+1);
+ keyval := y;
+ if(keyval == 9)
+ keyval := -1;
+ endif
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func clear_page()
+ gfx_Set(0,0);
+ gfx_Rectangle(0,0,MAX_WIDTH,MAX_HEIGHT,BLACK);
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+// function for debugging only
+func send_axis()
+ var y;
+ y := touch_Get(Y);
+ txt_MoveCursor(16,1);
+ to(COM0),print(y);
+ to(COM0),print("\n");
+ to(COM0),print(keyval);
+ to(COM0),print("\n");
+endfunc
+
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func read_serial()
+ var cnt_idx;
+ rx_ch := serin();
+ if(rx_ch < 0)
+ goto out;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if((rx_ch & 0x80) == 0x80)
+ id := rx_ch;
+ index:=0;
+ if (id == KEEPALIVE)
+ sys_SetTimer(0,3000);// 3 seconds
+ comm_idx++;
+ redraw_comm();
+ id:=0;
+ endif;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if (index < 100) // 100 is buffer capacity
+ RX_buffer[index] := rx_ch;
+ index++;
+ else
+ index := 0;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if(id == COMPS && index == 1)
+ redraw_comp_state(RX_buffer[0]);//draw_status();
+ id:=0;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if(id == CORNS && index == 2)
+ corns[0] := RX_buffer[0];
+ corns[1] := RX_buffer[1];
+ redraw_corns();//draw_status();
+ id:=0;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if(id == ACT_FSM && rx_ch == '\0')
+ cnt_idx := 0;
+ repeat
+ act_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
+ cnt_idx++;
+ until(RX_buffer[cnt_idx] == '\0')
+ act_fsm_state[cnt_idx] := '\0';
+ redraw_act_state();
+ id:=0;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if(id == MOVE_FSM && rx_ch == '\0')
+ cnt_idx := 0;
+ repeat
+ move_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
+ cnt_idx++;
+ until(RX_buffer[cnt_idx] == '\0')
+ move_fsm_state[cnt_idx] := '\0';
+ redraw_move_state();
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if(id == MAIN_FSM && rx_ch == '\0')
+ cnt_idx := 0;
+ repeat
+ main_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
+ cnt_idx++;
+ until(RX_buffer[cnt_idx] == '\0')
+ main_fsm_state[cnt_idx] := '\0';
+ redraw_main_state();
+ id:=0;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if (id == VOLTAGES && index == 17)
+ cnt_idx :=0;
+ repeat
+ voltages[cnt_idx] := RX_buffer[cnt_idx];
+ cnt_idx++;
+ until(cnt_idx == 17)
+ redraw_voltage();
+ id:=0;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if(id == LOCATION && index == 9)
+ cnt_idx := 0;
+ repeat
+ position[cnt_idx] := RX_buffer[cnt_idx];
+ cnt_idx++;
+ until(cnt_idx == 9)
+ redraw_position();
+ id:=0;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+ if(id == COLOR && index == 1)
+ if(RX_buffer[0] == 1)
+ dress_color := YELLOW;
+ endif
+ if(RX_buffer[0] == 0)
+ dress_color := BLUE;
+ endif
+ redraw_corns();
+ id:=0;
+ goto out;//return;
+ endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+out:
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func STATE_page()
+ var state, cnt,idx1,tmr;
+ sys_SetTimer(0,3000);
+ paint_voltage();
+ cnt:=0;
+ redraw_voltage();
+ paint_comp_states(0);
+ paint_corn();
+ com_Init(buffer,100,0);
+ cnt := 0; //draw states for all components
+ repeat
+ redraw_comp_state(comp_state[cnt]);
+ until(cnt++ == 8)
+ paint_position();
+ redraw_position();
+ redraw_corns();
+ redraw_main_state();
+ redraw_move_state();
+ redraw_act_state();
+ paint_comm();
+ redraw_comm();
+
+ gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLACK,FONT1,2,2, " To control screen ");
+ touch_DetectRegion(0, MAX_HEIGHT-30, MAX_WIDTH, MAX_HEIGHT);
+ touch_Set(TOUCH_ENABLE);
+ repeat
+ state := touch_Get(TOUCH_STATUS);
+ if(state == TOUCH_PRESS)
+ gfx_Button(DOWN,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");
+ endif
+ if(state == TOUCH_RELEASE)
+ gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");
+ page := 1;
+ break;
+ endif
+ read_serial();
+ if(sys_GetTimer(0) == 0)
+ idx1 := 0;
+ repeat
+ idx1++;
+ comp_state[idx1] := idx1;
+ until(idx1==8);
+ cnt := 0; //draw states for all components
+ repeat
+ redraw_comp_state(comp_state[cnt]);
+ until(cnt++ == 8)
+ draw_error();
+ endif
+ forever
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func CTRL_page()
+ var n, state, x;
+ n :=0;
+ keyval := -1; // initate key value
+ BT_text[0] := " FORK DOWN "; //set texts for all buttons
+ BT_text[1] := " FORK UP ";
+ BT_text[2] := " DOOR OPEN ";
+ BT_text[3] := " DOOR CLOSE ";
+ BT_text[4] := " START ROLL ";
+ BT_text[5] := " STOP ROLL ";
+ BT_text[6] := "SEND ALL STATE";
+ BT_text[7] := " SWITCH COLOR ";
+ BT_text[8] := " To state screen ";
+ touch_Set(TOUCH_ENABLE); // enable the touch screen
+ touch_DetectRegion(0, 0, MAX_WIDTH, MAX_HEIGHT);
+//*********************************************************************************************
+ repeat
+ BT_state[n] := UP; //set state for all buttons
+ BT_OLDstate[n] := DOWN;
+ until(++n == 9);
+//*********************************************************************************************
+ draw_keys();
+ repeat
+ sys_SetTimer(0,3000);
+ state := touch_Get(TOUCH_STATUS);
+ if(state == TOUCH_PRESS)
+ read_key();
+ send_axis(); //debugging only
+ if(keyval != -1)
+ if(keyval == 10 || keyval == 9)
+ BT_state[8] := DOWN;
+ gfx_Button(BT_state[8], 3, dY[8], collor[8], BLUE, FONT1, 2, 2, BT_text[8]);// misto redraw();
+ else
+ BT_state[keyval] := DOWN; // set that button is pushed
+ redraw();
+ endif;
+ endif
+ endif
+ if(state == TOUCH_RELEASE)
+ if(keyval != -1)
+ BT_state[keyval] := UP; //button was released
+ redraw();
+ page := 0;
+ if(keyval == 10 || keyval == 9)
+ gfx_Button(BT_state[8], 3, dY[8], collor[8], BLACK, FONT1, 2, 2, BT_text[8]);// misto redraw();
+ keyval := -1;
+ break;
+ endif;
+ send_cmd();
+ endif
+ endif
+ forever
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func main()
+ page := 0;
+ firstState := 0;
+ firstCtrl := 0;
+ comp_collor := RED;
+ data_init();
+ voltages[0]:=0xff;// voltage color initate
+ comm_idx := 3;
+
+ repeat
+ if(!page)// view state page
+ clear_page();
+ STATE_page();
+ else// view ctrl page
+ clear_page();
+ CTRL_page();
+ endif
+ forever
+endfunc
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+