#define RGB_TO_REGISTER(val) ((unsigned)((float)val / 255.0f * 4095u))
-static inline void _led_bi_set(bi_led_color_e color)
+static inline void _led_bi_set(bi_led_color_e color, bool store_current_color)
{
int red;
int green;
return;
}
+// if (color == s_info.current_color) {
+// _D("No change in bi led");
+// return;
+// }
+
+ if (store_current_color) {
+ s_info.current_color = color;
+ }
+
switch (color) {
case LED_COLOR_RED:
red = 1;
_D("BI: [%d, %d]", red, green);
}
-static inline void _rgb_gpio_set(bool red, bool green, bool blue)
+static inline void _rgb_gpio_set(bool red, bool green, bool blue, bool store_current_color)
{
if (!s_info.use_rgb_gpio) {
_D("gpio rgb led is turned OFF");
return;
}
+// if (red == s_info.current_rgb_gpio_color[0] &&
+// green == s_info.current_rgb_gpio_color[1] &&
+// blue == s_info.current_rgb_gpio_color[2]) {
+// _D("No change in gpio led");
+// return;
+// }
+
+ if (store_current_color) {
+ s_info.current_rgb_gpio_color[0] = red;
+ s_info.current_rgb_gpio_color[1] = green;
+ s_info.current_rgb_gpio_color[2] = blue;
+ }
_D("RGB GPIO: [%d, %d, %d]", red, green, blue);
int ret = peripheral_gpio_write(s_info.rgb_gpio[0], red);
ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
}
-static inline void _rgb_l2c_set(int red, int green, int blue)
+static inline void _rgb_l2c_set(int red, int green, int blue, bool store_current_color)
{
FUNCTION_START;
if (!s_info.use_rgb_l2c) {
return;
}
+// if (red == s_info.current_rgb_l2c_color[0] &&
+// green == s_info.current_rgb_l2c_color[1] &&
+// blue == s_info.current_rgb_l2c_color[2]) {
+// _D("No change in l2c led");
+// return;
+// }
+
+ if (store_current_color) {
+ s_info.current_rgb_l2c_color[0] = red;
+ s_info.current_rgb_l2c_color[1] = green;
+ s_info.current_rgb_l2c_color[2] = blue;
+ }
+
int ret = resource_pca9685_set_value_to_channel(DEFAULT_RGB_L2C_R, 0, RGB_TO_REGISTER(red));
ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
static gboolean _restore_bi_color_cb(gpointer data)
{
- _led_bi_set(s_info.current_color);
+ _led_bi_set(s_info.current_color, false);
return false;
}
static gboolean _restore_rgb_gpio_color_cb(gpointer data)
{
- _rgb_gpio_set(s_info.current_rgb_gpio_color[0], s_info.current_rgb_gpio_color[1], s_info.current_rgb_gpio_color[2]);
+ _rgb_gpio_set(s_info.current_rgb_gpio_color[0], s_info.current_rgb_gpio_color[1], s_info.current_rgb_gpio_color[2], false);
return false;
}
static gboolean _restore_rgb_l2c_color_cb(gpointer data)
{
FUNCTION_START;
- _rgb_l2c_set(s_info.current_rgb_l2c_color[0], s_info.current_rgb_l2c_color[1], s_info.current_rgb_l2c_color[2]);
+ _rgb_l2c_set(s_info.current_rgb_l2c_color[0], s_info.current_rgb_l2c_color[1], s_info.current_rgb_l2c_color[2], false);
FUNCTION_END;
return false;
}
peripheral_gpio_close(s_info.rgb_gpio[1]);
peripheral_gpio_close(s_info.rgb_gpio[2]);
- resource_led_rgb_l2c_set(0, 0, 0);
+ _rgb_l2c_set(0, 0, 0, true);
resource_pca9685_fini(DEFAULT_RGB_L2C_R);
resource_pca9685_fini(DEFAULT_RGB_L2C_G);
resource_pca9685_fini(DEFAULT_RGB_L2C_B);
}
-void resource_led_bi_set(bi_led_color_e color)
-{
- _D("Set led to: %d", color);
- if (color == s_info.current_color) {
- _D("No change in bi led");
- return;
- }
-
- s_info.current_color = color;
- _led_bi_set(color);
-}
-
-void resource_led_bi_blink(bi_led_color_e color, unsigned timeout)
-{
- if (color == s_info.current_color) {
- _D("No change in bi led");
- return;
- }
-
- _led_bi_set(color);
- g_timeout_add(timeout, _restore_bi_color_cb, NULL);
-}
-
-void resource_led_rgb_gpio_set(bool red, bool green, bool blue)
-{
- if (red == s_info.current_rgb_gpio_color[0] &&
- green == s_info.current_rgb_gpio_color[1] &&
- blue == s_info.current_rgb_gpio_color[2]) {
- _D("No change in gpio led");
- return;
- }
-
-
- s_info.current_rgb_gpio_color[0] = red;
- s_info.current_rgb_gpio_color[1] = green;
- s_info.current_rgb_gpio_color[2] = blue;
-
- _rgb_gpio_set(red, green, blue);
-}
-
-void resource_led_gpio_rgb_blink(bool red, bool green, bool blue, unsigned timeout)
-{
- if (red == s_info.current_rgb_gpio_color[0] &&
- green == s_info.current_rgb_gpio_color[1] &&
- blue == s_info.current_rgb_gpio_color[2]) {
- _D("No change in gpio led");
- return;
- }
-
- _rgb_gpio_set(red, green, blue);
- g_timeout_add(timeout, _restore_rgb_gpio_color_cb, NULL);
-}
-
-void resource_led_rgb_l2c_set(int red, int green, int blue)
-{
- if (red == s_info.current_rgb_l2c_color[0] &&
- green == s_info.current_rgb_l2c_color[1] &&
- blue == s_info.current_rgb_l2c_color[2]) {
- _D("No change in l2c led");
- return;
- }
-
- s_info.current_rgb_l2c_color[0] = red;
- s_info.current_rgb_l2c_color[1] = green;
- s_info.current_rgb_l2c_color[2] = blue;
-
- _rgb_l2c_set(red, green, blue);
-}
-
-void resource_led_rgb_l2c_blink(int red, int green, int blue, unsigned timeout)
-{
- if (red == s_info.current_rgb_l2c_color[0] &&
- green == s_info.current_rgb_l2c_color[1] &&
- blue == s_info.current_rgb_l2c_color[2]) {
- _D("No change in l2c led");
- return;
- }
-
- _rgb_l2c_set(red, green, blue);
- g_timeout_add(timeout, _restore_rgb_l2c_color_cb, NULL);
-}
-
-void resource_led_set_rgb_colors(char *key,
+static void _set_rgb(char *key, bool store_current,
int def_r_3bit, int def_g_3bit, int def_b_3bit,
int def_r_24bit, int def_g_24bit, int def_b_24bit,
bi_led_color_e bi_led)
{
- FUNCTION_START;
-
int red, green, blue;
char final_key[PATH_MAX];
snprintf(final_key, PATH_MAX, "3bit.%s", key);
bool modified = config_get_rgb_with_default("Rpi.led", final_key, def_r_3bit, def_g_3bit, def_b_3bit, &red, &green, &blue);
- resource_led_rgb_gpio_set(red, green, blue);
-
- _D("%s: 3bit color: [%d, %d, %d]", final_key, red, green, blue);
+ _rgb_gpio_set(red, green, blue, store_current);
snprintf(final_key, PATH_MAX, "24bit.%s", key);
modified |= config_get_rgb_with_default("Rpi.led", final_key, def_r_24bit, def_g_24bit, def_b_24bit, &red, &green, &blue);
- resource_led_rgb_l2c_set(red, green, blue);
-
- _D("%s: 24bit color: [%d, %d, %d]", final_key, red, green, blue);
+ _rgb_l2c_set(red, green, blue, store_current);
int value;
snprintf(final_key, PATH_MAX, "bicolor.%s", key);
modified |= config_get_int_with_default("Rpi.led", final_key, bi_led, &value);
- resource_led_bi_set(value);
+ _led_bi_set(value, store_current);
if (modified) {
config_save();
}
+}
+
+void resource_led_set_rgb_colors(char *key,
+ int def_r_3bit, int def_g_3bit, int def_b_3bit,
+ int def_r_24bit, int def_g_24bit, int def_b_24bit,
+ bi_led_color_e bi_led)
+{
+ FUNCTION_START;
- _D("%s: bicolor: [%d]", final_key, value);
+ _set_rgb(key, true, def_r_3bit, def_g_3bit, def_b_3bit, def_r_24bit, def_g_24bit, def_b_24bit, bi_led);
FUNCTION_END;
}
{
FUNCTION_START;
- resource_led_set_rgb_colors(key, def_r_3bit, def_g_3bit, def_b_3bit, def_r_24bit, def_g_24bit, def_b_24bit, bi_led);
-
+ _set_rgb(key, false, def_r_3bit, def_g_3bit, def_b_3bit, def_r_24bit, def_g_24bit, def_b_24bit, bi_led);
g_timeout_add(timeout, _restore_rgb_color_cb, NULL);