From: SnickerSun Date: Fri, 12 Apr 2024 10:21:15 +0000 (+0800) Subject: 重构ConfigModel,修改相关UI调用 X-Git-Tag: release_V1.2.70_20241020_135402~1205^2~4 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=c967642403664750a305a42a4e51b09016ba378d;p=mirrors%2FFD230.git 重构ConfigModel,修改相关UI调用 --- diff --git a/code/sdk/application/brandy/brandy_standard/main.c b/code/sdk/application/brandy/brandy_standard/main.c index aaecd65e1..62941e9cd 100755 --- a/code/sdk/application/brandy/brandy_standard/main.c +++ b/code/sdk/application/brandy/brandy_standard/main.c @@ -13,6 +13,7 @@ #include "application_version.h" #include "securec.h" #include "main.h" +#include "config/include/ConfigModelC.h" static startup_table ssb_to_app_table; static uint32_t g_psram_density; @@ -37,12 +38,7 @@ void app_main(const void *startup_details_table, const uint32_t density) board_init(ssb_to_app_table.ssb_to_application_flash_id, ssb_to_app_table.ssb_to_application_flash_unique_id); service_init(); - /** - * TODO: 在此处初始化配置信息,为后面服务启动提供参数信息 - * - * ConfigModel 初始化 - * - */ + thread_pri_init(); (void)osKernelStart(); diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index 4966c2d43..f1b1af17e 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -318,6 +318,15 @@ static void thread_main(const void *unused) uapi_pm_control(PM_DISPLAY_POWER_OFF); #endif + /** + * TODO: 在此处初始化配置信息,为后面服务启动提供参数信息 + * + * ConfigModel 初始化 + * + */ + ConfigModelInit(); + + #if DSP_EXIST == YES audio_init(); #endif @@ -363,7 +372,8 @@ static void thread_main(const void *unused) #endif #ifdef SUPPORT_BLE_SERVICE - svr_bluetooth_init(); + if(start_ble_service_on_bootup_flag()) + svr_bluetooth_init(); #endif #ifdef SUPPORT_ALIPAY_SEC diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 92cdfffbf..6bcb1e112 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -7,6 +7,7 @@ set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/include ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/include/slices/main ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/screennotify/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui ) @@ -44,7 +45,7 @@ set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/screensetting/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/uiservice/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/uisample/include - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ + # ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/UIInitializer/ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/InitComponent/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/uisample/uitest/framework/include @@ -411,9 +412,9 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/rotate/src/RotateView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/rotate/src/RotatePresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdateView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdatePresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdateModel.cpp + # ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdateView.cpp + # ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdatePresenter.cpp + # ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dialupdate/src/DialUpdateModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phoneservice/src/PhoneService.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phoneservice/src/PhoneAudio.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 957072159..3062b8e46 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -60,7 +60,7 @@ namespace OHOS void InitBloodSlice(void); void InitHeartSlice(void); void InitMainAlipaySlice(void); - void InitDialUpdateSlice(void); + // void InitDialUpdateSlice(void); void InitSaveEleSlice(void); void InitSaveBatSlice(void); void InitMessageSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 00b23109d..bc4002db7 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -113,8 +113,8 @@ #include "rotate/include/RotateView.h" #include "rotate/include/RotatePresenter.h" -#include "dialupdate/include/DialUpdatePresenter.h" -#include "dialupdate/include/DialUpdateView.h" +// #include "dialupdate/include/DialUpdatePresenter.h" +// #include "dialupdate/include/DialUpdateView.h" #include "config/include/ConfigModel.h" #include "rebootdevice/include/RebootModel.h" @@ -287,7 +287,7 @@ namespace OHOS {VIEW_MESSAGE, &NativeLauncher::InitMessageSlice}, {VIEW_ROTATE, &NativeLauncher::InitRotateSlice}, - {VIEW_DIALUPDATE, &NativeLauncher::InitDialUpdateSlice}, + // {VIEW_DIALUPDATE, &NativeLauncher::InitDialUpdateSlice}, {VIEW_BLOODOXY, &NativeLauncher::InitMainBloodOxyView}, {VIEW_HEART, &NativeLauncher::InitHeartSlice}, @@ -790,17 +790,17 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_ROTATE, rotate); } - void NativeLauncher::InitDialUpdateSlice(void) // 切换表盘 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitDialUpdateSlice"); - SliceProxy *dialupdate = new AbilitySliceProxy; - if (dialupdate == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dialupdate"); - return; - } - NativeAbility::GetInstance().AddSliceProxy(VIEW_DIALUPDATE, dialupdate); - } + // void NativeLauncher::InitDialUpdateSlice(void) // 切换表盘 + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitDialUpdateSlice"); + // SliceProxy *dialupdate = new AbilitySliceProxy; + // if (dialupdate == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dialupdate"); + // return; + // } + // NativeAbility::GetInstance().AddSliceProxy(VIEW_DIALUPDATE, dialupdate); + // } void NativeLauncher::InitClassicBluetoothSlice(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitClassicBluetoothSlice"); diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index 0831e6e39..b123e914e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -77,15 +77,16 @@ BluetoothModel *BluetoothModel::GetInstance(void) void BluetoothModel::Init() { - // bool ret = enable_bt_stack(); - // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt enable_bt_stack ret = %d", ret); + bool ret = enable_bt_stack(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt enable_bt_stack ret = %d", ret); BtInitCallBacks(); - - // svr_bluetooth_init(); +#ifdef SUPPORT_ALIPAY_SEC + // svr_alipay_bluetooth_init(); +#else BtInitCallBacksEx(); BtInitGatts(); - +#endif BtInitSpp(); SetUpListCase(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h index c62dfd4e8..c7f80f841 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h @@ -20,7 +20,7 @@ namespace OHOS private: // 用来记录蓝牙开关状态,默认关闭状态 - bool TradionalBlueToothToggleButtonState{false}; + bool ClassicBlueToothState{false}; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h index a5ef541e2..2e57752ab 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h @@ -35,8 +35,8 @@ namespace OHOS static ClassicBlueToothView *GetInstance(void); void ClassicBlueToothViewInit(void); void ClearAll(void); - bool GetTradionalBlueToothToggleButtonState(void); - void SetTradionalBlueToothToggleButtonState(bool state); + bool GetClassicBlueToothState(void); + void SetClassicBlueToothState(bool state); public: virtual void OnStart() override; diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp index b2d242268..b12dace38 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp @@ -6,7 +6,7 @@ namespace OHOS ClassicBlueToothModel::ClassicBlueToothModel() { ConfigModel *p_ConfigModel = ConfigModel::GetInstance(); - TradionalBlueToothToggleButtonState = p_ConfigModel->GetTradionalBlueToothToggleButtonState(); + ClassicBlueToothState = p_ConfigModel->GetClassicBlueToothState(); } ClassicBlueToothModel::~ClassicBlueToothModel() {} @@ -21,7 +21,7 @@ namespace OHOS /// @param value true 开启状态 false 关闭状态 void ClassicBlueToothModel::MarkTradionalBlueToothToggleButtonStatus(bool value) { - TradionalBlueToothToggleButtonState = value; + ClassicBlueToothState = value; } /// @brief 根据标记蓝牙开关的状态来确定蓝牙切换按钮是"开"还是"关状态 @@ -34,7 +34,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TradionalBlueToothToggleButtonStatusInit ClassicBlueToothPresenter GetInstance fail"); return false; } - Classicbluetoothpresenter->SetBluetoothDeviceSwitchState(TradionalBlueToothToggleButtonState); // 蓝牙开关状态 + Classicbluetoothpresenter->SetBluetoothDeviceSwitchState(ClassicBlueToothState); // 蓝牙开关状态 return true; } } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index fafb264c4..75bcee212 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -60,7 +60,7 @@ namespace OHOS } if (value != false) { - classicBlueToothView->SetTradionalBlueToothToggleButtonState(true); + classicBlueToothView->SetClassicBlueToothState(true); ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(false); // 将Model层保存的状态清除 } } @@ -121,12 +121,17 @@ namespace OHOS { case UICheckBox::SELECTED: WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); + + ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON,true); + #ifdef SUPPORT_BLE_SERVICE openBle();//主动开启蓝牙 #endif break; case UICheckBox::UNSELECTED: WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled"); + ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON,false); + #ifdef SUPPORT_BLE_SERVICE closeBle(); #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp index 0ed063035..aee7a4a7d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp @@ -30,16 +30,17 @@ namespace OHOS { BlueToothScrollView->RemoveAll(); - bool state = GetTradionalBlueToothToggleButtonState(); + bool state = GetClassicBlueToothState(); if (state == true) { ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(true); - ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(), "TradionalBlueToothToggleButtonState", true); + // ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON,true); + // ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(), "ClassicBlueToothState", true); } else { ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(false); - ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(), "TradionalBlueToothToggleButtonState", false); + // ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(), "ClassicBlueToothState", false); } delete Title; @@ -244,14 +245,14 @@ namespace OHOS /// @brief 获取蓝牙切换按钮的状态 /// @param void /// @return true 表示开启状态 false 表示开启状态 - bool ClassicBlueToothView::GetTradionalBlueToothToggleButtonState(void) + bool ClassicBlueToothView::GetClassicBlueToothState(void) { return TradionalBlueToothToggleButton->GetState(); } /// @brief 设置蓝牙切换按钮的状态 /// @param state true 开启 false 关闭 - void ClassicBlueToothView::SetTradionalBlueToothToggleButtonState(bool state) + void ClassicBlueToothView::SetClassicBlueToothState(bool state) { if (TradionalBlueToothToggleButton == nullptr) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h index 913597963..277e043dd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -19,195 +19,193 @@ namespace OHOS { class ConfigModel { - struct cat1_msg_config + public: + enum ConfigDataType { - char *imei; - int sim; - char *oper; - // uint8_t signal; + DATATYPE_INT, + DATATYPE_DOUBLE, + DATATYPE_STRING, + DATATYPE_BOOL, + DATATYPE_VECTOR_INT, + DATATYPE_VECTOR_DOUBLE, + DATATYPE_VECTOR_STRING, + DATATYPE_UNKNOWN, + } ; + enum ConfigItem + { + CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON, //关机前经典蓝牙服务状态,启动时仍然恢复其当时状态 + CONFIGMODEL_ITEM_SCREEN_BRIGHTNESS_VALUE, //屏幕亮度 + CONFIGMODEL_ITEM_SCREEN_OFF_TIMEOUT_VALUE, //屏幕自动息屏时间 默认 5秒 5000ms + CONFIGMODEL_ITEM_CAT1_SERVICE_ON, // 关机前Cat1 Service启动着,则重启仍然启动,反之亦然 + CONFIGMODEL_ITEM_CAT1_IMEI, //Cat1 imei + CONFIGMODEL_ITEM_CAT1_MODEMVER, //Cat1 modem version + CONFIGMODEL_ITEM_CAT1_PYVER, //Cat1 Python app version + CONFIGMODEL_ITEM_LANGUAGE_ID, //语言ID int id + CONFIGMODEL_ITEM_LANGUAGE_CODE, //语言Code string "zh","en" + CONFIGMODEL_ITEM_SILENT_MODE, //勿扰模式 + CONFIGMODEL_ITEM_VIBRATOR_SWITCH, // 马达 开关, 0 关, 1 å¼±, 2 中,3 强 + // CONFIGMODEL_ITEM_HRS_QUICKACCESS, + // CONFIGMODEL_ITEM_SPO2_QUICKACCESS, + CONFIGMODEL_ITEM_RAISE_TO_WAKE, //抬腕亮屏开关 + CONFIGMODEL_ITEM_ACTIVITY_VALUES_STEPCOUNT, //活动数据步数 + CONFIGMODEL_ITEM_ACTIVITY_VALUES_CALORIES, //活动数据卡路里, + CONFIGMODEL_ITEM_ACTIVITY_VALUES_STANDUP_TIMES, //活动数据站立次数 + CONFIGMODEL_ITEM_ACTIVITY_VALUES_DURATION, //活动数据运动时间 + CONFIGMODEL_ITEM_ACTIVITY_VALUES_DISTANCE, //活动数据运动距离 + CONFIGMODEL_ITEM_ACTIVITY_VALUES_TIMESTAMP, //活动数据更新时间戳 + CONFIGMODEL_ITEM_CUSTOM_DATA_HEIGHT, //用户数据身高 + CONFIGMODEL_ITEM_CUSTOM_DATA_WEIGHT, //用户数据体重 + CONFIGMODEL_ITEM_CUSTOM_DATA_SEX, //用户数据性别 + CONFIGMODEL_ITEM_CUSTOM_DATA_AGE, //用户数据年龄 + CONFIGMODEL_ITEM_CUSTOM_DATA_WEARING_MODE, //用户数据佩戴方式 + CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT, //运动目标步数 + CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES, //运动目标卡路里 + CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES, //运动目标站立次数 + CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION, //运动目标时长 + CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE, //运动目标距离 + CONFIGMODEL_ITEM_MAX, + } ; + + struct configmodel_item{ + ConfigDataType type; + const char* itemname; + char *defaultValue; }; - public: + + const char* get_config_name(ConfigItem item) + { + return configmodel_item_key_name[item].itemname; + } + + ConfigDataType get_config_datatype(ConfigItem item) + { + return configmodel_item_key_name[item].type; + } static ConfigModel *GetInstance(); - cJSON *GetcJSON(void); - bool LoadJsonData(void); - // template - // T ReadJsonData(const cJSON *json_obj, const char *field_name); - // template - // void WriteJsonData(cJSON *json_obj, const char *field_name, T data); + void Init(void); + /* -------------- 通用 读值 赋值 函数 ----------------- */ + int get_configData_int(ConfigItem item); + double get_configData_double(ConfigItem item); + bool get_configData_bool(ConfigItem item); + std::string get_configData_string(ConfigItem item); - /* -------------------------------------------------------------------------- */ - std::string ReadJsonData_String(const cJSON *json_obj, const char *field_name); - double ReadJsonData_Double(const cJSON *json_obj, const char *field_name); - int ReadJsonData_Int(const cJSON *json_obj, const char *field_name); - bool ReadJsonData_Bool(const cJSON *json_obj, const char *field_name); - int ReadJsonData_ArraySize(const cJSON *json_obj, const char *field_name); + void set_condigData_Int(ConfigItem item, int data); + void set_condigData_Double(ConfigItem item, double data); + void set_condigData_Bool(ConfigItem item, bool data); + void set_condigData_String(ConfigItem item, const char *data); + void set_condigData_VectorInt(ConfigItem item, const std::vector &data); + void set_condigData_VectorDouble(ConfigItem item, const std::vector &data); + void set_condigData_VectorString(ConfigItem item, const std::vector &data); - void WriteJsonData_Int(cJSON *json_obj, const char *field_name, int data); - void WriteJsonData_Double(cJSON *json_obj, const char *field_name, double data); - void WriteJsonData_Bool(cJSON *json_obj, const char *field_name, bool data); - void WriteJsonData_String(cJSON *json_obj, const char *field_name, const char *data); - void WriteJsonData_VectorInt(cJSON *json_obj, const char *field_name, const std::vector &data); - void WriteJsonData_VectorDouble(cJSON *json_obj, const char *field_name, const std::vector &data); - void WriteJsonData_VectorString(cJSON *json_obj, const char *field_name, const std::vector &data); + void reset_item_to_default(ConfigItem item); + + int sync_all_to_disk(void); + + + /* --------------------------------自定义封装 set与get方法 ------------------------------- */ + + bool GetRaiseToWake(void); - void WriteJsonToFile(char *json_string, const char *file_path); - /* -------------------------------------------------------------------------- */ - void ShowReadJsonData(void); - void Init(void); - /* -------------------------------- set与get方法 ------------------------------- */ - void SetRaiseToBrightnessCheckBoxButtonState(void); - bool GetRaiseToBrightnessCheckBoxButtonState(void); - void SetScreenBrightnessValue(void); unsigned GetScreenBrightnessValue(void); - void SetScreenDurationRadioButtonSlectValue(void); - unsigned int GetScreenDurationRadioButtonSlectValue(void); - void SetTradionalBlueToothToggleButtonState(void); - bool GetTradionalBlueToothToggleButtonState(void); - void SetHeartRateOrBloodOxygenQuickAccessSwitch(void); - int GetHeartRateOrBloodOxygenQuickAccessSwitch(void); - void SetDialId(dial_config *dial); - dial_config *GetDialId(); + + unsigned int GetScreenDuration(void); + + bool GetClassicBlueToothState(void); + void SetLanguage(int languageid); int GetLanguage(); + void SetLanguageCode(char *languagecode); + const char *GetLanguageCode(void); + char *Getimei(); char *GetpyVer(); char *GetmoderVer(); + void Setimei(char *str); void SetpyVer(char *str); void SetmoderVer(char *str); - void SetLanguageCode(char *languagecode); - const char *GetLanguageCode(void); - void SetVibrationReminder(bool state); - bool GetVibrationReminder(void); + + void SetVibrationReminder(int state); + int GetVibrationReminder(void); + void SetSilentMode(bool state); bool GetSilentMode(void); + void SetCat1_4Gability(bool state); bool GetCat1_4Gability(); + // -------------------------------------------------------------------------- */ private: + configmodel_item configmodel_item_key_name[CONFIGMODEL_ITEM_MAX] = + { + {ConfigDataType::DATATYPE_BOOL, "ClassicBT_Service_On", "true" },//CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON, //关机前经典蓝牙服务状态,启动时仍然恢复其当时状态 + {ConfigDataType::DATATYPE_INT, "ScreenBrightness", "255" },//CONFIGMODEL_ITEM_SCREEN_BRIGHTNESS_VALUE, + {ConfigDataType::DATATYPE_INT, "ScreenOffTimeoutValue", "5000" },//CONFIGMODEL_ITEM_SCREEN_OFF_TIMEOUT_VALUE, 自动息屏时间,默认5秒 5000ms + {ConfigDataType::DATATYPE_BOOL, "Cat1_Service_On", "false" },//CONFIGMODEL_ITEM_CAT1_SERVICE_ON, // 关机前Cat1 Service启动着,则重启仍然启动,反之亦然 + {ConfigDataType::DATATYPE_STRING, "Cat1_IMEI", "" },//CONFIGMODEL_ITEM_CAT1_IMEI, + {ConfigDataType::DATATYPE_STRING, "Cat1_ModemVer", "" },//CONFIGMODEL_ITEM_CAT1_MODEMVER, + {ConfigDataType::DATATYPE_STRING, "Cat1_PYVer", "" },//CONFIGMODEL_ITEM_CAT1_PYVER, + {ConfigDataType::DATATYPE_INT, "LanguageID", "-1" },//CONFIGMODEL_ITEM_LANGUAGE_ID, //默认没有选择语言 + {ConfigDataType::DATATYPE_STRING, "LanguageCode", "zh" },//CONFIGMODEL_ITEM_LANGUAGE_CODE, //默认没有选择语言 + {ConfigDataType::DATATYPE_BOOL, "SlientMode", "false" },//CONFIGMODEL_ITEM_SILENT_MODE, + {ConfigDataType::DATATYPE_INT, "VibratorSwitch", "1" },//CONFIGMODEL_ITEM_VIBRATOR_SWITCH, // 马达 开关, 0 关, 1 å¼±, 2 中,3 强 + // {ConfigDataType::DATATYPE_BOOL, "HRS_QuickAccess", "false"},//CONFIGMODEL_ITEM_HRS_SPO2_QUICKACCESS, + // {ConfigDataType::DATATYPE_BOOL, "SPO2_QuickAccess", "false"},//CONFIGMODEL_ITEM_HRS_SPO2_QUICKACCESS, + {ConfigDataType::DATATYPE_BOOL, "Rase2Wake", "true" },//CONFIGMODEL_ITEM_RAISE_TO_WAKE, + {ConfigDataType::DATATYPE_INT, "StepCount", "0" },//CONFIGMODEL_ITEM_ACTIVITY_VALUES_STEPCOUNT, //活动数据步数 + {ConfigDataType::DATATYPE_INT, "Calories", "0" },// CONFIGMODEL_ITEM_ACTIVITY_VALUES_CALORIES, //活动数据卡路里, + {ConfigDataType::DATATYPE_INT, "StandupTimes", "0" },// CONFIGMODEL_ITEM_ACTIVITY_VALUES_STANDUP_TIMES, //活动数据站立次数 + {ConfigDataType::DATATYPE_INT, "Duration", "0" },// CONFIGMODEL_ITEM_ACTIVITY_VALUES_DURATION, //活动数据运动时间 + {ConfigDataType::DATATYPE_DOUBLE, "Distance", "0.0" },// CONFIGMODEL_ITEM_ACTIVITY_VALUES_DISTANCE, //活动数据运动距离 + {ConfigDataType::DATATYPE_INT, "ActivityTimestamp", "0" },// CONFIGMODEL_ITEM_ACTIVITY_VALUES_TIMESTAMP, //活动数据更新时间戳 + {ConfigDataType::DATATYPE_INT, "height", "175" },// CONFIGMODEL_ITEM_CUSTOM_DATA_HEIGHT, //用户数据身高 (cm)(身高)(default : 175)(30 - 300) + {ConfigDataType::DATATYPE_DOUBLE, "weight", "70.0" },// CONFIGMODEL_ITEM_CUSTOM_DATA_WEIGHT, //用户数据体重 (kg)(體重)(default : 70)(10 - 300) + {ConfigDataType::DATATYPE_INT, "sex", "1" },// CONFIGMODEL_ITEM_CUSTOM_DATA_SEX, //用户数据性别 (default : 1 男性)(0 : 女性, 1 : 男性) + {ConfigDataType::DATATYPE_INT, "age", "30" },// CONFIGMODEL_ITEM_CUSTOM_DATA_AGE, //用户数据年龄 (年紀)(default : 30)(1 - 99) + {ConfigDataType::DATATYPE_INT, "WearingMode", "0" },// CONFIGMODEL_ITEM_CUSTOM_DATA_WEARING_MODE, //用户数据佩戴方式 (default : 左手)(0 : 左手 1 : 右手) + {ConfigDataType::DATATYPE_INT, "GoalStepCount", "10000" },// CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT, //运动目标步数 10000 + {ConfigDataType::DATATYPE_INT, "GoalCalories", "300" },// CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES, //运动目标卡路里 300(kcal) + {ConfigDataType::DATATYPE_INT, "GoalStandupTimes", "10" },// CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES, //运动目标站立次数 10 + {ConfigDataType::DATATYPE_INT, "GoalDuration", "30" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION, //运动目标时长 30(分钟) + {ConfigDataType::DATATYPE_DOUBLE, "GoalDistance", "8.0" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE, //运动目标距离 8.0(km) + }; ConfigModel(); // 私有构造函数,确保无法在外部实例化 ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造 ConfigModel &operator=(const ConfigModel &) = delete; // 禁止赋值运算符 ~ConfigModel(); + cJSON *GetcJSON(void); + bool LoadJsonData(void); + void DumpJsonItem(ConfigItem item); + /* --------------------------私有 通用 读写Json数据函数------------------------------------------------ */ + std::string ReadJsonData_String(const cJSON *json_obj, const char *field_name); + double ReadJsonData_Double(const cJSON *json_obj, const char *field_name); + int ReadJsonData_Int(const cJSON *json_obj, const char *field_name); + bool ReadJsonData_Bool(const cJSON *json_obj, const char *field_name); + int ReadJsonData_ArraySize(const cJSON *json_obj, const char *field_name); + + void WriteJsonData_Int(cJSON *json_obj, const char *field_name, int data); + void WriteJsonData_Double(cJSON *json_obj, const char *field_name, double data); + void WriteJsonData_Bool(cJSON *json_obj, const char *field_name, bool data); + void WriteJsonData_String(cJSON *json_obj, const char *field_name, const char *data); + void WriteJsonData_VectorInt(cJSON *json_obj, const char *field_name, const std::vector &data); + void WriteJsonData_VectorDouble(cJSON *json_obj, const char *field_name, const std::vector &data); + void WriteJsonData_VectorString(cJSON *json_obj, const char *field_name, const std::vector &data); + + void WriteJsonToFile(char *json_string, const char *file_path); + /* -------------------------------------------------------------------------- */ + void DumpJsonData(void); + + cJSON *get_item(ConfigItem item); private: const std::string filePath = "/system/ConfigModel.json"; cJSON *cjson_json{nullptr}; - /* ------------------------------- json中要读取的键 ------------------------------- */ - bool RaiseToBrightnessCheckBoxButtonState{false}; // 抬腕按钮状态 ,默认补选中 - unsigned char ScreenBrightnessValue{255}; // 亮度值 ,默认最大亮度 - unsigned int ScreenDurationRadioButtonSlectValue{1}; // 亮屏时长按钮选中编号 ,0对应5秒熄屏,1对应10秒熄屏,2对应15秒熄屏 - bool TradionalBlueToothToggleButtonState{false}; // 用来记录蓝牙开关状态,默认关闭状态 - int HeartRateOrBloodOxygenQuickAccessSwitch{0}; // 心率或血氧快速访问开关,默认快速访问血氧打开 - int dialid_; // 表盘Id - std::string dialname_; // 表盘名称 - int languageid_; // 语言状态 - char *imei_str = NULL; - char *pyVer = NULL; - char *moderVer = NULL; - std::string LanguageCode = "zh"; - bool VibrationReminder{false}; // 震动提醒 - bool SilentMode{false}; // 静音模式 - bool Cat1_4Gability{false}; // 4G能力开关 - cat1_msg_config cat1_msg_config_t; + + bool model_initialled{false}; /* -------------------------------------------------------------------------- */ }; - /// @brief 通用的读取数据函数,根据字段名称从 JSON 对象中读取对应值 - /// @tparam T - /// @param json_obj json 对象 field_name 字段名称 - /// @return 读取到的对应值 - // template - // T ConfigModel::ReadJsonData(const cJSON *json_obj, const char *field_name) - // { - // const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name); - // if (field_item != NULL) - // { - // if (cJSON_IsString(field_item)) - // { - // return T(field_item->string); - // } - // else if (cJSON_IsNumber(field_item)) - // { - // return T(field_item->valuedouble); - // } - // else if (cJSON_IsBool(field_item)) - // { - // return T(field_item->valueint); - // } - // else if (cJSON_IsArray(field_item)) - // { - // return T(cJSON_GetArraySize(field_item)); - // } - // else - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unsupported data type"); - // return T("Unsupported data type"); - // } - // } - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Field not found"); - // return T("Field not found"); - // } - - /// @brief 通用的写JSON数据函数 - /// @tparam T - /// @param json_obj json对象 - /// @param field_name 字段名称 - /// @param data 要写入的数据 - // template - // void ConfigModel::WriteJsonData(cJSON *json_obj, const char *field_name, T data) - // { - // if (json_obj == nullptr) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!"); - // return; - // } - - // cJSON *data_obj = cJSON_CreateNull(); - // if constexpr (std::is_same::value || std::is_same::value || std::is_same::value) - // { - // data_obj = cJSON_CreateNumber(static_cast(data)); - // } - // else if constexpr (std::is_same::value || std::is_same::value) - // { - // data_obj = cJSON_CreateNumber(data); - // } - // else if constexpr (std::is_same::value) - // { - // data_obj = cJSON_CreateBool(data); - // } - // else if constexpr (std::is_same::value || std::is_same::value) - // { - // data_obj = cJSON_CreateString(data); - // } - - // if (data_obj != nullptr) - // { - // cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); - - // char *jsonString = cJSON_Print(json_obj); - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // if (jsonString != nullptr) - // { - // FILE *file = fopen(filePath.c_str(), "wb"); - // if (file) - // { - // if (fputs(jsonString, file) != EOF) // 将 JSON 字符串写入文件 - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WriteJsonData success\n"); - // } - // fclose(file); - // } - // free(jsonString); - // } - // else - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jsonString is nullptr"); - // return; - // } - // } - // } /* ------------------------------ ImageAnimator ----------------------------- */ /* * 图片动画类 diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h new file mode 100644 index 000000000..202183bb1 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h @@ -0,0 +1,32 @@ +#ifndef _CONFIG_MODEL_C_H_ +#define _CONFIG_MODEL_C_H_ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif +#include + +/** + * 从存档文件初始化配置信息 +*/ +uint32_t ConfigModelInit(void); + +/*** + * 蓝牙服务是否开启 + */ +bool start_ble_service_on_bootup_flag(void); +/*** + * Cat1服务是否开启 + */ +bool poweron_cat1_on_bootup_flag(void); + +void sync_all_config_to_disk(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp index 095f69793..871aaa7ea 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp @@ -1,4 +1,5 @@ #include "config/include/ConfigModel.h" +#include "config/include/ConfigModelC.h" namespace OHOS { @@ -24,6 +25,81 @@ namespace OHOS return cjson_json; } + cJSON *ConfigModel::get_item(ConfigItem item) + { + return cJSON_GetObjectItem(GetcJSON(),get_config_name(item)); + } + + void ConfigModel::reset_item_to_default(ConfigItem item) + { + switch(get_config_datatype(item)) + { + case ConfigDataType::DATATYPE_BOOL: + + { + bool defaultvalue = false; + if (strncmp(configmodel_item_key_name[item].defaultValue,"true",sizeof("true"))==0) defaultvalue = true; + set_condigData_Bool(item,defaultvalue); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(bool):value(%d)", + get_config_name(item), + get_configData_bool(item)); + break; + case ConfigDataType::DATATYPE_DOUBLE: + { + double defaultvalue = atof(configmodel_item_key_name[item].defaultValue); + set_condigData_Double(item,defaultvalue); + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(double):value(%f)", + get_config_name(item), + get_configData_double(item)); + break; + case ConfigDataType::DATATYPE_INT : + { + int defaultvalue = atoi(configmodel_item_key_name[item].defaultValue); + set_condigData_Int(item,defaultvalue); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(int):value(%d)", + get_config_name(item), + get_configData_int(item)); + break; + case ConfigDataType::DATATYPE_STRING: + + set_condigData_String(item,configmodel_item_key_name[item].defaultValue); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(string):value(%s)", + get_config_name(item), + get_configData_string(item).c_str()); + break; + case ConfigDataType::DATATYPE_VECTOR_DOUBLE: + /** + * configmodel_item_key_name[item].defaultValue 转换成jsongArrayObj 再存入 + */ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(vector_double):value(%s)", + get_config_name(item), + ""); + break; + case ConfigDataType::DATATYPE_VECTOR_INT: + /** + * configmodel_item_key_name[item].defaultValue 转换成jsongArrayObj 再存入 + */ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(vector_int):value(%s)", + get_config_name(item), + ""); + break; + case ConfigDataType::DATATYPE_VECTOR_STRING: + /** + * configmodel_item_key_name[item].defaultValue 转换成jsongArrayObj 再存入 + */ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(vector_string):value(%s)", + get_config_name(item), + ""); + break; + + } + } + /// @brief 加载json文件 /// @param filePath 指定要加载和解析的 JSON 文件的路径 /// @return true 加载json文件成功,反之失败 @@ -36,6 +112,16 @@ namespace OHOS file.close(); // 解析JSON数据 cjson_json = cJSON_Parse(json_string.c_str()); + + for (int i = 0; i< ConfigItem::CONFIGMODEL_ITEM_MAX;i++) + { + ConfigItem item = (ConfigItem)i; + cJSON *obj=get_item(item); + if (obj == NULL) //没有变量则用默认值初始化 + { + reset_item_to_default(item); + } + } return true; } else @@ -149,11 +235,11 @@ namespace OHOS cJSON *data_obj = cJSON_CreateNumber(static_cast(data)); if (data_obj != nullptr) { - cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); - char *jsonString = cJSON_Print(json_obj); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // Write to file as before - WriteJsonToFile(jsonString, filePath.c_str()); + if (cJSON_GetObjectItem(json_obj,field_name)!=NULL){ + cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); + }else{ + cJSON_AddItemToObject(json_obj,field_name,data_obj); + } } else { @@ -178,11 +264,11 @@ namespace OHOS cJSON *data_obj = cJSON_CreateNumber(data); if (data_obj != nullptr) { - cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); - char *jsonString = cJSON_Print(json_obj); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // Write to file as before - WriteJsonToFile(jsonString, filePath.c_str()); + if (cJSON_GetObjectItem(json_obj,field_name)!=NULL){ + cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); + }else{ + cJSON_AddItemToObject(json_obj,field_name,data_obj); + } } else { @@ -206,12 +292,12 @@ namespace OHOS cJSON *data_obj = cJSON_CreateBool(data); if (data_obj != nullptr) - { - cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); - char *jsonString = cJSON_Print(json_obj); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // Write to file as before - WriteJsonToFile(jsonString, filePath.c_str()); + { + if (cJSON_GetObjectItem(json_obj,field_name)!=NULL){ + cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); + }else{ + cJSON_AddItemToObject(json_obj,field_name,data_obj); + } } else { @@ -236,11 +322,11 @@ namespace OHOS cJSON *data_obj = cJSON_CreateString(data); if (data_obj != nullptr) { - cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); - char *jsonString = cJSON_Print(json_obj); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // Write to file as before - WriteJsonToFile(jsonString, filePath.c_str()); + if (cJSON_GetObjectItem(json_obj,field_name)!=NULL){ + cJSON_ReplaceItemInObject(json_obj, field_name, data_obj); + }else{ + cJSON_AddItemToObject(json_obj,field_name,data_obj); + } } else { @@ -262,10 +348,6 @@ namespace OHOS cJSON_AddItemToArray(array_obj, cJSON_CreateNumber(static_cast(item))); } cJSON_ReplaceItemInObject(json_obj, field_name, array_obj); - char *jsonString = cJSON_Print(json_obj); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // Write to file as before - WriteJsonToFile(jsonString, filePath.c_str()); } void ConfigModel::WriteJsonData_VectorDouble(cJSON *json_obj, const char *field_name, const std::vector &data) @@ -282,10 +364,6 @@ namespace OHOS cJSON_AddItemToArray(array_obj, cJSON_CreateNumber(item)); } cJSON_ReplaceItemInObject(json_obj, field_name, array_obj); - char *jsonString = cJSON_Print(json_obj); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // Write to file as before - WriteJsonToFile(jsonString, filePath.c_str()); } void ConfigModel::WriteJsonData_VectorString(cJSON *json_obj, const char *field_name, const std::vector &data) @@ -302,10 +380,7 @@ namespace OHOS cJSON_AddItemToArray(array_obj, cJSON_CreateString(item.c_str())); } cJSON_ReplaceItemInObject(json_obj, field_name, array_obj); - char *jsonString = cJSON_Print(json_obj); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); - // Write to file as before - WriteJsonToFile(jsonString, filePath.c_str()); + } /* @@ -335,7 +410,6 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WriteJsonData to file success\n"); } fclose(fp); - free(json_string); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JSON data written to file: %s", file_path); @@ -345,219 +419,159 @@ namespace OHOS void ConfigModel::Init(void) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ConfigModel::Init"); + if (model_initialled == true) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ConfigModel::Init already done"); + return ; + } /* -------------------------------- 1.加载json文件 -------------------------------- */ - LoadJsonData(); + bool ret = LoadJsonData(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ConfigModel::Init %d",ret); + + /* ------------------------------ 2.显示读取到的json数据 ------------------------------ */ + DumpJsonData(); + model_initialled = true; + } + void ConfigModel::DumpJsonItem(ConfigItem item) + { + switch(get_config_datatype(item)) + { + case ConfigDataType::DATATYPE_BOOL: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(bool):value(%d)", + get_config_name(item), + get_configData_bool(item)); + break; + case ConfigDataType::DATATYPE_DOUBLE: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(double):value(%f)", + get_config_name(item), + get_configData_double(item)); + break; + case ConfigDataType::DATATYPE_INT : + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(int):value(%d)", + get_config_name(item), + get_configData_int(item)); + break; + case ConfigDataType::DATATYPE_STRING: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(string):value(%s)", + get_config_name(item), + get_configData_string(item).c_str()); + break; + case ConfigDataType::DATATYPE_VECTOR_DOUBLE: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(vector_double):value(%f)", + get_config_name(item), + ""); + break; + case ConfigDataType::DATATYPE_VECTOR_INT: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(vector_int):value(%d)", + get_config_name(item), + ""); + break; + case ConfigDataType::DATATYPE_VECTOR_STRING: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "item(%s):type(vector_string):value(%s)", + get_config_name(item), + ""); + break; - /* ---------------------------- 2.从加载的json文件读取数据初始化 --------------------------- */ - SetRaiseToBrightnessCheckBoxButtonState(); - SetScreenBrightnessValue(); - SetScreenDurationRadioButtonSlectValue(); - SetHeartRateOrBloodOxygenQuickAccessSwitch(); - SetHeartRateOrBloodOxygenQuickAccessSwitch(); - /* ------------------------------ 3.显示读取到的json数据 ------------------------------ */ - ShowReadJsonData(); + } } - /// @brief 显示读取到的json数据 - void ConfigModel::ShowReadJsonData(void) + void ConfigModel::DumpJsonData(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "/* -------------------------------- JsonData: ------------------------------- */\n"); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RaiseToBrightnessCheckBoxButtonState:%d", RaiseToBrightnessCheckBoxButtonState); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenBrightnessValue:%d", ScreenBrightnessValue); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadioButtonSlectValue:%d", ScreenDurationRadioButtonSlectValue); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TradionalBlueToothToggleButtonState:%d", TradionalBlueToothToggleButtonState); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartRateOrBloodOxygenQuickAccessSwitch:%d", HeartRateOrBloodOxygenQuickAccessSwitch); + for (int i = 0; i< ConfigItem::CONFIGMODEL_ITEM_MAX;i++) + { + DumpJsonItem((ConfigItem)i); + } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "/* -------------------------------------------------------------------------- */\n"); } /* -------------------------------- set与get方法 ------------------------------- */ - void ConfigModel::SetRaiseToBrightnessCheckBoxButtonState() - { - RaiseToBrightnessCheckBoxButtonState = ReadJsonData_Bool(GetcJSON(), "RaiseToBrightnessCheckBoxButtonState"); - } - - /// @brief 获取抬腕按钮状态 - bool ConfigModel::GetRaiseToBrightnessCheckBoxButtonState(void) - { - return RaiseToBrightnessCheckBoxButtonState; - } - - void ConfigModel::SetScreenBrightnessValue() + + bool ConfigModel::GetRaiseToWake(void) { - ScreenBrightnessValue = static_cast(ReadJsonData_Int(GetcJSON(), "ScreenBrightnessValue")); + return get_configData_bool(CONFIGMODEL_ITEM_RAISE_TO_WAKE); } - /// @brief 获取亮度值 unsigned ConfigModel::GetScreenBrightnessValue(void) { - return ScreenBrightnessValue; - } - - void ConfigModel::SetScreenDurationRadioButtonSlectValue() - { - ScreenDurationRadioButtonSlectValue = static_cast(ReadJsonData_Int(GetcJSON(), "ScreenDurationRadioButtonSlectValue")); + return get_configData_int(CONFIGMODEL_ITEM_SCREEN_BRIGHTNESS_VALUE) ; } /// @brief 获取亮屏时长三个单选框选中状况,0对应5秒熄屏,1对应10秒熄屏,2对应15秒熄屏 - unsigned int ConfigModel::GetScreenDurationRadioButtonSlectValue(void) - { - return ScreenDurationRadioButtonSlectValue; - } - - void ConfigModel::SetTradionalBlueToothToggleButtonState(void) + unsigned int ConfigModel::GetScreenDuration(void) { - TradionalBlueToothToggleButtonState = (ReadJsonData_Bool(GetcJSON(), "TradionalBlueToothToggleButtonState")); + return get_configData_int(CONFIGMODEL_ITEM_SCREEN_OFF_TIMEOUT_VALUE); } /// @brief 获取蓝牙开关状态 - bool ConfigModel::GetTradionalBlueToothToggleButtonState(void) - { - return TradionalBlueToothToggleButtonState; - } - - void ConfigModel::SetHeartRateOrBloodOxygenQuickAccessSwitch(void) + bool ConfigModel::GetClassicBlueToothState(void) { - HeartRateOrBloodOxygenQuickAccessSwitch = (ReadJsonData_Int(GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch")); + return get_configData_bool(CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON); } - /// @brief 获取“心率或血氧”快速访问开关 - int ConfigModel::GetHeartRateOrBloodOxygenQuickAccessSwitch(void) - { - return HeartRateOrBloodOxygenQuickAccessSwitch; - } - - /* --------------------------------- 表盘信息操作 --------------------------------- */ - void ConfigModel::SetDialId(dial_config *dial) - { - dialid_ = dial->dialid; - dialname_ = dial->dialname; - // 写入json数据 - WriteJsonData_Int(GetcJSON(), "Dial_Id", dialid_); - WriteJsonData_String(GetcJSON(), "Dial_Name", dialname_.c_str()); - } - - dial_config *ConfigModel::GetDialId() - { - // 读取json数据 - dialid_ = (ReadJsonData_Int(GetcJSON(), "Dial_Id")); - dialname_ = ReadJsonData_String(GetcJSON(), "Dial_Name"); - dial_config *dial = new dial_config(); - dial->dialid = dialid_; - dial->dialname = dialname_; - return dial; - } /* -------------------------------------------------------------------------- */ void ConfigModel::SetLanguage(int language) { - languageid_ = language; - WriteJsonData_Int(GetcJSON(), "Language_Id", languageid_); + set_condigData_Int(CONFIGMODEL_ITEM_LANGUAGE_ID,language); } int ConfigModel::GetLanguage() { - languageid_ = (ReadJsonData_Int(GetcJSON(), "Language_Id")); - return languageid_; + return get_configData_int(CONFIGMODEL_ITEM_LANGUAGE_ID); } void ConfigModel::SetLanguageCode(char *languagecode) { - LanguageCode = languagecode; - WriteJsonData_String(GetcJSON(), "Language_Code", LanguageCode.c_str()); // 应该放到关机时候写 + set_condigData_String(CONFIGMODEL_ITEM_LANGUAGE_CODE,languagecode); } const char *ConfigModel::GetLanguageCode(void) { - LanguageCode = ReadJsonData_String(GetcJSON(), "Language_Code"); // 应该放到开机时候读 - return LanguageCode.c_str(); + return get_configData_string(CONFIGMODEL_ITEM_LANGUAGE_CODE).c_str(); } char *ConfigModel::Getimei() { - return imei_str; + return (char*)get_configData_string(CONFIGMODEL_ITEM_CAT1_IMEI).c_str(); } char *ConfigModel::GetpyVer() { - - return pyVer; + return (char*)get_configData_string(CONFIGMODEL_ITEM_CAT1_PYVER).c_str(); } char *ConfigModel::GetmoderVer() { - - return moderVer; + return (char*)get_configData_string(CONFIGMODEL_ITEM_CAT1_MODEMVER).c_str(); } void ConfigModel::Setimei(char *str) { - if (imei_str == NULL || strcmp(imei_str, str) != 0) - { - if (imei_str == NULL) - { - imei_str = (char *)malloc(strlen(str)); - strcpy(imei_str, str); - } - else - { - memset(imei_str, 0, strlen(imei_str)); - strcpy(imei_str, str); - } - } - return; + set_condigData_String(CONFIGMODEL_ITEM_CAT1_IMEI,str); } void ConfigModel::SetpyVer(char *str) { - if (pyVer == NULL || strcmp(pyVer, str) != 0) - { - if (pyVer == NULL) - { - pyVer = (char *)malloc(strlen(str)); - strcpy(pyVer, str); - } - else - { - memset(pyVer, 0, strlen(pyVer)); - strcpy(pyVer, str); - } - } - return; + set_condigData_String(CONFIGMODEL_ITEM_CAT1_PYVER,str); } void ConfigModel::SetmoderVer(char *str) { - if (moderVer == NULL || strcmp(moderVer, str) != 0) - { - if (moderVer == NULL) - { - moderVer = (char *)malloc(strlen(str)); - strcpy(moderVer, str); - } - else - { - memset(moderVer, 0, strlen(moderVer)); - strcpy(moderVer, str); - } - } - return; + set_condigData_String(CONFIGMODEL_ITEM_CAT1_MODEMVER,str); } /* * @brief 设置震动提醒 - * @param {bool} true 开启 - * @param {bool} false 关闭 + * @param 马达 开关, 0 关, 1 å¼±, 2 中,3 强 */ - void ConfigModel::SetVibrationReminder(bool state) + void ConfigModel::SetVibrationReminder(int state) { - VibrationReminder = state; - WriteJsonData_Bool(GetcJSON(), "VibrationReminder", VibrationReminder); // 应该放到关机时候写 + set_condigData_Bool(CONFIGMODEL_ITEM_VIBRATOR_SWITCH,state); } /*获取震动提醒是否开启*/ - bool ConfigModel::GetVibrationReminder(void) + int ConfigModel::GetVibrationReminder(void) { - VibrationReminder = ReadJsonData_Bool(GetcJSON(), "VibrationReminder"); // 应该放到开机时候读 - return VibrationReminder; + return get_configData_int(CONFIGMODEL_ITEM_VIBRATOR_SWITCH); } /* @@ -567,15 +581,13 @@ namespace OHOS */ void ConfigModel::SetSilentMode(bool state) { - SilentMode = state; - WriteJsonData_Bool(GetcJSON(), "SilentMode", SilentMode); // 应该放到关机时候写 + set_condigData_Bool(CONFIGMODEL_ITEM_SILENT_MODE,state); } /*获取静音模式是否开启*/ bool ConfigModel::GetSilentMode(void) { - SilentMode = ReadJsonData_Bool(GetcJSON(), "SilentMode"); // 应该放到开机时候读 - return SilentMode; + return get_configData_bool(CONFIGMODEL_ITEM_SILENT_MODE); } /* @@ -584,8 +596,7 @@ namespace OHOS */ void ConfigModel::SetCat1_4Gability(bool state) { - Cat1_4Gability = state; - WriteJsonData_Bool(GetcJSON(), "Cat1_4Gability", Cat1_4Gability); // 应该放到开机时候读 + set_condigData_Bool(CONFIGMODEL_ITEM_CAT1_SERVICE_ON,state); } /* @@ -594,20 +605,83 @@ namespace OHOS */ bool ConfigModel::GetCat1_4Gability() { - Cat1_4Gability = ReadJsonData_Bool(GetcJSON(), "Cat1_4Gability"); // 应该放到关机机时候写 - return Cat1_4Gability; + return get_configData_bool(CONFIGMODEL_ITEM_CAT1_SERVICE_ON); + } + +/* ---------------------------------------------------------------------------- */ + int ConfigModel::get_configData_int(ConfigItem item) + { + return ReadJsonData_Int(GetcJSON(),get_config_name(item)); + + } + double ConfigModel::get_configData_double(ConfigItem item) + { + return ReadJsonData_Double(GetcJSON(),get_config_name(item)); + + } + bool ConfigModel::get_configData_bool(ConfigItem item) + { + return ReadJsonData_Bool(GetcJSON(),get_config_name(item)); + + } + std::string ConfigModel::get_configData_string(ConfigItem item) + { + return ReadJsonData_String(GetcJSON(),get_config_name(item)); + } + + void ConfigModel::set_condigData_Int(ConfigItem item, int data) + { + WriteJsonData_Int(GetcJSON(),get_config_name(item),data); + } + void ConfigModel::set_condigData_Double(ConfigItem item, double data) + { + WriteJsonData_Double(GetcJSON(),get_config_name(item),data); + } + void ConfigModel::set_condigData_Bool(ConfigItem item, bool data) + { + WriteJsonData_Bool(GetcJSON(),get_config_name(item),data); + + } + void ConfigModel::set_condigData_String(ConfigItem item, const char *data) + { + WriteJsonData_String(GetcJSON(),get_config_name(item),data); + } + void ConfigModel::set_condigData_VectorInt(ConfigItem item, const std::vector &data) + { + WriteJsonData_VectorInt(GetcJSON(),get_config_name(item),data); + + } + void ConfigModel::set_condigData_VectorDouble(ConfigItem item, const std::vector &data) + { + WriteJsonData_VectorDouble(GetcJSON(),get_config_name(item),data); + + } + void ConfigModel::set_condigData_VectorString(ConfigItem item, const std::vector &data) + { + WriteJsonData_VectorString(GetcJSON(),get_config_name(item),data); + + } + int ConfigModel::sync_all_to_disk(void) + { + char *jsonString = cJSON_Print(GetcJSON()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString); + // Write to file as before + WriteJsonToFile(jsonString, filePath.c_str()); + cJSON_free(jsonString); + } + /* ------------------------------ ImageAnimator ----------------------------- */ ImageAnimator::ImageAnimator() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ImageAnimator::ImageAnimator"); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ImageAnimator::ImageAnimator"); } ImageAnimator::~ImageAnimator() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ImageAnimator::~ImageAnimator"); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ImageAnimator::~ImageAnimator"); } /* @@ -691,4 +765,43 @@ namespace OHOS } } -} \ No newline at end of file +} + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +uint32_t ConfigModelInit(void) +{ + OHOS::ConfigModel::GetInstance()->Init(); + return 0; +} + +/*** + * 蓝牙服务是否开启 + */ +bool start_ble_service_on_bootup_flag(void) +{ + OHOS::ConfigModel::GetInstance()->GetCat1_4Gability(); + return false; +} +/*** + * Cat1服务是否开启 + */ +bool poweron_cat1_on_bootup_flag(void) +{ + OHOS::ConfigModel::GetInstance()->GetCat1_4Gability(); + return false; +} +void sync_all_config_to_disk(void) +{ + OHOS::ConfigModel::GetInstance()->sync_all_to_disk(); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp index 6c1252984..dc0f14825 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp @@ -122,7 +122,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetDialConfigPath:%d", Current_dial); - dial_config *dial = ConfigModel::GetInstance()->GetDialId(); + // dial_config *dial = ConfigModel::GetInstance()->GetDialId(); Current_dialname = dial->dialname; Current_dial = dial->dialid; diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessModel.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessModel.h index b684cfd0c..f4947bdad 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessModel.h @@ -25,7 +25,7 @@ namespace OHOS private: bool RaiseToBrightnessCheckBoxButtonState{false}; // 抬腕按钮状态 ,默认补选中 unsigned char ScreenBrightnessValue{255}; // 亮度值 ,默认最大亮度 - unsigned int ScreenDurationRadioButtonSlectValue{1}; // 亮屏时长 ,1对应10秒后熄屏 + unsigned int ScreenDurationIndex{1}; // 亮屏时长 ,1对应10秒后熄屏 unsigned int ScreenDurationTime{10000}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp index 6b8db084c..ab7a7f180 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp @@ -31,8 +31,8 @@ namespace OHOS unsigned char value = BrightnessControlViewSlider->GetValue(); DisplayBrightnessModel::GetInstance()->KeepScreenBrightnessValues(value); - ConfigModel::GetInstance()->WriteJsonData_Int(ConfigModel::GetInstance()->GetcJSON(),"ScreenBrightnessValue",value); - + // ConfigModel::GetInstance()->WriteJsonData_Int(ConfigModel::GetInstance()->GetcJSON(),"ScreenBrightnessValue",value); + ConfigModel::GetInstance()->set_condigData_Int(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_SCREEN_BRIGHTNESS_VALUE,value); delete BrightnessControlViewSlider; BrightnessControlViewSlider = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp index a154155c1..45d3abfb4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp @@ -9,9 +9,9 @@ namespace OHOS DisplayBrightnessModel::DisplayBrightnessModel() { ConfigModel *p_ConfigModel = ConfigModel::GetInstance(); - RaiseToBrightnessCheckBoxButtonState = p_ConfigModel->GetRaiseToBrightnessCheckBoxButtonState(); + RaiseToBrightnessCheckBoxButtonState = p_ConfigModel->GetRaiseToWake(); ScreenBrightnessValue = p_ConfigModel->GetScreenBrightnessValue(); - ScreenDurationRadioButtonSlectValue =p_ConfigModel->GetScreenDurationRadioButtonSlectValue(); + ScreenDurationIndex =p_ConfigModel->GetScreenDuration(); } DisplayBrightnessModel::~DisplayBrightnessModel() {} @@ -68,7 +68,7 @@ namespace OHOS /// @param value 0 5秒后熄屏 1 10秒后熄屏 2 15秒后熄屏 void DisplayBrightnessModel::KeepScreenDurationRadioButtonSlectStatus(unsigned int value) { - ScreenDurationRadioButtonSlectValue = value; + ScreenDurationIndex = value*5000+5000; } /// @brief 亮屏时长按钮选中状态初始化 @@ -82,7 +82,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessViewAndSubViewComponentsStatusInit DisplayBrightnessPresenter GetInstance fail"); return false; } - displayBrightnessPresent->SetScreenDurationRadioButtonSlectStatus(ScreenDurationRadioButtonSlectValue); + displayBrightnessPresent->SetScreenDurationRadioButtonSlectStatus( (ScreenDurationIndex - 5000)/5000); return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp index 32a70f2df..067dd11c9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp @@ -64,12 +64,12 @@ namespace OHOS if (state == UICheckBox::UICheckBoxState::SELECTED) { DisplayBrightnessModel::GetInstance()->SetRaiseToBrightnessCheckBoxButtonStatus(true); - ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(),"RaiseToBrightnessCheckBoxButtonState",true); + ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_RAISE_TO_WAKE,true); } else { DisplayBrightnessModel::GetInstance()->SetRaiseToBrightnessCheckBoxButtonStatus(false); - ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(),"RaiseToBrightnessCheckBoxButtonState",false); + ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_RAISE_TO_WAKE,false); } delete RaiseToBrightnessCheckBoxButton; diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp index 479c83d13..823358059 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp @@ -40,7 +40,8 @@ namespace OHOS } } DisplayBrightnessModel::GetInstance()->KeepScreenDurationRadioButtonSlectStatus(i); - ConfigModel::GetInstance()->WriteJsonData_Int(ConfigModel::GetInstance()->GetcJSON(),"ScreenDurationRadioButtonSlectValue",i); + /** 0 5000ms, 1 10000ms, 2 15000ms */ + ConfigModel::GetInstance()->set_condigData_Int(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_SCREEN_OFF_TIMEOUT_VALUE,i*5000+5000); delete ScreenDurationTitleLabel; ScreenDurationTitleLabel = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp index 8f46c7e3e..25aa4002d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp @@ -99,6 +99,7 @@ namespace OHOS char *defaultJsonString = cJSON_Print(defaultJson); outFile << defaultJsonString; // 写入包含默认值的JSON对象 outFile.close(); + cJSON_free(defaultJsonString); cJSON_Delete(defaultJson); inFile.open(jsonFilePath); // 重新打开文件 } diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp b/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp index bdb558f11..805bf131a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp @@ -56,8 +56,39 @@ namespace OHOS // static const char *ja = "user/res/font/ja.lang"; // static const char *de = "user/res/font/de.lang"; - static const uint8_t langcount = 2; - const char *resFiles[langcount] = {zh, en}; + // static const uint8_t langcount = 2; + const char *resFiles[MAX_LANGUAGE] = { + "user/res/font/zh.lang",// ZH_CN = 0, + "user/res/font/en.lang",// EN, + "user/res/font/zh.lang",// JA, + "user/res/font/zh.lang",// KO, + "user/res/font/zh.lang",// ES, + "user/res/font/zh.lang",// RU, + "user/res/font/zh.lang",// HR, + "user/res/font/zh.lang",// DE, + "user/res/font/zh.lang",// PT, + "user/res/font/zh.lang",// FR, + "user/res/font/zh.lang",// NL, + "user/res/font/zh.lang",// IT, + "user/res/font/zh.lang",// CS, + "user/res/font/zh.lang",// EL, + "user/res/font/zh.lang",// HI, + "user/res/font/zh.lang",// ID, + "user/res/font/zh.lang",// MS, + "user/res/font/zh.lang",// PL, + "user/res/font/zh.lang",// TH, + "user/res/font/zh.lang",// VI, + "user/res/font/zh.lang",// FI, + "user/res/font/zh.lang",// RO, + "user/res/font/zh.lang",// TR, + "user/res/font/zh.lang",// FA, + "user/res/font/zh.lang",// AR, + "user/res/font/zh.lang",// HE, + "user/res/font/zh.lang",// UK, + "user/res/font/zh.lang",// SV, + "user/res/font/zh.lang",// UZ, + "user/res/font/zh.lang"// AZ, + }; static language *g_planguage{nullptr}; @@ -84,7 +115,7 @@ namespace OHOS // 获取json里面的语言 int thelanguage = ConfigModel::GetInstance()->GetLanguage(); - FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, langcount, thelanguage); + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, MAX_LANGUAGE, thelanguage); return true; } @@ -104,7 +135,7 @@ namespace OHOS return false; } - FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, langcount, language_status); + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, MAX_LANGUAGE, language_status); UIFont::GetInstance()->SetCurrentLangId(language_status); ConfigModel::GetInstance()->SetLanguage(language_status); @@ -123,7 +154,7 @@ namespace OHOS // 获取语言Code对应的语言Id LanguageId currentLanguageId = LanguageManager::GetInstance().GetLanguageIdByCode(language_code); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %s", currentLanguageId, language_code); - FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, langcount, currentLanguageId); + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, MAX_LANGUAGE, currentLanguageId); UIFont::GetInstance()->SetCurrentLangId(currentLanguageId); ConfigModel::GetInstance()->SetLanguageCode(language_code); diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp index 69534af5f..4448b5848 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp @@ -65,6 +65,9 @@ namespace OHOS // 重启 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "REBOOTDEVICE_BUTTON OnClick"); RebootView::GetInstance()->ChangeView(REBOOTDEVICEVIEW, SHUTDOWNANIMATORVIEW); + start_shutdown_or_reboot(); + shutdown_reboot_prejobs(); + ShutDownAnimatorView::GetInstance()->GeShutDownImageAnimatorView()->Start(); isShutDownOperation = false; } @@ -74,6 +77,9 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SHUTDOWNDEVICE_BUTTON OnClick"); // GetPMSDefaultInterface()->ShutDownDevice(NULL, NULL); RebootView::GetInstance()->ChangeView(SHUTDOWNDEVICEVIEW, SHUTDOWNANIMATORVIEW); + start_shutdown_or_reboot(); + shutdown_reboot_prejobs(); + ShutDownAnimatorView::GetInstance()->GeShutDownImageAnimatorView()->Start(); isShutDownOperation = true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/QuickAccessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/QuickAccessView.cpp index 2a05b1007..3b210b9ae 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/QuickAccessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/QuickAccessView.cpp @@ -40,12 +40,12 @@ namespace OHOS if (QuickAccessRadioButton[0]->GetState() == UICheckBox::SELECTED) { SecondaryFunctionModel::GetInstance()->KeepHeartRateOrBloodOxygenQuickAccessRadioButtonSelectState(0); - ConfigModel::GetInstance()->WriteJsonData_Int(ConfigModel::GetInstance()->GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch", 0); + // ConfigModel::GetInstance()->WriteJsonData_Int(ConfigModel::GetInstance()->GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch", 0); } else if (QuickAccessRadioButton[1]->GetState() == UICheckBox::SELECTED) { SecondaryFunctionModel::GetInstance()->KeepHeartRateOrBloodOxygenQuickAccessRadioButtonSelectState(1); - ConfigModel::GetInstance()->WriteJsonData_Int(ConfigModel::GetInstance()->GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch", 1); + // ConfigModel::GetInstance()->WriteJsonData_Int(ConfigModel::GetInstance()->GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch", 1); } // 循环删除 UIImageView 和 UIRadioButton指针数组 diff --git a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionModel.cpp index b3aed18ea..30838239c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionModel.cpp @@ -8,7 +8,7 @@ namespace OHOS SecondaryFunctionModel::SecondaryFunctionModel() { ConfigModel *p_ConfigModel = ConfigModel::GetInstance(); - HeartRateOrBloodOxygenQuickAccessSwitch = p_ConfigModel->GetHeartRateOrBloodOxygenQuickAccessSwitch(); + // HeartRateOrBloodOxygenQuickAccessSwitch = p_ConfigModel->GetHeartRateOrBloodOxygenQuickAccessSwitch(); } SecondaryFunctionModel::~SecondaryFunctionModel() {} diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp index 134213dc8..4770968cd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp @@ -367,10 +367,8 @@ namespace OHOS { display_api->turn_on_screen(); } - int t=ConfigModel::GetInstance()->GetScreenDurationRadioButtonSlectValue(); - if(t>2) - t=1; - display_api->set_screen_set_keepon_timeout(5000+t*5000); + int t=ConfigModel::GetInstance()->GetScreenDuration(); + display_api->set_screen_set_keepon_timeout(t); // } } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 2f88f6760..50a9af674 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -1772,6 +1772,7 @@ static void SetAlarmDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *t } } + cJSON_free(json_format); value[data_len+17] = Calculate_CRC(value,data_len+17); sendBleData(value,data_len+17+1); }else @@ -1837,7 +1838,7 @@ static void aboutDeviceCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *to value[18] = lrc; sendBleData(value,19); } - + cJSON_free(json_format); } //查找手表 01 04 //设置查找手表的状态,1 校验成 2手表已找到,停止查找手表 @@ -1959,6 +1960,7 @@ static void GetCurDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tot value[18] = lrc; sendBleData(value,19); } + cJSON_free(json_format); } //获取当手表电池电量 static void GetBatteryLevelCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) @@ -2253,6 +2255,7 @@ void getSportData(char *buf) cJSON_Delete(dataJSON); int dataLen = strlen(json_format); memcpy(buf,json_format,dataLen); + cJSON_free(json_format); return; } @@ -3227,6 +3230,7 @@ static void trainiHistoryDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8 value[18] = Calculate_CRC(value,18); sendBleData(value,19); } + cJSON_free(json_format); } //同步睡眠数据 static void sleepDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp index 69c9fd0a8..1e10f1121 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp @@ -25,7 +25,7 @@ #include - +#include "config/include/ConfigModelC.h" #include "wearable_log.h" @@ -439,7 +439,7 @@ static int udp_packet_parse(char *rx_buffer, int len) { cat1_getsignal(); cat1_handle_version_msg(msg); - // restart_time_sync(); + restart_time_sync(); } break; @@ -585,12 +585,17 @@ errcode_t cat1_server_init(void) g_timer_time_sync = osTimerNew((osTimerFunc_t)time_sync_func, osTimerPeriodic, NULL, NULL); - if (g_timer_time_sync != NULL) - restart_time_sync(); - else + if ( poweron_cat1_on_bootup_flag() ) + { + uapi_cat1_power_on(1); + uapi_cat1_reset(0); + } + if (g_timer_time_sync == NULL) printf("g_timer_time_sync create failed\n"); g_timer_cat1_sleep = osTimerNew((osTimerFunc_t)timeout_handler_sleep_cat1, osTimerPeriodic, NULL, NULL); + if (g_timer_cat1_sleep == NULL) + printf("g_timer_cat1_sleep create failed\n"); return ERRCODE_SUCC; } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 1d896b389..ede379521 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -110,18 +110,46 @@ uint32_t zh_set_sn(uint8_t *buf_sn, uint32_t len_sn) } -extern uint32_t mcu_os_sys_reset(uint8_t *para, uint32_t para_len); -extern void uapi_sys_shipmode(uint32_t arg); - +extern uint32_t mcu_os_sys_reset(uint8_t *para, uint32_t para_len); +extern void uapi_sys_shipmode(uint32_t arg); +extern void sync_all_config_to_disk(void); void uapi_poweroff_device(void) { + uapi_sys_shipmode(0); } void uapi_reboot_device(void) { mcu_os_sys_reset(NULL,NULL); } +static bool doing_shutdown_or_reboot = false; +void shutdown_reboot_prejobs(void) +{ + PRINT("shutdown_reboot_prejobs !\r\n"); + app_task_definition_t taskcfg={0}; + taskcfg.create_queue_handle = NULL; + taskcfg.attr.name="shutdown_reboot_prejobs"; + taskcfg.attr.priority = osPriorityNormal; + taskcfg.attr.stack_size = 0x1000; + taskcfg.func = sync_all_config_to_disk; + taskcfg.use_mem = USE_EXTEND_MEM; + + errcode_t ret=uapi_create_osThread_custom(&taskcfg); + if(ret != ERRCODE_SUCC) + { + PRINT("create shutdown_reboot_prejobs thread failed %d!\r\n",ret); + + } +} +void start_shutdown_or_reboot(void) +{ + doing_shutdown_or_reboot = true; +} +bool is_doing_shutdown_or_reboot(void) +{ + return doing_shutdown_or_reboot; +} #include "upg.h" #include "upg_porting.h" errcode_t uaip_cmd_update_request(void) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index e4abda288..7b80de55b 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -102,6 +102,10 @@ int set_bmp(void); void get_gsensor_single(uint8_t *databuf); + +void shutdown_reboot_prejobs(void); +void start_shutdown_or_reboot(void); +bool is_doing_shutdown_or_reboot(void); #ifdef __cplusplus } #endif /* __cplusplus */