35 { |
35 { |
36 xbi(&DEBUG_PORT, DEBUG_LED); |
36 xbi(&DEBUG_PORT, DEBUG_LED); |
37 } |
37 } |
38 |
38 |
39 // dmx |
39 // dmx |
|
40 #define DMX_COUNT 255 |
|
41 |
40 /* |
42 /* |
41 * DMX state |
43 * DMX state |
42 */ |
44 */ |
43 static struct dmx_state { |
45 static struct dmx_state { |
44 byte out[256]; |
46 byte out[DMX_COUNT]; |
45 byte count; |
47 byte count; |
46 } dmx; |
48 } dmx; |
47 |
|
48 |
49 |
49 enum state { |
50 enum state { |
50 START = '\n', |
51 START = '\n', |
51 CMD = ';', |
52 CMD = ';', |
52 ARG = ',', |
53 ARG = ',', |
53 ERROR = '!', |
54 ERROR = '!', |
54 }; |
55 }; |
55 |
56 |
56 enum cmd { |
|
57 CMD_ |
|
58 }; |
|
59 |
|
60 #define CONSOLE_ARGS 8 |
57 #define CONSOLE_ARGS 8 |
61 |
58 |
62 /* |
59 /* |
63 * Console input state. |
60 * Console input state. |
64 */ |
61 */ |
65 static struct console { |
62 static struct console { |
66 enum state state; |
63 byte state; |
67 |
64 byte cmd; |
68 enum cmd cmd; |
65 byte argc; |
69 char argc; |
66 byte argv[CONSOLE_ARGS]; |
70 char argv[CONSOLE_ARGS]; |
|
71 } console; |
67 } console; |
72 |
68 |
73 /* |
69 /* |
|
70 * Clear output (no state). |
|
71 */ |
|
72 int cmd_clear () |
|
73 { |
|
74 dmx.count = 0; |
|
75 |
|
76 return 0; |
|
77 } |
|
78 |
|
79 /* |
|
80 * Set output to given sequence. |
|
81 */ |
|
82 int cmd_out () |
|
83 { |
|
84 byte i; |
|
85 |
|
86 for (i = 0; i < console.argc; i++) { |
|
87 dmx.out[i] = console.argv[i]; |
|
88 } |
|
89 |
|
90 dmx.count = i; |
|
91 |
|
92 return 0; |
|
93 } |
|
94 |
|
95 /* |
|
96 * Set output at offset. |
|
97 */ |
|
98 int cmd_set () |
|
99 { |
|
100 if (console.argc < 1) { |
|
101 return '!'; |
|
102 } |
|
103 |
|
104 byte i = console.argv[0]; |
|
105 |
|
106 for (byte a = 1; a < console.argc; a++) { |
|
107 dmx.out[i++] = console.argv[a]; |
|
108 } |
|
109 |
|
110 if (i > dmx.count) |
|
111 dmx.count = i; |
|
112 |
|
113 return 0; |
|
114 } |
|
115 |
|
116 /* |
|
117 * Set output to max. zeroes |
|
118 */ |
|
119 int cmd_zero () |
|
120 { |
|
121 byte count; |
|
122 |
|
123 if (console.argc == 0) { |
|
124 count = DMX_COUNT; |
|
125 } else if (console.argc == 1) { |
|
126 count = console.argv[0]; |
|
127 } else { |
|
128 return '!'; |
|
129 } |
|
130 |
|
131 // set |
|
132 byte i; |
|
133 for (i = 0; i < count; i++) { |
|
134 dmx.out[i] = 0; |
|
135 } |
|
136 dmx.count = i; |
|
137 |
|
138 return 0; |
|
139 } |
|
140 |
|
141 /* |
74 * Process console command. |
142 * Process console command. |
75 */ |
143 */ |
76 int command () |
144 int command () |
77 { |
145 { |
78 switch (console.cmd) { |
146 switch (console.cmd) { |
79 default: |
147 case 'c': return cmd_clear(); |
80 return '?'; |
148 case 'o': return cmd_out(); |
|
149 case 's': return cmd_set(); |
|
150 case 'z': return cmd_zero(); |
|
151 |
|
152 default: return '?'; |
81 } |
153 } |
82 } |
154 } |
83 |
155 |
84 /* |
156 /* |
85 * Process console input. |
157 * Process console input. |
106 ret = '\n'; |
178 ret = '\n'; |
107 } |
179 } |
108 |
180 |
109 // return to START with response |
181 // return to START with response |
110 console.state = START; |
182 console.state = START; |
111 return ret; |
183 return '\n'; // XXX: required to delimit command reponses.. |
112 |
184 |
113 } else if (c == ' ' || c == '\t') { |
185 } else if (c == ' ' || c == '\t' || c == ',') { |
114 // argument |
186 // argument |
115 if (console.state == CMD) { |
187 if (console.state == CMD) { |
116 console.state = ARG; |
188 console.state = ARG; |
117 console.argc = 0; |
189 console.argc = 0; |
118 |
190 |
119 return c; |
191 return ','; |
120 |
192 |
121 } else if (console.state == ARG) { |
193 } else if (console.state == ARG) { |
122 if (console.argc++ < CONSOLE_ARGS) { |
194 if (console.argc++ < CONSOLE_ARGS) { |
123 console.argv[console.argc] = 0; |
195 console.argv[console.argc] = 0; |
124 |
196 |
125 return c; |
197 return ','; |
126 } |
198 } |
127 } |
199 } |
128 |
200 |
129 // printable |
201 // printable |
130 } else if (32 < c && c < 128) { |
202 } else if (32 < c && c < 128) { |