+/***
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-13 17:05:26
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenPresenter.h
+ */
/*
* Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
bool OnClick(UIView &view, const ClickEvent &event) override;
bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
- uint64_t GetCurrentTime();
- int GetTDOA(uint64_t new_time, uint64_t old_time);
+ uint32_t GetCurrentTime();
+ int GetTDOA(uint32_t new_time, uint32_t old_time);
private:
bool CheckPointersValue(void);
static constexpr uint16_t PROGRESS_VALUE_MAX = 10;
static BloodOxygenPresenter *g_pMainView;
/* -------------------------------------------------------------------------- */
- // 获取当前的"时间分"
- uint64_t BloodOxygenPresenter::GetCurrentTime()
+ // 获取当前的时间戳
+ uint32_t BloodOxygenPresenter::GetCurrentTime()
{
-
- // time_t now = time(0);
- // struct tm *tblock = localtime(&now);
-
- /*优化为更安全的localtime_r()*/
- struct timeval tv;
- gettimeofday(&tv, NULL);
- struct tm tblock;
- localtime_r(&tv.tv_sec, &tblock);
-
- uint64_t current_time = tblock.tm_hour * 60 + tblock.tm_min;
- return current_time;
+ uint32_t time;
+ if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp");
+ return 0;
+ }
+ return time;
}
// 获取时间差,现在传进来的是两个时间戳
- int BloodOxygenPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
+ int BloodOxygenPresenter::GetTDOA(uint32_t new_time, uint32_t old_time)
{
if (new_time == old_time || old_time > new_time)
{
return 0;
}
-
- int time_diff = new_time - old_time;
- return time_diff;
+ int time_diff_seconds = new_time - old_time;
+ // 转换为分钟的差值
+ int time_diff_minutes = time_diff_seconds / 60;
+ return time_diff_minutes;
}
/* -------------------------------------------------------------------------- */
#include <ctime>
namespace OHOS
{
- static HealthService *g_pHealthService = nullptr;
- static constexpr const char *HEALTH_JSON_PATH_HEART = "/user/userdata/health/heart/";
-
- static constexpr const char *HEALTH_JSON_PATH_OXYGEN = "/user/userdata/health/oxygen/";
+ static HealthService *g_pHealthService = nullptr;
+ /*获取日期*/
std::string GetCurrentDate()
{
time_t now = time(0);
strftime(date, sizeof(date), "%Y%m%d", ltm);
return std::string(date);
}
- //static char *JSON_F_buf=NULL;
- const char *GET_HEALTH_JSON_PATH_C_STR_HEART()
- {
- return HEALTH_JSON_PATH_HEART;
- }
-
- const char *GET_HEALTH_JSON_PATH_C_STR_OXYGEN()
- {
- return HEALTH_JSON_PATH_OXYGEN;
- }
-
+ // static char *JSON_F_buf=NULL;
cJSON *heart_root = NULL;
cJSON *oxygen_root = NULL;
HealthService::HealthService()
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HealthService::HealthService");
g_pHealthService = this;
}
-
HealthService::~HealthService()
{
g_pHealthService = nullptr;
}
-
HealthService *HealthService::GetInstance()
{
static HealthService instance;
return &instance;
}
+
+ static constexpr const char *HEALTH_JSON_PATH = "/user/userdata/health/";
+ static constexpr const char *HEALTH_JSON_PATH_HEART = "/user/userdata/health/heart/";
+ static constexpr const char *HEALTH_JSON_PATH_OXYGEN = "/user/userdata/health/oxygen/";
+
/* --------------------------------- 文件IO操作 --------------------------------- */
/*创建文件夹*/
bool HealthService::CreateHealthFolder()
{
struct stat info;
+ // 判断HEALTH_JSON_PATH是否存在 不存在就创建
+ if (stat(HEALTH_JSON_PATH, &info) != 0)
+ {
+ if (mkdir(HEALTH_JSON_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mkdir HEALTH_JSON_PATH is error");
+ return false; // Failed to create folder
+ }
+ }
+ // 判断HEALTH_JSON_PATH_HEART是否存在 不存在就创建
if (stat(HEALTH_JSON_PATH_HEART, &info) != 0)
{
if (mkdir(HEALTH_JSON_PATH_HEART, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
{
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mkdir HEALTH_JSON_PATH_HEART is error");
return false; // Failed to create folder
}
}
+ // 判断HEALTH_JSON_PATH_OXYGEN是否存在 不存在就创建
if (stat(HEALTH_JSON_PATH_OXYGEN, &info) != 0)
{
if (mkdir(HEALTH_JSON_PATH_OXYGEN, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
{
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mkdir HEALTH_JSON_PATH_OXYGEN is error");
return false; // Failed to create folder
}
}
return true;
}
- /*获取日期*/
-
/*生成文件*/
std::string GetJsonFilePath(uint8_t type)
{
std::string currentDate = GetCurrentDate();
- if(type==HEALTH_TYPE_HEART)
+
+ if (type == HEALTH_TYPE_HEART)
{
return std::string(HEALTH_JSON_PATH_HEART) + currentDate + ".json";
}
{
return std::string(HEALTH_JSON_PATH_OXYGEN) + currentDate + ".json";
}
-
}
-
-
+ const char *GET_HEALTH_JSON_PATH_C_STR_HEART()
+ {
+ return HEALTH_JSON_PATH_HEART;
+ }
+ const char *GET_HEALTH_JSON_PATH_C_STR_OXYGEN()
+ {
+ return HEALTH_JSON_PATH_OXYGEN;
+ }
bool HealthService::LoadJsonData(uint8_t type)
{
// 创建健康数据文件夹
-
- if(!CreateHealthFolder())
+ if (!CreateHealthFolder())
{
return false;
}
-
-
// 获取当天日期对应的JSON文件路径
std::string jsonFilePath = GetJsonFilePath(type);
std::ifstream inFile(jsonFilePath);
- cJSON *defaultJson=NULL;
+ cJSON *defaultJson = NULL;
if (!inFile.is_open())
{
+#if 0
// 如果文件不存在,则创建一个包含默认值的JSON文件
- if(type==HEALTH_TYPE_HEART)
+ if (type == HEALTH_TYPE_HEART)
{
defaultJson = cJSON_Parse("{\
\"heart_latest_data\": {\
]\
}");
}
- else if(type==HEALTH_TYPE_OXYGEN)
+ else if (type == HEALTH_TYPE_OXYGEN)
{
defaultJson = cJSON_Parse("{\
\"spo2_latest_data\": {\
]\
}");
}
-
std::ofstream outFile(jsonFilePath);
if (!outFile.is_open())
{
cJSON_free(defaultJsonString);
cJSON_Delete(defaultJson);
inFile.open(jsonFilePath); // 重新打开文件
+#endif
}
// 读取JSON文件内容
std::string jsonDataString((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
const char *jsonData = jsonDataString.c_str();
- if(type==HEALTH_TYPE_HEART)
+ if (type == HEALTH_TYPE_HEART)
{
- heart_root = cJSON_Parse(jsonData);
+ heart_root = cJSON_Parse(jsonData);
}
- if(type==HEALTH_TYPE_OXYGEN)
+ if (type == HEALTH_TYPE_OXYGEN)
{
- oxygen_root = cJSON_Parse(jsonData);
+ oxygen_root = cJSON_Parse(jsonData);
}
-
-
return true;
}
#if 0
HeartRateData *data = new HeartRateData();
cJSON *latestData = cJSON_GetObjectItem(heart_root, "heart_latest_data");
data->Heart = cJSON_GetObjectItem(latestData, "value")->valueint;
- data->timestamp = cJSON_GetObjectItem(latestData, "timestamp")->valuedouble;
+ data->timestamp = cJSON_GetObjectItem(latestData, "timestamp")->valueint;
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ReadHeartRateData: value %d timestamp%d", data->Heart, data->timestamp);
cJSON_Delete(heart_root);
return data;
}
return true;
}
- bool HealthService::UpdateJsonData( uint8_t type)
+ bool HealthService::UpdateJsonData(uint8_t type)
{
std::string jsonFilePath = GetJsonFilePath(type);
std::ofstream outFile(jsonFilePath);
{
return false;
}
- char *jsonData=NULL;
+ char *jsonData = NULL;
- if(type==HEALTH_TYPE_HEART)
- jsonData = cJSON_Print(heart_root);
+ if (type == HEALTH_TYPE_HEART)
+ jsonData = cJSON_Print(heart_root);
else
- jsonData = cJSON_Print(oxygen_root);
+ jsonData = cJSON_Print(oxygen_root);
if (jsonData == NULL)
{
std::string bloodoxygenStr = std::to_string(spo2_);\r
bloodLabel->SetText(bloodoxygenStr.c_str());\r
// 更新时间\r
- uint64_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime();\r
- uint64_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime();\r
+ uint32_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime();\r
+ uint32_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime();\r
std::string TimeStr = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";\r
timeLabel->SetText(TimeStr.c_str());\r
}\r
if (bloodoxygen != 0)\r
{\r
// 更新时间\r
- uint64_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime();\r
- uint64_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime();\r
+ uint32_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime();\r
+ uint32_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime();\r
std::string TimeStr = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";\r
timeLabel->SetText(TimeStr.c_str());\r
}\r
bool OnClick(UIView &view, const ClickEvent &event) override;
bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
- uint64_t GetCurrentTime();
- int GetTDOA(uint64_t new_time, uint64_t old_time);
+ uint32_t GetCurrentTime();
+ int GetTDOA(uint32_t new_time, uint32_t old_time);
private:
bool CheckPointersValue(void);
HeartRateData *data = new HeartRateData;\r
data->Heart = heart;\r
data->timestamp = HeartPresenter::GetInstance()->GetCurrentTime();\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %lld", heart, data->timestamp);\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %d", heart, data->timestamp);\r
SetCheckTime(data->timestamp);\r
HealthService::GetInstance()->UpdateHeartRateData(*data);\r
// 更新卡片心率值\r
+/***
+ * @Date: 2024-04-17 16:49:23
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-13 17:09:11
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartPresenter.cpp
+ */
#include "common/task_manager.h"
#include "components/ui_label.h"
#include "heartrate/include/HeartBandoffView.h"
#include "health_service.h"
#include "cywee_service.h"
+#include "custom_utils.h"
#define HEARTKEYABLE 0
static constexpr uint16_t PROGRESS_VALUE_MIN = 0;
static constexpr uint16_t PROGRESS_VALUE_MAX = 10;
- uint64_t HeartPresenter::GetCurrentTime()
+ uint32_t HeartPresenter::GetCurrentTime()
{
- // time_t now = time(0);
- // struct tm *tblock = localtime(&now);
-
+#if 0
/*优化为更安全的localtime_r()*/
struct timeval tv;
gettimeofday(&tv, NULL);
struct tm tblock;
localtime_r(&tv.tv_sec, &tblock);
- uint64_t current_time = tblock.tm_hour * 60 + tblock.tm_min;
+ uint32_t current_time = tblock.tm_hour * 60 + tblock.tm_min;
return current_time;
+#endif
+ uint32_t time;
+ if (uapi_get_timestampe_ss(&time) != ERRCODE_SUCC)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get timestamp");
+ return 0;
+ }
+ return time;
}
- int HeartPresenter::GetTDOA(uint64_t new_time, uint64_t old_time)
+ int HeartPresenter::GetTDOA(uint32_t new_time, uint32_t old_time)
{
if (new_time == old_time || old_time > new_time)
{
return 0;
}
-
- int time_diff = new_time - old_time;
- return time_diff;
+ int time_diff_seconds = new_time - old_time;
+ // 转换为分钟的差值
+ int time_diff_minutes = time_diff_seconds / 60;
+ return time_diff_minutes;
}
HeartPresenter::HeartPresenter()
-/***
+/***
+ * @Date: 2024-06-12 11:24:16
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-06-13 15:08:56
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataPresenter.cpp
+ */
+/***
* @Date: 2024-04-15 14:19:47
* @LastEditors: Caisking 3449750381@qq.com
* @LastEditTime: 2024-06-11 15:34:57
{
if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
{
- NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
+ NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING_RECORD);
}
UNUSED(view);
return true;
// 根据控件id查找是哪个控件触发了点击回调
if (strcmp(view.GetViewId(), BUTTONBACK) == 0)
{
- NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
+ NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
}
return true;
}
/* DeInit:删除组件 */
void TraingEnddataView::DeInit()
{
- container_->RemoveAll();
scrollView_->RemoveAll();
+ container_->RemoveAll();
/*单位label*/
if (labeltype != nullptr)
{
delete imageLine7;
imageLine7 = nullptr;
}
+
+ if (scrollView_ != nullptr)
+ {
+ delete scrollView_;
+ scrollView_ = nullptr;
+ }
+
delete container_;
container_ = nullptr;
}
void TraingEnddataView::InitData()
{
SportData *enddata = TraingModel::GetInstance()->GetSportdata();
-
+
if (enddata == nullptr)
{
printf("Enddata is nullptr. Exiting InitData()...\r\n");
return;
}
- printf("Initializing TraingEnddataView data...\r\n");
+ // printf("Initializing TraingEnddataView data...\r\n");
// 训练图标Icon
std::string imageStr = TraingModel::GetInstance()->GetSportType(enddata->sportType);
if (!imageStr.empty())
labelduration->SetText(durationStr.c_str());
// 运动目标
- if (enddata->tag)
+ if (enddata->goaldegree)
{
std::string tagStr = std::to_string(enddata->goaldegree) + "%";
labeltag->SetText(tagStr.c_str());
// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckDataJson is ok");
return true;
}
-#if 0
+#if 1
bool TraingModel::SaveDataToJson(SportData *data)
{
if (data == nullptr)
return true;
}
#endif
+#if 0
bool TraingModel::SaveDataToJson(SportData *data)
{
if (data == nullptr)
WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "SaveDataToJson succeeded");
return true;
}
-
+#endif
/* 加载训练数据函数 */
std::vector<SportData> TraingModel::LoadDataFormJson()
{
TraingAquaticList->SetYScrollBarVisible(true); // 设置滑动滚动条
// 增加表冠控制
- TraingAquaticList->SetRotateFactor(2);
- TraingAquaticList->RequestFocus();
+ //TraingAquaticList->SetRotateFactor(2);
+ //TraingAquaticList->RequestFocus();
}
UIList *TraingAquaticView::GetList()
{
{
View<TraingAquaticPresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- RootView::GetInstance()->ClearFocus();
+ // RootView::GetInstance()->ClearFocus();
return;
}
}
\ No newline at end of file
TraingBallList->SetYScrollBarVisible(true); // 设置滑动滚动条
// 增加表冠控制
- TraingBallList->SetRotateFactor(2);
- TraingBallList->RequestFocus();
+ //TraingBallList->SetRotateFactor(2);
+ //TraingBallList->RequestFocus();
}
UIList *TraingBallView::GetList()
{
{
View<TraingBallPresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- RootView::GetInstance()->ClearFocus();
+ // RootView::GetInstance()->ClearFocus();
return;
}
}
\ No newline at end of file
TraingDanceList->SetYScrollBarVisible(true); // 设置滑动滚动条
// 增加表冠控制
- TraingDanceList->SetRotateFactor(2);
- TraingDanceList->RequestFocus();
+ //TraingDanceList->SetRotateFactor(2);
+ //TraingDanceList->RequestFocus();
}
UIList *TraingDanceView::GetList()
{
{
View<TraingDancePresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- RootView::GetInstance()->ClearFocus();
+ // RootView::GetInstance()->ClearFocus();
return;
}
}
\ No newline at end of file
TraingFitnessList->SetYScrollBarVisible(true); // 设置滑动滚动条
// 增加表冠控制
- TraingFitnessList->SetRotateFactor(2);
- TraingFitnessList->RequestFocus();
+ //TraingFitnessList->SetRotateFactor(2);
+ //TraingFitnessList->RequestFocus();
}
UIList *TraingFitnessView::GetList()
{
{
View<TraingFitnessPresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- RootView::GetInstance()->ClearFocus();
+ // RootView::GetInstance()->ClearFocus();
return;
}
}
\ No newline at end of file
TraingIceList->SetYScrollBarVisible(true); // 设置滑动滚动条
// 增加表冠控制
- scrollView->SetRotateFactor(2);
- scrollView->RequestFocus();
+ //scrollView->SetRotateFactor(2);
+ //scrollView->RequestFocus();
}
UIList *TraingIceView::GetList()
{
{
View<TraingIcePresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- RootView::GetInstance()->ClearFocus();
+ // RootView::GetInstance()->ClearFocus();
return;
}
}
\ No newline at end of file
TraingLimitList->SetYScrollBarVisible(true); // 设置滑动滚动条\r
\r
// 增加表冠控制\r
- TraingLimitList->SetRotateFactor(2);\r
- TraingLimitList->RequestFocus();\r
+ //TraingLimitList->SetRotateFactor(2);\r
+ //TraingLimitList->RequestFocus();\r
}\r
UIList *TraingLimitView::GetList()\r
{\r
{\r
View<TraingLimitPresenter>::OnStop();\r
RootView::GetInstance()->RemoveAll();\r
- RootView::GetInstance()->ClearFocus();\r
+ // RootView::GetInstance()->ClearFocus();\r
return;\r
}\r
}
\ No newline at end of file
scrollView->SetYScrollBarVisible(true); // 设置滑动滚动条\r
\r
// 增加表冠控制\r
- TraingMoreList->SetRotateFactor(2);\r
- TraingMoreList->RequestFocus();\r
+ //TraingMoreList->SetRotateFactor(2);\r
+ //TraingMoreList->RequestFocus();\r
}\r
UIList *TraingMoreView::GetList()\r
{\r
{\r
View<TraingMorePresenter>::OnStop();\r
RootView::GetInstance()->RemoveAll();\r
- RootView::GetInstance()->ClearFocus();\r
+ //RootView::GetInstance()->ClearFocus();\r
return;\r
}\r
}
\ No newline at end of file
TraingOtherList->SetYScrollBarVisible(true); // 设置滑动滚动条
// 增加表冠控制
- TraingOtherList->SetRotateFactor(2);
- TraingOtherList->RequestFocus();
+ //TraingOtherList->SetRotateFactor(2);
+ //TraingOtherList->RequestFocus();
}
UIList *TraingOtherView::GetList()
{
{
View<TraingOtherPresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- RootView::GetInstance()->ClearFocus();
+ //RootView::GetInstance()->ClearFocus();
return;
}
}
\ No newline at end of file
TraingRestList->SetYScrollBarVisible(true); // 设置滑动滚动条
// 增加表冠控制
- TraingRestList->SetRotateFactor(2);
- TraingRestList->RequestFocus();
+ //TraingRestList->SetRotateFactor(2);
+ //TraingRestList->RequestFocus();
}
UIList *TraingRestView::GetList()
{
{
View<TraingRestPresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- RootView::GetInstance()->ClearFocus();
+ //RootView::GetInstance()->ClearFocus();
return;
}
}
\ No newline at end of file
if (!sportDataVector.empty())
{
// 选择点击按键的历史数据
- SportData sportData = sportDataVector[index];
+ int arraynum = sportDataVector.size() - 1;
+ SportData sportData = sportDataVector[arraynum - index]; // 显示是倒序 id同理
NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA);
TraingModel::GetInstance()->SetSportdata(&sportData);
return true;
TraingRecordList->SetMaxScrollDistance(MAX_SCR_DIS);
recordView->SetYScrollBarVisible(true); // 设置滑动滚动条
-
- // 增加表冠控制
- TraingRecordList->SetRotateFactor(2);
- TraingRecordList->RequestFocus();
TraingRecordList->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingRecordPresenter::GetInstance()));
UIView::OnDragListener *recorddraglistener = static_cast<UIView::OnDragListener *>(TraingRecordPresenter::GetInstance());
{
View<TraingRecordPresenter>::OnStop();
RootView::GetInstance()->RemoveAll();
- if (TraingRecordModel::GetInstance().GetJsonStatus())
- RootView::GetInstance()->ClearFocus();
return;
}
}