[screen_reader] code refactoring - 013 - screen_reader_haptic 17/90117/1
authorAleksandra Dominas <a.dominas@samsung.com>
Mon, 19 Sep 2016 08:25:46 +0000 (10:25 +0200)
committerm.detko <m.detko@samsung.com>
Tue, 27 Sep 2016 11:08:48 +0000 (13:08 +0200)
Change-Id: Ie203311079230a8e4acda3519543cabd2f99c8fd

include/screen_reader_haptic.h
src/navigator.c
src/screen_reader.c
src/screen_reader_haptic.c
src/smart_notification.c

index 6bc6dcfdb379a8ee43f6ed933de8a07633d90ad4..7f313cdcbca8f561435867890bac466b23e8c1f1 100644 (file)
@@ -1,4 +1,38 @@
-void haptic_module_init(void);
-void haptic_module_disconnect(void);
-void haptic_vibrate_start(int duration, int feedback);
-void haptic_vibrate_stop(void);
+#ifndef SCREEN_READER_HAPTIC_H_
+#define SCREEN_READER_HAPTIC_H_
+
+/**
+ * @description
+ *
+ * Functions enabling usage of haptic module.
+ */
+#include "screen_reader.h"
+
+/**
+ * @brief Initializer for haptic module
+ *
+ */
+Haptic_Data *haptic_module_init(void);
+
+/**
+ * @brief Disconnect haptic handle
+ *
+ */
+void haptic_module_shutdown(Haptic_Data *haptic_data);
+
+/**
+ * @brief Start vibrations
+ *
+ * @param duration the play duration in miliseconds
+ * @param feedback the amount of intesity variation (0-100)
+ *
+ */
+void haptic_vibrate_start(int duration, int feedback, Haptic_Data *haptic_data);
+
+/**
+ * @brief Stop vibrations
+ *
+ */
+void haptic_vibrate_stop(Haptic_Data *haptic_data);
+
+#endif /* SCREEN_READER_HAPTIC_H_ */
index 2d1dbe7b6714a56669577c4d00a2beae2f226b88..bb50288a429f8c31b60a3e1833d12da328e54d60 100644 (file)
@@ -1084,7 +1084,7 @@ static Eina_Bool _highlight_access_object(AtspiAccessible *obj, Highlight_Type h
        return _do_action(obj, expected_action);
 }
 
-static void _current_highlight_object_set(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, AtspiAccessible * obj, Highlight_Type h_type)
+static void _current_highlight_object_set(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, AtspiAccessible * obj, Highlight_Type h_type)
 {
        DEBUG("START");
 
@@ -1137,7 +1137,7 @@ static void _current_highlight_object_set(Navigator_Data *nd, Screen_Reader_Vcon
                }
 
                if (get_haptic(vconf_data))
-                       haptic_vibrate_start(HAPTIC_VIBRATE_DURATION, HAPTIC_VIBRATE_INTENSITY);
+                       haptic_vibrate_start(HAPTIC_VIBRATE_DURATION, HAPTIC_VIBRATE_INTENSITY, haptic_data);
 
                role = atspi_accessible_get_role(obj, NULL);
                if (role != ATSPI_ROLE_PAGE_TAB && role != ATSPI_ROLE_POPUP_MENU) { /* ctxpopup outline does not show highlight frame */
@@ -1208,7 +1208,7 @@ void test_debug(AtspiAccessible *current_widget)
        g_object_unref(parent);
 }
 
-static void _focus_widget(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context, Gesture_Info *info)
+static void _focus_widget(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context, Gesture_Info *info)
 {
        DEBUG("START");
 
@@ -1219,13 +1219,13 @@ static void _focus_widget(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_
        if (flat_navi_context_current_at_x_y_set(context, info->x_beg, info->y_beg, &obj)) {
                nd->last_focus.x = info->x_beg;
                nd->last_focus.y = info->y_beg;
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_POINT);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_POINT);
        }
 
        DEBUG("END");
 }
 
-static void _focus_next(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _focus_next(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("START");
 
@@ -1237,13 +1237,13 @@ static void _focus_next(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_da
 
        obj = flat_navi_context_next(context, vconf_data);
        if (obj)
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_FIRST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_FIRST);
        else
                DEBUG("Next widget not found. Abort");
        DEBUG("END");
 }
 
-static void _focus_next_visible(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _focus_next_visible(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("START");
 
@@ -1267,13 +1267,13 @@ static void _focus_next_visible(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *
        while (obj && !visible);
 
        if (obj)
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_FIRST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_FIRST);
        else
                DEBUG("Next widget not found. Abort");
        DEBUG("END");
 }
 
-static void _focus_prev_visible(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _focus_prev_visible(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        AtspiAccessible *obj;
        AtspiStateSet *ss = NULL;
@@ -1294,12 +1294,12 @@ static void _focus_prev_visible(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *
        while (obj && !visible);
 
        if (obj)
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_LAST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_LAST);
        else
                DEBUG("Previous widget not found. Abort");
 }
 
-static void _focus_prev(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _focus_prev(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        AtspiAccessible *obj;
        if (!context) {
@@ -1309,7 +1309,7 @@ static void _focus_prev(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_da
 
        obj = flat_navi_context_prev(context, vconf_data);
        if (obj)
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_LAST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_LAST);
        else
                DEBUG("Previous widget not found. Abort");
 }
@@ -1850,7 +1850,7 @@ static void _widget_scroll_end(Gesture_Info *gi)
 }
 */
 
-static void _widget_scroll(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context, Gesture_Info *gi)
+static void _widget_scroll(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context, Gesture_Info *gi)
 {
        DEBUG("Recognized gesture state: %d", gi->state);
        int x_diff, y_diff;
@@ -1897,21 +1897,21 @@ static void _widget_scroll(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf
                if (abs(y_diff) >= abs(x_diff)) {
                        if (y_diff > 0) {
                                DEBUG("PREVIOUS");
-                               _focus_prev_visible(nd, vconf_data, context);
+                               _focus_prev_visible(nd, vconf_data, haptic_data, context);
                        }
                        else {
                                DEBUG("NEXT");
-                               _focus_next_visible(nd, vconf_data, context);
+                               _focus_next_visible(nd, vconf_data, haptic_data, context);
                        }
                }
                else {
                        if (x_diff > 0) {
                                DEBUG("PREVIOUS");
-                               _focus_prev_visible(nd, vconf_data, context);
+                               _focus_prev_visible(nd, vconf_data, haptic_data, context);
                        }
                        else {
                                DEBUG("NEXT");
-                               _focus_next_visible(nd, vconf_data, context);
+                               _focus_next_visible(nd, vconf_data, haptic_data, context);
                        }
                }
        }
@@ -1960,7 +1960,7 @@ static void _set_pause(void)
        DEBUG("END");
 }
 
-void auto_review_highlight_set(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+void auto_review_highlight_set(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        if (nd == NULL || vconf_data == NULL || context == NULL) {
                ERROR("NULL context");
@@ -1980,12 +1980,12 @@ void auto_review_highlight_set(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *v
                nd->auto_review_on = false;
        }
 
-       _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_FIRST);
+       _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_FIRST);
 
        DEBUG("END");
 }
 
-void auto_review_highlight_top(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+void auto_review_highlight_top(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("START");
        char *text_to_speak = NULL;
@@ -1993,7 +1993,7 @@ void auto_review_highlight_top(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *v
        AtspiAccessible *first = flat_navi_context_first(context);
 
        if (first != obj) {
-               _current_highlight_object_set(nd, vconf_data, first, HIGHLIGHT_FIRST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, first, HIGHLIGHT_FIRST);
        } else {
                text_to_speak = generate_what_to_read(obj, vconf_data);
                DEBUG("Text to speak: %s", text_to_speak);
@@ -2025,34 +2025,34 @@ static void _on_utterance()
        DEBUG("sd->navigator_data->auto_review_on == %d", sd->navigator_data->auto_review_on);
 
        if (sd->navigator_data->auto_review_on) {
-               auto_review_highlight_set(sd->navigator_data, sd->vconf_data, sd->flat_navi_context);
+               auto_review_highlight_set(sd->navigator_data, sd->vconf_data, sd->screen_reader_haptic_data, sd->flat_navi_context);
        }
        DEBUG("END");
 }
 
-static void _review_from_current(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _review_from_current(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("START");
 
        nd->focused_object = flat_navi_context_current_get(context);
        nd->auto_review_on = true;
-       auto_review_highlight_set(nd, vconf_data, context);
+       auto_review_highlight_set(nd, vconf_data, haptic_data, context);
 
        DEBUG("END");
 }
 
-static void _review_from_top(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _review_from_top(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("START");
 
        nd->focused_object = flat_navi_context_current_get(context);
        nd->auto_review_on = true;
-       auto_review_highlight_top(nd, vconf_data, context);
+       auto_review_highlight_top(nd, vconf_data, haptic_data, context);
 
        DEBUG("END");
 }
 
-static void _direct_scroll_back(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _direct_scroll_back(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("ONE_FINGER_FLICK_LEFT_RETURN");
        if (!context) {
@@ -2106,13 +2106,13 @@ static void _direct_scroll_back(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *
                if (flat_navi_context_current_set(context, obj)) {
                        DEBUG("current obj set");
                }
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_FIRST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_FIRST);
        }
        g_object_unref(parent);
        g_object_unref(current);
 }
 
-static void _direct_scroll_forward(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _direct_scroll_forward(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("ONE_FINGER_FLICK_RIGHT_RETURN");
 
@@ -2167,13 +2167,13 @@ static void _direct_scroll_forward(Navigator_Data *nd, Screen_Reader_Vconf_Data_
                if (flat_navi_context_current_set(context, obj)) {
                        DEBUG("current obj set");
                }
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_LAST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_LAST);
        }
        g_object_unref(parent);
        g_object_unref(current);
 }
 
-static void _direct_scroll_to_first(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _direct_scroll_to_first(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("ONE_FINGER_FLICK_UP_RETURN");
        if (!context) {
@@ -2182,13 +2182,13 @@ static void _direct_scroll_to_first(Navigator_Data *nd, Screen_Reader_Vconf_Data
        }
        AtspiAccessible *obj = flat_navi_context_first(context);
        if (obj)
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_FIRST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_FIRST);
        else
                DEBUG("First widget not found. Abort");
        DEBUG("END");
 }
 
-static void _direct_scroll_to_last(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Flat_Navi_Context *context)
+static void _direct_scroll_to_last(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_data, Haptic_Data *haptic_data, Flat_Navi_Context *context)
 {
        DEBUG("ONE_FINGER_FLICK_DOWN_RETURN");
        if (!context) {
@@ -2197,7 +2197,7 @@ static void _direct_scroll_to_last(Navigator_Data *nd, Screen_Reader_Vconf_Data_
        }
        AtspiAccessible *obj = flat_navi_context_last(context);
        if (obj)
-               _current_highlight_object_set(nd, vconf_data, obj, HIGHLIGHT_LAST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, obj, HIGHLIGHT_LAST);
        else
                DEBUG("Last widget not found. Abort");
        DEBUG("END");
@@ -2407,6 +2407,9 @@ static void _move_slider(Navigator_Data *nd, Screen_Reader_Vconf_Data_t *vconf_d
                return;
        }
 
+       if (get_sound_feedback(vconf_data))
+               smart_notification(LONG_PRESS_NOTIFICATION_EVENT, 0, 0);
+
        if (gi->state == 0) {
                comp = atspi_accessible_get_component_iface(obj);
                if (!comp) {
@@ -2552,6 +2555,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
        Navigator_Data *nd = sd->navigator_data;
        Flat_Navi_Context *context = sd->flat_navi_context;
        Screen_Reader_Vconf_Data_t *vconf_data = sd->vconf_data;
+       Haptic_Data *haptic_data = sd->screen_reader_haptic_data;
 
        if (nd == NULL) {
                ERROR("NULL context navigator_data");
@@ -2568,6 +2572,11 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                return;
        }
 
+       if (haptic_data == NULL) {
+               ERROR("NULL context");
+               return;
+       }
+
 #ifdef X11_ENABLED
        Ecore_X_Window keyboard_win;
 #else
@@ -2643,22 +2652,22 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                                        break;
                                }
 #endif
-                       _focus_widget(nd, vconf_data, context, info);
+                       _focus_widget(nd, vconf_data, haptic_data, context, info);
                }
                break;
        case TWO_FINGERS_HOVER:
-               _widget_scroll(nd, vconf_data, context, info);
+               _widget_scroll(nd, vconf_data, haptic_data, context, info);
                break;
        case ONE_FINGER_FLICK_LEFT:
                if (_check_access_object_internal(context, HIGHLIGHT_PREV)) break;
-               _focus_prev(nd, vconf_data, context);
+               _focus_prev(nd, vconf_data, haptic_data, context);
                if (_is_index_item(context))
                        _activate_widget(nd, vconf_data);
 
                break;
        case ONE_FINGER_FLICK_RIGHT:
                if (_check_access_object_internal(context, HIGHLIGHT_NEXT)) break;
-               _focus_next(nd, vconf_data, context);
+               _focus_next(nd, vconf_data, haptic_data, context);
                if (_is_index_item(context))
                        _activate_widget(nd, vconf_data);
 
@@ -2669,7 +2678,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                else if (_has_value(nd) && _is_enabled(nd))
                        _value_inc(nd);
                else
-                       _focus_prev(nd, vconf_data, context);
+                       _focus_prev(nd, vconf_data, haptic_data, context);
                break;
        case ONE_FINGER_FLICK_DOWN:
                if (_is_active_entry(context))
@@ -2677,7 +2686,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                else if (_has_value(nd) && _is_enabled(nd))
                        _value_dec(nd);
                else
-                       _focus_next(nd, vconf_data, context);
+                       _focus_next(nd, vconf_data, haptic_data, context);
                break;
        case ONE_FINGER_SINGLE_TAP:
 #if defined(ELM_ACCESS_KEYBOARD) && defined(X11_ENABLED)
@@ -2695,7 +2704,7 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                        }
 #endif
                if (!nd->prepared)
-                       _focus_widget(nd, vconf_data, context, info);
+                       _focus_widget(nd, vconf_data, haptic_data, context, info);
                break;
        case ONE_FINGER_DOUBLE_TAP:
 #if defined(ELM_ACCESS_KEYBOARD) && defined(X11_ENABLED)
@@ -2726,10 +2735,10 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
 #endif
                break;
        case THREE_FINGERS_SINGLE_TAP:
-               _review_from_top(nd, vconf_data, context);
+               _review_from_top(nd, vconf_data, haptic_data, context);
                break;
        case THREE_FINGERS_DOUBLE_TAP:
-               _review_from_current(nd, vconf_data, context);
+               _review_from_current(nd, vconf_data, haptic_data, context);
                break;
        case THREE_FINGERS_FLICK_DOWN:
                _quickpanel_change_state(QUICKPANEL_DOWN);
@@ -2738,22 +2747,22 @@ static void on_gesture_detected(void *data, const Eldbus_Message *msg)
                _quickpanel_change_state(QUICKPANEL_UP);
                break;
        case ONE_FINGER_FLICK_LEFT_RETURN:
-               _direct_scroll_back(nd, vconf_data, context);
+               _direct_scroll_back(nd, vconf_data, haptic_data, context);
                break;
        case ONE_FINGER_FLICK_RIGHT_RETURN:
-               _direct_scroll_forward(nd, vconf_data, context);
+               _direct_scroll_forward(nd, vconf_data, haptic_data, context);
                break;
        case ONE_FINGER_FLICK_UP_RETURN:
                if (_is_active_entry(context))
                        _caret_move_beg(nd);
                else
-                       _direct_scroll_to_first(nd, vconf_data, context);
+                       _direct_scroll_to_first(nd, vconf_data, haptic_data, context);
                break;
        case ONE_FINGER_FLICK_DOWN_RETURN:
                if (_is_active_entry(context))
                        _caret_move_end(nd);
                else
-                       _direct_scroll_to_last(nd, vconf_data, context);
+                       _direct_scroll_to_last(nd, vconf_data, haptic_data, context);
                break;
        default:
                DEBUG("Gesture type %d not handled in switch", info->type);
@@ -2784,6 +2793,12 @@ static void _view_content_changed(AtspiAccessible *root, void *user_data)
                return;
        }
 
+       Haptic_Data *haptic_data = sd->screen_reader_haptic_data;
+       if (haptic_data == NULL) {
+               ERROR("NULL context");
+               return;
+       }
+
        if (flat_navi_is_valid(sd->flat_navi_context, root))
                return;
 
@@ -2805,7 +2820,7 @@ static void _view_content_changed(AtspiAccessible *root, void *user_data)
                if(role == ATSPI_ROLE_PAGE_TAB ||       //add more roles...
                        role == ATSPI_ROLE_PAGE_TAB_LIST)
                {
-                       _current_highlight_object_set(nd, vconf_data, flat_navi_context_current_get(sd->flat_navi_context), HIGHLIGHT_FIRST);
+                       _current_highlight_object_set(nd, vconf_data, haptic_data, flat_navi_context_current_get(sd->flat_navi_context), HIGHLIGHT_FIRST);
                }
                else
                {
@@ -2820,7 +2835,7 @@ static void _view_content_changed(AtspiAccessible *root, void *user_data)
                break;
        case ATSPI_ROLE_POPUP_MENU:
        case ATSPI_ROLE_DIALOG :
-               _current_highlight_object_set(nd, vconf_data, flat_navi_context_current_get(sd->flat_navi_context), HIGHLIGHT_FIRST);
+               _current_highlight_object_set(nd, vconf_data, haptic_data, flat_navi_context_current_get(sd->flat_navi_context), HIGHLIGHT_FIRST);
                break;
        default :
                break;
index c133fa2924c48adedd9b3592a367a7da1ff9a460..9d504767fbd9ad8af58a283c2839357ba65a56c2 100644 (file)
@@ -42,6 +42,7 @@ Service_Data service_data = {
        .window_tracker_data = NULL,
        .spi_data = NULL,
        .vconf_data = NULL,
+       .screen_reader_haptic_data = NULL,
 
        //Set by vconf
        .run_service = 1,
index 028ba0e0b3aa06c2d4337b1ebfe443a4c100324a..93ae864238bada05d347d4d65d223311e1c8f102 100644 (file)
 #include <device/haptic.h>
 #include "logger.h"
 #include "smart_notification.h"
+#include "screen_reader_haptic.h"
 
-static haptic_device_h handle;
-static haptic_effect_h effect_handle;
+struct _screen_reader_haptic_data {
+       haptic_device_h handle;
+       haptic_effect_h effect_handle;
+};
 
 #define RED  "\x1B[31m"
 #define RESET "\033[0m"
@@ -28,21 +31,32 @@ static haptic_effect_h effect_handle;
  * @brief Initializer for haptic module
  *
  */
-void haptic_module_init(void)
+Haptic_Data *haptic_module_init(void)
 {
        int num;
+       Haptic_Data *haptic_data = calloc(1, sizeof(Haptic_Data));
+
+       if (haptic_data == NULL) {
+               ERROR("NULL context parameter");
+               return NULL;
+       }
 
        if (!device_haptic_get_count(&num)) {
                DEBUG(RED "Haptic device received!" RESET);
+               return haptic_data;
        } else {
                ERROR("Cannot receive haptic device count");
-               return;
+               free(haptic_data);
+               return NULL;
        }
 
-       if (!device_haptic_open(0, &handle)) {
+       if (!device_haptic_open(0, haptic_data->handle)) {
                DEBUG(RED "Device connected!" RESET);
+               return haptic_data;
        } else {
                ERROR("Cannot open haptic device");
+               free(haptic_data);
+               return NULL;
        }
 }
 
@@ -50,14 +64,22 @@ void haptic_module_init(void)
  * @brief Disconnect haptic handle
  *
  */
-void haptic_module_disconnect(void)
+void haptic_module_shutdown(Haptic_Data *haptic_data)
 {
-       if (!handle) {
+       if (haptic_data == NULL) {
+               ERROR("NULL context parameter");
+               free(haptic_data);
+               return;
+       }
+
+       if (!haptic_data->handle) {
                ERROR("Haptic handle lost");
+               free(haptic_data);
                return;
        }
-       if (!device_haptic_close(handle)) {
+       if (!device_haptic_close(haptic_data->handle)) {
                DEBUG("Haptic disconnected");
+               free(haptic_data);
        } else {
                ERROR("Haptic close error");
        }
@@ -67,13 +89,18 @@ void haptic_module_disconnect(void)
  * @brief Start vibrations
  *
  */
-void haptic_vibrate_start(int duration, int feedback)
+void haptic_vibrate_start(int duration, int feedback, Haptic_Data *haptic_data)
 {
-       if (!handle) {
+       if (haptic_data == NULL) {
+               ERROR("NULL context parameter");
+               return;
+       }
+
+       if (!haptic_data->handle) {
                ERROR("Haptic handle lost");
                return;
        }
-       if (!device_haptic_vibrate(handle, duration, feedback, &effect_handle)) {
+       if (!device_haptic_vibrate(haptic_data->handle, duration, feedback, haptic_data->effect_handle)) {
                DEBUG(RED "Vibrations started!" RESET);
        } else {
                ERROR("Cannot start vibration");
@@ -84,13 +111,18 @@ void haptic_vibrate_start(int duration, int feedback)
  * @brief Stop vibrations
  *
  */
-void haptic_vibrate_stop(void)
+void haptic_vibrate_stop(Haptic_Data *haptic_data)
 {
-       if (!handle) {
+       if (haptic_data == NULL) {
+               ERROR("NULL context parameter");
+               return;
+       }
+
+       if (!haptic_data->handle) {
                ERROR("Haptic handle lost");
                return;
        }
-       if (!device_haptic_stop(handle, &effect_handle)) {
+       if (!device_haptic_stop(haptic_data->handle, haptic_data->effect_handle)) {
                ERROR("Vibrations stopped!");
        } else {
                DEBUG(RED "Cannot stop vibration" RESET);
index 7c681c9334747de4868699bbd34ada993e2d4ed8..962397dc3296b47bb821a0430852a2565cdb4f56 100644 (file)
@@ -221,7 +221,7 @@ Smart_Notification_Data *smart_notification_init()
 void smart_notification_shutdown(Smart_Notification_Data *snd)
 {
 #ifndef SCREEN_READER_TV
-       haptic_module_disconnect();
+       haptic_module_shutdown(NULL); //TODO: pass haptic module context instead of NULL
 #endif
        free(snd);
 }