Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
77 | ligi | 1 | /******************************************* |
2 | * |
||
3 | * Handling of MK LCD |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
4 | ligi | 6 | * see README for further Infos |
7 | * |
||
77 | ligi | 8 | * |
9 | *******************************************/ |
||
4 | ligi | 10 | |
11 | public class MKLCD |
||
12 | implements Runnable |
||
13 | { |
||
14 | |||
15 | MKCommunicator mk=null; |
||
16 | |||
77 | ligi | 17 | // public String[] LCD_str; |
4 | ligi | 18 | |
77 | ligi | 19 | private String[][] lcd_buf; |
20 | private final static int MAX_LCD_PAGES=20; |
||
21 | int act_key=0; |
||
22 | int act_mk_page=0; |
||
23 | int act_user_page=0; |
||
24 | boolean initial_run=true; |
||
25 | |||
26 | int pages=0; |
||
27 | |||
28 | int pages_read=0; |
||
29 | |||
30 | byte init_state=0; |
||
31 | |||
32 | public String[] get_act_page() |
||
33 | { return lcd_buf[act_user_page]; } |
||
34 | |||
4 | ligi | 35 | public MKLCD(MKCommunicator _mk) |
36 | { |
||
77 | ligi | 37 | lcd_buf=new String[MAX_LCD_PAGES][4]; |
38 | |||
39 | for (int p=0;p<MAX_LCD_PAGES;p++) |
||
40 | { |
||
41 | lcd_buf[p][0]="buffering Page "; |
||
42 | lcd_buf[p][1]="please stay patient "; |
||
43 | lcd_buf[p][2]=" "; |
||
44 | lcd_buf[p][3]=" ;-) "; |
||
45 | } |
||
46 | |||
4 | ligi | 47 | mk=_mk; |
48 | new Thread( this ).start(); // fire up main Thread |
||
49 | } |
||
50 | |||
51 | public void run() |
||
52 | { |
||
53 | while(true) |
||
54 | { |
||
55 | try { |
||
77 | ligi | 56 | if (mk.connected) |
4 | ligi | 57 | trigger_LCD(); |
77 | ligi | 58 | Thread.sleep(100); |
4 | ligi | 59 | } |
60 | catch (Exception e) { } |
||
61 | } |
||
62 | } |
||
63 | |||
77 | ligi | 64 | public void set_page(int page) |
65 | { |
||
66 | act_user_page=page; |
||
67 | } |
||
4 | ligi | 68 | |
69 | public void handle_lcd_data(int[] data,int row) |
||
70 | { |
||
77 | ligi | 71 | if (row==0) // firs row indicates page |
72 | { |
||
73 | pages_read++; |
||
74 | act_mk_page=data[18]-48; |
||
75 | if (data[17]!=91) // [ |
||
76 | act_mk_page+=10*(data[17]-48); |
||
77 | if (act_mk_page>pages) |
||
78 | pages=act_mk_page; |
||
79 | if (( init_state==1)&&(act_mk_page==0)) |
||
80 | { init_state=2; act_key=1; } |
||
81 | else if ((init_state==2)&&(act_mk_page!=0)) |
||
82 | { init_state=3; act_key=2; } |
||
83 | |||
84 | |||
85 | } |
||
86 | |||
87 | lcd_buf[act_mk_page][row]=""; |
||
4 | ligi | 88 | for(int foo=0;foo<20;foo++) |
77 | ligi | 89 | lcd_buf[act_mk_page][row]+=(char)data[foo]; |
90 | |||
91 | if (init_state==-1) // init over |
||
92 | { |
||
93 | if (act_mk_page<act_user_page) |
||
94 | act_key=2; |
||
95 | |||
96 | if (act_mk_page>act_user_page) |
||
97 | act_key=1; |
||
98 | |||
99 | } |
||
100 | |||
101 | else if (init_state==3) |
||
102 | { |
||
103 | if (row==3) |
||
104 | { |
||
105 | if(act_mk_page==pages-1) |
||
106 | init_state=-1; |
||
107 | else |
||
108 | act_key=2; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | |||
4 | ligi | 113 | } |
114 | |||
77 | ligi | 115 | boolean init=true; |
4 | ligi | 116 | public void trigger_LCD() |
117 | { |
||
77 | ligi | 118 | if (mk.connected && mk.version.known) |
119 | try { |
||
120 | if (init_state==0) |
||
121 | { |
||
122 | mk.trigger_LCD(3); |
||
123 | init_state++; |
||
124 | } |
||
125 | else |
||
126 | mk.trigger_LCD(act_key); |
||
4 | ligi | 127 | |
77 | ligi | 128 | act_key=0; |
4 | ligi | 129 | } |
130 | catch (Exception e) { } |
||
131 | } |
||
132 | |||
133 | |||
134 | |||
135 | |||
77 | ligi | 136 | |
137 | |||
138 | |||
4 | ligi | 139 | public void LCD_NEXTPAGE() |
140 | { |
||
77 | ligi | 141 | if (act_user_page!=pages) |
142 | act_user_page++; |
||
143 | else |
||
144 | act_user_page=0; |
||
145 | |||
4 | ligi | 146 | } |
147 | |||
148 | public void LCD_PREVPAGE() |
||
149 | { |
||
77 | ligi | 150 | if (act_user_page!=0) |
151 | act_user_page--; |
||
152 | else |
||
153 | act_user_page=pages; |
||
4 | ligi | 154 | } |
155 | |||
156 | } |