Adaptation for 160 LED strip
WARNING: This includes an incompatbile protocol change: The module index and the action are now in separate bytes, as 8 bits are needed for the module index. Also, the module index is now 32 bit internally to make future upgrades easier.
This commit is contained in:
parent
fc33207e8f
commit
dda7385517
4
Makefile
4
Makefile
|
@ -10,8 +10,8 @@ LD=gcc
|
||||||
BUILD:=debug
|
BUILD:=debug
|
||||||
|
|
||||||
# basic build flags configuration
|
# basic build flags configuration
|
||||||
CFLAGS+=-std=c99 -Wall -pedantic -Wno-long-long -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64
|
CFLAGS+=-std=c99 -Wall -pedantic -Wno-long-long -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64 -pthread
|
||||||
LIBS+=-lm -lrt
|
LIBS+=-lm -lrt -pthread
|
||||||
|
|
||||||
# library specific flags
|
# library specific flags
|
||||||
# wiringPi
|
# wiringPi
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int fader_init(uint8_t nMod);
|
int fader_init(uint32_t nMod);
|
||||||
void fader_shutdown(void);
|
void fader_shutdown(void);
|
||||||
void fader_set_colour(uint8_t module, uint8_t r, uint8_t g, uint8_t b);
|
void fader_set_colour(uint32_t module, uint8_t r, uint8_t g, uint8_t b);
|
||||||
void fader_fade_colour(uint8_t module, uint8_t r, uint8_t g, uint8_t b);
|
void fader_fade_colour(uint32_t module, uint8_t r, uint8_t g, uint8_t b);
|
||||||
void fader_add_colour(uint8_t module, uint8_t r, uint8_t g, uint8_t b);
|
void fader_add_colour(uint32_t module, uint8_t r, uint8_t g, uint8_t b);
|
||||||
void fader_set_fadestep(uint8_t newFadestep);
|
void fader_set_fadestep(uint8_t newFadestep);
|
||||||
void fader_update(void);
|
void fader_update(void);
|
||||||
void fader_wait_frame(void);
|
void fader_wait_frame(void);
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int ws2801_init(uint8_t num_modules);
|
int ws2801_init(uint32_t num_modules);
|
||||||
void ws2801_shutdown(void);
|
void ws2801_shutdown(void);
|
||||||
void ws2801_set_colour(uint8_t module, uint8_t red, uint8_t green, uint8_t blue);
|
void ws2801_set_colour(uint32_t module, uint8_t red, uint8_t green, uint8_t blue);
|
||||||
void ws2801_send_update(void);
|
void ws2801_send_update(void);
|
||||||
|
|
||||||
#endif // WS2801_H
|
#endif // WS2801_H
|
||||||
|
|
14
src/fader.c
14
src/fader.c
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "../include/fader.h"
|
#include "../include/fader.h"
|
||||||
|
|
||||||
uint8_t numModules;
|
uint32_t numModules;
|
||||||
|
|
||||||
float fadestep = 1;
|
float fadestep = 1;
|
||||||
double nextFrame;
|
double nextFrame;
|
||||||
|
@ -22,7 +22,7 @@ struct Colour {
|
||||||
struct Colour *curColour;
|
struct Colour *curColour;
|
||||||
struct Colour *targetColour;
|
struct Colour *targetColour;
|
||||||
|
|
||||||
int fader_init(uint8_t nMod)
|
int fader_init(uint32_t nMod)
|
||||||
{
|
{
|
||||||
numModules = nMod;
|
numModules = nMod;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ int fader_init(uint8_t nMod)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint8_t i = 0; i < numModules; i++) {
|
for(uint32_t i = 0; i < numModules; i++) {
|
||||||
curColour[i].red = targetColour[i].red = 0;
|
curColour[i].red = targetColour[i].red = 0;
|
||||||
curColour[i].green = targetColour[i].green = 0;
|
curColour[i].green = targetColour[i].green = 0;
|
||||||
curColour[i].blue = targetColour[i].blue = 0;
|
curColour[i].blue = targetColour[i].blue = 0;
|
||||||
|
@ -56,7 +56,7 @@ void fader_shutdown(void)
|
||||||
free(targetColour);
|
free(targetColour);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fader_set_colour(uint8_t module, uint8_t r, uint8_t g, uint8_t b)
|
void fader_set_colour(uint32_t module, uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
curColour[module].red = targetColour[module].red = r;
|
curColour[module].red = targetColour[module].red = r;
|
||||||
curColour[module].green = targetColour[module].green = g;
|
curColour[module].green = targetColour[module].green = g;
|
||||||
|
@ -65,14 +65,14 @@ void fader_set_colour(uint8_t module, uint8_t r, uint8_t g, uint8_t b)
|
||||||
somethingChanged = 1;
|
somethingChanged = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fader_fade_colour(uint8_t module, uint8_t r, uint8_t g, uint8_t b)
|
void fader_fade_colour(uint32_t module, uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
targetColour[module].red = r;
|
targetColour[module].red = r;
|
||||||
targetColour[module].green = g;
|
targetColour[module].green = g;
|
||||||
targetColour[module].blue = b;
|
targetColour[module].blue = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fader_add_colour(uint8_t module, uint8_t r, uint8_t g, uint8_t b)
|
void fader_add_colour(uint32_t module, uint8_t r, uint8_t g, uint8_t b)
|
||||||
{
|
{
|
||||||
curColour[module].red += r;
|
curColour[module].red += r;
|
||||||
curColour[module].green += g;
|
curColour[module].green += g;
|
||||||
|
@ -133,7 +133,7 @@ void fade_colour(float *cur, const float *target, int *changed)
|
||||||
|
|
||||||
void fader_update(void)
|
void fader_update(void)
|
||||||
{
|
{
|
||||||
for(uint8_t i = 0; i < numModules; i++) {
|
for(uint32_t i = 0; i < numModules; i++) {
|
||||||
fade_colour(&(curColour[i].red), &(targetColour[i].red), &somethingChanged);
|
fade_colour(&(curColour[i].red), &(targetColour[i].red), &somethingChanged);
|
||||||
fade_colour(&(curColour[i].green), &(targetColour[i].green), &somethingChanged);
|
fade_colour(&(curColour[i].green), &(targetColour[i].green), &somethingChanged);
|
||||||
fade_colour(&(curColour[i].blue), &(targetColour[i].blue), &somethingChanged);
|
fade_colour(&(curColour[i].blue), &(targetColour[i].blue), &somethingChanged);
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#define PORT 2703
|
#define PORT 2703
|
||||||
|
|
||||||
#define NUM_MODULES 20
|
#define NUM_MODULES 160
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,10 +47,10 @@ int udpproto_process(void)
|
||||||
{
|
{
|
||||||
socklen_t remote_addr_len;
|
socklen_t remote_addr_len;
|
||||||
struct sockaddr remote_addr;
|
struct sockaddr remote_addr;
|
||||||
uint8_t pkgbuf[256];
|
uint8_t pkgbuf[65536];
|
||||||
ssize_t rcvbytes, offset = 0;
|
ssize_t rcvbytes, offset = 0;
|
||||||
|
|
||||||
uint8_t cmd, r, g, b, action, module;
|
uint8_t r, g, b, action, module;
|
||||||
int fds_ready;
|
int fds_ready;
|
||||||
|
|
||||||
// check if there is data to be read (to prevent blocking)
|
// check if there is data to be read (to prevent blocking)
|
||||||
|
@ -71,7 +71,7 @@ int udpproto_process(void)
|
||||||
|
|
||||||
// receive the data
|
// receive the data
|
||||||
remote_addr_len = sizeof(remote_addr);
|
remote_addr_len = sizeof(remote_addr);
|
||||||
rcvbytes = recvfrom(sock, pkgbuf, 256, 0, (struct sockaddr*)&remote_addr, &remote_addr_len);
|
rcvbytes = recvfrom(sock, pkgbuf, 65536, 0, (struct sockaddr*)&remote_addr, &remote_addr_len);
|
||||||
if(rcvbytes == -1) {
|
if(rcvbytes == -1) {
|
||||||
LOG(LVL_ERR, "udpproto: recvfrom() failed: %s.", strerror(errno));
|
LOG(LVL_ERR, "udpproto: recvfrom() failed: %s.", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -81,15 +81,13 @@ int udpproto_process(void)
|
||||||
|
|
||||||
// parse commands from packet
|
// parse commands from packet
|
||||||
offset = 0;
|
offset = 0;
|
||||||
while(offset <= rcvbytes - 3) {
|
while(offset <= rcvbytes - 4) {
|
||||||
cmd = pkgbuf[offset + 0];
|
action = pkgbuf[offset + 0];
|
||||||
r = pkgbuf[offset + 1];
|
module = pkgbuf[offset + 1];
|
||||||
g = pkgbuf[offset + 2];
|
r = pkgbuf[offset + 2];
|
||||||
b = pkgbuf[offset + 3];
|
g = pkgbuf[offset + 3];
|
||||||
offset += 4;
|
b = pkgbuf[offset + 4];
|
||||||
|
offset += 5;
|
||||||
action = (cmd & 0xC0) >> 6; // the upper 2 bits
|
|
||||||
module = cmd & 0x3F; // the lower 6 bits
|
|
||||||
|
|
||||||
switch(action) {
|
switch(action) {
|
||||||
case SET_COLOUR:
|
case SET_COLOUR:
|
||||||
|
@ -113,7 +111,7 @@ int udpproto_process(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rcvbytes / 4; // number of commands in packet
|
return rcvbytes / 5; // number of commands in packet
|
||||||
}
|
}
|
||||||
|
|
||||||
void udpproto_shutdown(void)
|
void udpproto_shutdown(void)
|
||||||
|
|
19
src/ws2801.c
19
src/ws2801.c
|
@ -15,11 +15,11 @@
|
||||||
#include "../include/ws2801.h"
|
#include "../include/ws2801.h"
|
||||||
|
|
||||||
static const char *spi_dev = "/dev/spidev0.0";
|
static const char *spi_dev = "/dev/spidev0.0";
|
||||||
static const uint32_t spi_speed = 250000; // clock freq in Hz
|
static const uint32_t spi_speed = 1000000; // clock freq in Hz
|
||||||
static const uint16_t spi_delay = 0; // us
|
static const uint16_t spi_delay = 0; // us
|
||||||
static const uint8_t spi_bits = 8; // bits per word
|
static const uint8_t spi_bits = 8; // bits per word
|
||||||
|
|
||||||
uint8_t numModules;
|
uint32_t numModules;
|
||||||
uint8_t *message;
|
uint8_t *message;
|
||||||
|
|
||||||
int spi_fd = 0;
|
int spi_fd = 0;
|
||||||
|
@ -40,12 +40,12 @@ void send_message(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ws2801_init(uint8_t nMod)
|
int ws2801_init(uint32_t nMod)
|
||||||
{
|
{
|
||||||
// Initialize SPI
|
// Initialize SPI
|
||||||
// We need to have stable data at falling edge of the spi interface (this
|
// We need to have stable data at falling edge of the spi interface (this
|
||||||
// means rising edge at the led strip, as the signal is inverted.
|
// means rising edge at the led strip, as the signal is inverted.
|
||||||
uint8_t spi_mode = SPI_NO_CS | SPI_CPOL;
|
uint8_t spi_mode = SPI_NO_CS; // | SPI_CPOL;
|
||||||
|
|
||||||
spi_fd = open(spi_dev, O_RDWR);
|
spi_fd = open(spi_dev, O_RDWR);
|
||||||
if(spi_fd < 0) {
|
if(spi_fd < 0) {
|
||||||
|
@ -87,11 +87,14 @@ void ws2801_shutdown(void)
|
||||||
if(message != NULL) { free(message); message = NULL; }
|
if(message != NULL) { free(message); message = NULL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws2801_set_colour(uint8_t module, uint8_t red, uint8_t green, uint8_t blue)
|
void ws2801_set_colour(uint32_t module, uint8_t red, uint8_t green, uint8_t blue)
|
||||||
{
|
{
|
||||||
message[3*module + 0] = ~red;
|
//message[3*module + 0] = ~red;
|
||||||
message[3*module + 1] = ~green;
|
//message[3*module + 1] = ~green;
|
||||||
message[3*module + 2] = ~blue;
|
//message[3*module + 2] = ~blue;
|
||||||
|
message[3*module + 0] = red;
|
||||||
|
message[3*module + 1] = blue;
|
||||||
|
message[3*module + 2] = green;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws2801_send_update(void)
|
void ws2801_send_update(void)
|
||||||
|
|
Loading…
Reference in a new issue