Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
310 | pangu | 1 | /* |
2 | * lprg.c |
||
3 | * little LED lighting program interpreter |
||
4 | * (c) 2009 pangu |
||
5 | */ |
||
6 | |||
7 | #include "main.h" |
||
8 | #include "lprg.h" |
||
9 | |||
10 | static lprg lpg; |
||
11 | |||
12 | void LED_ON(int i) { |
||
13 | switch (i) { |
||
14 | case 0: |
||
15 | LED_1_ON; |
||
16 | break; |
||
17 | case 1: |
||
18 | LED_2_ON; |
||
19 | break; |
||
20 | case 2: |
||
21 | LED_3_ON; |
||
22 | break; |
||
23 | case 3: |
||
24 | LED_4_ON; |
||
25 | break; |
||
26 | case 4: |
||
27 | LED_5_ON; |
||
28 | break; |
||
29 | case 5: |
||
30 | LED_6_ON; |
||
31 | break; |
||
32 | case 6: |
||
33 | LED_7_ON; |
||
34 | break; |
||
35 | case 7: |
||
36 | LED_8_ON; |
||
37 | break; |
||
38 | case 8: |
||
39 | LED_9_ON; |
||
40 | break; |
||
41 | case 9: |
||
42 | LED_10_ON; |
||
43 | break; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | void LED_OFF(int i) { |
||
48 | switch (i) { |
||
49 | case 0: |
||
50 | LED_1_OFF; |
||
51 | break; |
||
52 | case 1: |
||
53 | LED_2_OFF; |
||
54 | break; |
||
55 | case 2: |
||
56 | LED_3_OFF; |
||
57 | break; |
||
58 | case 3: |
||
59 | LED_4_OFF; |
||
60 | break; |
||
61 | case 4: |
||
62 | LED_5_OFF; |
||
63 | break; |
||
64 | case 5: |
||
65 | LED_6_OFF; |
||
66 | break; |
||
67 | case 6: |
||
68 | LED_7_OFF; |
||
69 | break; |
||
70 | case 7: |
||
71 | LED_8_OFF; |
||
72 | break; |
||
73 | case 8: |
||
74 | LED_9_OFF; |
||
75 | break; |
||
76 | case 9: |
||
77 | LED_10_OFF; |
||
78 | break; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | |||
83 | void lprg_init(char *code[]) { |
||
84 | int i; |
||
85 | |||
86 | if(!code) return; // do nothing with no input |
||
87 | |||
88 | for(i=0; i<LEDCOUNT; i++) { |
||
89 | lpg.wait[i] = 0; |
||
90 | lpg.cur[i] = 0; |
||
91 | lpg.code[i] = code[i]; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | |||
96 | void lprg_step(void) { // to be called every 10ms. perform next step in lighting prog |
||
97 | |||
98 | int i; |
||
99 | char a; |
||
100 | |||
101 | for(i=0;i<LEDCOUNT;i++) { |
||
102 | |||
103 | // need to wait? |
||
104 | if(lpg.wait[i]) { |
||
105 | lpg.wait[i]--; |
||
106 | continue; |
||
107 | } |
||
108 | |||
109 | // get current command |
||
110 | a = *(lpg.code[i]+lpg.cur[i]); |
||
111 | |||
112 | |||
113 | lpg.cur[i]++; |
||
114 | if(!lpg.code[i][lpg.cur[i]]) // wrap to start if commands for LED finished |
||
115 | lpg.cur[i] = 0; |
||
116 | |||
117 | |||
118 | // look at current char |
||
119 | switch(a) { |
||
120 | case 'A': // if its LED on, turn LED on |
||
121 | LED_ON(i); |
||
122 | break; |
||
123 | case 'a': // if its LED off, turn LED off |
||
124 | LED_OFF(i); |
||
125 | break; |
||
126 | // Wait flags: |
||
127 | // . 10 ms (. or any other char) |
||
128 | // : 20 ms |
||
129 | // ; 50 ms |
||
130 | // I 100 ms |
||
131 | // N 200 ms |
||
132 | // M 300 ms |
||
133 | // V 500 ms |
||
134 | // S 1s |
||
135 | case ':': |
||
136 | lpg.wait[i] = 1; |
||
137 | break; |
||
138 | case ';': |
||
139 | lpg.wait[i] = 4; |
||
140 | break; |
||
141 | case 'I': |
||
142 | lpg.wait[i] = 9; |
||
143 | break; |
||
144 | case 'N': |
||
145 | lpg.wait[i] = 19; |
||
146 | break; |
||
147 | case 'M': |
||
148 | lpg.wait[i] = 29; |
||
149 | break; |
||
150 | case 'V': |
||
151 | lpg.wait[i] = 49; |
||
152 | break; |
||
153 | case 'S': |
||
154 | lpg.wait[i] = 99; |
||
155 | break; |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 |