-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathrgb_leds.c
More file actions
91 lines (82 loc) · 2.06 KB
/
Copy pathrgb_leds.c
File metadata and controls
91 lines (82 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <r0ketlib/config.h>
#include <r0ketlib/select.h>
#include <r0ketlib/print.h>
#include <r0ketlib/display.h>
#include <rad1olib/light_ws2812_cortex.h>
#include <r0ketlib/fs_util.h>
#include <r0ketlib/keyin.h>
#include <string.h>
#include <campapp/rad1oconfig.h>
#define MAX_LED_FRAMES 64
#define BUF_SIZE 3*8*MAX_LED_FRAMES+2
unsigned char leds[BUF_SIZE];
unsigned int frames = 0;
unsigned int ctr = 0;
unsigned int framectr = 0;
void readRgbLedFile(void) {
int size = getFileSize(GLOBAL(ledfile));
frames = 0;
ctr = 0;
framectr = 0;
if(size > 0) {
if(size >= BUF_SIZE)
size = BUF_SIZE;
readFile(GLOBAL(ledfile), (char*)leds, size);
frames = (size-2)/(3*8);
}
}
/**************************************************************************/
void init_rgbLeds(void) {
readTextFile("ledfile.cfg",GLOBAL(ledfile),FLEN);
readRgbLedFile();
}
void tick_rgbLeds(void) {
if(GLOBAL(rgbleds)) {
if(frames > 0) {
if(ctr == 0) {
ws2812_sendarray(&leds[framectr*3*8+2], 3*8);
framectr++;
if(framectr >= frames)
framectr = 0;
}
ctr++;
// LED delay is in leds[0:1]
if(ctr >= ((leds[0]<<8) + leds[1]))
ctr = 0;
}
}
return;
}
//# MENU rgb_leds
void selectLedFile(void){
if(GLOBAL(rgbleds)) {
if(init_selectFile("L3D")){
while(selectFileRepeat(GLOBAL(ledfile),"L3D") >= 0) {
writeFile("ledfile.cfg", GLOBAL(ledfile), strlen(GLOBAL(ledfile)));
init_rgbLeds();
}
}
} else {
lcdClear();
lcdNl();
lcdPrintln("You need to enable");
lcdPrintln("<rgbleds> in the");
lcdPrintln("config to use");
lcdPrintln("this!");
lcdNl();
lcdPrintln(" LEFT: back");
lcdPrintln(" ENTER/RIGHT:");
lcdPrintln(" open config");
lcdDisplay();
while(1){
switch(getInput()){
case BTN_LEFT:
return;
case BTN_RIGHT:
case BTN_ENTER:
menu_config();
return;
}
}
}
}