Rev 77 |
Blame |
Last modification |
View Log
| RSS feed
/*******************************************
*
* Handling of MK LCD
*
* Author: Marcus -LiGi- Bueschleb
* see README for further Infos
*
*
*******************************************/
public class MKLCD
implements Runnable
{
MKCommunicator mk=
null;
// public String[] LCD_str;
private String[][] lcd_buf
;
private final static int MAX_LCD_PAGES=
20;
int act_key=
0;
int act_mk_page=
0;
int act_user_page=
0;
boolean initial_run=
true;
int pages=
0;
int pages_read=
0;
byte init_state=
0;
public String[] get_act_page
()
{ return lcd_buf
[act_user_page
]; }
public MKLCD
(MKCommunicator _mk
)
{
lcd_buf=
new String[MAX_LCD_PAGES
][4];
for (int p=
0;p
<MAX_LCD_PAGES
;p++
)
{
lcd_buf
[p
][0]=
"buffering Page ";
lcd_buf
[p
][1]=
"please stay patient ";
lcd_buf
[p
][2]=
" ";
lcd_buf
[p
][3]=
" ;-) ";
}
mk=_mk
;
new Thread( this ).
start(); // fire up main Thread
}
public void run
()
{
while(true)
{
try {
if (mk.
connected)
trigger_LCD
();
Thread.
sleep(100);
}
catch (Exception e
) { }
}
}
public void set_page
(int page
)
{
act_user_page=page
;
}
public void handle_lcd_data
(int[] data,
int row
)
{
if (row==
0) // firs row indicates page
{
pages_read++
;
act_mk_page=data
[18]-
48;
if (data
[17]!=
91) // [
act_mk_page+=
10*(data
[17]-
48);
if (act_mk_page
>pages
)
pages=act_mk_page
;
if (( init_state==
1)&&(act_mk_page==
0))
{ init_state=
2; act_key=
1; }
else if ((init_state==
2)&&(act_mk_page
!=
0))
{ init_state=
3; act_key=
2; }
}
lcd_buf
[act_mk_page
][row
]=
"";
for(int foo=
0;foo
<20;foo++
)
lcd_buf
[act_mk_page
][row
]+=
(char)data
[foo
];
if (init_state==-
1) // init over
{
if (act_mk_page
<act_user_page
)
act_key=
2;
if (act_mk_page
>act_user_page
)
act_key=
1;
}
else if (init_state==
3)
{
if (row==
3)
{
if(act_mk_page==pages-
1)
init_state=-
1;
else
act_key=
2;
}
}
}
boolean init=
true;
public void trigger_LCD
()
{
if (mk.
connected && mk.
version.
known)
try {
if (init_state==
0)
{
mk.
trigger_LCD(3);
init_state++
;
}
else
mk.
trigger_LCD(act_key
);
act_key=
0;
}
catch (Exception e
) { }
}
public void LCD_NEXTPAGE
()
{
if (act_user_page
!=pages
)
act_user_page++
;
else
act_user_page=
0;
}
public void LCD_PREVPAGE
()
{
if (act_user_page
!=
0)
act_user_page--
;
else
act_user_page=pages
;
}
}