Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
303 | ligi | 1 | /************************************************** |
2 | * |
||
3 | * class to handle Editing of MK Params |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
403 | ligi | 6 | * |
7 | * see README for further Infos |
||
8 | * |
||
303 | ligi | 9 | *************************************************/ |
10 | |||
11 | import javax.microedition.lcdui.*; |
||
12 | |||
13 | |||
14 | public class MKParamsEditor |
||
475 | ligi | 15 | implements MKParamDefinitions |
303 | ligi | 16 | { |
17 | |||
18 | public final static int TAB_COUNT=9; |
||
19 | |||
20 | |||
21 | |||
475 | ligi | 22 | public final static int TABID_CONFIGURATION=0; |
23 | public final static int TABID_CHANNELS=1; |
||
24 | public final static int TABID_STICK=2; |
||
25 | public final static int TABID_ALTITUDE=3; |
||
26 | public final static int TABID_GYRO=4; |
||
27 | public final static int TABID_LOOPING=5; |
||
28 | public final static int TABID_CAMMERA=6; |
||
29 | public final static int TABID_OTHER=7; |
||
30 | public final static int TABID_USER=8; |
||
31 | public String[] tab_names={"Configuration","Channels","Stick","Altitude","Gyro","Looping","Camera","Other","User"}; |
||
303 | ligi | 32 | |
475 | ligi | 33 | |
34 | public String[] param_names; |
||
35 | |||
36 | |||
37 | |||
325 | ligi | 38 | public int[] tab_entrys_count={6,8,3,6,4,6,6,6,4}; |
303 | ligi | 39 | |
40 | public String[][] tab_entrys={{"Altitude Contol","Switch for setpoint","Heading Hold","Compass","Orientation fixed","GPS"} |
||
41 | , |
||
42 | {"Accelerate","Gier","Nick","Roll","POTI1","POTI2","POTI3","POTI4"}, |
||
43 | {"Nick/Roll P-Rate","Nick/Roll D-Rate","Gier P-Rate"}, |
||
475 | ligi | 44 | |
45 | |||
303 | ligi | 46 | {"SetPoint","Min. Accelerate","Altitude P","Barometric D","Z-ACC effect ","Gain"}, |
47 | {"Gyro P-Rate","Gyro I-Rate","ACC Gyro Factor","Main I"}, |
||
48 | {"Up","Down","Left","Right","Gas Limit","Response threshold"}, |
||
49 | {"Servo Ctrl","Nick compensation","Invert direction","Servo min","Servo max","Servo refresh Rate"}, |
||
50 | |||
314 | ligi | 51 | {"Min Gas","Max Gas","Compass effect","voltage warning","distress gas time", "distress gas"}, |
303 | ligi | 52 | {"Param1","Param2","Param3","Param4"} |
53 | // {"","","","","",""}, |
||
54 | }; |
||
55 | |||
56 | public int[][] tab_entry_types={ |
||
57 | |||
58 | { PARAMTYPE_BOOLEAN ,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN }, |
||
59 | {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, |
||
60 | {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, |
||
61 | {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, |
||
62 | {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, |
||
63 | {PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, |
||
64 | {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, |
||
65 | {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, |
||
66 | {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE} |
||
67 | |||
475 | ligi | 68 | }; |
303 | ligi | 69 | |
70 | |||
71 | public int[][][] tab_entry_src={ |
||
72 | |||
73 | { {8,0} ,{8,1},{8,2},{8,3},{8,4},{8,5} }, |
||
74 | { {2,0} ,{3,0},{0,0},{1,0},{4,0},{5,0},{6,0},{7,0} }, |
||
75 | { {15,0} ,{16,0},{17,0} }, |
||
475 | ligi | 76 | { {11,0} ,{9,0},{12,0},{10,0},{14,0},{13,0} }, //! |
303 | ligi | 77 | { {22,0} ,{23,0},{20,0},{28,0} }, |
78 | { {40,0} ,{40,1},{40,2},{40,3},{38,0},{39,0} }, |
||
79 | { {33,0} ,{34,0},{40,2}/*!*/,{35,0},{36,0},{37,0} }, |
||
314 | ligi | 80 | { {18,0} ,{19,0},{21,0},{24,0},{26,0},{25,0} }, |
303 | ligi | 81 | { {29,0} ,{30,0},{31,0},{32,0} } |
82 | }; |
||
83 | |||
84 | private int act_tab=0; |
||
85 | private int act_y=0; |
||
86 | private int act_lcd_lines=10; |
||
87 | |||
88 | MKMiniCanvas canvas; |
||
89 | |||
90 | public String[] lcd_lines; |
||
91 | |||
92 | |||
93 | public MKParamsEditor(MKMiniCanvas _canvas) |
||
94 | { |
||
95 | |||
96 | canvas=_canvas; |
||
97 | lcd_lines=new String[40]; |
||
98 | refresh_lcd(); |
||
99 | } |
||
100 | |||
101 | |||
102 | public void paint ( Graphics g) |
||
103 | { |
||
104 | refresh_lcd(); |
||
105 | canvas.paint_lcd(g,false); |
||
106 | } |
||
107 | |||
108 | |||
109 | public void refresh_lcd() |
||
110 | { |
||
111 | if (canvas.mk!=null) |
||
112 | { |
||
475 | ligi | 113 | act_lcd_lines=tab_entrys_count[act_tab]*2+1; |
114 | for ( int i=0;i<act_lcd_lines;i++) |
||
115 | lcd_lines[i]=""; |
||
303 | ligi | 116 | |
475 | ligi | 117 | lcd_lines[0]=(act_tab==0?" ":"< ") + tab_names[act_tab] + (act_tab==(TAB_COUNT-1)?" ":" >"); |
303 | ligi | 118 | |
475 | ligi | 119 | for (int i=0;i<tab_entrys_count[act_tab];i++) |
411 | ligi | 120 | { |
475 | ligi | 121 | lcd_lines[1+2*i]=tab_entrys[act_tab][i]; |
122 | if (tab_entry_types[act_tab][i]== PARAMTYPE_BOOLEAN) |
||
123 | lcd_lines[2+2*i]=(((canvas.mk.params.get_field_from_act(tab_entry_src[act_tab][i][0])&(1<<tab_entry_src[act_tab][i][1]))==0)?"off":"on" ) ; |
||
124 | if (tab_entry_types[act_tab][i]== PARAMTYPE_BYTE) |
||
125 | { |
||
126 | lcd_lines[2+2*i]=""+canvas.mk.params.get_field_from_act(tab_entry_src[act_tab][i][0]); |
||
127 | if ((canvas.mk.params.get_field_from_act(tab_entry_src[act_tab][i][0])>250)&&(canvas.mk.params.get_field_from_act(tab_entry_src[act_tab][i][0])<256)) |
||
128 | lcd_lines[2+2*i]+="[Poti"+(canvas.mk.params.get_field_from_act(tab_entry_src[act_tab][i][0])-250) +"]"; |
||
129 | } |
||
130 | |||
411 | ligi | 131 | } |
132 | |||
475 | ligi | 133 | for (int i=0;i<act_lcd_lines;i++) |
134 | { |
||
135 | lcd_lines[i]=(act_y==i?"#":" ")+lcd_lines[i]; |
||
136 | } |
||
303 | ligi | 137 | |
475 | ligi | 138 | for ( int i=0;i<act_lcd_lines;i++) |
139 | while(lcd_lines[i].length()<20) |
||
140 | { |
||
141 | lcd_lines[i]+=" "; |
||
142 | } |
||
143 | |||
144 | canvas.lcd_lines=new String[act_lcd_lines]; |
||
145 | for(int i=0;i<act_lcd_lines;i++) |
||
146 | canvas.lcd_lines[i]=lcd_lines[i]; |
||
147 | |||
303 | ligi | 148 | } |
149 | else |
||
150 | { |
||
151 | canvas.lcd_lines=new String[1]; |
||
152 | canvas.lcd_lines[0]="reading params"; |
||
153 | } |
||
154 | |||
155 | } |
||
156 | |||
390 | ligi | 157 | |
158 | public final static int KEYCODE_CLEAR=-8; |
||
159 | |||
411 | ligi | 160 | public boolean editing_number=false; |
161 | |||
303 | ligi | 162 | public void keypress (int keyCode,int action) |
163 | { |
||
164 | if (act_y==0) switch (action) |
||
165 | { |
||
166 | case Canvas.RIGHT: |
||
167 | if (act_tab<TAB_COUNT-1) act_tab++; |
||
168 | break; |
||
169 | |||
170 | case Canvas.LEFT: |
||
171 | if (act_tab!=0) act_tab--; |
||
172 | break; |
||
173 | } |
||
174 | else |
||
175 | { |
||
390 | ligi | 176 | if(tab_entry_types[act_tab][act_y/2-1]==PARAMTYPE_BYTE) |
303 | ligi | 177 | { |
390 | ligi | 178 | if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) |
179 | { |
||
411 | ligi | 180 | if((editing_number)&&( Math.abs(canvas.mk.params.get_field_from_act(tab_entry_src[act_tab][act_y/2-1][0]))*10+(keyCode - Canvas.KEY_NUM0)<1000)) |
390 | ligi | 181 | canvas.mk.params.set_field_from_act(tab_entry_src[act_tab][act_y/2-1][0] , Math.abs(canvas.mk.params.get_field_from_act(tab_entry_src[act_tab][act_y/2-1][0]))*10+(keyCode - Canvas.KEY_NUM0)); |
411 | ligi | 182 | else |
183 | canvas.mk.params.set_field_from_act(tab_entry_src[act_tab][act_y/2-1][0] , (keyCode - Canvas.KEY_NUM0)); |
||
184 | editing_number=true; |
||
390 | ligi | 185 | return; |
186 | } |
||
187 | else |
||
188 | if ( keyCode==KEYCODE_CLEAR) |
||
189 | canvas.mk.params.set_field_from_act(tab_entry_src[act_tab][act_y/2-1][0],0); |
||
303 | ligi | 190 | } |
411 | ligi | 191 | editing_number=false; |
390 | ligi | 192 | |
193 | switch (action) |
||
194 | { |
||
195 | |||
196 | case Canvas.RIGHT: |
||
197 | switch(tab_entry_types[act_tab][act_y/2-1]) |
||
198 | { |
||
199 | case PARAMTYPE_BOOLEAN: |
||
200 | |||
201 | canvas.mk.params.field_from_act_xor(tab_entry_src[act_tab][act_y/2-1][0],1<<tab_entry_src[act_tab][act_y/2-1][1]); |
||
202 | break; |
||
203 | case PARAMTYPE_BYTE: |
||
411 | ligi | 204 | |
390 | ligi | 205 | canvas.mk.params.field_from_act_add(tab_entry_src[act_tab][act_y/2-1][0],1); |
206 | break; |
||
207 | } |
||
208 | break; |
||
209 | |||
210 | case Canvas.LEFT: |
||
211 | switch(tab_entry_types[act_tab][act_y/2-1]) |
||
212 | { |
||
213 | case PARAMTYPE_BOOLEAN: |
||
303 | ligi | 214 | |
390 | ligi | 215 | canvas.mk.params.field_from_act_xor(tab_entry_src[act_tab][act_y/2-1][0],1<<tab_entry_src[act_tab][act_y/2-1][1]); |
216 | |||
217 | break; |
||
218 | case PARAMTYPE_BYTE: |
||
411 | ligi | 219 | |
220 | canvas.mk.params.field_from_act_add(tab_entry_src[act_tab][act_y/2-1][0],-1); |
||
390 | ligi | 221 | break; |
222 | } |
||
223 | |||
224 | |||
225 | break; |
||
226 | } |
||
227 | |||
303 | ligi | 228 | } |
390 | ligi | 229 | |
303 | ligi | 230 | switch (action) |
231 | { |
||
232 | |||
233 | case Canvas.DOWN: |
||
234 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
||
314 | ligi | 235 | else act_y=0; |
303 | ligi | 236 | break; |
237 | |||
238 | case Canvas.UP: |
||
314 | ligi | 239 | if (act_y!=0) act_y-=2; |
240 | else act_y=act_lcd_lines-1; |
||
303 | ligi | 241 | break; |
242 | |||
243 | } |
||
244 | |||
245 | refresh_lcd(); |
||
246 | |||
247 | |||
248 | } |
||
249 | } |
||
250 |