系统:调试窗口增加电池相关服务 1120/1 1120/head
authorCaisking <3449750381@qq.com>
Tue, 8 Oct 2024 02:23:45 +0000 (10:23 +0800)
committerCaisking <3449750381@qq.com>
Tue, 8 Oct 2024 02:23:45 +0000 (10:23 +0800)
code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp

index df164c7..0d270bc 100644 (file)
@@ -37,8 +37,9 @@ namespace OHOS
         std::string get_cat1_runtime_status_t(void);
         std::string get_runtime_status_t(void);
         std::string get_system_log(void);
-        
-    private:
+        std::string get_battery_info(void);
+
+      private:
         DebugOutputViewEventListener();
         ~DebugOutputViewEventListener();
         DebugOutputViewEventListener(const DebugOutputViewEventListener &) = delete;
index 4142aaa..71a1fb3 100644 (file)
@@ -1,31 +1,26 @@
-#include "notification_manager.h"
-#include "wearable_log.h"
-#include "components/ui_label_button.h"
-#include "components/ui_image_view.h"
-#include "components/ui_label_ext.h"
-#include "components/ui_scroll_view.h"
 #include "../notify/debug_output_notification/debug_output_notification_adapter.h"
 #include "../notify/debug_output_notification/debug_output_notification_itemview.h"
-#include <custom_runtime.h>
-#include <custom_utils.h>
-#include <sstream>  
-#include <iomanip> 
-#include <sys/types.h>
-#include "bluetooth/include/BluetoothModel.h"
-#include "system/include/SystemLogModel.h"
-#include "wearable_log.h"
 #include "AppViewIDs.h"
 #include "NativeAbility.h"
+#include "battery_hal.h"
+#include "battery_service.h"
 #include "bleEvent.h"
+#include "bluetooth/include/BluetoothModel.h"
 #include "broadcast_feature.h"
 #include "broadcast_service.h"
 #include "cat1_ctl.h"
 #include "cat1_server.h"
+#include "components/ui_image_view.h"
+#include "components/ui_label_button.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_scroll_view.h"
 #include "custom_runtime.h"
 #include "custom_utils.h"
 #include "graphic_service.h"
 #include "lwip/apps/http_client.h"
+#include "notification_manager.h"
 #include "samgr_lite.h"
+#include "system/include/SystemLogModel.h"
 #include "tcxo.h"
 #include "thread_adapter.h"
 #include "thread_init.h"
 #include <array>
 #include <cmsis_os2.h>
 #include <cstdint>
+#include <custom_runtime.h>
+#include <custom_utils.h>
 #include <fstream>
+#include <iomanip>
 #include <iostream>
 #include <map>
 #include <service/graphic_service.h>
+#include <sstream>
 #include <string>
+#include <sys/types.h>
 #include <vector>
 namespace OHOS
 {
@@ -73,7 +73,10 @@ namespace OHOS
         debugOutputItemInfo[index++] = {1, "bt_ble_connectstat"};
         debugOutputItemInfo[index++] = {2, "cat1_runtime_status_t"};
         debugOutputItemInfo[index++] = {3, "runtime_status_t"};
+        //系统日志
         debugOutputItemInfo[index++] = {4, "system_log"};
+        //电池服务
+        debugOutputItemInfo[index++] = {5, "battery_service"};
         usedLen = index;
         /* -------------------------------- Add data -------------------------------- */
         for (uint8_t i = 0; i < usedLen; i++)
@@ -188,6 +191,7 @@ namespace OHOS
         return result;
     }
 
+    // 日志服务
     std::string DebugOutputViewEventListener::get_system_log()  
     {  
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_system_log");  
@@ -246,6 +250,37 @@ namespace OHOS
         return str.str(); // 返回拼接后的字符串  
     }
 
+
+    // 获取电池相关信息
+    std::string DebugOutputViewEventListener::get_battery_info() {
+      // 获取电池温度
+      float bat_temp = 0.0f;
+      batteryservice_get_battery_temp(&bat_temp);
+
+      // 获取 PCB 温度
+      float pcb_temp = 0.0f;
+      batteryservice_get_pcb_temp(&pcb_temp);
+
+      // 获取电量
+      float voltage = 0.0f;
+      uint8_t percent = batteryservice_get_voltage(&voltage);
+
+      // 获取充电状态
+      bool isCharging = get_charge_stat();
+
+      // 拼接字符串,并简化为保留两位小数
+      std::ostringstream oss;
+      oss << std::fixed
+          << std::setprecision(2) // 设置为固定小数位,保留两位小数
+          << "Bat Temp: " << bat_temp << " °C\n" 
+          << "PCB Temp: " << pcb_temp << " °C\n" 
+          << "Voltage: " << voltage << " V\n"   
+          << "Percent: " << static_cast<int>(percent)
+          << " %\n"                                   
+          << "Charge: " << (isCharging ? "Yes" : "No"); 
+
+      return oss.str();
+    }
     bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
     {
         std::string viewId = view.GetViewId();
@@ -293,6 +328,9 @@ namespace OHOS
         case 4:
             str = get_system_log();
             break;
+        case 5:
+            str = get_battery_info();
+            break;
         default:
             str = "--";
             break;