From 68ebeeb833685d85a09d3c287ba0be3ec9b9dbbf Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 8 Oct 2024 10:23:45 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E8=B0=83=E8=AF=95?= =?utf8?q?=E7=AA=97=E5=8F=A3=E5=A2=9E=E5=8A=A0=E7=94=B5=E6=B1=A0=E7=9B=B8?= =?utf8?q?=E5=85=B3=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../debug_output_notification.h | 5 +- .../debug_output_notification.cpp | 66 +++++++++++++++---- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h index df164c7fd..0d270bc7f 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h @@ -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; diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 4142aaa52..71a1fb3f0 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -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 -#include -#include -#include -#include -#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" @@ -34,11 +29,16 @@ #include #include #include +#include +#include #include +#include #include #include #include +#include #include +#include #include 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(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; -- 2.17.1