From b435687e33713deff6ab5185b3d0b35d1db1c82b Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Mon, 1 May 2023 21:05:26 +0200 Subject: [PATCH] Added the find my phone app/feature source files --- .../app/gfx/find_phone_screen.c | 191 ++++++++++++++++++ .../app/gfx/find_phone_screen.h | 36 ++++ 2 files changed, 227 insertions(+) create mode 100644 src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.c create mode 100644 src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.h diff --git a/src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.c b/src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.c new file mode 100644 index 0000000..9a8c755 --- /dev/null +++ b/src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.c @@ -0,0 +1,191 @@ +#include "find_phone_screen.h" +#include "menu_screen.h" +#include "translation.h" + +static void gesture_event_cb(lv_event_t *e) +{ + FindPhoneScreen_t *findPhoneScreen = e->user_data; + + lv_dir_t gesture; + switch(gesture = lv_indev_get_gesture_dir(lv_indev_get_act())) + { + case LV_DIR_LEFT: + LV_LOG_USER("GESTURE : LEFT"); + break; + case LV_DIR_RIGHT: + LV_LOG_USER("GESTURE : RIGHT"); + // We check if we were finding our phone ? + if(findPhoneScreen->finding_phone) + if(findPhoneScreen->sendFindPhoneBLECommandCb)findPhoneScreen->sendFindPhoneBLECommandCb(false); + // We create the menu screen and switch to it + extern MenuScreen_t menuScreen; + menu_screen_create(&menuScreen); + lv_scr_load_anim(menuScreen.display, LV_SCR_LOAD_ANIM_MOVE_RIGHT, 400, 0, true); + break; + case LV_DIR_TOP: + LV_LOG_USER("GESTURE : TOP"); + break; + case LV_DIR_BOTTOM: + LV_LOG_USER("GESTURE : BOTTOM"); + break; + default: + LV_LOG_USER("GESTURE : %u", gesture); + } +} + +static void cleanup_event_cb(lv_event_t *e) +{ + FindPhoneScreen_t *findPhoneScreen = e->user_data; + find_phone_screen_destroy(findPhoneScreen); + LV_LOG_USER("cleanup"); +} + +static void button_click_event_cb(lv_event_t *e) +{ + FindPhoneScreen_t *findPhoneScreen = e->user_data; + + if(!findPhoneScreen->finding_phone) + { + lv_obj_set_style_border_color(findPhoneScreen->innerCircle, lv_color_make(238, 17, 133), LV_PART_MAIN); + lv_label_set_text_static(findPhoneScreen->findPhoneButton.label, translation_get_word(TRANSLATION_FOUND_MY_PHONE_BTN)); + if(findPhoneScreen->sendFindPhoneBLECommandCb)findPhoneScreen->sendFindPhoneBLECommandCb(true); + findPhoneScreen->finding_phone = true; + } + else + { + lv_obj_set_style_border_color(findPhoneScreen->innerCircle, lv_color_make(67, 160, 71), LV_PART_MAIN); + lv_label_set_text_static(findPhoneScreen->findPhoneButton.label, translation_get_word(TRANSLATION_FIND_MY_PHONE_BTN)); + if(findPhoneScreen->sendFindPhoneBLECommandCb)findPhoneScreen->sendFindPhoneBLECommandCb(false); + findPhoneScreen->finding_phone = false; + } + + LV_LOG_USER("find my phone button clicked"); +} + +static void _disable_btn_no_ble_connection(FindPhoneScreen_t * const findPhoneScreen, bool connected) +{ + if(connected) + { + lv_obj_set_style_border_color(findPhoneScreen->innerCircle, lv_color_make(67, 160, 71), LV_PART_MAIN); + lv_label_set_text_static(findPhoneScreen->findPhoneButton.label, translation_get_word(TRANSLATION_FIND_MY_PHONE_BTN)); + lv_obj_clear_state(findPhoneScreen->findPhoneButton.button, LV_STATE_DISABLED); + } + else + { + lv_obj_set_style_border_color(findPhoneScreen->innerCircle, lv_color_make(96, 125, 139), LV_PART_MAIN); + lv_label_set_text_static(findPhoneScreen->findPhoneButton.label, translation_get_word(TRANSLATION_PHONE_NOT_CONNECTED)); + lv_obj_add_state(findPhoneScreen->findPhoneButton.button, LV_STATE_DISABLED); + } +} + +void find_phone_screen_init(FindPhoneScreen_t * const findPhoneScreen) +{ + if(!findPhoneScreen) + { + LV_LOG_ERROR("NULL pointer given !"); + return; + } + + memset(findPhoneScreen, 0, sizeof(FindPhoneScreen_t)); +} + +void find_phone_screen_register_BLE_command_send_cb(FindPhoneScreen_t * const findPhoneScreen, SendFindPhoneBLECommandCb_t sendFindPhoneBLECommandCb) +{ + if(!findPhoneScreen) + { + LV_LOG_ERROR("NULL pointer given !"); + return; + } + + findPhoneScreen->sendFindPhoneBLECommandCb = sendFindPhoneBLECommandCb; +} + +void find_phone_screen_notify_BLE_connection_state(FindPhoneScreen_t * const findPhoneScreen, bool connected) +{ + if(!findPhoneScreen) + { + LV_LOG_ERROR("NULL pointer given !"); + return; + } + + if(findPhoneScreen->ble_connection_state != connected) + { + findPhoneScreen->ble_connection_state = connected; + if(findPhoneScreen->display != NULL) + _disable_btn_no_ble_connection(findPhoneScreen, findPhoneScreen->ble_connection_state); + } +} + +void find_phone_screen_create(FindPhoneScreen_t * const findPhoneScreen) +{ + if(!findPhoneScreen) + { + LV_LOG_ERROR("NULL pointer given !"); + return; + } + + if(findPhoneScreen->display) + { + LV_LOG_ERROR("display should be NULL here !"); + lv_obj_del(findPhoneScreen->display); + findPhoneScreen->display = NULL; + } + findPhoneScreen->display = lv_obj_create(NULL); + lv_obj_set_style_bg_color(findPhoneScreen->display, lv_color_make(0xFF,0xFF,0xFF), LV_PART_MAIN); + + if(findPhoneScreen->innerCircle) + { + LV_LOG_ERROR("innerCircle should be NULL here !"); + lv_obj_del(findPhoneScreen->innerCircle); + findPhoneScreen->innerCircle = NULL; + } + findPhoneScreen->innerCircle = lv_obj_create(findPhoneScreen->display); + lv_obj_center(findPhoneScreen->innerCircle); + lv_obj_set_size(findPhoneScreen->innerCircle, 240, 240); + lv_obj_set_style_bg_color(findPhoneScreen->innerCircle, lv_color_make(0xFF,0xFF,0xFF), LV_PART_MAIN); + lv_obj_set_style_radius(findPhoneScreen->innerCircle, LV_RADIUS_CIRCLE, LV_PART_MAIN); + lv_obj_set_style_border_width(findPhoneScreen->innerCircle, 15, LV_PART_MAIN); + + if(findPhoneScreen->findPhoneButton.button) + { + LV_LOG_ERROR("button should be NULL here !"); + lv_obj_del(findPhoneScreen->findPhoneButton.button); + findPhoneScreen->findPhoneButton.button = NULL; + } + findPhoneScreen->findPhoneButton.button = lv_btn_create(findPhoneScreen->innerCircle); + lv_obj_center(findPhoneScreen->findPhoneButton.button); + lv_obj_set_size(findPhoneScreen->findPhoneButton.button, 155, 155); + lv_obj_set_style_radius(findPhoneScreen->findPhoneButton.button, LV_RADIUS_CIRCLE, LV_PART_MAIN); + lv_obj_set_style_shadow_spread(findPhoneScreen->findPhoneButton.button, 2, LV_PART_MAIN); + lv_obj_add_event_cb(findPhoneScreen->findPhoneButton.button, &(button_click_event_cb), LV_EVENT_CLICKED, findPhoneScreen); + + if(findPhoneScreen->findPhoneButton.label) + { + LV_LOG_ERROR("label should be NULL here !"); + lv_obj_del(findPhoneScreen->findPhoneButton.label); + findPhoneScreen->findPhoneButton.label = NULL; + } + findPhoneScreen->findPhoneButton.label = lv_label_create(findPhoneScreen->findPhoneButton.button); + lv_obj_center(findPhoneScreen->findPhoneButton.label); + lv_obj_set_style_text_align(findPhoneScreen->findPhoneButton.label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN); + lv_obj_set_style_text_font(findPhoneScreen->findPhoneButton.label, &lv_font_montserrat_28, LV_PART_MAIN); + + _disable_btn_no_ble_connection(findPhoneScreen, findPhoneScreen->ble_connection_state); + + + //We register the event callback to handle gestures + lv_obj_add_event_cb(findPhoneScreen->display, &(gesture_event_cb), LV_EVENT_GESTURE, findPhoneScreen); + //We register the event callback to handle the cleanup + lv_obj_add_event_cb(findPhoneScreen->display, &(cleanup_event_cb), LV_EVENT_DELETE, findPhoneScreen); +} + +void find_phone_screen_destroy(FindPhoneScreen_t * const findPhoneScreen) +{ + if(!findPhoneScreen) + { + LV_LOG_ERROR("NULL pointer given !"); + return; + } + + memset(findPhoneScreen, 0, offsetof(FindPhoneScreen_t, sendFindPhoneBLECommandCb)); +} diff --git a/src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.h b/src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.h new file mode 100644 index 0000000..a76a0ca --- /dev/null +++ b/src/W800_SDK_v1.00.10/app/gfx/find_phone_screen.h @@ -0,0 +1,36 @@ +#ifndef FIND_PHONE_SCREEN_H +#define FIND_PHONE_SCREEN_H + +#include "lvgl.h" + +typedef void (*SendFindPhoneBLECommandCb_t)(bool findPhone); + +typedef struct FindPhoneButton +{ + lv_obj_t *button; + lv_obj_t *label; +} FindPhoneButton_t; + +typedef struct FindPhoneScreen +{ + //Can be erased attributes + lv_obj_t *display; + lv_obj_t *innerCircle; + FindPhoneButton_t findPhoneButton; + bool finding_phone; + //Should not be erased attributes + SendFindPhoneBLECommandCb_t sendFindPhoneBLECommandCb; + bool ble_connection_state; +} FindPhoneScreen_t; + +void find_phone_screen_init(FindPhoneScreen_t * const findPhoneScreen); + +void find_phone_screen_register_BLE_command_send_cb(FindPhoneScreen_t * const findPhoneScreen, SendFindPhoneBLECommandCb_t sendFindPhoneBLECommandCb); + +void find_phone_screen_notify_BLE_connection_state(FindPhoneScreen_t * const findPhoneScreen, bool connected); + +void find_phone_screen_create(FindPhoneScreen_t * const findPhoneScreen); + +void find_phone_screen_destroy(FindPhoneScreen_t * const findPhoneScreen); + +#endif //FIND_PHONE_SCREEN_H