diff --git a/RpiLedBars/.vscode/c_cpp_properties.json b/RpiLedBars/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b7c0a7d --- /dev/null +++ b/RpiLedBars/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "linux-gcc-arm", + "compileCommands": "${workspaceFolder}/build/compile_commands.json", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/RpiLedBars/.vscode/settings.json b/RpiLedBars/.vscode/settings.json new file mode 100644 index 0000000..798b48e --- /dev/null +++ b/RpiLedBars/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cmake.sourceDirectory": "${workspaceFolder}/backend" +} \ No newline at end of file diff --git a/RpiLedBars/backend/CMakeLists.txt b/RpiLedBars/backend/CMakeLists.txt index 1f184dc..4b7d0e8 100644 --- a/RpiLedBars/backend/CMakeLists.txt +++ b/RpiLedBars/backend/CMakeLists.txt @@ -7,4 +7,6 @@ set(CMAKE_C_STANDARD 99) add_subdirectory(libs) +configure_file(cava_config ../ COPYONLY) + add_subdirectory(src) \ No newline at end of file diff --git a/RpiLedBars/backend/install.sh b/RpiLedBars/backend/install.sh index c3dbf49..135c5ad 100755 --- a/RpiLedBars/backend/install.sh +++ b/RpiLedBars/backend/install.sh @@ -1,5 +1,6 @@ # make -cp ./bin/pixled bin/service_pixled +install -v -D ../build/src/RpiLedBars cava_config -t /opt/pixled/ +# cp ./bin/pixled bin/service_pixled sudo -s bash -c "cp pixled.service /etc/systemd/system; systemctl daemon-reload" # sudo -s bash -c "systemctl enable pixled" sudo -s bash -c "systemctl restart pixled" \ No newline at end of file diff --git a/RpiLedBars/backend/libs/CMakeLists.txt b/RpiLedBars/backend/libs/CMakeLists.txt index 32e4307..c68072b 100644 --- a/RpiLedBars/backend/libs/CMakeLists.txt +++ b/RpiLedBars/backend/libs/CMakeLists.txt @@ -1,5 +1,7 @@ include(FetchContent) +set(FETCHCONTENT_FULLY_DISCONNECTED ON) + FetchContent_Declare( logc GIT_REPOSITORY "https://github.com/Tropicananass/log.c.git" diff --git a/RpiLedBars/backend/pixled.service b/RpiLedBars/backend/pixled.service index eb9a841..17d234a 100644 --- a/RpiLedBars/backend/pixled.service +++ b/RpiLedBars/backend/pixled.service @@ -1,9 +1,10 @@ [Unit] -Description=pixled +Description=RpiLedBars After=network.target [Service] -ExecStart=pixled -n 60 -d 2 +WorkingDirectory=/opt/pixled +ExecStart=/opt/pixled/RpiLedBars -n 60 -d 2 Restart=always User=root Group=root diff --git a/RpiLedBars/backend/src/rpi_param.c b/RpiLedBars/backend/src/rpi_param.c index e859de9..df95f9e 100644 --- a/RpiLedBars/backend/src/rpi_param.c +++ b/RpiLedBars/backend/src/rpi_param.c @@ -106,7 +106,7 @@ void set_sensitivity(int channel, int8_t sensitivity8) { } else { param.ledbar[channel].sensitivity = sensitivity; } - log_debug("Sensitivity : %f", sensitivity); + log_debug("Sensitivity[%d] : %f", channel, sensitivity); } void set_hue_base(int channel, int8_t hueBase8) { diff --git a/RpiLedBars/backend/src/tasks/cava/cava.c b/RpiLedBars/backend/src/tasks/cava/cava.c index 552b302..01983c5 100644 --- a/RpiLedBars/backend/src/tasks/cava/cava.c +++ b/RpiLedBars/backend/src/tasks/cava/cava.c @@ -187,7 +187,7 @@ static int start_cava_process() { if (cavaPid == 0) { /* Child process*/ // int fdLogOut; - char *args[] = {"cava", "-p", "/home/pi/LedBars/RpiLedBars/cava_config", NULL}; + char *args[] = {"cava", "-p", "./cava_config", NULL}; /* Close reading end of the pipe */ close(fdCavaPipe[0]); diff --git a/RpiLedBars/backend/src/tasks/websocket/websocket.c b/RpiLedBars/backend/src/tasks/websocket/websocket.c index b75718d..3926751 100644 --- a/RpiLedBars/backend/src/tasks/websocket/websocket.c +++ b/RpiLedBars/backend/src/tasks/websocket/websocket.c @@ -34,6 +34,8 @@ int client_fd = -1; +int channel = LED_NCHANS; + /*************************************************************************************************** * Internal Function Prototypes **************************************************************************************************/ @@ -77,6 +79,14 @@ void pattern_command_handler(char *payload); void color_command_handler(char *payload); +void modulate_command_handler(char *payload); + +void channel_command_handler(char *payload); + +void sensitivity_command_handler(char *payload); + +void gravity_command_handler(char *payload); + /*************************************************************************************************** * External Function Definitions **************************************************************************************************/ @@ -142,6 +152,18 @@ void onmessage(int fd, const unsigned char *msg, uint64_t size, int type) { case 'c': color_command_handler(payload); break; + case 's': + modulate_command_handler(payload); + break; + case 'h': + channel_command_handler(payload); + break; + case 'e': + sensitivity_command_handler(payload); + break; + case 'g': + gravity_command_handler(payload); + break; default: log_warn("Unkown command in \"%s\"", msgStr); @@ -187,8 +209,36 @@ void color_command_handler(char *payload) { log_debug(" - %s", tokenArray[n]); } if (atoi(tokenArray[0]) == 0) { - set_hue_base(LED_NCHANS, atoi(tokenArray[1]) * INT8_MAX / HUE_MAX); - set_saturation(LED_NCHANS, atoi(tokenArray[2]) * INT8_MAX / 100); - set_luminosity(LED_NCHANS, atoi(tokenArray[3]) * INT8_MAX / 100); + set_hue_base(channel, atoi(tokenArray[1]) * INT8_MAX / HUE_MAX); + set_saturation(channel, atoi(tokenArray[2]) * INT8_MAX / 100); + set_luminosity(channel, atoi(tokenArray[3]) * INT8_MAX / 100); + } else { + set_saturation(channel, atoi(tokenArray[2]) * INT8_MAX / 100); + set_luminosity(channel, atoi(tokenArray[3]) * INT8_MAX / 100); } +} + +void modulate_command_handler(char *payload) { + bool modulate; + modulate = strcmp(payload, "true") == 0; + log_debug("modulate :%s", modulate ? "true" : "false"); + set_hue_auto_shift(modulate); +} + +void channel_command_handler(char *payload) { + int newChannel = atoi(payload); + if (0 <= newChannel && newChannel <= LED_NCHANS) { + log_debug("Channel: %d", newChannel); + channel = newChannel; + } +} + +void sensitivity_command_handler(char *payload) { + int newSensitivity = atoi(payload); + set_sensitivity(channel, newSensitivity); +} + +void gravity_command_handler(char *payload) { + int newGravity = atoi(payload); + set_gravity(newGravity); } \ No newline at end of file diff --git a/RpiLedBars/cava_config b/RpiLedBars/cava_config new file mode 100644 index 0000000..f6075e6 --- /dev/null +++ b/RpiLedBars/cava_config @@ -0,0 +1,24 @@ +[general] +framerate = 60 +autosens = 0 +sensitivity = 200 +bars = 128 + +[input] +method = alsa +source = plughw:1 + +[output] +method = raw +channels = mono +mono_option = left +data_format = ascii +ascii_max_range=65535 +bit_format = 16bit + +[smoothing] +integral = 77 +monstercat = 0 +waves = 0 +gravity = 0 + diff --git a/RpiLedBars/frontend/ledbars.nginx b/RpiLedBars/frontend/ledbars.nginx index c956095..c15c93a 100644 --- a/RpiLedBars/frontend/ledbars.nginx +++ b/RpiLedBars/frontend/ledbars.nginx @@ -38,6 +38,6 @@ server { alias /home/pi/LedBars/RpiLedBars/frontend/web/; # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. - try_files $uri $uri/ index.html =404; + try_files $uri $uri/ =404; } } diff --git a/RpiLedBars/frontend/web/index.html b/RpiLedBars/frontend/web/index.html index 6dbaa4d..19961f0 100644 --- a/RpiLedBars/frontend/web/index.html +++ b/RpiLedBars/frontend/web/index.html @@ -30,6 +30,11 @@