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"
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"
17 static void device_system_cb(device_callback_e type, void *value, void *user_data);
20 * @brief Initializer for smart notifications
23 void system_notifications_init(void)
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);
30 device_add_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb, NULL);
34 * @brief Initializer for smart notifications
37 void system_notifications_shutdown(void)
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);
44 device_remove_callback(DEVICE_CALLBACK_DISPLAY_STATE, device_system_cb);
48 * @brief Device system callback handler
50 * @param type Device callback type
52 * @param user_data UNUSED
54 static void device_system_cb(device_callback_e type, void *value, void *user_data)
56 if(type == DEVICE_CALLBACK_BATTERY_LEVEL)
58 device_battery_level_e status;
59 if(device_battery_get_level_status(&status))
61 ERROR("Cannot get battery level status");
65 if(status == DEVICE_BATTERY_LEVEL_LOW)
67 tts_speak(BATTERY_LOW, TRUE);
69 else if(status == DEVICE_BATTERY_LEVEL_CRITICAL)
71 tts_speak(BATTERY_CRITICAL, TRUE);
73 else if(status == DEVICE_BATTERY_LEVEL_FULL)
75 tts_speak(BATTERY_FULL, TRUE);
78 else if(type == DEVICE_CALLBACK_BATTERY_CHARGING)
81 if(device_battery_is_charging(&charging))
83 ERROR("Cannot check if battery is charging");
89 tts_speak(CHARGING, FALSE);
93 tts_speak(NOT_CHARGING, FALSE);
96 else if(type == DEVICE_CALLBACK_DISPLAY_STATE)
98 display_state_e state;
99 if(device_display_get_state(&state))
101 ERROR("Cannot check if battery is charging");
105 if(state == DISPLAY_STATE_NORMAL)
107 tts_speak(SCREEN_ON, FALSE);
109 else if(state == DISPLAY_STATE_SCREEN_OFF)
111 tts_speak(SCREEN_OFF, FALSE);