训练:优化训练配速表心率表数据存储 1428/1
authorCaisking <3449750381@qq.com>
Tue, 19 Nov 2024 12:55:57 +0000 (20:55 +0800)
committerCaisking <3449750381@qq.com>
Tue, 19 Nov 2024 12:55:57 +0000 (20:55 +0800)
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp

index 042ad84..9aba0af 100644 (file)
@@ -48,6 +48,8 @@
 #include <sys/time.h>
 #include <vector>
 
+#include "bleService.h"
+
 extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm);
 
 #ifdef __cplusplus
@@ -591,6 +593,9 @@ void TraingModel::SetTimestamp() {
   if (currentState == ExerciseState::Start && !Startstate) {
     // 设置训练 runtime 为 1 训练中
     uapi_dev_runtime_set_train_status(1);
+    if (Openingway) {
+      uapi_ble_connect_param_update(10);
+    }
 
     // 更新用户数据
     SetUserSportdata();
@@ -630,6 +635,9 @@ void TraingModel::SetTimestamp() {
   } else if (currentState == ExerciseState::End && !Endstate) {
     // 设置训练 runtime 为 0 训练结束
     uapi_dev_runtime_set_train_status(0);
+    if (Openingway) {
+      uapi_ble_connect_param_update(50);
+    }
 
     sportdata->endtime = time;
 
@@ -640,7 +648,7 @@ void TraingModel::SetTimestamp() {
 
     // 记录运动数据
     // RecordSportData();
-  
+
     //配置最后的训练强度(平均心率为标准)
     SetIntensity(sportdata->avgheart);
 
@@ -1259,7 +1267,7 @@ bool TraingModel::SaveSportData() {
     // 保存心率表
     if (!SaveHeartTable()) {
       WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SaveHeartRateData is error!");
-      // uapi_dev_runtime_set_train_storage_status(0); // 恢复状态 
+      // uapi_dev_runtime_set_train_storage_status(0); // 恢复状态
       // return false;
     }
     // 保存速度表
@@ -1421,7 +1429,7 @@ void TraingModel::PrintPaceTable() {
 
   WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Pace Table:");
   for (const auto &entry : paceTable) {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "时间戳: %u, 配速: %.2f",
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "时间戳: %u, 配速: %d",
                   entry.timestamp, entry.pace);
   }
 }
@@ -1618,25 +1626,25 @@ std::string TraingModel::DisplayMotionDuration() {
 
   motionDuration = oss.str();
 
-  // 获取当前时间(以微秒为单位)
-  uint32_t currentTime = static_cast<uint32_t>(
-      std::chrono::duration_cast<std::chrono::microseconds>(
-          std::chrono::system_clock::now().time_since_epoch())
-          .count());
+  // // 获取当前时间(以微秒为单位)
+  // uint32_t currentTime = static_cast<uint32_t>(
+  //     std::chrono::duration_cast<std::chrono::microseconds>(
+  //         std::chrono::system_clock::now().time_since_epoch())
+  //         .count());
 
-  // 记录和检查上一次调用的时间
-  static uint32_t lastCallTime = 0;
-  if (currentTime - lastCallTime < 1000000) { // 小于1秒
-    return motionDuration;
-  }
-  lastCallTime = currentTime; // 更新最后调用时间
+  // // 记录和检查上一次调用的时间
+  // static uint32_t lastCallTime = 0;
+  // if (currentTime - lastCallTime < 1000000) { // 小于1秒
+  //   return motionDuration;
+  // }
+  // lastCallTime = currentTime; // 更新最后调用时间
 
   // 如果 g_motionTimes 不为零,进行计算和数据存储
   if (g_motionTimes > 0) {
     sportdata->duration = g_motionTimes; // 设置训练时长
 
     // 每分钟进行配速和心率数据存储
-    StoreDataIfMinutePassed();
+    // StoreDataIfMinutePassed();
   }
 
   return motionDuration; // 返回格式化的运动时长
@@ -1656,7 +1664,7 @@ void TraingModel::SendLiveDataIfNecessary() {
 
 // 每10秒进行配速和心率数据存储
 void TraingModel::StoreDataIfMinutePassed() {
-  if (sportdata->duration % 10 == 0) {
+  if (sportdata->duration % 5 == 0) {
     uint32_t timestamp;
     //进行数据的筛选
     if (uapi_get_timestampe_ss(&timestamp) == ERRCODE_SUCC) {
@@ -1683,6 +1691,10 @@ void TraingTimerCallback() {
   OHOS::TraingModel::GetInstance()->SendLiveDataIfNecessary();
   // 更新时间目标完成度
   OHOS::TraingModel::GetInstance()->CheckTimeTag();
+  // 特殊运动才存储心率配速表
+  if (OHOS::TraingModel::GetInstance()->GetIsSpecial())
+    OHOS::TraingModel::GetInstance()
+        ->StoreDataIfMinutePassed(); //存储心率配速表
 
   if ((sportdata->goaldegree >= 100) && (shock_count < 4)) {
     shock_count++;