Blame |
Last modification |
View Log
| RSS feed
/*
* lprg.c
* little LED lighting program interpreter
* (c) 2009 pangu
*/
#include "main.h"
#include "lprg.h"
static lprg lpg;
void LED_ON(int i) {
switch (i) {
case 0:
LED_1_ON;
break;
case 1:
LED_2_ON;
break;
case 2:
LED_3_ON;
break;
case 3:
LED_4_ON;
break;
case 4:
LED_5_ON;
break;
case 5:
LED_6_ON;
break;
case 6:
LED_7_ON;
break;
case 7:
LED_8_ON;
break;
case 8:
LED_9_ON;
break;
case 9:
LED_10_ON;
break;
}
}
void LED_OFF(int i) {
switch (i) {
case 0:
LED_1_OFF;
break;
case 1:
LED_2_OFF;
break;
case 2:
LED_3_OFF;
break;
case 3:
LED_4_OFF;
break;
case 4:
LED_5_OFF;
break;
case 5:
LED_6_OFF;
break;
case 6:
LED_7_OFF;
break;
case 7:
LED_8_OFF;
break;
case 8:
LED_9_OFF;
break;
case 9:
LED_10_OFF;
break;
}
}
void lprg_init(char *code[]) {
int i;
if(!code) return; // do nothing with no input
for(i=0; i<LEDCOUNT; i++) {
lpg.wait[i] = 0;
lpg.cur[i] = 0;
lpg.code[i] = code[i];
}
}
void lprg_step(void) { // to be called every 10ms. perform next step in lighting prog
int i;
char a;
for(i=0;i<LEDCOUNT;i++) {
// need to wait?
if(lpg.wait[i]) {
lpg.wait[i]--;
continue;
}
// get current command
a = *(lpg.code[i]+lpg.cur[i]);
lpg.cur[i]++;
if(!lpg.code[i][lpg.cur[i]]) // wrap to start if commands for LED finished
lpg.cur[i] = 0;
// look at current char
switch(a) {
case 'A': // if its LED on, turn LED on
LED_ON(i);
break;
case 'a': // if its LED off, turn LED off
LED_OFF(i);
break;
// Wait flags:
// . 10 ms (. or any other char)
// : 20 ms
// ; 50 ms
// I 100 ms
// N 200 ms
// M 300 ms
// V 500 ms
// S 1s
case ':':
lpg.wait[i] = 1;
break;
case ';':
lpg.wait[i] = 4;
break;
case 'I':
lpg.wait[i] = 9;
break;
case 'N':
lpg.wait[i] = 19;
break;
case 'M':
lpg.wait[i] = 29;
break;
case 'V':
lpg.wait[i] = 49;
break;
case 'S':
lpg.wait[i] = 99;
break;
}
}
}