734 lines
25 KiB
C++
734 lines
25 KiB
C++
#include "TjdUiAppProductPresenter.h"
|
|
#include "NativeAbility.h"
|
|
#include "TjdUiAppProductModel.h"
|
|
#include "TjdUiAppProductView.h"
|
|
#include "TjdUiOnKeyListener.h"
|
|
#include "TjdUiRegisterManager.h"
|
|
#include "TjdUiSettingCenter.h"
|
|
#include "dock/input_device.h"
|
|
#include "graphic_service.h"
|
|
#include "hal_tick.h"
|
|
#include "service_gps.h"
|
|
#include "sys_config.h"
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
|
|
namespace TJD {
|
|
|
|
TJD_REGIST_SLICE(TJD_APP_VIEW_PRODUCTION, TjdUiAppProductView, TjdUiAppProductPresenter);
|
|
|
|
#define PRODUCT_GET_PAY_STR_MAX_LENGTH 20
|
|
|
|
#define ENABLE_PRINT_INFO 1
|
|
#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__) // 错误信息打印一般常开
|
|
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印一般常开
|
|
#else
|
|
#define static_print_info(...)
|
|
#define static_print_warn(...)
|
|
#define static_print_error(...)
|
|
#define static_print_debug(...)
|
|
#endif
|
|
|
|
#define AGING_RESULT_PATH "/user/aging_test_result.txt"
|
|
|
|
static TjdUiAppProductPresenter *g_productPresenter = nullptr;
|
|
|
|
TjdUiAppProductPresenter::TjdUiAppProductPresenter() { g_productPresenter = this; }
|
|
|
|
TjdUiAppProductPresenter::~TjdUiAppProductPresenter() { g_productPresenter = nullptr; }
|
|
|
|
TjdUiAppProductPresenter *TjdUiAppProductPresenter::GetInstance(void) { return g_productPresenter; }
|
|
|
|
static void GnssServiceChanged(bool open)
|
|
{
|
|
TjdUiAppProductPresenter *presenter = TjdUiAppProductPresenter::GetInstance();
|
|
if (presenter == nullptr) {
|
|
return;
|
|
}
|
|
presenter->GnssChangedEvent(open);
|
|
}
|
|
|
|
static void GnssRmcDataProcess(gnss_rmc_data_t *rmc_data)
|
|
{
|
|
TjdUiAppProductView *productView = TjdUiAppProductView::GetInstance();
|
|
if (productView == nullptr) {
|
|
return;
|
|
}
|
|
std::stringstream ss;
|
|
ss << "(" << rmc_data->latitude << ", " << rmc_data->longitude << ")";
|
|
// productView->ModifyGpsValue(GnssMsgType::RMC, ss.str().c_str());
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::PushGsvToMap(std::string starNum, int snr) { gsvData[starNum] = snr; }
|
|
|
|
void TjdUiAppProductPresenter::UpdataGsvData(void)
|
|
{
|
|
view_->SetStarNumber(-1, gsvData.size());
|
|
view_->RefrashGpsPlot();
|
|
}
|
|
|
|
static void GnssGgaDataProcess(const struct minmea_sentence_gga *frame)
|
|
{
|
|
TjdUiAppProductView *productView = TjdUiAppProductView::GetInstance();
|
|
if (productView == nullptr) {
|
|
return;
|
|
}
|
|
int num = frame->satellites_tracked;
|
|
productView->SetStarNumber(num, -1);
|
|
// productView->ModifyGpsValue(GnssMsgType::GGA, gga);
|
|
}
|
|
|
|
static void GnssVtgDataProcess(gnss_vtg_data_t *vtg_data)
|
|
{
|
|
TjdUiAppProductView *productView = TjdUiAppProductView::GetInstance();
|
|
if (productView == nullptr) {
|
|
return;
|
|
}
|
|
std::stringstream ss;
|
|
ss << "(" << vtg_data->true_track_degrees << "," << vtg_data->magnetic_track_degrees << "," << vtg_data->speed_knots
|
|
<< "," << vtg_data->speed_kph << ")";
|
|
// productView->ModifyGpsValue(GnssMsgType::VTG, ss.str().c_str());
|
|
}
|
|
|
|
static void GnssGsvDataProcess(const GnssSatelliteList *satList)
|
|
{
|
|
TjdUiAppProductPresenter *presenter = TjdUiAppProductPresenter::GetInstance();
|
|
if (presenter == nullptr) {
|
|
return;
|
|
}
|
|
int usableSatNum = 0;
|
|
int visableSatNum = 0;
|
|
|
|
GnssSatelliteStatusInfo satInfos = satList->gps;
|
|
for (uint32_t i = 0; i < satInfos.satViewedCnt; ++i) {
|
|
std::string svid = "GP" + std::to_string(satInfos.satelliteStatus[i].svid);
|
|
presenter->PushGsvToMap(svid, satInfos.satelliteStatus[i].cnr);
|
|
}
|
|
usableSatNum += satInfos.satUsedCnt;
|
|
visableSatNum += satInfos.satViewedCnt;
|
|
|
|
satInfos = satList->bds;
|
|
for (uint32_t i = 0; i < satInfos.satViewedCnt; ++i) {
|
|
std::string svid = "GB" + std::to_string(satInfos.satelliteStatus[i].svid);
|
|
presenter->PushGsvToMap(svid, satInfos.satelliteStatus[i].cnr);
|
|
}
|
|
usableSatNum += satInfos.satUsedCnt;
|
|
visableSatNum += satInfos.satViewedCnt;
|
|
|
|
satInfos = satList->glonass;
|
|
for (uint32_t i = 0; i < satInfos.satViewedCnt; ++i) {
|
|
std::string svid = "GL" + std::to_string(satInfos.satelliteStatus[i].svid);
|
|
presenter->PushGsvToMap(svid, satInfos.satelliteStatus[i].cnr);
|
|
}
|
|
usableSatNum += satInfos.satUsedCnt;
|
|
visableSatNum += satInfos.satViewedCnt;
|
|
|
|
satInfos = satList->galileo;
|
|
for (uint32_t i = 0; i < satInfos.satViewedCnt; ++i) {
|
|
std::string svid = "GA" + std::to_string(satInfos.satelliteStatus[i].svid);
|
|
presenter->PushGsvToMap(svid, satInfos.satelliteStatus[i].cnr);
|
|
}
|
|
usableSatNum += satInfos.satUsedCnt;
|
|
visableSatNum += satInfos.satViewedCnt;
|
|
|
|
satInfos = satList->qzss;
|
|
for (uint32_t i = 0; i < satInfos.satViewedCnt; ++i) {
|
|
std::string svid = "GQ" + std::to_string(satInfos.satelliteStatus[i].svid);
|
|
presenter->PushGsvToMap(svid, satInfos.satelliteStatus[i].cnr);
|
|
}
|
|
usableSatNum += satInfos.satUsedCnt;
|
|
visableSatNum += satInfos.satViewedCnt;
|
|
|
|
presenter->UpdataGsvData();
|
|
|
|
TjdUiAppProductView *productView = TjdUiAppProductView::GetInstance();
|
|
if (productView == nullptr) {
|
|
return;
|
|
}
|
|
productView->SetStarNumber(usableSatNum, visableSatNum);
|
|
}
|
|
|
|
static void OnLocationChange(const GnssLocation* location)
|
|
{
|
|
static_print_debug("OnLocationChange");
|
|
if (location->fieldValidity & GNSS_LOCATION_LAT_VALID) {
|
|
static_print_debug("latitude: %f", location->latitude);
|
|
}
|
|
if (location->fieldValidity & GNSS_LOCATION_LONG_VALID) {
|
|
static_print_debug("longitude: %f", location->longitude);
|
|
}
|
|
if (location->fieldValidity & GNSS_LOCATION_HORIZONTAL_ACCURACY_VALID) {
|
|
static_print_debug("horizontalAccuracy: %f", location->horizontalAccuracy);
|
|
}
|
|
if (location->fieldValidity & GNSS_LOCATION_VERTICAL_ACCURACY_VALID) {
|
|
static_print_debug("verticalAccuracy: %f", location->verticalAccuracy);
|
|
}
|
|
}
|
|
|
|
static void OnSignalQualityUpdate(GnssQualityLevel signal)
|
|
{
|
|
TjdUiAppProductPresenter *presenter = TjdUiAppProductPresenter::GetInstance();
|
|
if (presenter == nullptr) {
|
|
return;
|
|
}
|
|
presenter->GnssSignalProcess(signal);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::GnssSignalProcess(GnssQualityLevel &signal)
|
|
{
|
|
static_print_debug("OnSignalQualityUpdate");
|
|
static_print_debug("signal: %d", signal);
|
|
if (signal == GnssQualityLevel::GNSS_QUAL_POOR) {
|
|
view_->SetGpsState("信号弱");
|
|
} else if (signal == GnssQualityLevel::GNSS_QUAL_MEDIUM) {
|
|
view_->SetGpsState("信号中");
|
|
} else if (signal == GnssQualityLevel::GNSS_QUAL_HIGH) {
|
|
view_->SetGpsState("信号强");
|
|
}
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::OnStart()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
|
|
GnssCallbackIfaces gnssCallbackIfaces = {
|
|
.onGsvUpdate = GnssGsvDataProcess,
|
|
.onLocationUpdate = OnLocationChange,
|
|
.onSignalQualityUpdate = OnSignalQualityUpdate,
|
|
};
|
|
|
|
GnssServiceRegisterCallback(&gnssCallbackIfaces);
|
|
|
|
// gnss_service_cb_t gnssServiceCb = {.service_changed_cb = GnssServiceChanged,
|
|
// .rmc_status_cb = GnssRmcDataProcess,
|
|
// .gga_status_cb = GnssGgaDataProcess,
|
|
// .vtg_status_cb = GnssVtgDataProcess};
|
|
// register_gnss_changed_cb(&gnssServiceCb);
|
|
view_->ShowView(ProductViewIndex::PRODUCT_SELECT_LIST);
|
|
TjdUiAppProductModel::GetInstance().SetKeepScreenOn(true);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::OnStop()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
unregister_gnss_changed_cb();
|
|
TjdUiAppProductModel::GetInstance().GPSOperate(InterfaceType::CLOSE, nullptr);
|
|
TjdUiAppProductModel::GetInstance().SetKeepScreenOn(false);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::Notify(void)
|
|
{
|
|
if (notifyEnable_) {
|
|
return;
|
|
}
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
uint8_t heartRateValue = 0;
|
|
GSensorInfo gsensorInfo = {};
|
|
|
|
switch (TjdUiAppProductView::currentViewIndex_) {
|
|
case ProductViewIndex::PRODUCT_HEART_RATE_TEST:
|
|
model.HeartRateOperate(InterfaceType::GET_DATA, &heartRateValue);
|
|
view_->SetHeartRateValue(heartRateValue);
|
|
break;
|
|
case ProductViewIndex::PRODUCT_GSENSOR_TEST:
|
|
model.GsensorOperate(InterfaceType::GET_DATA, &gsensorInfo);
|
|
view_->SetGSensorValue(gsensorInfo.step, gsensorInfo.x, gsensorInfo.y, gsensorInfo.z);
|
|
break;
|
|
case ProductViewIndex::PRODUCT_AGING_TEST: {
|
|
uint32_t time = OHOS::HALTick::GetInstance().GetElapseTime(agingTestResult_.startTime_) / 1000;
|
|
uint8_t power = model.GetPower();
|
|
view_->AngingSetValue(power, time);
|
|
if (agingTestResult_.testItem_.lcdTest) {
|
|
// clang-format off
|
|
switch (agingTestCount_) {
|
|
case 0: view_->SetAgingTestColor(0xFFD9001B); break;
|
|
case 1: view_->SetAgingTestColor(0xFFFFFFFF); break;
|
|
case 2: view_->SetAgingTestColor(0xFF0000FF); break;
|
|
default: break;
|
|
}
|
|
// clang-format on
|
|
if (++agingTestCount_ >= 3) {
|
|
agingTestCount_ = 0;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event)
|
|
{
|
|
if (TjdUiAppProductView::currentViewIndex_ == ProductViewIndex::PRODUCT_TP_SLIDE_TEST ||
|
|
TjdUiAppProductView::currentViewIndex_ == ProductViewIndex::PRODUCT_TP_REPORT_TEST) {
|
|
view_->DragTpSlidePos(event.GetCurrentPos());
|
|
return true;
|
|
}
|
|
return TjdUiScreenDragListener::OnDrag(view, event);
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
|
|
{
|
|
if (TjdUiAppProductView::currentViewIndex_ == ProductViewIndex::PRODUCT_TP_SLIDE_TEST) {
|
|
// view_->DragTpSlidePos(event.GetCurrentPos());
|
|
return true;
|
|
}
|
|
return TjdUiScreenDragListener::OnDragEnd(view, event);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::SetNotifyEnable(uint16_t timeMs, bool enable)
|
|
{
|
|
notifyEnable_ = enable;
|
|
if (enable) {
|
|
SetPeriod(timeMs);
|
|
}
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ResetTestView(void)
|
|
{
|
|
view_->SetLcdFullColor(0xFFD9001B);
|
|
view_->ClearTpBtnMap();
|
|
view_->SetHeartRateValue(0);
|
|
view_->SetGSensorValue(0, 0, 0, 0);
|
|
view_->SetRespButtonState(OHOS::UIButton::ButtonState::RELEASED);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ViewExitEvent(bool isSwipe)
|
|
{
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
|
|
switch (TjdUiAppProductView::currentViewIndex_) {
|
|
case ProductViewIndex::PRODUCT_SELECT_LIST:
|
|
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN);
|
|
break;
|
|
case ProductViewIndex::PRODUCT_AGING_CHOOSE_TEST:
|
|
case ProductViewIndex::PRODUCT_TP_REPORT_TEST:
|
|
view_->ShowView(ProductViewIndex::PRODUCT_SELECT_LIST);
|
|
break;
|
|
case ProductViewIndex::PRODUCT_GPS_REPORT_TEST:
|
|
if (!isSwipe) {
|
|
GPSEndEvent();
|
|
view_->ShowView(ProductViewIndex::PRODUCT_SELECT_LIST);
|
|
}
|
|
break;
|
|
case ProductViewIndex::PRODUCT_AGING_TEST:
|
|
AgingEndEvent();
|
|
view_->ShowView(ProductViewIndex::PRODUCT_AGING_CHOOSE_TEST);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::NormalTestEndEvent(void) { view_->ShowView(PRODUCT_SELECT_LIST); }
|
|
|
|
void TjdUiAppProductPresenter::GPSEndEvent(void)
|
|
{
|
|
TjdUiAppProductModel::GetInstance().GPSOperate(InterfaceType::CLOSE, nullptr);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::AgingEndEvent(void)
|
|
{
|
|
SetNotifyEnable(0, false);
|
|
if (agingTestResult_.testItem_.heartRate) {
|
|
TjdUiAppProductModel::GetInstance().HeartRateOperate(InterfaceType::CLOSE, nullptr);
|
|
}
|
|
if (agingTestResult_.testItem_.speaker) {
|
|
TjdUiAppProductModel::GetInstance().SpeakerOperate(InterfaceType::CLOSE, nullptr);
|
|
}
|
|
if (agingTestResult_.testItem_.motor) {
|
|
TjdUiAppProductModel::GetInstance().MotorOperate(InterfaceType::CLOSE, nullptr);
|
|
}
|
|
agingTestResult_.endPower_ = TjdUiAppProductModel::GetInstance().GetPower();
|
|
agingTestResult_.endTime_ = OHOS::HALTick::GetInstance().GetElapseTime(agingTestResult_.startTime_) / 1000;
|
|
SaveAgingResultToFile(agingTestResult_);
|
|
view_->AngingReset();
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::SaveAgingResultToFile(AngingTestResult &result)
|
|
{
|
|
// 打开文件(如果存在则清除内容)
|
|
std::ofstream file(AGING_RESULT_PATH, std::ios::out | std::ios::trunc);
|
|
if (!file.is_open()) {
|
|
// 处理文件打开失败的情况
|
|
return;
|
|
}
|
|
|
|
// 写入结果到文件
|
|
file << result.startTime_ << std::endl;
|
|
file << result.endTime_ << std::endl;
|
|
file << static_cast<int>(result.startPower_) << std::endl;
|
|
file << static_cast<int>(result.endPower_) << std::endl;
|
|
file << result.testItem_.lcdTest << std::endl;
|
|
file << result.testItem_.heartRate << std::endl;
|
|
file << result.testItem_.motor << std::endl;
|
|
file << result.testItem_.speaker << std::endl;
|
|
file.close();
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::GetAgingResultToFile(AngingTestResult *result)
|
|
{
|
|
if (result == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
// 打开文件
|
|
std::ifstream file(AGING_RESULT_PATH, std::ios::in);
|
|
if (!file.is_open()) {
|
|
// 处理文件打开失败的情况
|
|
return false;
|
|
}
|
|
|
|
// 从文件中读取结果
|
|
int temp;
|
|
file >> result->startTime_;
|
|
file >> result->endTime_;
|
|
file >> temp;
|
|
result->startPower_ = static_cast<uint8_t>(temp);
|
|
file >> temp;
|
|
result->endPower_ = static_cast<uint8_t>(temp);
|
|
file >> result->testItem_.lcdTest;
|
|
file >> result->testItem_.heartRate;
|
|
file >> result->testItem_.motor;
|
|
file >> result->testItem_.speaker;
|
|
|
|
file.close();
|
|
return true;
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::GnssChangedEvent(bool open)
|
|
{
|
|
if (open) {
|
|
std::string openStr = "运行中";
|
|
if (!gpsNormal_) {
|
|
openStr += "-星历异常";
|
|
}
|
|
view_->SetGpsState(openStr.c_str());
|
|
} else {
|
|
view_->SetGpsState("关闭");
|
|
}
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
if (TjdUiAppProductView::currentViewIndex_ == ProductViewIndex::PRODUCT_BUTTON_TEST) {
|
|
if (event.GetState() == OHOS::InputDevice::STATE_PRESS) {
|
|
view_->SetRespButtonState(OHOS::UIButton::ButtonState::PRESSED);
|
|
} else if (event.GetState() == OHOS::InputDevice::STATE_RELEASE) {
|
|
view_->SetRespButtonState(OHOS::UIButton::ButtonState::RELEASED);
|
|
}
|
|
return true;
|
|
}
|
|
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) {
|
|
return true;
|
|
}
|
|
ViewExitEvent(false);
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::OnPress(OHOS::UIView &view, const OHOS::PressEvent &event)
|
|
{
|
|
if (TjdUiAppProductView::currentViewIndex_ == ProductViewIndex::PRODUCT_TP_REPORT_TEST) {
|
|
view_->DragTpSlidePos(event.GetCurrentPos());
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickSelectList(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
if (viewId == PRODUCT_NORMAL_BTN_VIEW_ID) {
|
|
ResetTestView();
|
|
view_->ShowView(PRODUCT_LCD_TEST);
|
|
} else if (viewId == PRODUCT_AGING_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_AGING_CHOOSE_TEST);
|
|
} else if (viewId == PRODUCT_TOUCH_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_TP_REPORT_TEST);
|
|
} else if (viewId == PRODUCT_GPS_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_GPS_REPORT_TEST);
|
|
} else if (viewId == PRODUCT_BACK_BTN_VIEW_ID) {
|
|
ViewExitEvent(false);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickAgingChooseTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
if (viewId == PRODUCT_NEXT_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_AGING_TEST);
|
|
} else if (viewId == PRODUCT_BACK_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_SELECT_LIST);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickLcdTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
switch (lcdColorIndex_++) {
|
|
case 0:
|
|
view_->SetLcdFullColor(0xFFFFFFFF);
|
|
break;
|
|
case 1:
|
|
view_->SetLcdFullColor(0xFF0000FF);
|
|
break;
|
|
case 2:
|
|
view_->ShowView(PRODUCT_TP_CLICK_TEST);
|
|
lcdColorIndex_ = 0;
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickTpTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
if (view_->IsTpBtnSelectedAll()) {
|
|
view_->ShowView(PRODUCT_HEART_RATE_TEST);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::SlideTpTest(void)
|
|
{
|
|
if (view_->IsTpBtnSelectedAll()) {
|
|
TjdUiAppProductModel::GetInstance().HeartRateOperate(InterfaceType::OPEN, nullptr);
|
|
view_->ShowView(PRODUCT_HEART_RATE_TEST);
|
|
SetNotifyEnable(250, true);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickHeartRateTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
if (viewId == PRODUCT_NEXT_BTN_VIEW_ID) {
|
|
model.HeartRateOperate(InterfaceType::CLOSE, nullptr);
|
|
view_->ShowView(PRODUCT_GSENSOR_TEST);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickGsensorTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
if (viewId == PRODUCT_NEXT_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_SPEAKER_TEST);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickSpeakerTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
if (viewId == PRODUCT_NEXT_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_MOTOR_TEST);
|
|
bool redo = false;
|
|
redo = false;
|
|
model.SpeakerOperate(InterfaceType::CLOSE, nullptr);
|
|
model.MotorOperate(InterfaceType::OPEN, &redo);
|
|
} else if (viewId == PRODUCT_ONCE_BTN_VIEW_ID) {
|
|
bool redo = false;
|
|
model.SpeakerOperate(InterfaceType::OPEN, &redo);
|
|
} else if (viewId == PRODUCT_REPEAT_BTN_VIEW_ID) {
|
|
bool redo = true;
|
|
model.SpeakerOperate(InterfaceType::OPEN, &redo);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickMotorTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
if (viewId == PRODUCT_NEXT_BTN_VIEW_ID) {
|
|
model.MotorOperate(InterfaceType::CLOSE, nullptr);
|
|
view_->ShowView(PRODUCT_MICROPHONE_TEST);
|
|
} else if (viewId == PRODUCT_ONCE_BTN_VIEW_ID) {
|
|
bool redo = false;
|
|
model.MotorOperate(InterfaceType::OPEN, &redo);
|
|
} else if (viewId == PRODUCT_REPEAT_BTN_VIEW_ID) {
|
|
bool redo = true;
|
|
model.MotorOperate(InterfaceType::OPEN, &redo);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickMicrophoneTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
if (viewId == PRODUCT_NEXT_BTN_VIEW_ID) {
|
|
view_->ShowView(PRODUCT_BUTTON_TEST);
|
|
TjdUiAppProductModel::GetInstance().MicrophoneOperate(InterfaceType::CLOSE, nullptr);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickButtonTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
std::string viewId = view.GetViewId();
|
|
if (viewId == PRODUCT_NEXT_BTN_VIEW_ID) {
|
|
NormalTestEndEvent();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::ClickGPSTest(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
static bool gpsStart = false;
|
|
std::string viewId = view.GetViewId();
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppProductPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
// clang-format off
|
|
switch (TjdUiAppProductView::currentViewIndex_) {
|
|
case ProductViewIndex::PRODUCT_SELECT_LIST: return ClickSelectList(view, event);
|
|
case ProductViewIndex::PRODUCT_AGING_CHOOSE_TEST: return ClickAgingChooseTest(view, event);
|
|
case ProductViewIndex::PRODUCT_LCD_TEST: return ClickLcdTest(view, event);
|
|
case ProductViewIndex::PRODUCT_TP_CLICK_TEST: return ClickTpTest(view, event);
|
|
case ProductViewIndex::PRODUCT_HEART_RATE_TEST: return ClickHeartRateTest(view, event);
|
|
case ProductViewIndex::PRODUCT_GSENSOR_TEST: return ClickGsensorTest(view, event);
|
|
case ProductViewIndex::PRODUCT_SPEAKER_TEST: return ClickSpeakerTest(view, event);
|
|
case ProductViewIndex::PRODUCT_MOTOR_TEST: return ClickMotorTest(view, event);
|
|
case ProductViewIndex::PRODUCT_MICROPHONE_TEST: return ClickMicrophoneTest(view, event);
|
|
case ProductViewIndex::PRODUCT_BUTTON_TEST: return ClickButtonTest(view, event);
|
|
case ProductViewIndex::PRODUCT_GPS_REPORT_TEST: return ClickGPSTest(view, event);
|
|
default: break;
|
|
}
|
|
// clang-format on
|
|
return false;
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::StartJumpTimer(ProductViewIndex jumpView)
|
|
{
|
|
if (jumpTimerId_ == nullptr) {
|
|
jumpTimerId_ = osTimerNew(
|
|
[](void *arg) {
|
|
ProductViewIndex jumpView = static_cast<ProductViewIndex>(reinterpret_cast<intptr_t>(arg));
|
|
GraphicService::GetInstance()->PostGraphicEvent([jumpView]() {
|
|
TjdUiAppProductView *view = TjdUiAppProductView::GetInstance();
|
|
TjdUiAppProductPresenter *presenter = TjdUiAppProductPresenter::GetInstance();
|
|
if (view == nullptr) {
|
|
return;
|
|
}
|
|
view->ShowView(jumpView);
|
|
presenter->DeleteJumpTimer();
|
|
});
|
|
},
|
|
osTimerOnce, reinterpret_cast<void *>(static_cast<intptr_t>(jumpView)), nullptr);
|
|
if (jumpTimerId_ == nullptr) {
|
|
static_print_error("TjdUiAppAlipayModel::AlipayStartBind Create timer fail.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
int32_t ret = osTimerStart(jumpTimerId_, 2000);
|
|
if (ret != 0) {
|
|
static_print_error("TjdUiAppAlipayModel::AlipayStartBind Start timer fail");
|
|
return;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::DeleteJumpTimer(void)
|
|
{
|
|
if (jumpTimerId_ != nullptr) {
|
|
osTimerDelete(jumpTimerId_);
|
|
jumpTimerId_ = nullptr;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowLcdTestEvent(void) {}
|
|
|
|
void TjdUiAppProductPresenter::ShowHeartRateEvent(void)
|
|
{
|
|
TjdUiAppProductModel::GetInstance().HeartRateOperate(InterfaceType::OPEN, nullptr);
|
|
SetNotifyEnable(250, true);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowSpeakerEvent(void)
|
|
{
|
|
SetNotifyEnable(250, false);
|
|
bool redo = false;
|
|
TjdUiAppProductModel::GetInstance().SpeakerOperate(InterfaceType::OPEN, &redo);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowMotorEvent(void)
|
|
{
|
|
bool redo = false;
|
|
TjdUiAppProductModel::GetInstance().MotorOperate(InterfaceType::OPEN, &redo);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowMicrophoneEvent(void)
|
|
{
|
|
TjdUiAppProductModel::GetInstance().MicrophoneOperate(InterfaceType::OPEN, nullptr);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowAgintChooseTestEvent(void)
|
|
{
|
|
AngingTestResult result;
|
|
if (GetAgingResultToFile(&result)) {
|
|
view_->AngingChooseSetRecord(result);
|
|
}
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowAgintTestEvent(void)
|
|
{
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
agingTestCount_ = 1;
|
|
agingTestResult_.testItem_ = view_->GetAgingTestItem();
|
|
if (agingTestResult_.testItem_.heartRate) {
|
|
model.HeartRateOperate(InterfaceType::OPEN, nullptr);
|
|
}
|
|
if (agingTestResult_.testItem_.speaker) {
|
|
model.SpeakerOperate(InterfaceType::OPEN, nullptr);
|
|
}
|
|
if (agingTestResult_.testItem_.motor) {
|
|
bool redo = true;
|
|
model.MotorOperate(InterfaceType::OPEN, &redo);
|
|
}
|
|
view_->AngingSetStatus(agingTestResult_.testItem_);
|
|
agingTestResult_.startTime_ = OHOS::HALTick::GetInstance().GetTime();
|
|
agingTestResult_.startPower_ = model.GetPower();
|
|
SetNotifyEnable(1000, true);
|
|
model.SetKeepScreenOn(true);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowGpsEvent(void)
|
|
{
|
|
TjdUiAppProductModel &model = TjdUiAppProductModel::GetInstance();
|
|
gpsNormal_ = model.GPSIsNormal();
|
|
view_->SetGpsState("启动中...");
|
|
model.SetKeepScreenOn(true);
|
|
model.GPSOperate(InterfaceType::OPEN, nullptr);
|
|
}
|
|
|
|
void TjdUiAppProductPresenter::ShowViewEvent(ProductViewIndex showIndex)
|
|
{
|
|
// clang-format off
|
|
switch (showIndex) {
|
|
case PRODUCT_LCD_TEST: ShowLcdTestEvent(); break;
|
|
case PRODUCT_HEART_RATE_TEST: ShowHeartRateEvent(); break;
|
|
case PRODUCT_SPEAKER_TEST: ShowSpeakerEvent(); break;
|
|
case PRODUCT_MOTOR_TEST: ShowMotorEvent(); break;
|
|
case PRODUCT_MICROPHONE_TEST: ShowMicrophoneEvent(); break;
|
|
case PRODUCT_AGING_CHOOSE_TEST: ShowAgintChooseTestEvent(); break;
|
|
case PRODUCT_AGING_TEST: ShowAgintTestEvent(); break;
|
|
case PRODUCT_GPS_REPORT_TEST: ShowGpsEvent(); break;
|
|
default: break;
|
|
}
|
|
// clang-format on
|
|
}
|
|
|
|
} // namespace TJD
|