static BATTERY_DATA_T *bat_t;
static uint32_t len = 0;
+void battery_file_check(BATTERY_DATA_T newStruct, const char *filename)
+{
+ FILE *fp;
+ BATTERY_DATA_T data[200];
+ uint8_t count = 0;
+ uint8_t oldest = 0;
+ fp = fopen(filename, "r+b");
+ if(!fp)
+ fp = fopen(filename, "wb");
+
+ fseek(fp, 0, SEEK_END);
+ count = ftell(fp) / sizeof(BATTERY_DATA_T);
+ fseek(fp, 0, SEEK_SET);
+ // PRINT("battery data count %d \n",count);
+ if (count >= 180)
+ {
+ fread(data, sizeof(BATTERY_DATA_T), count, fp);
+
+ for (int i = 1; i < count; i++)
+ {
+ if (data[i].tm < data[oldest].tm)
+ {
+ oldest = i;
+ }
+ }
+
+ data[oldest] = newStruct;
+
+ fseek(fp, 0, SEEK_SET);
+ fwrite(data, sizeof(BATTERY_DATA_T), count, fp);
+ }
+ else
+ {
+ fseek(fp, 0, SEEK_END);
+ fwrite(&newStruct, sizeof(BATTERY_DATA_T), 1, fp);
+ }
+
+ fclose(fp);
+}
+
+
void battery_get_data_t(BATTERY_DATA_T **data,uint16_t *length)
{
if(!len)
void battery_get_data(void)
{
- len = uapi_get_file_size("/user/userdata/battery_data.bin");
+ len = uapi_get_file_size("/user/userdata/bat_data.bin");
if(!len)
return;
bat_t = (BATTERY_DATA_T *)malloc(len);
FILE *fp;
- fp = fopen("/user/userdata/battery_data.bin", "rb");
+ fp = fopen("/user/userdata/bat_data.bin", "rb");
if (fp == NULL)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery_data file open failed");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bat_data file open failed");
free(bat_t);
return;
}
if(fread(bat_t, 1, len, fp) != len)
{
free(bat_t);
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery_data file read failed");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bat_data file read failed");
}
fclose(fp);
}
//保存电池信息到文件
void battery_save_data(void)
{
- len = uapi_get_file_size("/user/userdata/battery_data.bin");
- if(len > sizeof(BATTERY_DATA_T) * 24 * 7)
- {
- uapi_delete_files("/user/userdata/battery_data.bin");
- }
+ // len = uapi_get_file_size("/user/userdata/battery_data.bin");
+ // if(len > sizeof(BATTERY_DATA_T) * 24 * 7)
+ // {
+ // uapi_delete_files("/user/userdata/battery_data.bin");
+ // }
BATTERY_DATA_T data;
float voltage;
data.voltage = voltage;
data.percent = percent;
uapi_get_timestampe_ss(&data.tm);
+ data.stat = get_charge_stat();
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "data.voltage : %f , data[i].percent : %d tm : %d",data.voltage,data.percent,data.tm);
- uapi_save_file_data("user/userdata/battery_data.bin",(uint8_t *)&data,sizeof(BATTERY_DATA_T),"ab");
-
+ // uapi_save_file_data("user/userdata/battery_data.bin",(uint8_t *)&data,sizeof(BATTERY_DATA_T),"ab");
+ battery_file_check(data,"user/userdata/bat_data.bin");
uapi_save_file_data("/user/userdata/battery.bin",&percent,1,"wb");
}
#include "diag_log.h"
namespace OHOS
{
+ static int get_battery_percent_flag = 0;
+ static int refreshbutton_is_visible = 1; //刷新按钮是否显示
/**************************************************************************************************** */
// 辅助函数
UIToggleButton* toggleButton = nullptr;
UIToggleButton* toggleButtonOffline = nullptr;
UILabelButton *debugOutputbleServiceLabelButton{nullptr};
+ UILabelButton *nextorprepageLabelButton{nullptr};
static constexpr const char *DEBUGOUTPUTLABELBUTTON = "debugOutputLabelButton";
static constexpr const char *DEBUGOUTPUTBLESERVICELABELBUTTON = "debugOutputbleServiceLabelButton";
+ static constexpr const char *NEXTORPREPAGELABELBUTTON = "nextorprepageLabelButton";
/* -------------------------------------------------------------------------- */
void DebugOutputViewEventListener::InitDebugOutputItem()
return get_wear_status_str(); // 返回结果字符串
}
- // 获取佩戴状态
+
+ // 获取电池状态
std::string DebugOutputViewEventListener::get_battery_percent(void)
{
std::string result;
+ std::string charge_stat;
+ int index = 0;
// 进行文件读取
do_custom_fileoperate_service_check_msg(
CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_READ, nullptr, 0);
if(len == 0)
return result;
- for(int i = 0; i < len/sizeof(BATTERY_DATA_T); i++)
+ len = len/sizeof(BATTERY_DATA_T);
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "111111len : %d",len);
+
+ if(get_battery_percent_flag == 1)
+ {
+ nextorprepageLabelButton->SetText("第二页");
+ get_battery_percent_flag = 2;
+ if(len >= 120)
+ {
+ index = 60;
+ len = 120;
+ }
+ else if(len >= 60 && len < 120)
+ index = 60;
+ else
+ return result;
+ }
+ else if(get_battery_percent_flag == 2)
+ {
+ nextorprepageLabelButton->SetText("第三页");
+ get_battery_percent_flag = 3;
+ if(len >= 120)
+ index = 120;
+ else
+ return result;
+ }
+ else
+ {
+ nextorprepageLabelButton->SetText("第一页");
+ get_battery_percent_flag = 1;
+ if(len >= 60)
+ len = 90;
+ }
+ for(int i = index; i < len; i++)
{
std::string timestr;
char labelTime[20] = {0};
}
std::ostringstream oss;
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data[i].voltage : %f , data[i].percent : %d",data[i].voltage,data[i].percent);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "data[%d].voltage : %f , data[%d].percent : %d",i,data[i].voltage,i,data[i].percent);
+
+ if(data[i].stat)
+ // charge_stat = static_cast<int>(i) + ":充电中";
+ charge_stat = "充电中";
+ else
+ // charge_stat = static_cast<int>(i) + ":未充电";
+ charge_stat = "未充电";
+
+ // result += std::to_string(i) + ":" + charge_stat + "[" + timestr + "]\n" + std::to_string(data[i].voltage) + " V, " + std::to_string(data[i].percent) + "%\n";
oss << std::fixed
<< std::setprecision(3) // 设置为固定小数位,保留两位小数
- <<"["<<timestr<< "] :\n"
- << data[i].voltage << " V, "
- << static_cast<int>(data[i].percent)
- << "%\n";
+ << charge_stat
+ <<", ["<<timestr<< "] ,"
+ << data[i].voltage << "V , "
+ << static_cast<int>(i) << "%\n";
result += oss.str();
// result += std::to_string(i*10) + " min , " + std::to_string(data[i].voltage) + "V , "+ std::to_string(data[i].percent) + "%" + "\n";
viewIndex = GetCurViewIndex();
}
//点击开启按键
- else if (viewId == "uart_at_set") {
+ else if (viewId == "uart_at_set")
+ {
if (toggleButton) {
if (toggleButton->GetState() == false) {
// toggleButton->SetState(false);
// viewIndex = GetCurViewIndex();
return true; //进行UI刷新
}//点击开启按键
- else if (viewId == "offline_log_switch") {
+ else if (viewId == "offline_log_switch")
+ {
if (toggleButtonOffline) {
if (toggleButtonOffline->GetState() == false) {
int ret1 = enable_offline_log_nv(0);
// viewIndex = GetCurViewIndex();
return true; //进行UI刷新
}
- else if (viewId == "hrs_ble_switch") {
+ else if (viewId == "hrs_ble_switch")
+ {
if (toggleButtonOffline) {
if (toggleButtonOffline->GetState() == false) {
send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_CLOSE_HRS_BLE);
}
return true; //进行UI刷新
}
+ else if (viewId == NEXTORPREPAGELABELBUTTON)
+ {
+ // std::string str;
+ viewIndex = GetCurViewIndex();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"111111 viewIndex : %d",viewIndex);
+ // if(nextorprepageLabelButton)
+ // {
+ // if(get_battery_percent_flag == 0)
+ // {
+ // nextorprepageLabelButton->SetText("下一页");
+ // // str = get_battery_percent();
+ // }
+ // else if(get_battery_percent_flag == 1)
+ // {
+ // nextorprepageLabelButton->SetText("上一页");
+ // // str = get_battery_percent();
+ // }
+ // }
+ }
else // 如果点击的是列表中的itemview
{
DebugOutputItemView *debugOutputItemView = static_cast<DebugOutputItemView *>(&view);
str = get_wear_status();
break;
case 16:
+ refreshbutton_is_visible = 0;
str = get_battery_percent();
+ if (nextorprepageLabelButton)
+ {
+ if (nextorprepageLabelButton->IsVisible() == false)
+ {
+ nextorprepageLabelButton->SetVisible(true);
+ }
+ }
break;
case 17:
str = get_offline_log_status();
{
debugOutputLabel->SetText(str.c_str());
}
- if (debugOutputLabelButton)
+ if(refreshbutton_is_visible) {
+ if (debugOutputLabelButton)
+ {
+ debugOutputLabelButton->SetY(debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
+ debugOutputLabelButton->Invalidate();
+ }
+ }
+ else
{
- debugOutputLabelButton->SetY(debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
- debugOutputLabelButton->Invalidate();
+ debugOutputLabelButton->SetVisible(false);
}
debugOutputLabel->Invalidate();
}
{
if (hideView == 1)
{
+ refreshbutton_is_visible = 1;
DebugGroupView->Remove(DebugScrollView[1]);
if (DebugScrollView[1] != nullptr)
{
delete debugOutputLabel;
debugOutputLabel = nullptr;
+ delete toggleButton;
+ toggleButton = nullptr;
+
+ delete nextorprepageLabelButton;
+ nextorprepageLabelButton = nullptr;
+
+ delete toggleButtonOffline;
+ toggleButtonOffline = nullptr;
+
delete debugOutputLabelButton;
debugOutputLabelButton = nullptr;
DebugScrollView[1]->SetScrollBlankSize(70);
DebugScrollView[1]->SetReboundSize(35);
DebugScrollView[1]->SetThrowDrag(true);
+ DebugScrollView[1]->SetMaxScrollDistance(1000);
UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
if (dragListener == nullptr)
{
debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
DebugScrollView[1]->Add(debugOutputLabel);
/* -------------------------------------------------------------------------- */
+ if (nextorprepageLabelButton == nullptr)
+ {
+ nextorprepageLabelButton = new UILabelButton();
+ if (nextorprepageLabelButton == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "nextorprepageLabelButton is new fail!!");
+ return nullptr;
+ }
+ }
+ nextorprepageLabelButton->SetPosition(143, 20);
+ nextorprepageLabelButton->Resize(100, 100);
+ nextorprepageLabelButton->SetViewId(NEXTORPREPAGELABELBUTTON);
+ nextorprepageLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
+ nextorprepageLabelButton->SetText("下一页");
+ nextorprepageLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
+ nextorprepageLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffff0000, UIButton::PRESSED);
+ nextorprepageLabelButton->SetVisible(false);
+ DebugScrollView[1]->Add(nextorprepageLabelButton);
+ UIView::OnClickListener *nextorpreclickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
+ if (nextorpreclickListener == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "nextorpreclickListener is new fail!!");
+ return nullptr;
+ }
+ nextorprepageLabelButton->SetOnClickListener(nextorpreclickListener);
+ /* -------------------------------------------------------------------------- */
if (debugOutputLabelButton == nullptr)
{
debugOutputLabelButton = new UILabelButton();
delete debugOutputbleServiceLabelButton;
debugOutputbleServiceLabelButton = nullptr;
- delete toggleButton;
- toggleButton = nullptr;
-
- delete toggleButtonOffline;
- toggleButtonOffline = nullptr;
-
delete DebugScrollView[0];
DebugScrollView[0] = nullptr;
}