diff --git a/Makefile b/Makefile index 42d6279..1c73d00 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,8 @@ LD=gcc BUILD:=debug # basic build flags configuration -CFLAGS+=-std=c99 -Wall -pedantic -Wno-long-long -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64 -LIBS+=-lm -lrt +CFLAGS+=-std=c99 -Wall -pedantic -Wno-long-long -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64 -pthread +LIBS+=-lm -lrt -pthread # library specific flags # wiringPi diff --git a/include/fader.h b/include/fader.h index 6eaa405..f729161 100644 --- a/include/fader.h +++ b/include/fader.h @@ -3,11 +3,11 @@ #include -int fader_init(uint8_t nMod); +int fader_init(uint32_t nMod); void fader_shutdown(void); -void fader_set_colour(uint8_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_add_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(uint32_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_update(void); void fader_wait_frame(void); diff --git a/include/ws2801.h b/include/ws2801.h index 7db9b57..3791842 100644 --- a/include/ws2801.h +++ b/include/ws2801.h @@ -3,9 +3,9 @@ #include -int ws2801_init(uint8_t num_modules); +int ws2801_init(uint32_t num_modules); 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); #endif // WS2801_H diff --git a/src/fader.c b/src/fader.c index 8de1791..2e8dba2 100644 --- a/src/fader.c +++ b/src/fader.c @@ -6,7 +6,7 @@ #include "../include/fader.h" -uint8_t numModules; +uint32_t numModules; float fadestep = 1; double nextFrame; @@ -22,7 +22,7 @@ struct Colour { struct Colour *curColour; struct Colour *targetColour; -int fader_init(uint8_t nMod) +int fader_init(uint32_t nMod) { numModules = nMod; @@ -38,7 +38,7 @@ int fader_init(uint8_t nMod) 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].green = targetColour[i].green = 0; curColour[i].blue = targetColour[i].blue = 0; @@ -56,7 +56,7 @@ void fader_shutdown(void) 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].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; } -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].green = g; 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].green += g; @@ -133,7 +133,7 @@ void fade_colour(float *cur, const float *target, int *changed) 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].green), &(targetColour[i].green), &somethingChanged); fade_colour(&(curColour[i].blue), &(targetColour[i].blue), &somethingChanged); diff --git a/src/main.c b/src/main.c index a43d5be..6bf699b 100644 --- a/src/main.c +++ b/src/main.c @@ -12,7 +12,7 @@ #define PORT 2703 -#define NUM_MODULES 20 +#define NUM_MODULES 160 int main(void) { diff --git a/src/udpproto.c b/src/udpproto.c index a30cf65..6085ae4 100644 --- a/src/udpproto.c +++ b/src/udpproto.c @@ -47,10 +47,10 @@ int udpproto_process(void) { socklen_t remote_addr_len; struct sockaddr remote_addr; - uint8_t pkgbuf[256]; + uint8_t pkgbuf[65536]; ssize_t rcvbytes, offset = 0; - uint8_t cmd, r, g, b, action, module; + uint8_t r, g, b, action, module; int fds_ready; // check if there is data to be read (to prevent blocking) @@ -71,7 +71,7 @@ int udpproto_process(void) // receive the data 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) { LOG(LVL_ERR, "udpproto: recvfrom() failed: %s.", strerror(errno)); return -1; @@ -81,15 +81,13 @@ int udpproto_process(void) // parse commands from packet offset = 0; - while(offset <= rcvbytes - 3) { - cmd = pkgbuf[offset + 0]; - r = pkgbuf[offset + 1]; - g = pkgbuf[offset + 2]; - b = pkgbuf[offset + 3]; - offset += 4; - - action = (cmd & 0xC0) >> 6; // the upper 2 bits - module = cmd & 0x3F; // the lower 6 bits + while(offset <= rcvbytes - 4) { + action = pkgbuf[offset + 0]; + module = pkgbuf[offset + 1]; + r = pkgbuf[offset + 2]; + g = pkgbuf[offset + 3]; + b = pkgbuf[offset + 4]; + offset += 5; switch(action) { 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) diff --git a/src/ws2801.c b/src/ws2801.c index a3a5def..7f8966f 100644 --- a/src/ws2801.c +++ b/src/ws2801.c @@ -15,11 +15,11 @@ #include "../include/ws2801.h" 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 uint8_t spi_bits = 8; // bits per word -uint8_t numModules; +uint32_t numModules; uint8_t *message; 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 // 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. - 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); if(spi_fd < 0) { @@ -87,11 +87,14 @@ void ws2801_shutdown(void) 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 + 1] = ~green; - message[3*module + 2] = ~blue; + //message[3*module + 0] = ~red; + //message[3*module + 1] = ~green; + //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)