${PROJECT_ROOT_DIR}/src/resource/resource_PCA9685.c
${PROJECT_ROOT_DIR}/src/resource/resource_servo_motor.c
${PROJECT_ROOT_DIR}/src/resource/resource_lap_counter.c
+ ${PROJECT_ROOT_DIR}/src/resource/resource_led.c
${PROJECT_ROOT_DIR}/src/cloud/car_info.c
${PROJECT_ROOT_DIR}/src/cloud/car_info_serializer.c
${PROJECT_ROOT_DIR}/src/cloud/lap_info.c
} \
} while (0)
-#define retvm_error_message(expr, ret, val, fmt, arg...) do { \
+#define retv_error_message(expr, err, ret) do { \
if (expr) { \
- _E(fmt, ##arg); \
- _E("(%s) Error= {%s} -> %s() return", #expr, get_error_message(ret), __FUNCTION__); \
- return val; \
+ _E("(%s) Error= {%s} -> %s() return", #expr, get_error_message(err), __FUNCTION__); \
+ return ret; \
} \
} while (0)
-#define retv_error_message(expr, ret) do { \
+#define ret_error_message(expr, ret) do { \
if (expr) { \
_E("(%s) Error= {%s} -> %s() return", #expr, get_error_message(ret), __FUNCTION__); \
return; \
#include "resource/resource_motor_driver_L298N.h"
#include "resource/resource_servo_motor.h"
#include "resource/resource_lap_counter.h"
+#include "resource/resource_led.h"
void resource_close_all(void);
--- /dev/null
+/*
+* Copyright (c) 2018 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#ifndef RESOURCE_RESOURCE_LED_H_
+#define RESOURCE_RESOURCE_LED_H_
+
+typedef enum _led_color_e {
+ LED_COLOR_NONE,
+ LED_COLOR_RED,
+ LED_COLOR_GREEN,
+} led_color_e;
+
+void resource_led_init(void);
+void resource_led_destroy(void);
+void resource_led_set(led_color_e color);
+void resource_led_blink(led_color_e color, unsigned timeout);
+
+#endif /* RESOURCE_RESOURCE_LED_H_ */
message_manager_init();
controller_connection_manager_listen();
lap_counter_init();
+ resource_led_init();
+
_D("Car settings: Stering[%d +/- %d] Engine[%d - %d], CamAzimuth[%d +/- %d], CamElev[%d - %d]",
s_info.stering_center, s_info.stering_range,
controller_connection_manager_set_command_received_cb(__command_received_cb);
controller_connection_manager_set_user_name_received_cb(__user_name_received_cb);
+ resource_led_set(LED_COLOR_RED);
+
return true;
}
static void service_app_terminate(void *data)
{
app_data *ad = data;
+ resource_led_set(LED_COLOR_NONE);
resource_set_servo_motor_value(s_info.stering_pin, STERING_SERVO_CENTER);
resource_set_servo_motor_value(s_info.elevation_pin, ELEVATION_MIN);
resource_set_servo_motor_value(s_info.azimuth_pin, (AZIMUTH_MIN + AZIMUTH_MAX) / 2);
resource_lap_counter_destroy();
+ resource_led_destroy();
if (ad->idle_h)
g_source_remove(ad->idle_h);
#include "log.h"
#include "config.h"
#include "net-util.h"
+#include "resource/resource_led.h"
typedef struct communication_data_ {
gboolean is_initialized;
{
if (result == SUCCESS) {
_I("POST SUCCESS");
+ resource_led_set(LED_COLOR_GREEN);
}
else {
_I("POST FAILURE");
+ resource_led_set(LED_COLOR_RED);
}
}
#include <stdlib.h>
#include <time.h>
#include "cloud/cloud_communication.h"
+#include "resource/resource_led.h"
#define MIN_LAP_TIME 5
#define MAX_NAME_LENGTH 256
_D("----------------------------------------------");
cloud_communication_post_lap(lap.tv_sec * 1e3 + lap.tv_nsec / 1e6, s_info.user_name);
+
return lap;
}
{
struct timespec timestamp;
int ret = clock_gettime(CLOCK_MONOTONIC, ×tamp);
- retv_error_message(ret != 0, ret);
+ ret_error_message(ret != 0, ret);
if (s_info.last_timestamp.tv_nsec != 0 || s_info.last_timestamp.tv_sec != 0) {
_calculate_lap_time(&s_info.last_timestamp, ×tamp);
} else {
_D("Initial lap");
+ resource_led_blink(LED_COLOR_NONE, 1000);
}
s_info.last_timestamp.tv_sec = timestamp.tv_sec;
#include <time.h>
#include "log.h"
#include "lap_counter/lap_counter.h"
+#include "resource/resource_led.h"
#include "config.h"
#define DEFAULT_LAP_GPIO 26
lap_counter_get_lap_time();
}
-
s_info.gpio_prev_value = gpio_value;
}
}
ret = peripheral_gpio_open(pin, &s_info.gpio);
- retv_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
+ ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
ret = peripheral_gpio_set_direction(s_info.gpio, PERIPHERAL_GPIO_DIRECTION_IN);
CHECK_GPIO_ERROR(s_info.gpio, ret);
--- /dev/null
+/*
+* Copyright (c) 2018 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Flora License, Version 1.1 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <glib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <peripheral_io.h>
+#include <time.h>
+#include "log.h"
+#include "resource/resource_led.h"
+#include "config.h"
+
+#define DEFAULT_LED_RED 17
+#define DEFAULT_LED_GREEN 27
+#define CONFIG_KEY_RPI_PIN_LED_RED "led.red"
+#define CONFIG_KEY_RPI_PIN_LED_GREEN "led.green"
+#define CONFIG_GRP_RPI "Rpi"
+
+typedef struct _led_s {
+ peripheral_gpio_h gpio_red;
+ peripheral_gpio_h gpio_green;
+ led_color_e current_color;
+} led_s;
+
+static led_s s_info = { 0, };
+
+#define CHECK_GPIO_ERROR(pin, ret) \
+ if (ret != PERIPHERAL_ERROR_NONE) { \
+ peripheral_gpio_close(pin); \
+ _E("GPIO ERROR: %s, %s[%d]", get_error_message(ret), __FILE__, __LINE__); \
+ return ; \
+ }
+
+
+static inline void _led_set(led_color_e color)
+{
+ int red;
+ int green;
+
+
+ switch (color) {
+ case LED_COLOR_RED:
+ red = 1;
+ green = 0;
+ break;
+ case LED_COLOR_GREEN:
+ red = 0;
+ green = 1;
+ break;
+ default:
+ red = 0;
+ green = 0;
+ break;
+ }
+
+ int ret = peripheral_gpio_write(s_info.gpio_red, red);
+ CHECK_GPIO_ERROR(s_info.gpio_red, ret);
+
+ peripheral_gpio_write(s_info.gpio_green, green);
+ CHECK_GPIO_ERROR(s_info.gpio_green, ret);
+}
+
+static gboolean _restore_color_cb(gpointer data)
+{
+ _led_set(s_info.current_color);
+ return false;
+}
+
+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);
+
+ if (modified) {
+ config_save();
+ }
+
+ peripheral_gpio_open(pin, &gpio);
+// ret_error_message(ret != PERIPHERAL_ERROR_NONE, ret);
+
+ peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
+// CHECK_GPIO_ERROR(gpio, ret);
+
+ return gpio;
+
+}
+
+void resource_led_init(void)
+{
+ _D("Initialize Led");
+
+ s_info.gpio_red = _init_gpio(DEFAULT_LED_RED, CONFIG_KEY_RPI_PIN_LED_RED);
+ s_info.gpio_green = _init_gpio(DEFAULT_LED_GREEN, CONFIG_KEY_RPI_PIN_LED_GREEN);
+
+
+ int ret = peripheral_gpio_write(s_info.gpio_green, 1);
+ CHECK_GPIO_ERROR(s_info.gpio_green, ret);
+}
+
+void resource_led_destroy(void)
+{
+ peripheral_gpio_close(s_info.gpio_red);
+ peripheral_gpio_close(s_info.gpio_green);
+}
+
+void resource_led_set(led_color_e color)
+{
+ _D("Set led to: %d", color);
+ if (color == s_info.current_color) {
+ return;
+ }
+
+ s_info.current_color = color;
+ _led_set(color);
+}
+
+void resource_led_blink(led_color_e color, unsigned timeout)
+{
+ if (color == s_info.current_color) {
+ return;
+ }
+
+ _led_set(color);
+ g_timeout_add(timeout, _restore_color_cb, NULL);
+}
+