From: luozheng <1732036298@qq.com> Date: Fri, 12 Jul 2024 02:54:04 +0000 (+0800) Subject: 增加功能键的按下和长按事件 X-Git-Tag: release_V1.2.70_20241020_135402~825 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=7a5b1eadf069ad227c3f74df7820c84e4747e825;p=mirrors%2FFD230.git 增加功能键的按下和长按事件 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h index 4606d9fba..7f6f5331c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-12 11:44:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-10 21:13:23 + * @LastEditTime: 2024-07-12 10:23:32 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%A */ @@ -30,6 +30,8 @@ public: void SetExitsView(bool value); bool RegisterPowerKeyLongPressEvent(void); bool RegisterPowerKeyDoubleClickEvent(void); + bool RegisterFuncKeyPressEvent(void); + bool RegisterFuncKeyLongPressEvent(void); bool RegisterFuncKeyClickEvent(void); bool RegisterFuncKeyDoubleClickEvent(void); void RegisterAllKeyEvents(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp index fd61ab6a3..e33b2937e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-28 11:50:42 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-11 20:16:48 + * @LastEditTime: 2024-07-12 10:42:15 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp */ @@ -127,7 +127,73 @@ namespace OHOS int32_t ret = uapi_button_register_event_cb(HandlePowerKeyDoubleClick, BUTTON_PWR_CLICKUP_2); if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey Click Event error, ret = %d", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey DoubleClick Event error, ret = %d", ret); + return false; + } + return true; + } + + static void HandFuncKeyOnPress(void) + { + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + display_api->turn_on_screen(); + return; + } + + /*注册功能键的按下事件*/ + bool RebootModel::RegisterFuncKeyPressEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootModel::RegisterFuncKeyPressEvent"); + // Register FuncKey Press event here + int32_t ret = uapi_button_register_event_cb(HandFuncKeyOnPress, BUTTON1_PRESS); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey Press Event error, ret = %d", ret); + return false; + } + return true; + } + + static void HandFuncKeyOnLongPress(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandFuncKeyOnLongPress"); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + + if (display_api->get_screen_state() == SCREEN_ON) + { + uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + if (curSliceId == VIEW_AI_VOICE) // 如果当前已在ai语音界面不做切换 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VIEW_AI_VOICE is not switched"); + return; + } + // 全局切换到Ai语音界面 + NativeAbility::GetInstance().EnterSlice(VIEW_AI_VOICE); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Screen is not on, skipping AI voice change"); + } + } + + /*注册功能键的长按(2s)事件*/ + bool RebootModel::RegisterFuncKeyLongPressEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootModel::RegisterFuncKeyLongPressEvent"); + int32_t ret = uapi_button_register_event_cb(HandFuncKeyOnLongPress, BUTTON1_LONGPRESS_2S); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey LongPress Event error, ret = %d", ret); return false; } return true; @@ -208,6 +274,8 @@ namespace OHOS { RegisterPowerKeyDoubleClickEvent(); RegisterPowerKeyLongPressEvent(); + RegisterFuncKeyPressEvent(); + RegisterFuncKeyLongPressEvent(); RegisterFuncKeyClickEvent(); RegisterFuncKeyDoubleClickEvent(); } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 85c6042c3..ae59e87ac 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -312,7 +312,6 @@ void startup_post_init_task(void) power_off_cat1(); } uapi_gei_btmac_and_chipinfo(); - uapi_func_lcd_on(); } void startup_post_init(void) @@ -2336,14 +2335,3 @@ void uapi_gei_btmac_and_chipinfo(void) wstp_print("^^^^ BTMAC=%s ^^^^ CyweeChipInfo=%s\n",btaddr_str,chipinfo); } - -static void func_button_callback_press(void) -{ - const power_display_svr_api_t *display_api = power_display_svr_get_api(); - display_api->turn_on_screen(); -} - -void uapi_func_lcd_on(void) -{ - uapi_button_register_event_cb(func_button_callback_press, 24); -} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 588f10166..ad232bd86 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -228,7 +228,6 @@ void uapi_factorytest_hide_test_tp_button(void); void uapi_efuse_test_write(uint8_t *data,uint32_t byte_number,uint8_t len); void uapi_efuse_test_read(uint32_t byte_number,uint8_t len); void uapi_gei_btmac_and_chipinfo(void); -void uapi_func_lcd_on(void); #include "custom_utilscpp.h"