diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 5 | ||||
-rw-r--r-- | src/cloud/cloud_communication.c | 4 | ||||
-rw-r--r-- | src/lap_counter/lap_counter.c | 2 | ||||
-rw-r--r-- | src/resource/resource_led.c | 75 |
4 files changed, 54 insertions, 32 deletions
@@ -369,6 +369,9 @@ static bool service_app_create(void *data) controller_connection_manager_set_user_name_received_cb(__user_name_received_cb); resource_bi_led_set(LED_COLOR_RED); + resource_rgb_gpio_set(0, 0, 1); + resource_rgb_l2c_set(0, 0, 255); + return true; } @@ -392,6 +395,8 @@ static void service_app_terminate(void *data) { app_data *ad = data; resource_bi_led_set(LED_COLOR_NONE); + resource_rgb_gpio_set(0, 0, 0); + resource_rgb_l2c_set(0, 0, 0); resource_set_servo_motor_value(s_info.stering_pin, STERING_SERVO_CENTER); resource_set_servo_motor_value(s_info.elevation_pin, ELEVATION_MIN); diff --git a/src/cloud/cloud_communication.c b/src/cloud/cloud_communication.c index d42796c..482057f 100644 --- a/src/cloud/cloud_communication.c +++ b/src/cloud/cloud_communication.c @@ -119,10 +119,14 @@ static void post_response_cb(request_result_e result, void *user_data) if (result == SUCCESS) { _I("POST SUCCESS"); resource_bi_led_set(LED_COLOR_GREEN); + resource_rgb_gpio_set(0, 1, 0); + resource_rgb_l2c_set(0, 255, 0); } else { _I("POST FAILURE"); resource_bi_led_set(LED_COLOR_RED); + resource_rgb_gpio_set(1, 0, 0); + resource_rgb_l2c_set(255, 0, 0); } } diff --git a/src/lap_counter/lap_counter.c b/src/lap_counter/lap_counter.c index db94890..347c72f 100644 --- a/src/lap_counter/lap_counter.c +++ b/src/lap_counter/lap_counter.c @@ -114,6 +114,8 @@ void lap_counter_get_lap_time() } else { _D("Initial lap"); resource_bi_led_blink(LED_COLOR_RED, 1000); + resource_gpio_rgb_blink(1, 0, 1, 1000); + resource_rgb_l2c_blink(255, 0, 255, 1000); } s_info.last_timestamp.tv_sec = timestamp.tv_sec; diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c index dcfef73..9c40a5d 100644 --- a/src/resource/resource_led.c +++ b/src/resource/resource_led.c @@ -43,9 +43,9 @@ #define CONFIG_KEY_RPI_USE_L2C_RGB "rgb.l2c.use" -#define DEFAULT_RGB_GPIO_R 14 -#define DEFAULT_RGB_GPIO_G 15 -#define DEFAULT_RGB_GPIO_B 18 +#define DEFAULT_RGB_GPIO_R 23 +#define DEFAULT_RGB_GPIO_G 24 +#define DEFAULT_RGB_GPIO_B 25 #define DEFAULT_RGB_L2C_R 8 #define DEFAULT_RGB_L2C_G 9 @@ -119,6 +119,13 @@ static inline void _led_bi_set(bi_led_color_e color) static inline void _rgb_gpio_set(bool red, bool green, bool blue) { + if (!s_info.use_rgb_gpio) { + _D("gpio rgb led is turned OFF"); + return; + } + + _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); @@ -127,20 +134,14 @@ static inline void _rgb_gpio_set(bool red, bool green, bool blue) ret = peripheral_gpio_write(s_info.rgb_gpio[2], blue); ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret); - - _D("RGB GPIO: [%d, %d, %d]", red, green, blue); } -static inline void _rgb_l2c_set(bool red, bool green, bool blue) +static inline void _rgb_l2c_set(int red, int green, int blue) { -//#define R 51 -//#define G 231 -//#define B 157 - -//#define R 88 -//#define G 51 -//#define B 231 - + if (!s_info.use_rgb_l2c) { + _D("l2c rgb led is turned OFF"); + return; + } 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); @@ -175,20 +176,20 @@ static gboolean _restore_rgb_l2c_color_cb(gpointer data) static peripheral_gpio_h _init_gpio(int default_gpio, char *key) { peripheral_gpio_h gpio; - int ret = PERIPHERAL_ERROR_NONE; + int pin = 0; bool modified = config_get_int_with_default(CONFIG_GRP_RPI, key, default_gpio, &pin); - _D("gpio: %d", pin); + _D("Initializing gpio: %d", pin); if (modified) { config_save(); } - peripheral_gpio_open(pin, &gpio); + int ret = peripheral_gpio_open(pin, &gpio); retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, 0); - peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); + ret = peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW); retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret, 0); return gpio; @@ -227,6 +228,18 @@ static void _init_rgb_gpio_led(void) s_info.rgb_gpio[2] = _init_gpio(DEFAULT_RGB_GPIO_B, CONFIG_KEY_RPI_RGB_GPIO_B); } +void _init_l2c(int default_channel, char *config_key) +{ + int channel; + bool modified = config_get_int_with_default(CONFIG_GRP_RPI, config_key, default_channel, &channel); + if (modified) { + config_save(); + } + + int ret = resource_pca9685_init(channel, 60); + ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret); +} + static void _init_rgb_l2c_led(void) { bool modified = config_get_int_with_default(CONFIG_GRP_RPI, CONFIG_KEY_RPI_USE_L2C_RGB, 1, &s_info.use_rgb_l2c); @@ -239,21 +252,16 @@ static void _init_rgb_l2c_led(void) return; } - int ret = resource_pca9685_init(DEFAULT_RGB_L2C_R, 60); - ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret); - - ret = resource_pca9685_init(DEFAULT_RGB_L2C_G, 60); - ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret); - - ret = resource_pca9685_init(DEFAULT_RGB_L2C_B, 60); - ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret); + _init_l2c(DEFAULT_RGB_L2C_R, CONFIG_KEY_RPI_RGB_L2C_R); + _init_l2c(DEFAULT_RGB_L2C_G, CONFIG_KEY_RPI_RGB_L2C_G); + _init_l2c(DEFAULT_RGB_L2C_B, CONFIG_KEY_RPI_RGB_L2C_B); } void resource_led_init(void) { _D("Initialize Led"); - _init_bi_led(); _init_rgb_gpio_led(); + _init_bi_led(); _init_rgb_l2c_led(); } @@ -262,6 +270,12 @@ void resource_led_destroy(void) peripheral_gpio_close(s_info.gpio_bi_led[LED_COLOR_RED]); peripheral_gpio_close(s_info.gpio_bi_led[LED_COLOR_GREEN]); + peripheral_gpio_close(s_info.rgb_gpio[0]); + peripheral_gpio_close(s_info.rgb_gpio[1]); + peripheral_gpio_close(s_info.rgb_gpio[2]); + + resource_rgb_l2c_set(0, 0, 0); + resource_pca9685_fini(DEFAULT_RGB_L2C_R); resource_pca9685_fini(DEFAULT_RGB_L2C_G); resource_pca9685_fini(DEFAULT_RGB_L2C_B); @@ -276,8 +290,6 @@ void resource_bi_led_set(bi_led_color_e color) s_info.current_color = color; _led_bi_set(color); - - peripheral_gpio_write(s_info.rgb_gpio[LED_COLOR_RED], 1); } void resource_bi_led_blink(bi_led_color_e color, unsigned timeout) @@ -318,7 +330,7 @@ void resource_gpio_rgb_blink(bool red, bool green, bool blue, unsigned timeout) g_timeout_add(timeout, _restore_rgb_gpio_color_cb, NULL); } -void resource_rgb_l2c_set(bool red, bool green, bool blue) +void resource_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] && @@ -326,7 +338,6 @@ void resource_rgb_l2c_set(bool red, bool green, bool blue) 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; @@ -334,7 +345,7 @@ void resource_rgb_l2c_set(bool red, bool green, bool blue) _rgb_l2c_set(red, green, blue); } -void resource_rgb_l2c_blink(bool red, bool green, bool blue, unsigned timeout) +void resource_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] && |