Rev 81 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
81 | ligi | 1 | /*************************************************************** |
2 | * |
||
3 | * Code for on Device Debugging of DUBwise |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * |
||
7 | * see README for further Infos |
||
8 | * |
||
9 | ***************************************************************/ |
||
10 | |||
11 | import javax.microedition.lcdui.*; |
||
12 | |||
13 | |||
14 | public class DUBwiseDebug |
||
15 | extends Canvas |
||
16 | { |
||
17 | |||
18 | |||
19 | public boolean showing=false; |
||
20 | public String debug_msg=""; |
||
21 | |||
22 | private byte[] debug_screen_sequence={KEY_POUND,KEY_NUM4,KEY_NUM2}; |
||
23 | private byte debug_screen_sequence_pos=0; |
||
24 | |||
25 | |||
26 | public final static int DEBUG_HISTORY_LENGTH=100; |
||
27 | |||
28 | |||
29 | public String[] debug_msgs; |
||
30 | public int debug_pos=0; |
||
31 | |||
32 | int y_off=0; |
||
33 | |||
34 | |||
35 | public DUBwiseDebug() |
||
36 | { |
||
37 | debug_msgs=new String[DEBUG_HISTORY_LENGTH]; |
||
38 | for (int tmp_i=0;tmp_i<DEBUG_HISTORY_LENGTH;tmp_i++) |
||
39 | debug_msgs[tmp_i]=""; |
||
40 | } |
||
41 | |||
42 | public void log(String str) |
||
43 | { |
||
44 | debug_msgs[debug_pos]=str; |
||
45 | debug_pos++; |
||
46 | if (debug_pos==DEBUG_HISTORY_LENGTH) |
||
47 | debug_pos=0; |
||
48 | debug_msgs[debug_pos]=str; |
||
49 | } |
||
50 | |||
51 | public void paint (Graphics g) |
||
52 | { |
||
53 | |||
54 | Font debug_font= Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); |
||
55 | |||
56 | g.setFont(debug_font); |
||
57 | |||
58 | g.setColor(0x0000FF); |
||
59 | g.fillRect(0,0,this.getWidth(),this.getHeight()); |
||
60 | g.setColor(0xFFFFFF); |
||
61 | |||
62 | y_off=0; |
||
63 | for (int tmp_pos=debug_pos;((tmp_pos>0)&&(y_off<this.getHeight()));tmp_pos--) |
||
64 | { |
||
65 | debug_msg=debug_msgs[tmp_pos]; |
||
66 | String tmp_str=""; |
||
67 | |||
68 | for(int tmp_i=0;tmp_i<debug_msg.length();tmp_i++) |
||
69 | { |
||
70 | if ((debug_msg.charAt(tmp_i)=='\r')||(debug_msg.charAt(tmp_i)=='\n')) |
||
71 | { |
||
72 | g.drawString(tmp_str,5,y_off,Graphics.TOP | Graphics.LEFT); |
||
73 | y_off+=debug_font.getHeight(); |
||
74 | tmp_str=""; |
||
75 | } |
||
76 | else |
||
77 | tmp_str+=debug_msg.charAt(tmp_i); |
||
78 | } |
||
79 | g.drawString(tmp_str,0,y_off,Graphics.TOP | Graphics.LEFT); |
||
80 | y_off+=debug_font.getHeight(); |
||
81 | } |
||
82 | |||
83 | } |
||
84 | |||
85 | public void process_key(int keyCode) |
||
86 | { |
||
87 | |||
88 | |||
89 | if (!showing) |
||
90 | { |
||
91 | if (keyCode==debug_screen_sequence[debug_screen_sequence_pos]) |
||
92 | { |
||
93 | debug_screen_sequence_pos++; |
||
94 | if(debug_screen_sequence_pos==debug_screen_sequence.length) |
||
95 | { |
||
96 | showing=true; |
||
97 | debug_screen_sequence_pos=0; |
||
98 | } |
||
99 | } |
||
100 | else |
||
101 | debug_screen_sequence_pos=0; |
||
102 | } |
||
103 | else |
||
104 | { |
||
105 | if (keyCode==KEY_STAR) |
||
106 | showing=false; |
||
107 | } |
||
108 | |||
109 | |||
110 | } |
||
111 | |||
112 | |||
113 | |||
114 | } |