增加功能键的按下和长按事件
authorluozheng <1732036298@qq.com>
Fri, 12 Jul 2024 02:54:04 +0000 (10:54 +0800)
committerluozheng <1732036298@qq.com>
Fri, 12 Jul 2024 02:54:04 +0000 (10:54 +0800)
code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h
code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index 4606d9f..7f6f533 100644 (file)
@@ -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);
index fd61ab6..e33b293 100644 (file)
@@ -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();
     }
index 85c6042..ae59e87 100644 (file)
@@ -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
index 588f101..ad232bd 100644 (file)
@@ -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"