From: Michal Skorupinski Date: Fri, 30 Nov 2018 11:18:25 +0000 (+0100) Subject: Changed the way that the led colors are stored in the config file X-Git-Url: http://review.tizen.org/git/?p=apps%2Fnative%2Fgear-racing-car.git;a=commitdiff_plain;h=d3146510ebd527ee5229ff0c5fe799b06d4b3fb7 Changed the way that the led colors are stored in the config file Change-Id: I8bbe86ca966792ae13ee3442ea99c965413babed Signed-off-by: Michal Skorupinski --- diff --git a/inc/log.h b/inc/log.h index 974ca98..14af56e 100644 --- a/inc/log.h +++ b/inc/log.h @@ -42,8 +42,8 @@ #define _E(fmt, arg...) log_print(DLOG_ERROR, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) #endif -#define FUNCTION_START _D("\033[0;32m ***************************** START ***************************** \033[0m") -#define FUNCTION_END _D("\033[0;32m ***************************** END ***************************** \033[0m") +#define FUNCTION_START _D("\033[0;32m ************** %s() START ************** \033[0m", __FUNCTION__) +#define FUNCTION_END _D("\033[0;32m ************** %s() END ************** \033[0m", __FUNCTION__) #define retvm_if(expr, val, fmt, arg...) do { \ if (expr) { \ diff --git a/src/config.c b/src/config.c index cb6ecaf..6689d86 100644 --- a/src/config.c +++ b/src/config.c @@ -265,23 +265,25 @@ bool config_get_rgb_with_default(char *group, char *key, int default_r, int default_g, int default_b, int *red, int *green, int *blue) { - bool modified = false; - int color; + GError *error; + gsize length; - if (config_get_int(group, key, &color) != 0) { + gint *list = g_key_file_get_integer_list(gk, group, key, &length, &error); - color = (default_r & 0xFF) << 16; - color += (default_g & 0xFF) << 8; - color += (default_b & 0xFF) << 0; + if (length <= 0) { + gint list[3] = { default_r, default_g, default_b}; + g_key_file_set_integer_list (gk, group, key, list, 3); - config_set_int(group, key, color); + *red = default_r; + *green = default_g; + *blue = default_b; - modified = true; + return true; } - *red = (color >> 16) & 0xFF; - *green = (color >> 8) & 0xFF; - *blue = (color >> 0) & 0xFF; + *red = list[0]; + *green = list[1]; + *blue = list[2]; - return modified; + return false; } diff --git a/src/messages/message_manager.c b/src/messages/message_manager.c index 4dcc7e1..094cc73 100644 --- a/src/messages/message_manager.c +++ b/src/messages/message_manager.c @@ -71,7 +71,7 @@ int message_manager_init() return 0; } - mgr.conn = udp_connection_create(DEFAULT_PORT); //TODO load from config + mgr.conn = udp_connection_create(DEFAULT_PORT); if (!mgr.conn) { return -1; } diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c index 71bd003..df11e7c 100644 --- a/src/resource/resource_led.c +++ b/src/resource/resource_led.c @@ -139,6 +139,7 @@ static inline void _rgb_gpio_set(bool red, bool green, bool blue) static inline void _rgb_l2c_set(int red, int green, int blue) { + FUNCTION_START; if (!s_info.use_rgb_l2c) { _D("l2c rgb led is turned OFF"); return; @@ -154,6 +155,7 @@ static inline void _rgb_l2c_set(int red, int green, int blue) ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret); _D("RGB L2C: [%d, %d, %d] -> [%d, %d, %d]", red, green, blue, RGB_TO_REGISTER(red), RGB_TO_REGISTER(green), RGB_TO_REGISTER(blue)); + FUNCTION_END; } static gboolean _restore_bi_color_cb(gpointer data) @@ -170,16 +172,22 @@ static gboolean _restore_rgb_gpio_color_cb(gpointer data) 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]); + FUNCTION_END; return false; } static gboolean _restore_rgb_color_cb(gpointer data) { + FUNCTION_START; + _restore_bi_color_cb(data); _restore_rgb_gpio_color_cb(data); _restore_rgb_l2c_color_cb(data); + FUNCTION_END; + return false; } @@ -213,6 +221,9 @@ static void _init_bi_led(void) config_save(); } + _D("Use bi_led: %d", s_info.use_bi_led); + + if (s_info.use_bi_led) { s_info.gpio_bi_led[LED_COLOR_RED] = _init_gpio(DEFAULT_BI_LED_RED, CONFIG_KEY_RPI_BI_LED_RED); s_info.gpio_bi_led[LED_COLOR_GREEN] = _init_gpio(DEFAULT_BI_LED_GREEN, CONFIG_KEY_RPI_BI_LED_GREEN); @@ -228,6 +239,8 @@ static void _init_rgb_gpio_led(void) config_save(); } + _D("Use rgb_gpio_led: %d", s_info.use_rgb_gpio); + if (!s_info.use_rgb_gpio) { _D("RGB GPIO is turned off"); return; @@ -257,6 +270,8 @@ static void _init_rgb_l2c_led(void) config_save(); } + _D("Use rgb_l2c_led: %d", s_info.use_rgb_l2c); + if (!s_info.use_rgb_l2c) { _D("RGB L2C is turned off"); return; @@ -269,10 +284,12 @@ static void _init_rgb_l2c_led(void) void resource_led_init(void) { + FUNCTION_START; _D("Initialize Led"); _init_rgb_gpio_led(); _init_bi_led(); _init_rgb_l2c_led(); + FUNCTION_END; } void resource_led_destroy(void) @@ -295,6 +312,7 @@ 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; } @@ -305,6 +323,7 @@ void resource_led_bi_set(bi_led_color_e 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; } @@ -317,6 +336,7 @@ 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; } @@ -333,6 +353,7 @@ void resource_led_gpio_rgb_blink(bool red, bool green, bool blue, unsigned timeo 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; } @@ -345,6 +366,7 @@ 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; } @@ -360,6 +382,7 @@ 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; } @@ -372,6 +395,8 @@ void resource_led_set_rgb_colors(char *key, 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]; @@ -395,7 +420,10 @@ void resource_led_set_rgb_colors(char *key, if (modified) { config_save(); } + _D("%s: bicolor: [%d]", final_key, value); + + FUNCTION_END; } void resource_led_blink_rgb_colors(char *key, @@ -403,7 +431,12 @@ void resource_led_blink_rgb_colors(char *key, int def_r_24bit, int def_g_24bit, int def_b_24bit, bi_led_color_e bi_led, int timeout) { + 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); g_timeout_add(timeout, _restore_rgb_color_cb, NULL); + + + FUNCTION_END; }