/**************************************************
*
* class to handle Editing of MK Params
*
* Author: Marcus -LiGi- Bueschleb
*
* see README for further Infos
*
*************************************************/
import javax.microedition.lcdui.*;
public class MKParamsEditor
implements MKParamDefinitions
{
public final static int TAB_COUNT=
9;
public final static int TABID_CONFIGURATION=
0;
public final static int TABID_CHANNELS=
1;
public final static int TABID_STICK=
2;
public final static int TABID_ALTITUDE=
3;
public final static int TABID_GYRO=
4;
public final static int TABID_LOOPING=
5;
public final static int TABID_CAMMERA=
6;
public final static int TABID_OTHER=
7;
public final static int TABID_USER=
8;
public String[] tab_names=
{"Configuration",
"Channels",
"Stick",
"Altitude",
"Gyro",
"Looping",
"Camera",
"Other",
"User"};
public String[] param_names
;
public int[] tab_entrys_count=
{6,
8,
3,
6,
4,
6,
6,
6,
4};
public String[][] tab_entrys=
{{"Altitude Contol",
"Switch for setpoint",
"Heading Hold",
"Compass",
"Orientation fixed",
"GPS"}
,
{"Accelerate",
"Gier",
"Nick",
"Roll",
"POTI1",
"POTI2",
"POTI3",
"POTI4"},
{"Nick/Roll P-Rate",
"Nick/Roll D-Rate",
"Gier P-Rate"},
{"SetPoint",
"Min. Accelerate",
"Altitude P",
"Barometric D",
"Z-ACC effect ",
"Gain"},
{"Gyro P-Rate",
"Gyro I-Rate",
"ACC Gyro Factor",
"Main I"},
{"Up",
"Down",
"Left",
"Right",
"Gas Limit",
"Response threshold"},
{"Servo Ctrl",
"Nick compensation",
"Invert direction",
"Servo min",
"Servo max",
"Servo refresh Rate"},
{"Min Gas",
"Max Gas",
"Compass effect",
"voltage warning",
"distress gas time",
"distress gas"},
{"Param1",
"Param2",
"Param3",
"Param4"}
// {"","","","","",""},
};
public int[][] tab_entry_types=
{
{ PARAMTYPE_BOOLEAN ,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN
},
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BOOLEAN,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
}
};
public int[][][] tab_entry_src=
{
{ {8,
0} ,
{8,
1},
{8,
2},
{8,
3},
{8,
4},
{8,
5} },
{ {2,
0} ,
{3,
0},
{0,
0},
{1,
0},
{4,
0},
{5,
0},
{6,
0},
{7,
0} },
{ {15,
0} ,
{16,
0},
{17,
0} },
{ {11,
0} ,
{9,
0},
{12,
0},
{10,
0},
{14,
0},
{13,
0} },
//!
{ {22,
0} ,
{23,
0},
{20,
0},
{28,
0} },
{ {40,
0} ,
{40,
1},
{40,
2},
{40,
3},
{38,
0},
{39,
0} },
{ {33,
0} ,
{34,
0},
{40,
2}/*!*/,
{35,
0},
{36,
0},
{37,
0} },
{ {18,
0} ,
{19,
0},
{21,
0},
{24,
0},
{26,
0},
{25,
0} },
{ {29,
0} ,
{30,
0},
{31,
0},
{32,
0} }
};
private int act_tab=
0;
private int act_y=
0;
private int act_lcd_lines=
10;
MKMiniCanvas canvas
;
public String[] lcd_lines
;
public MKParamsEditor
(MKMiniCanvas _canvas
)
{
canvas=_canvas
;
lcd_lines=
new String[40];
refresh_lcd
();
}
public void paint
( Graphics g
)
{
refresh_lcd
();
canvas.
paint_lcd(g,
false);
}
public void refresh_lcd
()
{
if (canvas.
mk!=
null)
{
act_lcd_lines=tab_entrys_count
[act_tab
]*2+
1;
for ( int i=
0;i
<act_lcd_lines
;i++
)
lcd_lines
[i
]=
"";
lcd_lines
[0]=
(act_tab==
0?" ":
"< ") + tab_names
[act_tab
] +
(act_tab==
(TAB_COUNT-
1)?" ":
" >");
for (int i=
0;i
<tab_entrys_count
[act_tab
];i++
)
{
lcd_lines
[1+
2*i
]=tab_entrys
[act_tab
][i
];
if (tab_entry_types
[act_tab
][i
]== PARAMTYPE_BOOLEAN
)
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" ) ;
if (tab_entry_types
[act_tab
][i
]== PARAMTYPE_BYTE
)
{
lcd_lines
[2+
2*i
]=
""+canvas.
mk.
params.
get_field_from_act(tab_entry_src
[act_tab
][i
][0]);
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))
lcd_lines
[2+
2*i
]+=
"[Poti"+
(canvas.
mk.
params.
get_field_from_act(tab_entry_src
[act_tab
][i
][0])-
250) +
"]";
}
}
for (int i=
0;i
<act_lcd_lines
;i++
)
{
lcd_lines
[i
]=
(act_y==i
?"#":
" ")+lcd_lines
[i
];
}
for ( int i=
0;i
<act_lcd_lines
;i++
)
while(lcd_lines
[i
].
length()<20)
{
lcd_lines
[i
]+=
" ";
}
canvas.
lcd_lines=
new String[act_lcd_lines
];
for(int i=
0;i
<act_lcd_lines
;i++
)
canvas.
lcd_lines[i
]=lcd_lines
[i
];
}
else
{
canvas.
lcd_lines=
new String[1];
canvas.
lcd_lines[0]=
"reading params";
}
}
public final static int KEYCODE_CLEAR=-
8;
public boolean editing_number=
false;
public void keypress
(int keyCode,
int action
)
{
if (act_y==
0) switch (action
)
{
case Canvas.
RIGHT:
if (act_tab
<TAB_COUNT-
1) act_tab++
;
break;
case Canvas.
LEFT:
if (act_tab
!=
0) act_tab--
;
break;
}
else
{
if(tab_entry_types
[act_tab
][act_y/
2-
1]==PARAMTYPE_BYTE
)
{
if ((keyCode
>=
Canvas.
KEY_NUM0) && (keyCode
<=
Canvas.
KEY_NUM9))
{
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))
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));
else
canvas.
mk.
params.
set_field_from_act(tab_entry_src
[act_tab
][act_y/
2-
1][0] ,
(keyCode -
Canvas.
KEY_NUM0));
editing_number=
true;
return;
}
else
if ( keyCode==KEYCODE_CLEAR
)
canvas.
mk.
params.
set_field_from_act(tab_entry_src
[act_tab
][act_y/
2-
1][0],
0);
}
editing_number=
false;
switch (action
)
{
case Canvas.
RIGHT:
switch(tab_entry_types
[act_tab
][act_y/
2-
1])
{
case PARAMTYPE_BOOLEAN:
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]);
break;
case PARAMTYPE_BYTE:
canvas.
mk.
params.
field_from_act_add(tab_entry_src
[act_tab
][act_y/
2-
1][0],
1);
break;
}
break;
case Canvas.
LEFT:
switch(tab_entry_types
[act_tab
][act_y/
2-
1])
{
case PARAMTYPE_BOOLEAN:
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]);
break;
case PARAMTYPE_BYTE:
canvas.
mk.
params.
field_from_act_add(tab_entry_src
[act_tab
][act_y/
2-
1][0],-
1);
break;
}
break;
}
}
switch (action
)
{
case Canvas.
DOWN:
if (act_y
<(act_lcd_lines-
2)) act_y+=
2;
else act_y=
0;
break;
case Canvas.
UP:
if (act_y
!=
0) act_y-=
2;
else act_y=act_lcd_lines-
1;
break;
}
refresh_lcd
();
}
}