diff options
author | Michal Skorupinski <m.skorupinsk@samsung.com> | 2018-09-20 12:59:45 +0200 |
---|---|---|
committer | Krzysztof Wieclaw <k.wieclaw@samsung.com> | 2018-10-04 15:14:16 +0200 |
commit | 7e4bd4b5b7293fcf2fb93211720786ffa4e40c95 (patch) | |
tree | 98b4720917a3a88e33f21cf012d2fdcb483898be | |
parent | e7ef745002f73f7e3f79ccf11c6d97e996320830 (diff) | |
download | gear-racing-controller-7e4bd4b5b7293fcf2fb93211720786ffa4e40c95.tar.gz gear-racing-controller-7e4bd4b5b7293fcf2fb93211720786ffa4e40c95.tar.bz2 gear-racing-controller-7e4bd4b5b7293fcf2fb93211720786ffa4e40c95.zip |
Bezel configuration prepared
Change-Id: I9c33e7f176d9a76ccd2cdf4731891f7ca94fc9b0
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
-rw-r--r-- | inc/config.h | 23 | ||||
-rw-r--r-- | inc/model/model_device_to_connection.h | 2 | ||||
-rw-r--r-- | inc/model/model_hw.h | 2 | ||||
-rw-r--r-- | src/config.c | 43 | ||||
-rw-r--r-- | src/gear-racing-controller.c | 3 | ||||
-rw-r--r-- | src/model/model_device_to_connection.c | 10 | ||||
-rw-r--r-- | src/model/model_hw.c | 82 |
7 files changed, 124 insertions, 41 deletions
diff --git a/inc/config.h b/inc/config.h new file mode 100644 index 0000000..254021c --- /dev/null +++ b/inc/config.h @@ -0,0 +1,23 @@ +/* +* 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 CONFIG_H_ +#define CONFIG_H_ + +void config_set_sensor_steering_bezel_velocity(); +void config_set_bezel_steering_sensor_velocity(); + +#endif /* CONFIG_H_ */ diff --git a/inc/model/model_device_to_connection.h b/inc/model/model_device_to_connection.h index 28c5515..1a18898 100644 --- a/inc/model/model_device_to_connection.h +++ b/inc/model/model_device_to_connection.h @@ -31,4 +31,6 @@ void model_device_to_connection_axis_y(float value); void model_device_to_connection_bezel(float value); void model_device_to_connection_buttons(float value); +void model_device_to_connection_set_control_roles(e_device axis_x, e_device axis_y, e_device bezel, e_device buttons); + #endif /* MODEL_DEVICE_TO_CONNECTION_H_ */ diff --git a/inc/model/model_hw.h b/inc/model/model_hw.h index dfc9b0b..eecc204 100644 --- a/inc/model/model_hw.h +++ b/inc/model/model_hw.h @@ -32,4 +32,6 @@ void model_hw_unsubscirbe_event(void); void model_hw_subscribe_event(t_model_hw_update_cb model_update_cb); void model_hw_deactivate_rotatry(bool deactivate); +void model_hw_set_bezel_params(float step, float dead_zone, bool use_blocker, int blocker_count, bool set_to_zero_when_stop); + #endif /* MODEL_HW_H_ */ diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000..ccb6d39 --- /dev/null +++ b/src/config.c @@ -0,0 +1,43 @@ +/* +* 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 "model/model_hw.h" +#include "model/model_device_to_connection.h" +#include "gear-racing-controller.h" + +//void config_set_control_roles(e_device axis_x, e_device axis_y, e_device bezel, e_device buttons) +//{ +// model_device_to_connection_set_control_roles(axis_x, axis_y, bezel, buttons); +//} +// +//void config_set_bezel_step(float step, float dead_zone, bool use_blocker, int blocker_count, bool set_to_zero_when_stop) +//{ +// model_hw_set_bezel_params(step, dead_zone, use_blocker, blocker_count, set_to_zero_when_stop); +//} + + +void config_set_sensor_steering_bezel_velocity() +{ + model_device_to_connection_set_control_roles(STERING_MODE_DIRETION, STERING_MODE_CAM_ELEVATION, STERING_MODE_THROTTLE, STERING_MODE_CAM_AZIMUTH); + model_hw_set_bezel_params(0.03f, 0.001f, true, 15, true); +} + +void config_set_bezel_steering_sensor_velocity() +{ + model_device_to_connection_set_control_roles(STERING_MODE_CAM_AZIMUTH, STERING_MODE_THROTTLE, STERING_MODE_DIRETION, STERING_MODE_CAM_ELEVATION); + model_hw_set_bezel_params(-0.1f, 0.001f, false, 0, false); +} diff --git a/src/gear-racing-controller.c b/src/gear-racing-controller.c index 6861517..b613e57 100644 --- a/src/gear-racing-controller.c +++ b/src/gear-racing-controller.c @@ -20,9 +20,12 @@ #include "model/model_hw.h" #include "model/model_car_connection.h" #include "net-util.h" +#include "config.h" static bool app_create(void *data) { + config_set_sensor_steering_bezel_velocity(); + model_sensors_init(); model_hw_init(); model_car_connection_init(); diff --git a/src/model/model_device_to_connection.c b/src/model/model_device_to_connection.c index cb8b357..fe47f46 100644 --- a/src/model/model_device_to_connection.c +++ b/src/model/model_device_to_connection.c @@ -67,7 +67,7 @@ void model_device_to_connection_axis_y(float value) void model_device_to_connection_bezel(float value) { - _send_data(s_info.bezel, -value); + _send_data(s_info.bezel, value); } void model_device_to_connection_buttons(float value) @@ -75,3 +75,11 @@ void model_device_to_connection_buttons(float value) _send_data(s_info.buttons, value); } +void model_device_to_connection_set_control_roles(e_device axis_x, e_device axis_y, e_device bezel, e_device buttons) +{ + s_info.axis_x = axis_x; + s_info.axis_y = axis_y; + s_info.bezel = bezel; + s_info.buttons = buttons; +} + diff --git a/src/model/model_hw.c b/src/model/model_hw.c index 5078fe5..dbb1086 100644 --- a/src/model/model_hw.c +++ b/src/model/model_hw.c @@ -23,55 +23,44 @@ #include "log.h" -#define THROTTLE_STEP 0.03 -#define THROTTLE_DEADZONE 0.001f - -#define USE_DIRECTION_BLOCKER - -#ifdef USE_DIRECTION_BLOCKER -typedef enum _e_movement_direction { - DIR_FORWARD = 15, - DIR_STOP = 0, - DIR_BACKWARD = -15, -} e_movement_direction; -#endif - typedef struct _s_model_hw { t_model_hw_update_cb hw_update_cb; float bezel_position; bool rotary_deactivated; + + float bezel_step; + float bezel_dead_zone; + bool use_direction_blocker; + int blocker_count; + bool set_to_zero_when_stop; } s_model_hw; static s_model_hw s_info = { 0, }; -#ifdef USE_DIRECTION_BLOCKER -static inline void _update_direction_blocker(e_movement_direction *last_movement_dir, int step, int direction, e_movement_direction new_dir) +static inline void _update_direction_blocker(int *last_movement_dir, int step, int direction, int new_dir) { - if (*last_movement_dir * direction > DIR_STOP) { + if (*last_movement_dir * direction > 0) { *last_movement_dir += step; s_info.bezel_position = 0; } else { *last_movement_dir = new_dir; } } -#endif static Eina_Bool _rotary_cb(void *data, Eext_Rotary_Event_Info *info) { static s_model_hw_cb_data cb_data = { 0, }; -#ifndef USE_DIRECTION_BLOCKER - float prev = s_info.bezel_position; -#endif - if (s_info.rotary_deactivated) { return true; } + float prev = s_info.bezel_position; + if (info->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE) { - s_info.bezel_position += THROTTLE_STEP; + s_info.bezel_position += s_info.bezel_step; } else { - s_info.bezel_position -= THROTTLE_STEP; + s_info.bezel_position -= s_info.bezel_step; } if (s_info.bezel_position > 1) { @@ -81,30 +70,29 @@ static Eina_Bool _rotary_cb(void *data, Eext_Rotary_Event_Info *info) } -#ifdef USE_DIRECTION_BLOCKER - static e_movement_direction last_movement_dir = DIR_STOP; + if (s_info.use_direction_blocker) { + static int last_movement_dir = 0; - if (fabsf(s_info.bezel_position) < THROTTLE_DEADZONE) { - s_info.bezel_position = 0; - } if (s_info.bezel_position < 0.0f) { - _update_direction_blocker(&last_movement_dir, -1, 1, DIR_BACKWARD); - } else if(s_info.bezel_position > 0.0f) { - _update_direction_blocker(&last_movement_dir, 1, -1, DIR_FORWARD); - } -#else + if (fabsf(s_info.bezel_position) < s_info.bezel_dead_zone) { + s_info.bezel_position = 0; + } else if (s_info.bezel_position < 0.0f) { + _update_direction_blocker(&last_movement_dir, -1, 1, -s_info.blocker_count); + } else if(s_info.bezel_position > 0.0f) { + _update_direction_blocker(&last_movement_dir, 1, -1, s_info.blocker_count); + } + } else { - if (fabsf(s_info.bezel_position) < THROTTLE_DEADZONE) { - s_info.bezel_position = 0; - } else if (s_info.bezel_position * prev < 0.0f) { - s_info.bezel_position = 0; + if (fabsf(s_info.bezel_position) < s_info.bezel_dead_zone) { + s_info.bezel_position = 0; + } else if (s_info.bezel_position * prev < 0.0f) { + s_info.bezel_position = 0; + } } -#endif - cb_data.bezel_position = s_info.bezel_position; s_info.hw_update_cb(&cb_data); - _D("THROTTLE: %f", cb_data.bezel_position); + _D("BEZEL: %f", cb_data.bezel_position); model_device_to_connection_bezel(s_info.bezel_position); return true; @@ -113,6 +101,11 @@ static Eina_Bool _rotary_cb(void *data, Eext_Rotary_Event_Info *info) void model_hw_deactivate_rotatry(bool deactivate) { static s_model_hw_cb_data cb_data = { 0, }; + + if (!s_info.set_to_zero_when_stop) { + return; + } + s_info.rotary_deactivated = deactivate; s_info.bezel_position = 0; @@ -137,3 +130,12 @@ void model_hw_unsubscirbe_event(void) { s_info.hw_update_cb = NULL; } + +void model_hw_set_bezel_params(float step, float dead_zone, bool use_blocker, int blocker_count, bool set_to_zero_when_stop) +{ + s_info.bezel_step = step; + s_info.bezel_dead_zone = dead_zone; + s_info.use_direction_blocker = use_blocker; + s_info.blocker_count = blocker_count; + s_info.set_to_zero_when_stop = set_to_zero_when_stop; +} |