界面增加电量接口,实现电量显示
authorCaisking <3449750381@qq.com>
Tue, 19 Dec 2023 10:34:39 +0000 (18:34 +0800)
committerCaisking <3449750381@qq.com>
Tue, 19 Dec 2023 10:34:39 +0000 (18:34 +0800)
code/sdk/application/wearable/nativeapp/CMakeLists.txt
code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h
code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp

index 653e403..a5eda24 100755 (executable)
@@ -40,6 +40,7 @@ set(PRIVATE_HEADER
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/smart_voice/smart_voice_service/interfaces/innerkits/native_c/include
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/smart_voice/voice_engine_hal/interfaces/innerkits/native_c/include
     ${CMAKE_CURRENT_SOURCE_DIR}/../ohos_deps
+    ${CMAKE_CURRENT_SOURCE_DIR}/../../battery
 
     ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/utils/innerkits
     ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include
index 0f55177..43d443c 100755 (executable)
@@ -36,7 +36,9 @@
 #include "components/ui_box_progress.h"
 #include "components/ui_image_view.h"
 #include "components/ui_label.h"
+#include "battery.h"
 
+extern uint8_t battery_get_voltage(float *voltage);
 namespace OHOS {
 static constexpr int16_t SEC_TO_MILLI = 1000;
 static constexpr int16_t USEC_TO_MILLI = 1000;
@@ -73,7 +75,10 @@ public:
     ~ProgressCallback() {}
     virtual void Callback(UIView *view)
     {
-        int value = std::rand() % 101; // 生成一个介于 0 和 100 之间的随机数
+        //int value = std::rand() % 101; // 生成一个介于 0 和 100 之间的随机数
+        float voltage = 0.0F ;
+        // battery_get_voltage_by_channel(&voltage,channel);
+        uint8_t value = battery_get_voltage(&voltage);
         char* progress1ForeImageSrc = nullptr;
         char* progress1BackImageSrc = nullptr;
         if (value <= 10) {
index 5e16365..6f2cd3f 100755 (executable)
@@ -13,6 +13,8 @@
 #include "common/image_cache_manager.h"
 #include <time.h>
 
+
+
 namespace OHOS {
 static MainClockView *g_pMainClockView = nullptr;
 
@@ -452,7 +454,7 @@ bool MainClockView::InitSweepClock(void)
     if (progress == nullptr) {
         progress = new UIBoxProgress();
     }
-    progress->SetPosition(182, 58);         // widget's left position and top position
+    progress->SetPosition(180, 58);         // widget's left position and top position
     progress->Resize(31, 19);          // widget's width and height
     progress->SetViewId("progress1");// Set style
     progress->SetStyle(STYLE_BACKGROUND_OPA, 0xff);