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

244 lines
7.6 KiB
C++
Raw 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 "TjdUiAppHrPresenter.h"
#include "TjdUiAppHrModel.h"
#include "TjdUiAppHrView.h"
#include "TjdUiRegisterManager.h"
#include "TjdUiScreenManage.h"
#include "dock/input_device.h"
#include "power_display_service.h"
#include "rtc_api.h"
#include "sql_setting.h"
#include "sys_config.h"
#include "ui_screennotify.h"
// #include "core/render_manager.h"
#define CHECK_MEMORY_LEAK 0
#if CHECK_MEMORY_LEAK
#include "gfx_utils/mem_check.h"
#endif
#include "motor.h"
using namespace OHOS;
#define ENABLE_PRINT_INFO 1
#define DEBUG_ENABLE 0
#if ENABLE_PRINT_INFO
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
#if DEBUG_ENABLE
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__)
#else
#define static_print_debug(...)
#endif
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#endif
namespace TJD {
TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_HR, TjdUiAppHrView, TjdUiAppHrPresenter, IMG_MENU_LIST_MENU_HEARTRATE,
STR_ID_00);
static TjdUiAppHrPresenter *g_pv_HrPresenter = nullptr;
TjdUiAppHrPresenter::TjdUiAppHrPresenter()
{
static_print_info("TjdUiAppHrPresenter::construct...");
#if CHECK_MEMORY_LEAK
MemCheck::GetInstance()->EnableLeakCheck(true);
#endif
g_pv_HrPresenter = this;
}
TjdUiAppHrPresenter::~TjdUiAppHrPresenter()
{
static_print_info("~TjdUiAppHrPresenter::destruct...");
#if CHECK_MEMORY_LEAK
MemCheck::GetInstance()->EnableLeakCheck(false);
#endif
g_pv_HrPresenter = nullptr;
}
TjdUiAppHrPresenter *TjdUiAppHrPresenter::GetInstance(void) { return g_pv_HrPresenter; }
void TjdUiAppHrPresenter::OnStart()
{
static_print_info("TjdUiAppHrPresenter::OnStart...");
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
TimeTaskStart();
SetPeriod(1000);
}
void TjdUiAppHrPresenter::OnPause()
{
static_print_info("TjdUiAppHrPresenter::OnPause...");
UIImageAnimatorView *animator = TjdUiAppHrView::GetInstance()->GetAnimatorView();
if (animator != nullptr) {
if (animator->GetState() == Animator::RUNNING)
animator->Pause();
}
Presenter<TjdUiAppHrView>::OnPause();
if (view_->GetSwipeView()) {
view_->GetSwipeView()->ClearFocus();
}
}
void TjdUiAppHrPresenter::OnResume()
{
static_print_info("TjdUiAppHrPresenter::OnResume...");
UIImageAnimatorView *animator = TjdUiAppHrView::GetInstance()->GetAnimatorView();
if (animator != nullptr) {
if (animator->GetState() == Animator::PAUSE)
animator->Resume();
else if (animator->GetState() == Animator::STOP)
animator->Start();
}
Presenter<TjdUiAppHrView>::OnResume();
if (view_->GetSwipeView()) {
view_->GetSwipeView()->RequestFocus();
view_->GetSwipeView()->SetRotateFactor(1.0);
}
}
void TjdUiAppHrPresenter::OnStop()
{
static_print_info("TjdUiAppHrPresenter::OnStop...");
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
TimeTaskStop();
}
void TjdUiAppHrPresenter::OnSwipe(UISwipeView &view) { static_print_info("swipeView page:%d", view.GetCurrentPage()); }
void TjdUiAppHrPresenter::Notify(void)
{
// printf("fps: %lf\n",RenderManager::GetInstance().GetFPS());
// static_print_info("TjdUiAppHrPresenter::Notify");
if (timerFlag) {
HrProcess();
}
}
void TjdUiAppHrPresenter::ViewExitEvent(OHOS::UIView &view, const OHOS::DragEvent &event)
{
if (HR_SWIPEVIEW_ID == std::string(view.GetViewId())) {
ExitHrView();
}
static_print_info("OnDragEnd:HR_SWIPEVIEW");
}
bool TjdUiAppHrPresenter::OnClick(UIView &view, const ClickEvent &event) { return false; }
bool TjdUiAppHrPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
{
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) {
return true;
}
ExitHrView();
return false;
}
void TjdUiAppHrPresenter::ExitHrView(void) { OHOS::NativeAbility::GetInstance().ChangePreSlice(); }
void TjdUiAppHrPresenter::HrProcess(void)
{
uint32_t index = GetCurTimeIndex();
TjdUiAppHrModel::GetInstance().UpdateHrCurValue();
uint8_t hrValue = TjdUiAppHrModel::GetInstance().GetHrCurValue();
TjdUiAppHrModel::GetInstance().HeartRateControlHandler(HeartRateAction::GetStatus, nullptr);
printf("hrValue is %d", hrValue);
if ( TjdUiAppHrView::herarRateWaitTime_ >= 10)
view_->UpdateHrViewData(index, hrValue);
if (hrValue && exitTimerCount_++ > 5) {
TimeTaskStop();
motor_param_t motorParam = {.cycle1_on = 250, .cycle1_off = 750, .cycle1_cnt = 1, .duty = 100};
tjd_driver_motor_user_start(&motorParam);
}
}
uint8_t TjdUiAppHrPresenter::HeartRateGetWearStatus(void)
{
TjdUiAppHrModel::GetInstance().UpdateWearStatus();
uint8_t wearStatus = TjdUiAppHrModel::GetInstance().GetWearStatus();
// sys_ui_log_i("wearStatus is %s", wearStatus ? (wearStatus == 1 ? "weared" : "init") : "no wear");
if (wearStatus == 0) {
if (refreshStatus && refreshCount++ > 1) {
refreshStatus = false;
refreshCount = 0;
TimeTaskStop();
TjdUiAppHrView::GetInstance()->ChangedView(HR_UNWEAR_VIEW, HR_SWIPE_VIEW);
}
return 0;
}
refreshCount = 0; // 若已配带,刷新计数
if (wearStatus == 1) {
return 1;
}
return 2;
}
uint32_t TjdUiAppHrPresenter::GetCurTimeIndex(void)
{
struct rtc_time local_time;
struct rtc_class_ops *handel = tjd_driver_rtc_get_ops();
handel->get_rtc_time(&local_time);
uint32_t totalMinutes = local_time.tm_hour * 60 + local_time.tm_min;
// 计算索引值每5分钟一个索引
uint32_t index = totalMinutes / 5;
return index;
}
#define SCREEN_AUTO_OFF_TIME (1000 * 60 * 60)
void TjdUiAppHrPresenter::TimeTaskStart(void)
{
if (timerFlag != true) {
needsUpdate_ = true;
TjdUiAppHrModel::GetInstance().HeartRateControlHandler(HeartRateAction::Start, nullptr);
TjdUiScreenManage::SetScreenKeepOnTimeout(SCREEN_AUTO_OFF_TIME);
timerFlag = true;
exitTimerCount_ = 0;
refreshStatus = true;
if (TjdUiAppHrView::GetInstance()->flickerTimer) {
TjdUiAppHrView::GetInstance()->flickerTimer->Start();
}
if (TjdUiAppHrView::GetInstance()->imageAnimator1_) {
TjdUiAppHrView::GetInstance()->imageAnimator1_->Start();
}
}
}
void TjdUiAppHrPresenter::TimeTaskStop(void)
{
if (timerFlag != false) {
timerFlag = false;
needsUpdate_ = false;
refreshCount = 0;
exitTimerCount_ = 0;
TjdUiAppHrView::herarRateWaitTime_ = 0;
TjdUiScreenManage::ResetScreenKeepOnTimeout();
if (TjdUiAppHrView::GetInstance()->flickerTimer) {
TjdUiAppHrView::GetInstance()->flickerTimer->Stop();
}
if (TjdUiAppHrView::GetInstance()->imageAnimator1_) {
TjdUiAppHrView::GetInstance()->imageAnimator1_->Stop();
}
TjdUiAppHrModel::GetInstance().HeartRateControlHandler(HeartRateAction::Stop, nullptr);
TjdUiAppHrModel::GetInstance().InitWeekHrViewInfo();
TjdUiAppHrView::GetInstance()->UpdateRodViewGroup();
}
}
} // namespace TJD