mcu_hi3321_watch/tjd/ui/app/hr/TjdUiAppHrModel.cpp
2025-05-26 20:15:20 +08:00

86 lines
2.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "TjdUiAppHrModel.h"
#include "TjdUiAppHrView.h"
#include "graphic_types.h"
#include "power_display_service.h"
#include "service_hrsensor.h"
#include "sql_fit.h"
#include "sql_setting.h"
#include <stdio.h>
using namespace OHOS;
namespace TJD {
TjdUiAppHrModel &TJD::TjdUiAppHrModel::GetInstance(void)
{
static TjdUiAppHrModel instance;
return instance;
}
//心率值转换为坐标值HrValue 心率值return 屏幕坐标y值
uint8_t HrValue2RodValue(uint8_t HrValue)
{
if (HrValue == 0 || HrValue == 255) {
return 0;
}
return 145 + 0.8 * (200 - HrValue);
}
void TjdUiAppHrModel::HrPointArrayInit(void)
{
uint8_t *storeArray;
int32_t num = sql_fit_get_hr_daydata(&storeArray);
for (int i = 0; i < 288; ++i) {
array[i].x = i;
array[i].y = storeArray[i];
}
}
void TjdUiAppHrModel::InitWeekHrViewInfo(void)
{
uint8_t HrMaxArray[7] = {0};
uint8_t HrMinArray[7] = {0};
for (int i = 0; i < 7; i++) {
HrMaxArray[i] = sql_fit_get_hr_max(i);
HrMinArray[i] = sql_fit_get_hr_min(i);
};
for (int i = 0; i < 7; i++) {
WeekHrViewHigh[i] = HrValue2RodValue(HrMaxArray[i]);
WeekHrViewLow[i] = HrValue2RodValue(HrMinArray[i]) - WeekHrViewHigh[i];
}
}
void TjdUiAppHrModel::UpdateWearStatus(void) { wearStatus = tjd_service_hrs_get_ops()->hrs_wear_status(); }
void TjdUiAppHrModel::UpdateHrCurValue(void) { hrCurValue = tjd_service_hrsensor_get_cur_hrvalue(); }
uint8_t TjdUiAppHrModel::HeartRateControlHandler(HeartRateAction action, void *param)
{
uint8_t ret = 0;
hr_api_info_t hr_api_info = {HR_SERVICE_UI_HR, 0xffffffff};
service_hrs_api *hrsensorInfo = tjd_service_hrs_get_ops();
switch (action) {
case HeartRateAction::Start:
hrsensorInfo->open(hr_api_info);
break;
case HeartRateAction::Stop:
hrsensorInfo->close();
break;
case HeartRateAction::GetStatus:
ret = TjdUiAppHrPresenter::GetInstance()->HeartRateGetWearStatus();
break;
default:
break;
}
return ret;
}
} // namespace TJD