diff options
author | 한준규/Tizen Platform Lab(SR)/Engineer/삼성전자 <junkyu.han@samsung.com> | 2018-01-12 14:57:28 +0900 |
---|---|---|
committer | GitHub Enterprise <noreply-CODE@samsung.com> | 2018-01-12 14:57:28 +0900 |
commit | a43ff64e2f04bb1c4d028681e955a9ea54bad643 (patch) | |
tree | 9cbdfa246aa594c543b40315d925b2223aac89db | |
parent | a53dd70733047afb659ac731da988d042b8ad0d2 (diff) | |
parent | 60b1989a3d99ebb4c41e2a9895543f311d74cad5 (diff) | |
download | gear-racing-controller-a43ff64e2f04bb1c4d028681e955a9ea54bad643.tar.gz gear-racing-controller-a43ff64e2f04bb1c4d028681e955a9ea54bad643.tar.bz2 gear-racing-controller-a43ff64e2f04bb1c4d028681e955a9ea54bad643.zip |
Merge pull request #4 from RS7-TizenReferenceSampleApplication/jjoggo
Send average value of current 10 data
-rw-r--r-- | src/resource_accelerometer.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/resource_accelerometer.c b/src/resource_accelerometer.c index 4a8a885..fb4a233 100644 --- a/src/resource_accelerometer.c +++ b/src/resource_accelerometer.c @@ -26,15 +26,30 @@ #include "view.h" #include "log.h" +#define AVERAGE_COUNT 11 +#define BASE_VALUE 100 + static void __finalize(void); static void __start_sensing(void); static void __stop_sensing(void); +static void __initialize_average_value_info(); static void __sensor_value_changed_cb(sensor_h sensor, sensor_event_s *event, void *data); +typedef struct _average_value_info { + int servo[11]; + int speed[11]; + int servo_sum; + int speed_sum; + int front; + bool ready_to_send; +} average_value_info; + static struct __accel_info_s { resource_info *sensor_info; + average_value_info avr_val; } accel_info = { .sensor_info = NULL, + .avr_val = { 0, }, }; resource_info *resource_accelerometer_init_sensor(resource_info *sensor_info) @@ -120,16 +135,39 @@ static void __finalize(void) } resource_info_free(accel_info.sensor_info); + __initialize_average_value_info(); } static void __sensor_value_changed_cb(sensor_h sensor, sensor_event_s *event, void *data) { _D("Time: [%llu], X: [%f], Y: [%f]", event->timestamp, event->values[0], event->values[1]); + accel_info.avr_val.servo_sum -= accel_info.avr_val.servo[accel_info.avr_val.front]; + accel_info.avr_val.speed_sum -= accel_info.avr_val.speed[accel_info.avr_val.front]; + + accel_info.avr_val.servo[accel_info.avr_val.front] = event->values[0] * -BASE_VALUE; + accel_info.avr_val.speed[accel_info.avr_val.front] = event->values[1] * -BASE_VALUE; + + accel_info.avr_val.servo_sum += accel_info.avr_val.servo[accel_info.avr_val.front]; + accel_info.avr_val.speed_sum += accel_info.avr_val.speed[accel_info.avr_val.front]; + + accel_info.avr_val.front++; + + if (accel_info.avr_val.front >= AVERAGE_COUNT + 1) + accel_info.avr_val.ready_to_send = 1; + + if (accel_info.avr_val.front % (AVERAGE_COUNT + 1) == 0) + accel_info.avr_val.front = 1; + + if (!accel_info.avr_val.ready_to_send) + return; + commu_data_s temp = { NULL, NULL }; - temp.servo = event->values[0] * -100; - temp.speed = event->values[1] * -100; + temp.servo = accel_info.avr_val.servo_sum / AVERAGE_COUNT; + temp.speed = accel_info.avr_val.speed_sum / AVERAGE_COUNT; + + _D("AVERAGE --- Time: [%llu], Servo: [%d], Speed: [%d]", event->timestamp, temp.servo, temp.speed); view_update_view_with_data((void *)&temp); communication_center_send_data((void *)&temp); @@ -146,6 +184,11 @@ static void __start_sensing(void) } } +static void __initialize_average_value_info(void) +{ + memset(&(accel_info.avr_val), 0, sizeof(accel_info.avr_val)); +} + static void __stop_sensing(void) { int ret = 0; @@ -163,5 +206,6 @@ static void __stop_sensing(void) view_update_view_with_data((void *)&temp); communication_center_send_data((void *)&temp); + __initialize_average_value_info(); } |