Merge "Add function to generate description from nested object hierarchy" into tizen
[profile/tv/apps/native/screen-reader.git] / src / screen_reader_system.c
1 #include <device/battery.h>
2 #include <device/display.h>
3 #include <device/callback.h>
4 #include "screen_reader.h"
5 #include "screen_reader_tts.h"
6 #include "smart_notification.h"
7 #include "logger.h"
8
9 #define CHARGING "Battery charger connected"
10 #define NOT_CHARGING "Battery charger disconnected"
11 #define SCREEN_ON "Screen is on"
12 #define SCREEN_OFF "Screen is off"
13 #define BATTERY_LOW "Battery level is low"
14 #define BATTERY_FULL "Battery level is full"
15 #define BATTERY_CRITICAL "Battery level is critical"
16
17 static void device_system_cb(device_callback_e type, void *value, void *user_data);
18
19 /**
20  * @brief Initializer for smart notifications
21  *
22  */
23 void system_notifications_init(void)
24 {
25     // BATTERY LOW/FULL
26     device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb, NULL);
27     // BATTERY CHARGING/NOT-CHARGING
28     device_add_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb, NULL);
29     // SCREEN OFF/ON
30     device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb, NULL);
31 }
32
33 /**
34  * @brief Initializer for smart notifications
35  *
36  */
37 void system_notifications_shutdown(void)
38 {
39     // BATTERY LOW/FULL
40     device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb);
41     // BATTERY CHARGING/NOT-CHARGING
42     device_remove_callback(DEVICE_CALLBACK_BATTERY_CHARGING, device_system_cb);
43     // SCREEN OFF/ON
44     device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb);
45 }
46
47 /**
48  * @brief Device system callback handler
49  *
50  * @param type Device callback type
51  * @param value UNUSED
52  * @param user_data UNUSED
53  */
54 static void device_system_cb(device_callback_e type, void *value, void *user_data)
55 {
56     if(type == DEVICE_CALLBACK_BATTERY_LEVEL)
57       {
58          device_battery_level_e status;
59          if(device_battery_get_level_status(&status))
60            {
61               ERROR("Cannot get battery level status");
62               return;
63            }
64
65          if(status == DEVICE_BATTERY_LEVEL_LOW)
66            {
67               tts_speak(BATTERY_LOW, TRUE);
68            }
69          else if(status == DEVICE_BATTERY_LEVEL_CRITICAL)
70            {
71               tts_speak(BATTERY_CRITICAL, TRUE);
72            }
73          else if(status == DEVICE_BATTERY_LEVEL_FULL)
74            {
75               tts_speak(BATTERY_FULL, TRUE);
76            }
77       }
78     else if(type == DEVICE_CALLBACK_BATTERY_CHARGING)
79       {
80          bool charging;
81          if(device_battery_is_charging(&charging))
82            {
83               ERROR("Cannot check if battery is charging");
84               return;
85            }
86
87          if(charging)
88            {
89               tts_speak(CHARGING, FALSE);
90            }
91          else
92            {
93               tts_speak(NOT_CHARGING, FALSE);
94            }
95       }
96     else if(type == DEVICE_CALLBACK_DISPLAY_STATE)
97       {
98          display_state_e state;
99          if(device_display_get_state(&state))
100            {
101               ERROR("Cannot check if battery is charging");
102               return;
103            }
104
105          if(state == DISPLAY_STATE_NORMAL)
106            {
107               tts_speak(SCREEN_ON, FALSE);
108            }
109          else if(state == DISPLAY_STATE_SCREEN_OFF)
110            {
111               tts_speak(SCREEN_OFF, FALSE);
112            }
113       }
114 }