New protocol for multiple strips
This commit is contained in:
parent
0ae3492b82
commit
d4e7d558bd
4
Makefile
4
Makefile
|
@ -1,5 +1,5 @@
|
|||
LUA_CFLAGS=$(shell pkg-config --cflags lua)
|
||||
LUA_LIBS=$(shell pkg-config --libs lua)
|
||||
LUA_CFLAGS=$(shell pkg-config --cflags lua53)
|
||||
LUA_LIBS=$(shell pkg-config --libs lua53)
|
||||
|
||||
CC=gcc
|
||||
CFLAGS+=-O2 -Wall -march=native -pedantic -std=c99 -D_POSIX_C_SOURCE=20120607L -D_XOPEN_SOURCE $(LUA_CFLAGS)
|
||||
|
|
4
config.h
4
config.h
|
@ -16,13 +16,13 @@
|
|||
// configuration variables for musiclight2
|
||||
|
||||
// networking
|
||||
#define HOST "192.168.23.222"
|
||||
#define HOST "musiclight0.wiese.icmp.camp"
|
||||
#define PORT 2703
|
||||
|
||||
// FFT transformation parameters
|
||||
#define FFT_EXPONENT 8 // ATTENTION: when you change this, run gen_lut.py with this value as argument
|
||||
#define BLOCK_LEN (1 << FFT_EXPONENT) // 2^FFT_EXPONENT
|
||||
#define SAMPLE_RATE 44100
|
||||
#define SAMPLE_RATE 48000
|
||||
#define DATALEN (BLOCK_LEN / 2)
|
||||
|
||||
// Number of parts in the sample buffer
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
WS2801_HOST = "zybot"
|
||||
WS2801_HOST = "10.42.6.183"
|
||||
WS2801_PORT = 2703
|
||||
|
||||
NUM_MODULES = 54
|
||||
CENTER_MODULE = 54
|
||||
NUM_MODULES = 60
|
||||
CENTER_MODULE = 30
|
||||
|
||||
GAMMA = 2.0
|
||||
|
|
|
@ -7,8 +7,8 @@ M = 2.3 -- mass
|
|||
D = 1 -- spring strength
|
||||
DAMPING = {} -- filled in init()
|
||||
|
||||
num_modules = 54
|
||||
center_module = 54
|
||||
num_modules = 60
|
||||
center_module = 60
|
||||
|
||||
num_masses = math.floor(num_modules/2)
|
||||
excitement_pos = 1
|
||||
|
@ -63,7 +63,7 @@ function periodic()
|
|||
local whiteEnergy = get_energy_in_band(12000, 22000);
|
||||
local centerIndex = 2 * center_module + 1;
|
||||
|
||||
print(maxRedEnergy .. "\t" .. maxGreenEnergy .. "\t" .. maxBlueEnergy .. "\t" .. maxWhiteEnergy)
|
||||
--print(maxRedEnergy .. "\t" .. maxGreenEnergy .. "\t" .. maxBlueEnergy .. "\t" .. maxWhiteEnergy)
|
||||
|
||||
maxRedEnergy = maxRedEnergy * COOLDOWN_FACTOR
|
||||
if redEnergy > maxRedEnergy then
|
||||
|
@ -170,7 +170,7 @@ end
|
|||
|
||||
function init(nmod, cmod)
|
||||
num_modules = nmod
|
||||
center_module = cmod
|
||||
center_module = nmod --cmod
|
||||
|
||||
num_masses = nmod --math.floor(nmod/2)
|
||||
excitement_pos = 1
|
||||
|
|
34
main.c
34
main.c
|
@ -36,6 +36,8 @@
|
|||
// Number of new samples put into the buffer each frame
|
||||
#define READ_SAMPLES (BLOCK_LEN / BUFFER_PARTS)
|
||||
|
||||
#define NUM_SK6812 4
|
||||
|
||||
value_type fft[BLOCK_LEN];
|
||||
value_type rms;
|
||||
value_type redEnergy, greenEnergy, blueEnergy;
|
||||
|
@ -45,7 +47,7 @@ sample signal[BLOCK_LEN];
|
|||
|
||||
sem_t fftSemaphore;
|
||||
|
||||
struct sk6812_ctx sk6812[3];
|
||||
struct sk6812_ctx sk6812;
|
||||
|
||||
int running = 1;
|
||||
|
||||
|
@ -222,17 +224,13 @@ int main(int argc, char **argv) {
|
|||
fadeStep = lua_tointeger(L, -1);
|
||||
useFading = fadeStep > 0;
|
||||
if(useFading) {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
sk6812_set_fadestep(&(sk6812[i]), fadeStep);
|
||||
}
|
||||
sk6812_set_fadestep(&sk6812, fadeStep);
|
||||
printf("Fading enabled with fadestep %i.\n", fadeStep);
|
||||
}
|
||||
|
||||
// initialize the WS2801 library
|
||||
printf("Connecting to %s:%i\n", host, port);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
sk6812_init(&(sk6812[i]), host, port + i);
|
||||
}
|
||||
sk6812_init(&sk6812, host, port);
|
||||
|
||||
// create semaphores
|
||||
sem_init(&fftSemaphore, 0, 1);
|
||||
|
@ -254,40 +252,38 @@ int main(int argc, char **argv) {
|
|||
lua_readdoublearray(L, green, num_modules);
|
||||
lua_readdoublearray(L, red, num_modules);
|
||||
|
||||
for(int s = 0; s < 3; s++) {
|
||||
for(int s = 0; s < NUM_SK6812; s++) {
|
||||
if(useFading) {
|
||||
for(i = 0; i < num_modules; i++) {
|
||||
sk6812_fade_color(&(sk6812[s]), i,
|
||||
sk6812_fade_color(&sk6812, s, i,
|
||||
255 * gamma_correct(red[i], gamma),
|
||||
255 * gamma_correct(green[i], gamma),
|
||||
255 * gamma_correct(blue[i], gamma),
|
||||
255 * gamma_correct(white[i], gamma));
|
||||
}
|
||||
sk6812_commit(&(sk6812[s]));
|
||||
} else {
|
||||
for(i = 0; i < num_modules; i++) {
|
||||
sk6812_set_color(&(sk6812[s]), i,
|
||||
sk6812_set_color(&sk6812, s, i,
|
||||
255 * gamma_correct(red[i], gamma),
|
||||
255 * gamma_correct(green[i], gamma),
|
||||
255 * gamma_correct(blue[i], gamma),
|
||||
255 * gamma_correct(white[i], gamma));
|
||||
}
|
||||
sk6812_commit(&(sk6812[s]));
|
||||
}
|
||||
}
|
||||
|
||||
sk6812_commit(&sk6812);
|
||||
|
||||
if(lastUpdateTime < nextFrame - 1) {
|
||||
printf("Idle for 1 second -> stopping updates.\n");
|
||||
|
||||
for(i = 0; i < num_modules; i++) {
|
||||
for(int s = 0; s < 3; s++) {
|
||||
sk6812_fade_color(&(sk6812[s]), i, 0, 0, 0, 20);
|
||||
for(int s = 0; s < NUM_SK6812; s++) {
|
||||
sk6812_fade_color(&sk6812, s, i, 0, 0, 0, 20);
|
||||
}
|
||||
}
|
||||
|
||||
for(int s = 0; s < 3; s++) {
|
||||
sk6812_commit(&(sk6812[s]));
|
||||
}
|
||||
sk6812_commit(&sk6812);
|
||||
|
||||
active = 0;
|
||||
}
|
||||
|
@ -300,8 +296,8 @@ int main(int argc, char **argv) {
|
|||
sleep_until(nextFrame);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
sk6812_shutdown(&(sk6812[i]));
|
||||
for(int i = 0; i < NUM_SK6812; i++) {
|
||||
sk6812_shutdown(&sk6812);
|
||||
}
|
||||
|
||||
// free arrays
|
||||
|
|
|
@ -2,7 +2,7 @@ COOLDOWN_FACTOR = 0.9995
|
|||
OVERDRIVE = 1.50
|
||||
EXPONENT = 1.5
|
||||
|
||||
M = 1.3--1.7 -- mass
|
||||
M = 5.0--1.7 -- mass
|
||||
D = 1 -- spring strength
|
||||
DAMPING = {} -- filled in init()
|
||||
|
||||
|
@ -169,8 +169,8 @@ function init(nmod, cmod)
|
|||
num_modules = nmod
|
||||
center_module = cmod
|
||||
|
||||
num_masses = math.floor(nmod/2)
|
||||
excitement_pos = math.floor(cmod/2)
|
||||
num_masses = math.floor(nmod)
|
||||
excitement_pos = math.floor(cmod)
|
||||
|
||||
for i = 1,nmod do
|
||||
red[i] = 0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
#dd if=/tmp/mpd.fifo bs=1024 | ./musiclight2
|
||||
./musiclight2 $* < /tmp/musiclight.fifo
|
||||
./musiclight2 $* < /tmp/mpd.fifo
|
||||
|
|
9
sk6812.c
9
sk6812.c
|
@ -62,9 +62,10 @@ int sk6812_init(struct sk6812_ctx *ctx, const char *host, unsigned short port) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void sk6812_set_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
void sk6812_set_color(struct sk6812_ctx *ctx, uint8_t strip, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
ctx->packetQueue[ctx->queueIndex].action = SET_COLOR;
|
||||
ctx->packetQueue[ctx->queueIndex].module = htons(module);
|
||||
ctx->packetQueue[ctx->queueIndex].strip = strip;
|
||||
ctx->packetQueue[ctx->queueIndex].data[0] = r;
|
||||
ctx->packetQueue[ctx->queueIndex].data[1] = g;
|
||||
ctx->packetQueue[ctx->queueIndex].data[2] = b;
|
||||
|
@ -72,9 +73,10 @@ void sk6812_set_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8_
|
|||
ctx->queueIndex++;
|
||||
}
|
||||
|
||||
void sk6812_fade_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
void sk6812_fade_color(struct sk6812_ctx *ctx, uint8_t strip, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
ctx->packetQueue[ctx->queueIndex].action = FADE_COLOR;
|
||||
ctx->packetQueue[ctx->queueIndex].module = htons(module);
|
||||
ctx->packetQueue[ctx->queueIndex].strip = strip;
|
||||
ctx->packetQueue[ctx->queueIndex].data[0] = r;
|
||||
ctx->packetQueue[ctx->queueIndex].data[1] = g;
|
||||
ctx->packetQueue[ctx->queueIndex].data[2] = b;
|
||||
|
@ -82,9 +84,10 @@ void sk6812_fade_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8
|
|||
ctx->queueIndex++;
|
||||
}
|
||||
|
||||
void sk6812_add_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
void sk6812_add_color(struct sk6812_ctx *ctx, uint8_t strip, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
|
||||
ctx->packetQueue[ctx->queueIndex].action = ADD_COLOR;
|
||||
ctx->packetQueue[ctx->queueIndex].module = htons(module);
|
||||
ctx->packetQueue[ctx->queueIndex].strip = strip;
|
||||
ctx->packetQueue[ctx->queueIndex].data[0] = r;
|
||||
ctx->packetQueue[ctx->queueIndex].data[1] = g;
|
||||
ctx->packetQueue[ctx->queueIndex].data[2] = b;
|
||||
|
|
7
sk6812.h
7
sk6812.h
|
@ -13,6 +13,7 @@
|
|||
|
||||
struct __attribute__((__packed__)) SK6812Packet {
|
||||
uint8_t action;
|
||||
uint8_t strip;
|
||||
uint16_t module;
|
||||
uint8_t data[4];
|
||||
};
|
||||
|
@ -25,9 +26,9 @@ struct sk6812_ctx {
|
|||
};
|
||||
|
||||
int sk6812_init(struct sk6812_ctx *ctx, const char *host, unsigned short port);
|
||||
void sk6812_set_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
void sk6812_fade_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
void sk6812_add_color(struct sk6812_ctx *ctx, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
void sk6812_set_color(struct sk6812_ctx *ctx, uint8_t strip, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
void sk6812_fade_color(struct sk6812_ctx *ctx, uint8_t strip, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
void sk6812_add_color(struct sk6812_ctx *ctx, uint8_t strip, uint16_t module, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
|
||||
void sk6812_set_fadestep(struct sk6812_ctx *ctx, uint8_t fadestep);
|
||||
int sk6812_commit(struct sk6812_ctx *ctx);
|
||||
void sk6812_shutdown(struct sk6812_ctx *ctx);
|
||||
|
|
Loading…
Reference in a new issue