Support multiple strips
This commit is contained in:
parent
fc7173afff
commit
4734b8eaeb
2
make.sh
2
make.sh
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||||
make $@
|
make $@
|
||||||
|
|
48
src/main.c
48
src/main.c
|
@ -17,14 +17,14 @@
|
||||||
#define PORT 2703
|
#define PORT 2703
|
||||||
|
|
||||||
#define NUM_MODULES 60
|
#define NUM_MODULES 60
|
||||||
#define GPIO_IDX 960
|
#define NUM_STRIPS 4
|
||||||
#define BASE_ADDR ((void*)0x40000000U)
|
|
||||||
|
|
||||||
#define INTERVAL 0.01
|
#define INTERVAL 0.01
|
||||||
|
|
||||||
struct CmdLineArgs {
|
struct CmdLineArgs {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint32_t num_modules;
|
uint32_t num_modules;
|
||||||
|
uint32_t num_strips;
|
||||||
};
|
};
|
||||||
|
|
||||||
void wait_frame(double *nextFrame, double interval)
|
void wait_frame(double *nextFrame, double interval)
|
||||||
|
@ -39,7 +39,7 @@ int parse_args(int argc, char **argv, struct CmdLineArgs *args)
|
||||||
unsigned long tmp_ul;
|
unsigned long tmp_ul;
|
||||||
unsigned long long tmp_ull;
|
unsigned long long tmp_ull;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "p:a:g:n:")) != -1) {
|
while((opt = getopt(argc, argv, "p:s:n:")) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'p': // port
|
case 'p': // port
|
||||||
tmp_ul = strtoul(optarg, NULL, 0);
|
tmp_ul = strtoul(optarg, NULL, 0);
|
||||||
|
@ -54,6 +54,9 @@ int parse_args(int argc, char **argv, struct CmdLineArgs *args)
|
||||||
case 'n': // number of modules
|
case 'n': // number of modules
|
||||||
args->num_modules = strtoul(optarg, NULL, 0);
|
args->num_modules = strtoul(optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
case 's': // number of modules
|
||||||
|
args->num_strips = strtoul(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -65,8 +68,6 @@ int parse_args(int argc, char **argv, struct CmdLineArgs *args)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct sk6812_ctx ctx;
|
|
||||||
struct fader_ctx fader_ctx;
|
|
||||||
struct hat_spi_ctx hat_ctx;
|
struct hat_spi_ctx hat_ctx;
|
||||||
|
|
||||||
struct CmdLineArgs args;
|
struct CmdLineArgs args;
|
||||||
|
@ -79,39 +80,47 @@ int main(int argc, char **argv)
|
||||||
// default arguments
|
// default arguments
|
||||||
args.port = PORT;
|
args.port = PORT;
|
||||||
args.num_modules = NUM_MODULES;
|
args.num_modules = NUM_MODULES;
|
||||||
|
args.num_strips = NUM_STRIPS;
|
||||||
|
|
||||||
// parse command line arguments
|
// parse command line arguments
|
||||||
if(parse_args(argc, argv, &args) == -1) {
|
if(parse_args(argc, argv, &args) == -1) {
|
||||||
LOG(LVL_FATAL, "Error while parsing command line arguments!\n\n"
|
LOG(LVL_FATAL, "Error while parsing command line arguments!\n\n"
|
||||||
"Usage: %s [-p port] [-a base_address] [-g gpio_index] [-n number_of_modules]\n\n", argv[0]);
|
"Usage: %s [-p port] [-s number_of_strips] [-n number_of_modules]\n\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct fader_ctx fader_ctx[args.num_strips];
|
||||||
|
struct sk6812_ctx ctx[args.num_strips];
|
||||||
|
|
||||||
// initialize SPI interface for hat
|
// initialize SPI interface for hat
|
||||||
if(hat_spi_init(&hat_ctx) == -1) {
|
if(hat_spi_init(&hat_ctx) == -1) {
|
||||||
LOG(LVL_FATAL, "Could not initialize SPI interface.");
|
LOG(LVL_FATAL, "Could not initialize SPI interface.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hat_spi_config(&hat_ctx, NUM_MODULES*4) == -1) {
|
if(hat_spi_config(&hat_ctx, args.num_modules*4) == -1) {
|
||||||
LOG(LVL_FATAL, "Could not configure LED driver hat.");
|
LOG(LVL_FATAL, "Could not configure LED driver hat.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize sk6812 library
|
// initialize sk6812 library
|
||||||
if(sk6812_init(&ctx, &hat_ctx, 0, NUM_MODULES) == -1) {
|
for(int i = 0; i < args.num_strips; i++) {
|
||||||
LOG(LVL_FATAL, "Could not initialize SK6812 library.");
|
if(sk6812_init(&(ctx[i]), &hat_ctx, i, args.num_modules) == -1) {
|
||||||
return 1;
|
LOG(LVL_FATAL, "Could not initialize SK6812 library.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialise the LED fader
|
// initialise the LED fader
|
||||||
if(fader_init(&fader_ctx, NUM_MODULES, &ctx) == -1) {
|
for(int i = 0; i < args.num_strips; i++) {
|
||||||
LOG(LVL_FATAL, "Could not initialize the LED fader.");
|
if(fader_init(&(fader_ctx[i]), args.num_modules, &(ctx[i])) == -1) {
|
||||||
return 1;
|
LOG(LVL_FATAL, "Could not initialize the LED fader.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialise the UDP server
|
// initialise the UDP server
|
||||||
if(udpproto_init(PORT, &fader_ctx, 1) == -1) {
|
if(udpproto_init(PORT, fader_ctx, args.num_strips) == -1) {
|
||||||
LOG(LVL_FATAL, "Could not initialize the UDP server.");
|
LOG(LVL_FATAL, "Could not initialize the UDP server.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -120,14 +129,19 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
udpproto_process();
|
udpproto_process();
|
||||||
fader_update(&fader_ctx);
|
for(int i = 0; i < args.num_strips; i++) {
|
||||||
|
fader_update(&(fader_ctx[i]));
|
||||||
|
}
|
||||||
|
hat_spi_flush(&hat_ctx);
|
||||||
wait_frame(&nextFrame, INTERVAL);
|
wait_frame(&nextFrame, INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// shut down all modules
|
// shut down all modules
|
||||||
udpproto_shutdown();
|
udpproto_shutdown();
|
||||||
fader_shutdown(&fader_ctx);
|
for(int i = 0; i < args.num_strips; i++) {
|
||||||
sk6812_shutdown(&ctx);
|
fader_shutdown(&(fader_ctx[i]));
|
||||||
|
sk6812_shutdown(&(ctx[i]));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue