using cmake to build project and submodules
This commit is contained in:
parent
aff6d66622
commit
2faa518b32
7
.gitmodules
vendored
7
.gitmodules
vendored
@ -1,9 +1,4 @@
|
||||
[submodule "RpiLedBars/libs/log.c"]
|
||||
path = RpiLedBars/libs/log.c
|
||||
url = https://github.com/rxi/log.c.git
|
||||
|
||||
[submodule "RpiLedBars/cava"]
|
||||
path = RpiLedBars/cava
|
||||
url = https://github.com/karlstav/cava.git
|
||||
[submodule "RpiLedBars/libs/wsServer"]
|
||||
path = RpiLedBars/libs/wsServer
|
||||
url = https://github.com/Theldus/wsServer
|
||||
|
2
RpiLedBars/.gitignore
vendored
2
RpiLedBars/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
bin
|
||||
obj
|
@ -1,38 +0,0 @@
|
||||
CC := gcc
|
||||
CFLAGS := -Wall -g -Ilibs/log.c/src -Ilibs/wsServer/include
|
||||
LDFLAGS := -L.libs -lws -lwiringPi -lasound -lfftw3 -lpthread -lm
|
||||
|
||||
SRC := src
|
||||
OBJ := obj
|
||||
BIN := bin/pixled
|
||||
|
||||
SOURCES := $(shell find $(SRC) -type f -name "*.c")
|
||||
OBJECTS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SOURCES))
|
||||
|
||||
.PHONY: all clean install
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
libs/log.c/obj/log.o: libs/log.c/src/log.c
|
||||
if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi
|
||||
$(CC) -c $< -o $@ -DLOG_USE_COLOR
|
||||
|
||||
.libs/log.la: libs/log.c/obj/log.o
|
||||
if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi
|
||||
ar r $@ $^
|
||||
ranlib $@
|
||||
|
||||
$(OBJ)/%.o: $(SRC)/%.c
|
||||
if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
$(BIN): $(OBJECTS) .libs/log.la
|
||||
if [ ! -d "$(dir $@)" ]; then mkdir -p "$(dir $@)"; fi
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
install:
|
||||
$(shell install --backup bin/pixled /usr/local/bin/)
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ) .libs libs/*/obj
|
14
RpiLedBars/backend/.gitignore
vendored
Normal file
14
RpiLedBars/backend/.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
bin
|
||||
obj
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
build
|
10
RpiLedBars/backend/CMakeLists.txt
Normal file
10
RpiLedBars/backend/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
# set the project name
|
||||
project(RpiLedBars VERSION 0.5 LANGUAGES C)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
add_subdirectory(libs)
|
||||
|
||||
add_subdirectory(src)
|
@ -12,14 +12,13 @@ source = plughw:1
|
||||
method = raw
|
||||
channels = mono
|
||||
mono_option = left
|
||||
;raw_target = /dev/stdout
|
||||
data_format = ascii
|
||||
ascii_max_range=65535
|
||||
bit_format = 16bit
|
||||
|
||||
[smoothing]
|
||||
integral = 0
|
||||
monstercat = 1
|
||||
integral = 77
|
||||
monstercat = 0
|
||||
waves = 0
|
||||
gravity = 0
|
||||
|
14
RpiLedBars/backend/libs/CMakeLists.txt
Normal file
14
RpiLedBars/backend/libs/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
logc
|
||||
GIT_REPOSITORY "https://github.com/Tropicananass/log.c.git"
|
||||
)
|
||||
|
||||
FetchContent_Declare(
|
||||
ws
|
||||
GIT_REPOSITORY "https://github.com/Tropicananass/wsServer.git"
|
||||
)
|
||||
|
||||
# add the log.c and ws libraries
|
||||
FetchContent_MakeAvailable(logc ws)
|
14
RpiLedBars/backend/src/CMakeLists.txt
Normal file
14
RpiLedBars/backend/src/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
add_subdirectory(tasks)
|
||||
add_subdirectory(drivers)
|
||||
|
||||
# add the executable
|
||||
add_executable(${PROJECT_NAME}
|
||||
rpi_midi_controller.c
|
||||
rpi_param.c
|
||||
rpi_pattern.c
|
||||
main.c)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE m asound)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE logc)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_tasks ${PROJECT_NAME}_drivers)
|
14
RpiLedBars/backend/src/drivers/CMakeLists.txt
Normal file
14
RpiLedBars/backend/src/drivers/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# add the executable
|
||||
add_library(${PROJECT_NAME}_drivers
|
||||
common.c
|
||||
dma/rpi_dma.c
|
||||
dma/rpi_videocore.c
|
||||
gpio/rpi_gpio.c
|
||||
leddriver/rpi_leddriver.c
|
||||
selector/rpi_selector.c
|
||||
smi/rpi_smi.c)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}_drivers PRIVATE wiringPi)
|
||||
target_link_libraries(${PROJECT_NAME}_drivers PRIVATE logc)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}_drivers PUBLIC dma gpio leddriver selector smi)
|
@ -44,12 +44,13 @@ void selector_setup() {
|
||||
}
|
||||
|
||||
int selector_get_position() {
|
||||
int newPosition = -1;
|
||||
for (size_t i = 0; i < selectorPinNumber; ++i) {
|
||||
if (digitalRead(selectorPins[i])) {
|
||||
return i;
|
||||
newPosition = i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return newPosition;
|
||||
}
|
||||
|
||||
char *selector_tostr() {
|
@ -1,11 +1,13 @@
|
||||
/** @file rpi_selector.h
|
||||
* @brief This module is used to manage selector on gpio
|
||||
*/
|
||||
#if !defined(__RPI_SELECTOR_H__)
|
||||
#define __RPI_SELECTOR_H__
|
||||
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
**************************************************************************************************/
|
||||
#if !defined(__RPI_SELECTOR_H__)
|
||||
#define __RPI_SELECTOR_H__
|
||||
#include <stdbool.h>
|
||||
|
||||
/***************************************************************************************************
|
||||
* Preprocessor Constants and Macros
|
@ -19,11 +19,11 @@
|
||||
#include "log.h"
|
||||
|
||||
#include "drivers/leddriver/rpi_leddriver.h"
|
||||
#include "drivers/selector/rpi_selector.h"
|
||||
|
||||
#include "tasks/artnet/rpi_artnet.h"
|
||||
#include "tasks/cava/rpi_cava.h"
|
||||
#include "tasks/websocket/rpi_websocket.h"
|
||||
#include "artnet.h"
|
||||
#include "cava.h"
|
||||
#include "selector.h"
|
||||
#include "websocket.h"
|
||||
|
||||
#include "rpi_midi_controller.h"
|
||||
#include "rpi_param.h"
|
||||
@ -93,9 +93,9 @@ int main(int argc, char const *argv[]) {
|
||||
|
||||
param_setup();
|
||||
midi_controller_setup();
|
||||
selector_setup();
|
||||
leddriver_setup();
|
||||
websocket_start();
|
||||
selector_start();
|
||||
|
||||
parseCommandLineArgs(argc, argv);
|
||||
|
||||
@ -114,7 +114,7 @@ int main(int argc, char const *argv[]) {
|
||||
mode = 2;
|
||||
}
|
||||
} else {
|
||||
mode = selector_get_position();
|
||||
mode = param_access->pixled.mode;
|
||||
}
|
||||
/* todo thread ? */
|
||||
midi_controller_execute();
|
@ -9,10 +9,14 @@
|
||||
#include "rpi_param.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "drivers/selector/rpi_selector.h"
|
||||
#include "websocket.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
* Preprocessor Constants and Macros
|
||||
**************************************************************************************************/
|
||||
@ -21,9 +25,9 @@
|
||||
* Type and Contant Definitions
|
||||
**************************************************************************************************/
|
||||
|
||||
pixled_param_t const dummyPixledParam = {.chanLedCount = 0};
|
||||
pixled_param_t const dummyPixledParam = {.mode = 0, .chanLedCount = 0};
|
||||
auton_param_t const dummyAutonParam = {
|
||||
.sensitivity = 10, .gravity = 80, .pattern = 1, .isHueAutoShiftEnabled = true};
|
||||
.sensitivity = 10, .gravity = 80, .pattern = 0, .isHueAutoShiftEnabled = true};
|
||||
ledbar_param_t const dummyLedbarParam = {.sensitivity = 1.,
|
||||
.hueBase = 121,
|
||||
.hueInterval = -100,
|
||||
@ -40,6 +44,8 @@ ledbar_param_t const dummyLedbarParam = {.sensitivity = 1.,
|
||||
|
||||
param_t param;
|
||||
|
||||
pthread_mutex_t paramLockMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/***************************************************************************************************
|
||||
* Internal Function Prototypes
|
||||
**************************************************************************************************/
|
||||
@ -57,10 +63,22 @@ void param_setup() {
|
||||
param_access = ¶m;
|
||||
}
|
||||
|
||||
void set_mode(unsigned int mode) {
|
||||
if (mode != param.pixled.mode) {
|
||||
pthread_mutex_lock(¶mLockMutex);
|
||||
param.pixled.mode = mode;
|
||||
log_debug("Mode : %d", mode);
|
||||
websocket_send_mode(mode);
|
||||
pthread_mutex_unlock(¶mLockMutex);
|
||||
}
|
||||
}
|
||||
|
||||
void set_pattern(unsigned int pattern) {
|
||||
if (pattern != param.auton.pattern) {
|
||||
pthread_mutex_lock(¶mLockMutex);
|
||||
param.auton.pattern = pattern;
|
||||
log_debug("Pattern : %d", pattern);
|
||||
pthread_mutex_unlock(¶mLockMutex);
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int mode;
|
||||
unsigned int chanLedCount;
|
||||
} pixled_param_t;
|
||||
|
||||
@ -91,6 +92,13 @@ param_t *param_access;
|
||||
*/
|
||||
void param_setup();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in] mode
|
||||
*/
|
||||
void set_mode(unsigned int mode);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
@ -93,7 +93,6 @@ void bounce_led_and_color(uint16_t *spectrumArray, unsigned int spectrumLength)
|
||||
|
||||
increment_autoshift(ledBarIndex);
|
||||
}
|
||||
|
||||
leddriver_refresh();
|
||||
}
|
||||
|
11
RpiLedBars/backend/src/tasks/CMakeLists.txt
Normal file
11
RpiLedBars/backend/src/tasks/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# add the executable
|
||||
add_library(${PROJECT_NAME}_tasks
|
||||
artnet/artnet.c
|
||||
cava/cava.c
|
||||
selector/selector.c
|
||||
websocket/websocket.c)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}_tasks PRIVATE pthread)
|
||||
target_link_libraries(${PROJECT_NAME}_tasks PRIVATE logc ws)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}_tasks PUBLIC includes)
|
@ -7,7 +7,7 @@
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
**************************************************************************************************/
|
||||
#include "rpi_artnet.h"
|
||||
#include "artnet.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
@ -20,8 +20,9 @@
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "artnet_packets.h"
|
||||
#include "artnet_utils.h"
|
||||
#include "log.h"
|
||||
#include "rpi_artnet_utils.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
* Preprocessor Constants and Macros
|
@ -3,8 +3,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rpi_artnet_op_codes.h"
|
||||
#include "rpi_artnet_utils.h"
|
||||
#include "artnet_op_codes.h"
|
||||
#include "artnet_utils.h"
|
||||
|
||||
typedef struct {
|
||||
char id[8];
|
@ -5,7 +5,7 @@
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
**************************************************************************************************/
|
||||
#include "rpi_cava.h"
|
||||
#include "cava.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
@ -1,16 +1,16 @@
|
||||
/** @file rpi_artnet.h
|
||||
/** @file artnet.h
|
||||
* @brief This module contains continuous tasks for artnet node communications.
|
||||
*
|
||||
* This is the header file for the definition of services to allow managing thread acting as artnet
|
||||
* node.
|
||||
*/
|
||||
#if !defined(__RPI_ARTNET_H__)
|
||||
#define __RPI_ARTNET_H__
|
||||
#if !defined(__ARTNET_H__)
|
||||
#define __ARTNET_H__
|
||||
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
**************************************************************************************************/
|
||||
#include "rpi_artnet_packets.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/***************************************************************************************************
|
||||
* Preprocessor Constants and Macros
|
||||
@ -47,4 +47,4 @@ void artnet_stop();
|
||||
*/
|
||||
int artnet_get_dmx_data(unsigned int univerve, uint8_t *dmxData[]);
|
||||
|
||||
#endif /* __RPI_ARTNET_H__ */
|
||||
#endif /* __ARTNET_H__ */
|
@ -1,8 +1,8 @@
|
||||
/** @file rpi_cava.h
|
||||
/** @file cava.h
|
||||
* @brief This module contains continuous tasks for cava (spectrum analyzer) comunication
|
||||
*/
|
||||
#if !defined(__RPI_CAVA_H__)
|
||||
#define __RPI_CAVA_H__
|
||||
#if !defined(__CAVA_H__)
|
||||
#define __CAVA_H__
|
||||
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
@ -28,17 +28,10 @@
|
||||
* External Function Prototypes
|
||||
**************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Start artnet node module
|
||||
**/
|
||||
void setup_cava();
|
||||
|
||||
int cava_get_buffer(uint16_t **buffer_dst);
|
||||
|
||||
void close_cava();
|
||||
|
||||
void cava_start();
|
||||
|
||||
void cava_stop();
|
||||
|
||||
#endif /* __RPI_CAVA_H__ */
|
||||
#endif /* __CAVA_H__ */
|
34
RpiLedBars/backend/src/tasks/includes/selector.h
Normal file
34
RpiLedBars/backend/src/tasks/includes/selector.h
Normal file
@ -0,0 +1,34 @@
|
||||
/** @file selector.h
|
||||
* @brief This module contains continuous tasks for cava (spectrum analyzer) comunication
|
||||
*/
|
||||
#if !defined(__SELECTOR_TASK_H__)
|
||||
#define __SELECTOR_TASK_H__
|
||||
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
**************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
* Preprocessor Constants and Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
* Type and Contant Definitions
|
||||
**************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
* Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
* External Function Prototypes
|
||||
**************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Start selector listener module
|
||||
**/
|
||||
void selector_start();
|
||||
|
||||
void selector_stop();
|
||||
|
||||
#endif /* __SELECTOR_TASK_H__ */
|
@ -1,9 +1,9 @@
|
||||
/** @file rpi_websocket..h
|
||||
/** @file websocket.h
|
||||
* @brief This module
|
||||
*/
|
||||
|
||||
#if !defined(__RPI_WEBSOCKET_H__)
|
||||
#define __RPI_WEBSOCKET_H__
|
||||
#if !defined(__WEBSOCKET_H__)
|
||||
#define __WEBSOCKET_H__
|
||||
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
@ -30,4 +30,14 @@
|
||||
**/
|
||||
void websocket_start();
|
||||
|
||||
#endif /* __RPI_WEBSOCKET_H__ */
|
||||
/**
|
||||
* @brief Start websocket module
|
||||
**/
|
||||
void websocket_stop();
|
||||
|
||||
/**
|
||||
* @brief Send mode to websocket client
|
||||
**/
|
||||
void websocket_send_mode(int mode);
|
||||
|
||||
#endif /* __WEBSOCKET_H__ */
|
87
RpiLedBars/backend/src/tasks/selector/selector.c
Normal file
87
RpiLedBars/backend/src/tasks/selector/selector.c
Normal file
@ -0,0 +1,87 @@
|
||||
/** @file selector.c
|
||||
* @brief This module contains continuous tasks for cava (spectrum analyzer) comunication
|
||||
*/
|
||||
|
||||
/***************************************************************************************************
|
||||
* Includes
|
||||
**************************************************************************************************/
|
||||
#include "selector.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../drivers/selector/rpi_selector.h"
|
||||
#include "../../rpi_param.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
* Preprocessor Constants and Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
#define LISTENER_INTERVAL 500000
|
||||
|
||||
/***************************************************************************************************
|
||||
* Type and Contant Definitions
|
||||
**************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
* Persistent Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
pthread_t selectorListener;
|
||||
/**
|
||||
* Boolean for interrupting the main thread loop
|
||||
*/
|
||||
bool isSelectorListenerRunning = false;
|
||||
|
||||
/***************************************************************************************************
|
||||
* Internal Function Prototypes
|
||||
**************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function is used to thread main execution function
|
||||
*
|
||||
* @param arg not used.
|
||||
*
|
||||
* @return NULL.
|
||||
*/
|
||||
static void *listen_to_selector(void *arg);
|
||||
|
||||
/***************************************************************************************************
|
||||
* External Function Definitions
|
||||
**************************************************************************************************/
|
||||
|
||||
void selector_start() {
|
||||
isSelectorListenerRunning = true;
|
||||
pthread_create(&selectorListener, NULL, listen_to_selector, NULL);
|
||||
}
|
||||
|
||||
void selector_stop() {
|
||||
isSelectorListenerRunning = false;
|
||||
if (pthread_join(selectorListener, NULL) != 0) {
|
||||
log_error("pthread_join: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* Internal Function Definitions
|
||||
**************************************************************************************************/
|
||||
|
||||
static void *listen_to_selector(void *arg) {
|
||||
int previousPosition;
|
||||
selector_setup();
|
||||
|
||||
while (isSelectorListenerRunning) {
|
||||
int newPosition = selector_get_position();
|
||||
if (newPosition != -1 && newPosition != previousPosition) {
|
||||
set_mode(newPosition);
|
||||
previousPosition = newPosition;
|
||||
}
|
||||
usleep(LISTENER_INTERVAL);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/** @file rpi_websocket..c
|
||||
/** @file websocket.c
|
||||
* @brief This module
|
||||
*/
|
||||
|
||||
@ -6,14 +6,15 @@
|
||||
* Includes
|
||||
**************************************************************************************************/
|
||||
|
||||
#include "rpi_websocket.h"
|
||||
#include "websocket.h"
|
||||
|
||||
#include <log.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ws.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "ws.h"
|
||||
|
||||
#include "../../rpi_param.h"
|
||||
|
||||
@ -31,7 +32,7 @@
|
||||
* Persistent Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
char *tokenArray[MAX_TOKEN] = {NULL};
|
||||
int client_fd = -1;
|
||||
|
||||
/***************************************************************************************************
|
||||
* Internal Function Prototypes
|
||||
@ -70,6 +71,12 @@ void onclose(int fd);
|
||||
*/
|
||||
void onmessage(int fd, const unsigned char *msg, uint64_t size, int type);
|
||||
|
||||
void mode_command_handler(char *payload);
|
||||
|
||||
void pattern_command_handler(char *payload);
|
||||
|
||||
void color_command_handler(char *payload);
|
||||
|
||||
/***************************************************************************************************
|
||||
* External Function Definitions
|
||||
**************************************************************************************************/
|
||||
@ -84,6 +91,15 @@ void websocket_start() {
|
||||
|
||||
void websocket_stop() {}
|
||||
|
||||
void websocket_send_mode(int mode) {
|
||||
char msg[] = "m:0";
|
||||
msg[2] = '0' + mode;
|
||||
if (client_fd != -1) {
|
||||
log_debug("Sending mode \"%s\"", msg);
|
||||
ws_sendframe_txt(client_fd, msg, true);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* Internal Function Definitions
|
||||
**************************************************************************************************/
|
||||
@ -93,6 +109,7 @@ void onopen(int fd) {
|
||||
cli = ws_getaddress(fd);
|
||||
log_debug("Connection opened, client: %d | addr: %s", fd, cli);
|
||||
free(cli);
|
||||
client_fd = fd;
|
||||
}
|
||||
|
||||
void onclose(int fd) {
|
||||
@ -100,20 +117,68 @@ void onclose(int fd) {
|
||||
cli = ws_getaddress(fd);
|
||||
log_debug("Connection closed, client: %d | addr: %s", fd, cli);
|
||||
free(cli);
|
||||
client_fd = -1;
|
||||
}
|
||||
|
||||
void onmessage(int fd, const unsigned char *msg, uint64_t size, int type) {
|
||||
char msgStr[size];
|
||||
char *cli;
|
||||
cli = ws_getaddress(fd);
|
||||
char msgStr[size + 1];
|
||||
char *command, *payload;
|
||||
char *cli = ws_getaddress(fd);
|
||||
log_trace("Received message: %s (size: %" PRId64 ", type: %d), from: %s/%d", msg, size, type, cli,
|
||||
fd);
|
||||
|
||||
if (msg[0] == '{' && msg[size - 1] == '}') {
|
||||
strcpy(msgStr, (char *)msg);
|
||||
command = strtok(msgStr, ":");
|
||||
if (command != NULL) {
|
||||
payload = strtok(NULL, ":");
|
||||
if (payload != NULL && strlen(command) == 1) {
|
||||
switch (command[0]) {
|
||||
case 'm':
|
||||
mode_command_handler(payload);
|
||||
break;
|
||||
case 'p':
|
||||
pattern_command_handler(payload);
|
||||
break;
|
||||
case 'c':
|
||||
color_command_handler(payload);
|
||||
break;
|
||||
|
||||
default:
|
||||
log_warn("Unkown command in \"%s\"", msgStr);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log_warn("Empty payload in \"%s\"", msgStr);
|
||||
}
|
||||
} else {
|
||||
log_warn("No command found in \"%s\"", msgStr);
|
||||
}
|
||||
|
||||
free(cli);
|
||||
}
|
||||
|
||||
void mode_command_handler(char *payload) {
|
||||
int newMode = atoi(payload);
|
||||
if (0 <= newMode && newMode <= 3) {
|
||||
set_mode(newMode);
|
||||
} else {
|
||||
log_warn("Unknown mode : %s", payload);
|
||||
}
|
||||
}
|
||||
|
||||
void pattern_command_handler(char *payload) {
|
||||
int newPattern = atoi(payload);
|
||||
if (0 <= newPattern && newPattern <= 3) {
|
||||
set_pattern(newPattern);
|
||||
} else {
|
||||
log_warn("Unknown pattern : %s", payload);
|
||||
}
|
||||
}
|
||||
|
||||
void color_command_handler(char *payload) {
|
||||
int i = 0;
|
||||
memcpy(msgStr, msg + 1, size - 2);
|
||||
msgStr[size - 2] = '\0';
|
||||
tokenArray[i] = strtok(msgStr, ",");
|
||||
char *tokenArray[MAX_TOKEN] = {NULL};
|
||||
tokenArray[i] = strtok(payload, ",");
|
||||
while (tokenArray[i] && i < MAX_TOKEN - 1) {
|
||||
tokenArray[++i] = strtok(NULL, ",");
|
||||
}
|
||||
@ -125,15 +190,5 @@ void onmessage(int fd, const unsigned char *msg, uint64_t size, int type) {
|
||||
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);
|
||||
} else if (atoi(tokenArray[0]) == 1) {
|
||||
/* code */
|
||||
} else {
|
||||
/* code */
|
||||
}
|
||||
} else {
|
||||
log_warn("Invalid json format: %s (size: %" PRId64 ", type: %d), from: %s/%d", msg, size, type,
|
||||
cli, fd);
|
||||
}
|
||||
|
||||
free(cli);
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit 1b7c395bac21877bfb18db8378559e10f8661b32
|
||||
Subproject commit 4c0acb788535beac6b3c142d5a8abc9aee4cf93e
|
@ -1 +0,0 @@
|
||||
Subproject commit f9ea34994bd58ed342d2245cd4110bb5c6790153
|
@ -1 +0,0 @@
|
||||
Subproject commit db03ae8487cca3d2919a96af920eb65653d9da99
|
Loading…
Reference in New Issue
Block a user