update and test with rpi zero 2
This commit is contained in:
		@@ -137,40 +137,48 @@ int main(int argc, char const *argv[]) {
 | 
			
		||||
 **************************************************************************************************/
 | 
			
		||||
 | 
			
		||||
void parseCommandLineArgs(int argc, char const *argv[]) {
 | 
			
		||||
  int args = 0;
 | 
			
		||||
  int argIt = 0;
 | 
			
		||||
 | 
			
		||||
  while (argc > ++args) // Process command-line args
 | 
			
		||||
  while (argc > ++argIt) // Process command-line args
 | 
			
		||||
  {
 | 
			
		||||
    if (argv[args][0] == '-') {
 | 
			
		||||
      switch (toupper(argv[args][1])) {
 | 
			
		||||
    if (argv[argIt][0] == '-' && argv[argIt][2] == '\0') {
 | 
			
		||||
      switch (toupper(argv[argIt][1])) {
 | 
			
		||||
      case 'N': // -N: number of LEDs per channel
 | 
			
		||||
        if (args >= argc - 1) {
 | 
			
		||||
        if (argIt >= argc - 1) {
 | 
			
		||||
          log_error("no numeric value");
 | 
			
		||||
          exit(-EXIT_FAILURE);
 | 
			
		||||
        } else {
 | 
			
		||||
          param_access->pixled.chanLedCount = atoi(argv[++args]);
 | 
			
		||||
          int ledCount = atoi(argv[++argIt]);
 | 
			
		||||
          param_access->pixled.chanLedCount = ledCount <= CHAN_MAXLEDS ? ledCount : CHAN_MAXLEDS;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case 'D': // -D: debug level
 | 
			
		||||
        if (args >= argc - 1) {
 | 
			
		||||
        if (argIt >= argc - 1) {
 | 
			
		||||
          log_error("no debug level");
 | 
			
		||||
          exit(-EXIT_FAILURE);
 | 
			
		||||
        } else {
 | 
			
		||||
          logLevel = atoi(argv[++args]);
 | 
			
		||||
          logLevel = atoi(argv[++argIt]);
 | 
			
		||||
          log_set_level(logLevel);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case 'T': // -T: test mode
 | 
			
		||||
        IsTestMode = true;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      default: // Otherwise error
 | 
			
		||||
        log_error("Unrecognised option '%c'\n", argv[args][1]);
 | 
			
		||||
        fprintf(stderr, "Options:\n"
 | 
			
		||||
                        "  -t        Test mode (flash LEDs)\n"
 | 
			
		||||
                        "  -n num    number of LEDs per channel\n"
 | 
			
		||||
                        "  -d lvl    debug level\n");
 | 
			
		||||
        log_error("Unknown option '%c'\n", argv[argIt][1]);
 | 
			
		||||
        fprintf(stderr,
 | 
			
		||||
                "Options:\n"
 | 
			
		||||
                "  -t        Test mode (flash LEDs)\n"
 | 
			
		||||
                "  -n num    number of LEDs per channel (max : %d)\n"
 | 
			
		||||
                "  -d lvl    debug level\n",
 | 
			
		||||
                CHAN_MAXLEDS);
 | 
			
		||||
        exit(-EXIT_FAILURE);
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      log_warn("Unknown option '%s'\n", argv[argIt]);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -288,10 +296,10 @@ void execute_autonomous_mode() {
 | 
			
		||||
  if ((ret = cava_get_buffer(&buffer)) == 0) {
 | 
			
		||||
    switch (param_access->auton.pattern) {
 | 
			
		||||
    case 0:
 | 
			
		||||
      bounce_led_and_color(buffer, CAVA_BAR_NUMBER);
 | 
			
		||||
      bounce_led(buffer, CAVA_BAR_NUMBER);
 | 
			
		||||
      break;
 | 
			
		||||
    case 1:
 | 
			
		||||
      bounce_led(buffer, CAVA_BAR_NUMBER);
 | 
			
		||||
      bounce_led_and_color(buffer, CAVA_BAR_NUMBER);
 | 
			
		||||
      break;
 | 
			
		||||
    case 2:
 | 
			
		||||
      bounce_led_and_travel(buffer, CAVA_BAR_NUMBER);
 | 
			
		||||
 
 | 
			
		||||
@@ -43,6 +43,7 @@ ledbar_param_t const dummyLedbarParam = {.sensitivity = 1.,
 | 
			
		||||
 **************************************************************************************************/
 | 
			
		||||
 | 
			
		||||
param_t param;
 | 
			
		||||
param_t *param_access = NULL;
 | 
			
		||||
 | 
			
		||||
pthread_mutex_t paramLockMutex = PTHREAD_MUTEX_INITIALIZER;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,10 @@ typedef struct {
 | 
			
		||||
} auton_param_t;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @var ledbar_param_t::sensitivity
 | 
			
		||||
 *  sensitivity of the led bar
 | 
			
		||||
 */
 | 
			
		||||
typedef struct {
 | 
			
		||||
  float sensitivity;
 | 
			
		||||
@@ -81,7 +84,7 @@ typedef struct {
 | 
			
		||||
 * Global Variables
 | 
			
		||||
 **************************************************************************************************/
 | 
			
		||||
 | 
			
		||||
param_t *param_access;
 | 
			
		||||
extern param_t *param_access;
 | 
			
		||||
 | 
			
		||||
/***************************************************************************************************
 | 
			
		||||
 * External Function Prototypes
 | 
			
		||||
@@ -89,56 +92,92 @@ param_t *param_access;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
void param_setup();
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 * @brief Set the mode object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] mode
 | 
			
		||||
 */
 | 
			
		||||
void set_mode(unsigned int mode);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 * @brief Set the pattern object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] pattern
 | 
			
		||||
 */
 | 
			
		||||
void set_pattern(unsigned int pattern);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 * @brief Set the hue auto shift object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] HasToBeEnabled
 | 
			
		||||
 */
 | 
			
		||||
void set_hue_auto_shift(bool HasToBeEnabled);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 * @brief Set the gravity object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] gravity8
 | 
			
		||||
 */
 | 
			
		||||
void set_gravity(int8_t gravity8);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 * @brief Set the sensitivity object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] channel
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] sensitivity8
 | 
			
		||||
 */
 | 
			
		||||
void set_sensitivity(int channel, int8_t sensitivity8);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set the hue base object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] channel
 | 
			
		||||
 * @param[in] hueBase8
 | 
			
		||||
 */
 | 
			
		||||
void set_hue_base(int channel, int8_t hueBase8);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set the hue interval object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] channel
 | 
			
		||||
 * @param[in] hueInterval8
 | 
			
		||||
 */
 | 
			
		||||
void set_hue_interval(int channel, int8_t hueInterval8);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set the hue auto shift interval object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] channel
 | 
			
		||||
 * @param[in] hueInterval8
 | 
			
		||||
 */
 | 
			
		||||
void set_hue_auto_shift_interval(int channel, int8_t hueInterval8);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set the hue auto shift speed object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] channel
 | 
			
		||||
 * @param[in] hueSpeed8
 | 
			
		||||
 */
 | 
			
		||||
void set_hue_auto_shift_speed(int channel, int8_t hueSpeed8);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set the luminosity object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] channel
 | 
			
		||||
 * @param[in] luminosity8
 | 
			
		||||
 */
 | 
			
		||||
void set_luminosity(int channel, int8_t luminosity8);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set the saturation object
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] channel
 | 
			
		||||
 * @param[in] saturation8
 | 
			
		||||
 */
 | 
			
		||||
void set_saturation(int channel, int8_t saturation8);
 | 
			
		||||
 | 
			
		||||
#endif /* __RPI_PARAM_H__ */
 | 
			
		||||
@@ -51,51 +51,64 @@ int baseLedIndexArray[LED_NCHANS];
 | 
			
		||||
 * Internal Function Prototypes
 | 
			
		||||
 **************************************************************************************************/
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Get the max on interval object
 | 
			
		||||
 * 
 | 
			
		||||
 * @param array 
 | 
			
		||||
 * @param length 
 | 
			
		||||
 * @param intervalMin 
 | 
			
		||||
 * @param intervalSize 
 | 
			
		||||
 * @return uint16_t 
 | 
			
		||||
 */
 | 
			
		||||
uint16_t get_max_on_interval(uint16_t *array, unsigned int length, size_t intervalMin,
 | 
			
		||||
                             size_t intervalSize);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief 
 | 
			
		||||
 * 
 | 
			
		||||
 * @param value 
 | 
			
		||||
 * @param valueIndex 
 | 
			
		||||
 * @return uint16_t 
 | 
			
		||||
 */
 | 
			
		||||
uint16_t apply_sensitivity(uint16_t value, unsigned int valueIndex);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Get the led to light count object
 | 
			
		||||
 * 
 | 
			
		||||
 * @param barValue 
 | 
			
		||||
 * @param barIndex 
 | 
			
		||||
 * @return unsigned int 
 | 
			
		||||
 */
 | 
			
		||||
unsigned int get_led_to_light_count(uint16_t barValue, unsigned int barIndex);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Get the first led to light object
 | 
			
		||||
 * 
 | 
			
		||||
 * @param barIndex 
 | 
			
		||||
 * @return unsigned int 
 | 
			
		||||
 */
 | 
			
		||||
unsigned int get_first_led_to_light(unsigned int barIndex);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Get the hsv color object
 | 
			
		||||
 * 
 | 
			
		||||
 * @param barIndex 
 | 
			
		||||
 * @param shiftRatio 
 | 
			
		||||
 * @return uint32_t 
 | 
			
		||||
 */
 | 
			
		||||
uint32_t get_hsv_color(unsigned int barIndex, float shiftRatio);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief 
 | 
			
		||||
 * 
 | 
			
		||||
 * @param barIndex 
 | 
			
		||||
 */
 | 
			
		||||
void increment_autoshift(unsigned int barIndex);
 | 
			
		||||
 | 
			
		||||
/***************************************************************************************************
 | 
			
		||||
 * External Function Definitions
 | 
			
		||||
 **************************************************************************************************/
 | 
			
		||||
 | 
			
		||||
void bounce_led_and_color(uint16_t *spectrumArray, unsigned int spectrumLength) {
 | 
			
		||||
  for (size_t ledBarIndex = 0; ledBarIndex < LED_NCHANS; ++ledBarIndex) {
 | 
			
		||||
    size_t intervalSize = spectrumLength / LED_NCHANS;
 | 
			
		||||
    uint16_t barMax = 0;
 | 
			
		||||
    unsigned int ledToLightCount = 0;
 | 
			
		||||
 | 
			
		||||
    barMax = get_max_on_interval(spectrumArray, spectrumLength, ledBarIndex * intervalSize,
 | 
			
		||||
                                 intervalSize);
 | 
			
		||||
    barMax = apply_sensitivity(barMax, ledBarIndex);
 | 
			
		||||
    ledToLightCount = get_led_to_light_count(barMax, ledBarIndex);
 | 
			
		||||
 | 
			
		||||
    uint32_t color = get_hsv_color(ledBarIndex, (ledToLightCount - 1) /
 | 
			
		||||
                                                    (float)param_access->pixled.chanLedCount);
 | 
			
		||||
 | 
			
		||||
    for (size_t i = 0; i < ledToLightCount; ++i) {
 | 
			
		||||
      rgbData[i][ledBarIndex] = color;
 | 
			
		||||
      rgb_txdata(rgbData[i], i);
 | 
			
		||||
    }
 | 
			
		||||
    for (size_t i = ledToLightCount; i < param_access->pixled.chanLedCount; ++i) {
 | 
			
		||||
      rgbData[i][ledBarIndex] = 0x000000;
 | 
			
		||||
      rgb_txdata(rgbData[i], i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    increment_autoshift(ledBarIndex);
 | 
			
		||||
  }
 | 
			
		||||
  leddriver_refresh();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void bounce_led(uint16_t *spectrumArray, unsigned int spectrumLength) {
 | 
			
		||||
  for (size_t ledBarIndex = 0; ledBarIndex < LED_NCHANS; ++ledBarIndex) {
 | 
			
		||||
    size_t intervalSize = spectrumLength / LED_NCHANS;
 | 
			
		||||
@@ -124,6 +137,34 @@ void bounce_led(uint16_t *spectrumArray, unsigned int spectrumLength) {
 | 
			
		||||
  leddriver_refresh();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void bounce_led_and_color(uint16_t *spectrumArray, unsigned int spectrumLength) {
 | 
			
		||||
  for (size_t ledBarIndex = 0; ledBarIndex < LED_NCHANS; ++ledBarIndex) {
 | 
			
		||||
    size_t intervalSize = spectrumLength / LED_NCHANS;
 | 
			
		||||
    uint16_t barMax = 0;
 | 
			
		||||
    unsigned int ledToLightCount = 0;
 | 
			
		||||
 | 
			
		||||
    barMax = get_max_on_interval(spectrumArray, spectrumLength, ledBarIndex * intervalSize,
 | 
			
		||||
                                 intervalSize);
 | 
			
		||||
    barMax = apply_sensitivity(barMax, ledBarIndex);
 | 
			
		||||
    ledToLightCount = get_led_to_light_count(barMax, ledBarIndex);
 | 
			
		||||
 | 
			
		||||
    uint32_t color = get_hsv_color(ledBarIndex, (ledToLightCount - 1) /
 | 
			
		||||
                                                    (float)param_access->pixled.chanLedCount);
 | 
			
		||||
 | 
			
		||||
    for (size_t i = 0; i < ledToLightCount; ++i) {
 | 
			
		||||
      rgbData[i][ledBarIndex] = color;
 | 
			
		||||
      rgb_txdata(rgbData[i], i);
 | 
			
		||||
    }
 | 
			
		||||
    for (size_t i = ledToLightCount; i < param_access->pixled.chanLedCount; ++i) {
 | 
			
		||||
      rgbData[i][ledBarIndex] = 0x000000;
 | 
			
		||||
      rgb_txdata(rgbData[i], i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    increment_autoshift(ledBarIndex);
 | 
			
		||||
  }
 | 
			
		||||
  leddriver_refresh();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void bounce_led_and_travel(uint16_t *spectrumArray, unsigned int spectrumLength) {
 | 
			
		||||
  for (size_t ledBarIndex = 0; ledBarIndex < LED_NCHANS; ++ledBarIndex) {
 | 
			
		||||
    size_t intervalSize = spectrumLength / LED_NCHANS;
 | 
			
		||||
 
 | 
			
		||||
@@ -31,16 +31,6 @@
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] spectrumArray array of value from spectral analysis
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] spectrumLength length of spectrum array
 | 
			
		||||
 */
 | 
			
		||||
void bounce_led_and_color(uint16_t *spectrumArray, unsigned int spectrumLength);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] spectrumArray array of value from spectral analysis
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] spectrumLength length of spectrum array
 | 
			
		||||
 */
 | 
			
		||||
void bounce_led(uint16_t *spectrumArray, unsigned int spectrumLength);
 | 
			
		||||
@@ -49,7 +39,14 @@ void bounce_led(uint16_t *spectrumArray, unsigned int spectrumLength);
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] spectrumArray array of value from spectral analysis
 | 
			
		||||
 * @param[in] spectrumLength length of spectrum array
 | 
			
		||||
 */
 | 
			
		||||
void bounce_led_and_color(uint16_t *spectrumArray, unsigned int spectrumLength);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] spectrumArray array of value from spectral analysis
 | 
			
		||||
 * @param[in] spectrumLength length of spectrum array
 | 
			
		||||
 */
 | 
			
		||||
void bounce_led_and_travel(uint16_t *spectrumArray, unsigned int spectrumLength);
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,7 @@
 | 
			
		||||
 | 
			
		||||
int client_fd = -1;
 | 
			
		||||
 | 
			
		||||
int channel = LED_NCHANS;
 | 
			
		||||
int current_channel = LED_NCHANS;
 | 
			
		||||
 | 
			
		||||
/***************************************************************************************************
 | 
			
		||||
 * Internal Function Prototypes
 | 
			
		||||
@@ -73,18 +73,74 @@ void onclose(int fd);
 | 
			
		||||
 */
 | 
			
		||||
void onmessage(int fd, const unsigned char *msg, uint64_t size, int type);
 | 
			
		||||
 | 
			
		||||
void mode_command_handler(char *payload);
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void mode_command_handler(const char *payload);
 | 
			
		||||
 | 
			
		||||
void pattern_command_handler(char *payload);
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void pattern_command_handler(const char *payload);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void color_command_handler(char *payload);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void hue_interval_command_handler(char *payload);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void modulate_command_handler(char *payload);
 | 
			
		||||
 | 
			
		||||
void channel_command_handler(char *payload);
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void modulation_interval_command_handler(char *payload);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void modulation_speed_command_handler(char *payload);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void channel_command_handler(const char *payload);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void sensitivity_command_handler(char *payload);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief
 | 
			
		||||
 *
 | 
			
		||||
 * @param payload
 | 
			
		||||
 */
 | 
			
		||||
void gravity_command_handler(char *payload);
 | 
			
		||||
 | 
			
		||||
/***************************************************************************************************
 | 
			
		||||
@@ -130,45 +186,65 @@ void onclose(int fd) {
 | 
			
		||||
  client_fd = -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define FOREACH_CMD(FNCT)                                                                          \
 | 
			
		||||
  FNCT(mode)                                                                                       \
 | 
			
		||||
  FNCT(pattern)                                                                                    \
 | 
			
		||||
  FNCT(channel)
 | 
			
		||||
 | 
			
		||||
#define GENERATE_SWITCH(CASE)                                                                      \
 | 
			
		||||
  if (!strcmp(command, #CASE)) {                                                                   \
 | 
			
		||||
    CASE##_command_handler(payload);                                                               \
 | 
			
		||||
  } else
 | 
			
		||||
 | 
			
		||||
void onmessage(int fd, const unsigned char *msg, uint64_t size, int type) {
 | 
			
		||||
  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);
 | 
			
		||||
 | 
			
		||||
  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;
 | 
			
		||||
      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;
 | 
			
		||||
    if (payload != NULL) {
 | 
			
		||||
 | 
			
		||||
      default:
 | 
			
		||||
        log_warn("Unkown command in \"%s\"", msgStr);
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      FOREACH_CMD(GENERATE_SWITCH) log_warn("Unkown command %s in \"%s\"", command, msg);
 | 
			
		||||
      // switch (command[0]) {
 | 
			
		||||
      // case 'm':
 | 
			
		||||
      //   mode_command_handler(payload);
 | 
			
		||||
      //   break;
 | 
			
		||||
      // case 'p':
 | 
			
		||||
      //   pattern_command_handler(payload);
 | 
			
		||||
      //   break;
 | 
			
		||||
      // case 'i':
 | 
			
		||||
      //   hue_interval_command_handler(payload);
 | 
			
		||||
      //   break;
 | 
			
		||||
      // case 'c':
 | 
			
		||||
      //   color_command_handler(payload);
 | 
			
		||||
      //   break;
 | 
			
		||||
      // case 's':
 | 
			
		||||
      //   modulate_command_handler(payload);
 | 
			
		||||
      //   break;
 | 
			
		||||
      // case 't':
 | 
			
		||||
      //   modulation_interval_command_handler(payload);
 | 
			
		||||
      //   break;
 | 
			
		||||
      // case 'u':
 | 
			
		||||
      //   modulation_speed_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);
 | 
			
		||||
      //   break;
 | 
			
		||||
      // }
 | 
			
		||||
    } else {
 | 
			
		||||
      log_warn("Empty payload in \"%s\"", msgStr);
 | 
			
		||||
    }
 | 
			
		||||
@@ -179,7 +255,7 @@ void onmessage(int fd, const unsigned char *msg, uint64_t size, int type) {
 | 
			
		||||
  free(cli);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mode_command_handler(char *payload) {
 | 
			
		||||
void mode_command_handler(const char *payload) {
 | 
			
		||||
  int newMode = atoi(payload);
 | 
			
		||||
  if (0 <= newMode && newMode <= 3) {
 | 
			
		||||
    set_mode(newMode);
 | 
			
		||||
@@ -188,7 +264,7 @@ void mode_command_handler(char *payload) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pattern_command_handler(char *payload) {
 | 
			
		||||
void pattern_command_handler(const char *payload) {
 | 
			
		||||
  int newPattern = atoi(payload);
 | 
			
		||||
  if (0 <= newPattern && newPattern <= 3) {
 | 
			
		||||
    set_pattern(newPattern);
 | 
			
		||||
@@ -209,33 +285,46 @@ void color_command_handler(char *payload) {
 | 
			
		||||
    log_debug(" - %s", tokenArray[n]);
 | 
			
		||||
  }
 | 
			
		||||
  if (atoi(tokenArray[0]) == 0) {
 | 
			
		||||
    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);
 | 
			
		||||
    set_hue_base(current_channel, atoi(tokenArray[1]) * INT8_MAX / HUE_MAX);
 | 
			
		||||
    set_saturation(current_channel, atoi(tokenArray[2]) * INT8_MAX / 100);
 | 
			
		||||
    set_luminosity(current_channel, atoi(tokenArray[3]) * INT8_MAX / 100);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hue_interval_command_handler(char *payload) {
 | 
			
		||||
  int hueInterval = atoi(payload);
 | 
			
		||||
  log_debug("hueInterval: %d", hueInterval);
 | 
			
		||||
  set_hue_interval(current_channel, hueInterval);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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); 
 | 
			
		||||
  set_hue_auto_shift(modulate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void channel_command_handler(char *payload) {
 | 
			
		||||
void modulation_interval_command_handler(char *payload) {
 | 
			
		||||
  int modulationInterval = atoi(payload);
 | 
			
		||||
  set_hue_auto_shift_interval(8, modulationInterval);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void modulation_speed_command_handler(char *payload) {
 | 
			
		||||
  int modulationSpeed = atoi(payload);
 | 
			
		||||
  set_hue_auto_shift_speed(8, modulationSpeed);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void channel_command_handler(const char *payload) {
 | 
			
		||||
  int newChannel = atoi(payload);
 | 
			
		||||
  if (0 <= newChannel && newChannel <= LED_NCHANS) {
 | 
			
		||||
    log_debug("Channel: %d", newChannel);
 | 
			
		||||
    channel = newChannel;
 | 
			
		||||
    current_channel = newChannel;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sensitivity_command_handler(char *payload) {
 | 
			
		||||
  int newSensitivity = atoi(payload);
 | 
			
		||||
  set_sensitivity(channel, newSensitivity);
 | 
			
		||||
  set_sensitivity(current_channel, newSensitivity);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void gravity_command_handler(char *payload) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user