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