//充电中 UI
UIViewGroup *UIViewGroup_charge =nullptr;
- UICircleProgress *circleProgress1_=nullptr;
+ UICircleProgress *batteryprogress = nullptr;
UIImageView *image_circle = nullptr;
UIImageView *image_lightning=nullptr;
osTimerId_t Chargeing_timer= NULL;
- void Chargeing_Timer_CallBack(int data)
- {
- float voltage = 0.0F;
- uint8_t power = 0;
- power = battery_get_voltage(&voltage);
-
- char buf[16]={0};
- sprintf(buf,"%d%c",power,'%');
- //printf("power:%s\r\n",buf);
- time_t currtime;
- struct tm *timeinfo;
- time(&currtime);
- timeinfo = localtime(&currtime);
-
- char time_buf[16]={0};
- sprintf_s(time_buf,16,"%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min);
-
- if(UILabel_time)
- UILabel_time->SetText(time_buf);
- if(UILabel_power)
- UILabel_power->SetText(buf);
-
- RootView::GetInstance()->Invalidate();
-
-
+ // 刷新回调
+ void Chargeing_Timer_CallBack(int data) {
+ float voltage = 0.0F;
+ uint8_t power = battery_get_voltage(&voltage);
+
+ // 使用 std::to_string 生成电池电量字符串
+ std::string powerstr = std::to_string(power) + "%";
+
+ // 获取当前时间
+ time_t seconds;
+ time(&seconds);
+ struct tm pTM;
+ localtime_r(&seconds, &pTM); // 使用 localtime_r 以确保线程安全
+
+ // 解析时间并格式化为字符串
+ std::string stringtime =
+ (pTM.tm_hour < 10 ? "0" : "") + std::to_string(pTM.tm_hour) + ":" +
+ (pTM.tm_min < 10 ? "0" : "") + std::to_string(pTM.tm_min);
+
+ // 刷新时间标签
+ if (UILabel_time) {
+ UILabel_time->SetText(stringtime.c_str());
+ }
+
+ // 刷新电池百分比标签
+ if (UILabel_power) {
+ UILabel_power->SetText(powerstr.c_str());
+ }
+
+ // 刷新进度条
+ if (batteryprogress) {
+ batteryprogress->SetValue(power);
+ }
+
+ // 刷新 UI
+ if (UILabel_time) {
+ UILabel_time->Invalidate();
+ }
+ if (UILabel_power) {
+ UILabel_power->Invalidate();
+ }
+ if (batteryprogress) {
+ batteryprogress->Invalidate();
+ }
}
bool is_UIViewGroup_charge(void)
Chargeing_timer = NULL;
}
- if(circleProgress1_)
- {
- delete circleProgress1_;
- circleProgress1_ = nullptr;
+ if (batteryprogress) {
+ delete batteryprogress;
+ batteryprogress = nullptr;
}
if(image_lightning)
{
char time_buf[16]={0};
sprintf_s(time_buf,16,"%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min);
- if (circleProgress1_ == nullptr) {
- circleProgress1_ = new UICircleProgress();
+ if (batteryprogress == nullptr) {
+ batteryprogress = new UICircleProgress();
}
- circleProgress1_->SetPosition(123, 123); // widget's left position and top position
- circleProgress1_->Resize(224, 222); // widget's width and height
- circleProgress1_->SetViewId("circleProgress1");// Set style
- circleProgress1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+ batteryprogress->SetPosition(
+ 123, 123); // widget's left position and top position
+ batteryprogress->Resize(224, 222); // widget's width and height
+ batteryprogress->SetViewId("circleProgress1"); // Set style
+ batteryprogress->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
// Set additional property
// Set BackgroundStyle
- circleProgress1_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
- circleProgress1_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x05);
- circleProgress1_->SetBackgroundStyle(STYLE_BORDER_OPA, 0x07);
- circleProgress1_->SetBackgroundStyle(STYLE_LINE_OPA, 0x07);
- circleProgress1_->SetBackgroundStyle(STYLE_LINE_WIDTH, 22);
+ batteryprogress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ batteryprogress->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x05);
+ batteryprogress->SetBackgroundStyle(STYLE_BORDER_OPA, 0x07);
+ batteryprogress->SetBackgroundStyle(STYLE_LINE_OPA, 0x07);
+ batteryprogress->SetBackgroundStyle(STYLE_LINE_WIDTH, 22);
// Set ForegroundStyle
- circleProgress1_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
- circleProgress1_->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000);
- circleProgress1_->SetForegroundStyle(STYLE_LINE_COLOR, 0xff4FC34C);
- circleProgress1_->SetForegroundStyle(STYLE_LINE_WIDTH, 22);
- circleProgress1_->SetCenterPosition(111, 109);
- circleProgress1_->SetRadius(108);
- circleProgress1_->SetEndAngle(359);
- circleProgress1_->SetValue(power);
- circleProgress1_->SetVisible(true);
- circleProgress1_->SetCapType(CAP_ROUND);
-
+ batteryprogress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
+ batteryprogress->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000);
+ batteryprogress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff4FC34C);
+ batteryprogress->SetForegroundStyle(STYLE_LINE_WIDTH, 22);
+ batteryprogress->SetCenterPosition(111, 109);
+ batteryprogress->SetRadius(108);
+ batteryprogress->SetEndAngle(359);
+ batteryprogress->SetValue(power);
+ batteryprogress->SetVisible(true);
+ // batteryprogress->SetCapType(CAP_ROUND); 不使用圆形边缘
if (image_lightning == nullptr) {
image_lightning = new UIImageView();
UIViewGroup_charge->Add(image_lightning);
UIViewGroup_charge->Add(image_circle);
-
-
- UIViewGroup_charge->Add(circleProgress1_);
+ UIViewGroup_charge->Add(batteryprogress);
UIViewGroup_charge->Add(UILabel_time);
UIViewGroup_charge->Add(UILabel_power);