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

330 lines
12 KiB
C++

#include "TjdUiAppSettingModel.h"
#include "TjdUiAppMainView.h"
#include "TjdUiAppSettingPresenter.h"
#include "TjdUiImageIds.h"
#include "TjdUiMessageCommon.h"
#include "TjdUiMultiLanguage.h"
#include "ble_api.h"
#include "graphic_service.h"
#include "power_display_service.h"
#include "service_charger.h"
#include "sys_config.h"
#include "tp_api.h"
#include <iomanip>
#include <sstream>
extern "C"
{
#include "sql_bt.h"
#include "sql_fit.h"
#include "sql_setting.h"
#include "task_driver_event.h"
}
#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
static const char url[] = {"http://dw.ss-tjd.com/download/index4.html?name=Lefun&mac="};
namespace TJD {
static void PostFuncEvent(std::function<void()> func)
{
GraphicService::GetInstance()->PostGraphicEvent([func]() { func(); });
}
TjdUiAppSettingModel::TjdUiAppSettingModel()
{
const char *path = TJD_IMAGE_PATH "img_setting.bin";
// clang-format off
motionIconList_.clear();
motionIconList_.push_back({STR_ID_502, TJD_MAIN_PAGE_EFFECT_NONE, IMG_SETTING_STYLE_01, path});
motionIconList_.push_back({STR_ID_503, TJD_MAIN_PAGE_EFFECT_CURTAIN, IMG_SETTING_STYLE_02, path});
motionIconList_.push_back({STR_ID_504, TJD_MAIN_PAGE_EFFECT_CURTAIN_FADE_IN_OUT, IMG_SETTING_STYLE_03, path});
motionIconList_.push_back({STR_ID_505, TJD_MAIN_PAGE_EFFECT_CURTAIN_GAOSI, IMG_SETTING_STYLE_07, path});
motionIconList_.push_back({STR_ID_506, TJD_MAIN_PAGE_EFFECT_TURN_PAGE, IMG_SETTING_STYLE_04, path});
motionIconList_.push_back({STR_ID_507, TJD_MAIN_PAGE_EFFECT_ROTATE_TURN, IMG_SETTING_STYLE_04, path});
motionIconList_.push_back({STR_ID_508, TJD_MAIN_PAGE_EFFECT_CENTER_ZOOM, IMG_SETTING_STYLE_05, path});
motionIconList_.push_back({STR_ID_509, TJD_MAIN_PAGE_EFFECT_3D, IMG_SETTING_STYLE_06, path});
styleIconList_.clear();
styleIconList_.push_back({STR_ID_477, MENU_STYLE_LIST, IMG_SETTING_ICON_STYLE_03, path});
styleIconList_.push_back({STR_ID_475, MENU_STYLE_CELLUAR, IMG_SETTING_ICON_STYLE_01, path});
styleIconList_.push_back({STR_ID_476, MENU_STYLE_SPHERE, IMG_SETTING_ICON_STYLE_02, path});
styleIconList_.push_back({STR_ID_478, MENU_STYLE_GRID, IMG_SETTING_ICON_STYLE_04, path});
// clang-format on
}
TjdUiAppSettingModel *TjdUiAppSettingModel::GetInstance(void)
{
static TjdUiAppSettingModel instance;
return &instance;
}
std::string TjdUiAppSettingModel::GetConnectUrl()
{
uint8_t *mac = sql_bt_get_mac_addr();
const uint8_t count = 6;
std::stringstream ss;
for (uint8_t i = 0; i < count; ++i) {
ss << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << static_cast<int>(mac[i]);
}
return url + ss.str();
}
bool TjdUiAppSettingModel::IsOpenBle() { return sql_bt_get_bt_switch_mode(); }
bool TjdUiAppSettingModel::SetOpenBle(bool status)
{
if (status) {
PostFuncEvent([]() { tjd_open_bluetooth_only(); });
} else {
PostFuncEvent([]() { tjd_close_bluetooth_only(); });
}
sql_bt_set_bt_switch_mode(status);
return true;
}
bool TjdUiAppSettingModel::IsConnectApp() { return tjd_get_ble_is_connect(); }
const std::string &TjdUiAppSettingModel::GetUserName()
{
char name[32] = {0};
sql_fit_get_user_name(name);
userName_ = name;
return userName_;
}
const std::string &TjdUiAppSettingModel::GetBleName()
{
uint8_t name[255];
uint8_t len = 255;
gap_ble_get_local_name(name, &len);
std::string nameStr(reinterpret_cast<char *>(name), len);
if (nameStr.empty()) {
nameStr = "TH18ALefun";
}
bleName_ = nameStr;
return bleName_;
}
uint8_t TjdUiAppSettingModel::GetUserHeight() { return sql_fit_get_user_height(); }
uint8_t TjdUiAppSettingModel::GetUserWeight() { return sql_fit_get_user_weight(); }
const std::string TjdUiAppSettingModel::GetMacAddress()
{
uint8_t *mac = sql_bt_get_mac_addr();
const uint8_t count = 6;
std::stringstream ss;
for (uint8_t i = 0; i < count; ++i) {
if (i != 0) {
ss << ":";
}
ss << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << static_cast<int>(mac[i]);
}
return ss.str();
}
const std::string TjdUiAppSettingModel::GetVersion()
{
std::ostringstream oss;
oss << "SV" << DEVICE_SOFT_VERSION_H << "." << DEVICE_SOFT_VERSION_L << "_"
<< "HV" << DEVICE_HARD_VERSION_H << "." << DEVICE_HARD_VERSION_L;
return oss.str();
}
const std::string TjdUiAppSettingModel::GetKernelVersion()
{
std::ostringstream oss;
oss << DEVICE_KERNEL_TYPE_STR << "_T" << std::setw(5) << std::setfill('0') << DEVICE_KERNEL_PROJECT_ID << "_"
<< std::setw(20) << std::setfill('0') << std::hex << DEVICE_KERNEL_DEVICE_ID;
return oss.str();
}
void TjdUiAppSettingModel::SetNotification(bool notification)
{
if (notification == 0) {
TjdUiAppMainView::SetMessageRead(0);
}
sql_setting_set_notification(notification);
}
bool TjdUiAppSettingModel::GetNotification(void) { return sql_setting_get_notification(); }
void TjdUiAppSettingModel::SetScreenWakes(bool screenWakes) { sql_setting_set_screen_wakes(screenWakes); }
bool TjdUiAppSettingModel::GetScreenWakes(void) { return sql_setting_get_screen_wakes(); }
void TjdUiAppSettingModel::SetLanguage(language_enum language) { sql_setting_set_language(language); }
language_enum TjdUiAppSettingModel::GetLanguage(void) { return sql_setting_get_language(); }
void TjdUiAppSettingModel::SetDoNotDisturb(bool status) { sql_setting_set_dnd_all_day(status); }
bool TjdUiAppSettingModel::GetDoNotDisturb(void) { return sql_setting_get_dnd_all_day(); }
void TjdUiAppSettingModel::SetDoNotDisturbPeriodEnable(bool status) { sql_setting_set_dnd_period_enable(status); }
bool TjdUiAppSettingModel::GetDoNotDisturbPeriodEnable(void) { return sql_setting_get_dnd_period_enable(); }
void TjdUiAppSettingModel::SetDoNotDisturbPeriod(uint8_t startHour, uint8_t startMinute, uint8_t endHour,
uint8_t endMinute)
{
sql_setting_set_dnd_period(true, startHour, startMinute, endHour, endMinute);
}
void TjdUiAppSettingModel::GetDoNotDisturbPeriod(uint8_t &startHour, uint8_t &startMinute, uint8_t &endHour,
uint8_t &endMinute)
{
sql_setting_get_dnd_period(&startHour, &startMinute, &endHour, &endMinute);
}
void TjdUiAppSettingModel::SetScreenBrightnessLevel(uint8_t brightness, bool isSave)
{
const power_display_svr_api_t *display_api = power_display_svr_get_api();
display_api->set_brightness_mode(MANUAL);
display_api->set_brightness(brightness);
if (isSave) {
sql_setting_set_brightness(brightness);
}
}
uint8_t TjdUiAppSettingModel::GetScreenBrightness() { return sql_setting_get_brightness(); }
void TjdUiAppSettingModel::SetScreenAutoBrightness(bool autoBrightness)
{
const power_display_svr_api_t *display_api = power_display_svr_get_api();
errcode_t ret = display_api->set_brightness_mode(autoBrightness ? AUTO : MANUAL);
if (ret != ERRCODE_SUCC) {
static_print_error("set_brightness_mode failed, ret = %d", ret);
}
}
bool TjdUiAppSettingModel::GetScreenAutoBrightness()
{
const power_display_svr_api_t *display_api = power_display_svr_get_api();
return display_api->get_brightness_mode() == AUTO;
}
void TjdUiAppSettingModel::SetPowerSavingMode(bool status) { sql_setting_set_power_saving_mode(status); }
bool TjdUiAppSettingModel::GetPowerSavingMode(void) { return sql_setting_get_power_saving_mode(); }
void TjdUiAppSettingModel::SetShowOffScreenView(bool status)
{
sql_setting_set_off_screen(status);
power_display_gui_enable_aod(status);
}
bool TjdUiAppSettingModel::GetShowOffScreenView(void) { return sql_setting_get_off_screen(); }
void TjdUiAppSettingModel::SetShowOffScreenViewType(uint8_t type) { sql_setting_set_off_screen_view_type(type); }
uint8_t TjdUiAppSettingModel::GetShowOffScreenViewType(void) { return sql_setting_get_off_screen_view_type(); }
void TjdUiAppSettingModel::SetBedsideClock(bool status) { sql_setting_set_bedside_clock(status); }
bool TjdUiAppSettingModel::GetBedsideClock(void) { return sql_setting_get_bedside_clock(); }
void TjdUiAppSettingModel::SetKeepScreenSec(uint16_t sec) { return sql_setting_set_keep_screen_time(sec); }
uint16_t TjdUiAppSettingModel::GetKeepScreenTime(void) { return sql_setting_get_keep_screen_time(); }
void TjdUiAppSettingModel::SetMotionEnable(bool status) { sql_setting_set_motion_enable(status); }
bool TjdUiAppSettingModel::GetMotionEnable(void) { return sql_setting_get_motion_enable(); }
void TjdUiAppSettingModel::SetMotionEndEnable(bool status) { sql_setting_set_motion_end_enable(status); }
bool TjdUiAppSettingModel::GetMotionEndEnable(void) { return sql_setting_get_motion_end_enable(); }
void TjdUiAppSettingModel::SetMotionOutTime(uint32_t time) { sql_setting_set_motion_out_time(time); }
uint32_t TjdUiAppSettingModel::GetMotionOutTime(void) { return sql_setting_get_motion_out_time(); }
void TjdUiAppSettingModel::SetPasswordEnable(bool status) { sql_setting_set_password_enable(status); }
bool TjdUiAppSettingModel::GetPasswordEnable(void) { return sql_setting_get_password_enable(); }
void TjdUiAppSettingModel::SetPassword(const char *password)
{
password_ = password;
sql_setting_set_password(password);
}
std::string &TjdUiAppSettingModel::GetPassword()
{
char password[6] = {0};
sql_setting_get_password(password);
std::string passwordTmp(password, 4);
password_ = passwordTmp;
return password_;
}
void TjdUiAppSettingModel::SetPinchToAnswer(bool status) { sql_setting_set_pinch_to_answer(status); }
bool TjdUiAppSettingModel::GetPinchToAnswer(void) { return sql_setting_get_pinch_to_answer(); }
void TjdUiAppSettingModel::SetCoverToTurnOffScreen(bool status)
{
tjd_driver_tp_set_wakeup_enable(status);
sql_setting_set_cover_to_turn_off_screen(status);
}
bool TjdUiAppSettingModel::GetCoverToTurnOffScreen(void) { return sql_setting_get_cover_to_turn_off_screen(); }
void TjdUiAppSettingModel::SetLeftKeySetting(uint32_t setting) { sql_setting_set_switch_downkey_app(setting); }
uint32_t TjdUiAppSettingModel::GetLeftKeySetting(void) { return sql_setting_get_switch_downkey_app(); }
void TjdUiAppSettingModel::SetFloatingWindow(uint16_t *id) { sql_setting_set_floating_window_map(id, 10); }
const uint16_t *TjdUiAppSettingModel::GetFloatingWindow() { return sql_setting_get_floating_window_map(nullptr); }
void TjdUiAppSettingModel::SetAnimation(uint8_t animation)
{
sql_setting_set_animation(static_cast<MainCardEffect>(animation));
}
uint8_t TjdUiAppSettingModel::GetAnimation(void) { return static_cast<int16_t>(sql_setting_get_animation()); }
E_MenuStyle TjdUiAppSettingModel::GetWatchFaceMenuStyle(void) { return sql_setting_get_menu_style(); }
bool TjdUiAppSettingModel::GetSwitchBrightScreen() { return sql_fit_get_switch_bright_screen(); }
void TjdUiAppSettingModel::SetSwitchBrightScreen(bool status) { sql_fit_set_switch_bright_screen(status); }
uint8_t TjdUiAppSettingModel::GetPower(void) { return tjd_service_charger_get_battery(); }
void TjdUiAppSettingModel::SetVolume(uint8_t volume) { sql_setting_set_volume(volume); }
uint8_t TjdUiAppSettingModel::GetVolume(void) { return sql_setting_get_volume(); }
void TjdUiAppSettingModel::SetVolumeMute(bool mute) { sql_setting_set_volume_mute(mute); }
bool TjdUiAppSettingModel::GetVolumeMute(void) { return sql_setting_get_volume_mute(); }
void TjdUiAppSettingModel::SetTouchShake(bool shake) { sql_setting_set_touch_shake(shake); }
bool TjdUiAppSettingModel::GetTouchShake(void) { return sql_setting_get_touch_shake(); }
void TjdUiAppSettingModel::SetTouchShakeLevel(uint8_t level) { sql_setting_set_touch_shake_level(level); }
uint8_t TjdUiAppSettingModel::GetTouchShakeLevel(void) { return sql_setting_get_touch_shake_level(); }
} // namespace TJD