From: SnickerSun Date: Mon, 15 Apr 2024 03:44:56 +0000 (+0800) Subject: 手动对比 同步 regular_origin 提交 9ae001f4ab8e29de501d80ebe5d44246bd1f6c5b 的代码,并根据源码作者评审... X-Git-Tag: release_V1.2.70_20241020_135402~1194 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=refs%2Fchanges%2F4%2Fhead;p=mirrors%2FFD230.git 手动对比 同步 regular_origin 提交 9ae001f4ab8e29de501d80ebe5d44246bd1f6c5b 的代码,并根据源码作者评审,更新到当下最新。 --- diff --git a/autobuild.sh b/autobuild.sh index a1f7a39dc..954225c7f 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -3,7 +3,7 @@ version=HEAD DATE=$(date +%Y%m%d_%H%M%S) HOMEDIR=$PWD -DEFAULT_BUILD_TYPE=debug +DEFAULT_BUILD_TYPE=release DEFAULT_TARGET_PACK_NAME=pack_brandy_native_js TARGET_PACK_NAME=$DEFAULT_TARGET_PACK_NAME diff --git a/code/sdk/application/brandy/brandy_standard/main.c b/code/sdk/application/brandy/brandy_standard/main.c index aaecd65e1..53f6f289c 100755 --- a/code/sdk/application/brandy/brandy_standard/main.c +++ b/code/sdk/application/brandy/brandy_standard/main.c @@ -37,12 +37,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..4b14ac0c8 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 @@ -354,22 +363,32 @@ static void thread_main(const void *unused) #ifdef ENABLE_SLIP slip_uart_init(); #endif -#ifdef SUPPORT_CAT1_SERVICE - cat1_server_init(); -#endif + #ifdef ENABLE_CYWEE uapi_cywee_service_init(); #endif #ifdef SUPPORT_BLE_SERVICE - svr_bluetooth_init(); + if(start_ble_service_on_bootup_flag()) + { + PRINT("start custom protocol classic bt ble service !\r\n"); + openBle(); + + } #endif #ifdef SUPPORT_ALIPAY_SEC uapi_alipay_svr_init(); #endif // ble_hid_server_init(); + +#ifdef SUPPORT_CAT1_SERVICE + cat1_server_init(); +#endif + + startup_post_init(); + set_startup_finish_flag(); diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 92cdfffbf..b2c504792 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 @@ -330,7 +331,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherReportView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/FutureWeatherPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/FutureWeatherView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/GetWeatherDataErrorPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/GetWeatherDataErrorView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherControlView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherView.cpp @@ -411,9 +411,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 @@ -478,10 +478,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetTimePresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetCaluliView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetCaluliPresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingEndnoteView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingEndnotePresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingEndnote2View.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingEndnote2Presenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingEnddataView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingEnddataPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingWinView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index f3c6a7bb8..53d0e823f 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -44,7 +44,6 @@ typedef enum : uint16_t VIEW_SHUTDOWN_OR_REBOOT, // 关机或重启界面 VIEW_WEATHER, // 天气 VIEW_FUTURE_WEATHER, // 未来天气 - VIEW_GET_WEATHER_DATA_ERROR, // 获取天气数据失败 VIEW_SYSTEM, // 系统 VIEW_SOUND_VIBRATION, // 声音与震动 VIEW_SYSTEM_VOLUME, // 系统音量 @@ -80,8 +79,6 @@ typedef enum : uint16_t VIEW_TRAININGSETDIST, // 设置训练路程 VIEW_TRAININGSETSTEP, // 设置训练步数 VIEW_TRAININGCRAD, // 训练控制卡片 - VIEW_TRAININGENDNOTE, // 结束训练提醒 - VIEW_TRAININGENDNOTE2, // 结束训练时间太短 VIEW_TRAININGENDDATA, // 训练结束详细数据 VIEW_TRAININGSTRONG, // 训练强度介绍 VIEW_TRAININGWIN, // 目标达成 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 957072159..80e354d6e 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -41,7 +41,6 @@ namespace OHOS /* -------------------------------------------------------------------------- */ void InitWeatherSlice(void); void InitFutureWeatherSlice(void); - void InitGetWeatherDataErrorSlice(void); void InitSystemSlice(void); void InitSoundAndVibrationSlice(void); void InitSystemVolumeSlice(void); @@ -60,7 +59,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); @@ -74,8 +73,6 @@ namespace OHOS void InitTraingSetDistSlice(void); void InitTraingSetStepSlice(void); void InitTraingCardSlice(void); - void InitTraingEndnoteSlice(void); - void InitTraingEndnote2Slice(void); void InitTraingEnddataSlice(void); void InitTraingWinSlice(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..a7852c0ff 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -70,8 +70,6 @@ #include "weather/include/MainWeatherView.h" #include "weather/include/FutureWeatherPresenter.h" #include "weather/include/FutureWeatherView.h" -#include "weather/include/GetWeatherDataErrorPresenter.h" -#include "weather/include/GetWeatherDataErrorView.h" #include "system/include/SystemPresenter.h" #include "system/include/SystemView.h" @@ -113,8 +111,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" @@ -172,10 +170,6 @@ #include "traing/include/TraingSetDistView.h" #include "traing/include/TraingSetSeptPresenter.h" #include "traing/include/TraingSetSeptView.h" -#include "traing/include/TraingEndnotePresenter.h" -#include "traing/include/TraingEndnoteView.h" -#include "traing/include/TraingEndnote2Presenter.h" -#include "traing/include/TraingEndnote2View.h" #include "traing/include/TraingEnddataPresenter.h" #include "traing/include/TraingEnddataView.h" #include "traing/include/TraingStrongPresenter.h" @@ -266,7 +260,6 @@ namespace OHOS {VIEW_SHUTDOWN_OR_REBOOT, &NativeLauncher::InitRebootSlice}, {VIEW_WEATHER, &NativeLauncher::InitWeatherSlice}, // 天气 {VIEW_FUTURE_WEATHER, &NativeLauncher::InitFutureWeatherSlice}, // 未来天气 - {VIEW_GET_WEATHER_DATA_ERROR, &NativeLauncher::InitGetWeatherDataErrorSlice}, // 获取天气数据失败 {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址 {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址 {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 @@ -287,7 +280,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}, @@ -313,8 +306,6 @@ namespace OHOS {VIEW_TRAININGSETDIST, &NativeLauncher::InitTraingSetDistSlice}, // 设置目标距离 {VIEW_TRAININGSETSTEP, &NativeLauncher::InitTraingSetStepSlice}, // 设置目标步数 {VIEW_TRAININGCRAD, &NativeLauncher::InitTraingCardSlice}, // 训练卡片 - {VIEW_TRAININGENDNOTE, &NativeLauncher::InitTraingEndnoteSlice}, // 训练结束提醒 - {VIEW_TRAININGENDNOTE2, &NativeLauncher::InitTraingEndnote2Slice}, // 训练结束时间太短提醒 {VIEW_TRAININGENDDATA, &NativeLauncher::InitTraingEnddataSlice}, // 训练结束详细数据 {VIEW_TRAININGWIN, &NativeLauncher::InitTraingWinSlice}, // 训练目标达成 {VIEW_TRAINING_RECORD, &NativeLauncher::InitTraingRecordSlice}, // 训练目标达成 @@ -684,16 +675,7 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_FUTURE_WEATHER, futureweather); } - void NativeLauncher::InitGetWeatherDataErrorSlice(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitGetWeatherDataErrorSlice"); - SliceProxy *getweatherdataerror = new AbilitySliceProxy; - if (getweatherdataerror == nullptr) - { - return; - } - NativeAbility::GetInstance().AddSliceProxy(VIEW_GET_WEATHER_DATA_ERROR, getweatherdataerror); - } + void NativeLauncher::InitSystemSlice(void) // 系统 { @@ -790,17 +772,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"); @@ -954,16 +936,6 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGCRAD, traingcardview); } - void NativeLauncher::InitTraingEndnoteSlice(void) - { - SliceProxy *traingendnoteview = new AbilitySliceProxy; - NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGENDNOTE, traingendnoteview); - } - void NativeLauncher::InitTraingEndnote2Slice(void) - { - SliceProxy *traingendnote2view = new AbilitySliceProxy; - NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGENDNOTE2, traingendnote2view); - } void NativeLauncher::InitTraingEnddataSlice(void) { SliceProxy *traingenddataview = new AbilitySliceProxy; diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index e64c1f0a5..4145204b1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -29,7 +29,6 @@ namespace OHOS {VIEW_COMPASS, PNG_APPLIST_COMPASS_IMAGE, PNG_APPLIST_COMPASS_IMAGE, "指南针", nullptr}, {VIEW_BLOODOXY, PNG_APPLIST_SPO2_IMAGE, PNG_APPLIST_SPO2_IMAGE, "血氧饱和度", nullptr}, {VIEW_HEART, PNG_APPLIST_HEART_IMAGE, PNG_APPLIST_HEART_IMAGE, "心率检测", nullptr}, - {VIEW_INDOORWALK, PNG_APPLIST_WALK_IMAGE, PNG_APPLIST_WALK_IMAGE, "室内步行", nullptr}, {VIEW_WEATHER, PNG_APPLIST_WEATHER_IMAGE, PNG_APPLIST_WEATHER_IMAGE, "天气", nullptr}, {VIEW_TRAINING, PNG_APPLIST_TRAINING_IMAGE, PNG_APPLIST_TRAINING_IMAGE, "体能训练", nullptr}, {VIEW_TRAINING_RECORD, PNG_APPLIST_TRAINING_RECORD_IMAGE, PNG_APPLIST_TRAINING_RECORD_IMAGE, "训练记录", nullptr}, @@ -51,6 +50,7 @@ namespace OHOS {VIEW_OFFLINEVOICE, PNG_APPLIST_VOCASSIST_IMAGE, PNG_APPLIST_VOCASSIST_IMAGE, "语音助手", nullptr}, {VIEW_UISAMPLE, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "示例", nullptr}, {VIEW_MESSAGE, PNG_APPLIST_CALLER_IMAGE, PNG_APPLIST_CALLER_IMAGE, "信息通知", nullptr}, + {VIEW_INDOORWALK, PNG_APPLIST_WALK_IMAGE, PNG_APPLIST_WALK_IMAGE, "室内步行", nullptr}, #endif }; 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..9ec56c47a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -81,11 +81,12 @@ void BluetoothModel::Init() // 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 5853092a9..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,14 +121,19 @@ 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();//主动开启蓝牙 + 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(); + closeBle(); #endif break; default: 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..de5abd701 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -19,224 +19,191 @@ 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(); - char *Getimei(); - char *GetpyVer(); - char *GetmoderVer(); + void SetLanguageCode(char *languagecode); + std::string GetLanguageCode(void); + + std::string Getimei(); + std::string GetpyVer(); + std::string 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", "false" },//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); - 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; - /* -------------------------------------------------------------------------- */ - }; - - /// @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 ----------------------------- */ - /* - * 图片动画类 - */ - class ImageAnimator - { - public: - struct ImageAnimatorConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - - int numFrames; - int time; // 更新的时间间隔 - } imageAnimatorConfig; - // 构造函数 - ImageAnimator(); - // 析构函数 - ~ImageAnimator(); + 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); - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); + void WriteJsonToFile(char *json_string, const char *file_path); + /* -------------------------------------------------------------------------- */ + void DumpJsonData(void); - void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const char **imagePaths, const ImageAnimatorConfig &imageAnimatorConfig); + cJSON *get_item(ConfigItem item); - void FreeImagePathsArray(const char **imagePaths, const int numImages); + private: + const std::string filePath = "/system/ConfigModel.json"; + cJSON *cjson_json{nullptr}; - void DeleteImageAnimatorInfo(ImageAnimatorInfo *&imageAnimatorInfo); + bool model_initialled{false}; + /* -------------------------------------------------------------------------- */ }; } #endif \ No newline at end of file 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..e64594fb3 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 { @@ -10,6 +11,7 @@ namespace OHOS ConfigModel::~ConfigModel() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " ConfigModel::~ConfigModel"); + //手表全生命周期存在,所以不考虑析构释放内存 } ConfigModel *ConfigModel::GetInstance() @@ -24,6 +26,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 +113,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 +236,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 +265,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 +293,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 +323,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 +349,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 +365,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 +381,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 +411,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 +420,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() + + bool ConfigModel::GetRaiseToWake(void) { - RaiseToBrightnessCheckBoxButtonState = ReadJsonData_Bool(GetcJSON(), "RaiseToBrightnessCheckBoxButtonState"); + return get_configData_bool(CONFIGMODEL_ITEM_RAISE_TO_WAKE); } - - /// @brief 获取抬腕按钮状态 - bool ConfigModel::GetRaiseToBrightnessCheckBoxButtonState(void) - { - return RaiseToBrightnessCheckBoxButtonState; - } - - void ConfigModel::SetScreenBrightnessValue() - { - ScreenBrightnessValue = static_cast(ReadJsonData_Int(GetcJSON(), "ScreenBrightnessValue")); - } - /// @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) + unsigned int ConfigModel::GetScreenDuration(void) { - return ScreenDurationRadioButtonSlectValue; - } - - void ConfigModel::SetTradionalBlueToothToggleButtonState(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) - { - HeartRateOrBloodOxygenQuickAccessSwitch = (ReadJsonData_Int(GetcJSON(), "HeartRateOrBloodOxygenQuickAccessSwitch")); - } - - /// @brief 获取“心率或血氧”快速访问开关 - int ConfigModel::GetHeartRateOrBloodOxygenQuickAccessSwitch(void) - { - return HeartRateOrBloodOxygenQuickAccessSwitch; - } - - /* --------------------------------- 表盘信息操作 --------------------------------- */ - void ConfigModel::SetDialId(dial_config *dial) + bool ConfigModel::GetClassicBlueToothState(void) { - dialid_ = dial->dialid; - dialname_ = dial->dialname; - // 写入json数据 - WriteJsonData_Int(GetcJSON(), "Dial_Id", dialid_); - WriteJsonData_String(GetcJSON(), "Dial_Name", dialname_.c_str()); + return get_configData_bool(CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON); } - 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) + std::string ConfigModel::GetLanguageCode(void) { - LanguageCode = ReadJsonData_String(GetcJSON(), "Language_Code"); // 应该放到开机时候读 - return LanguageCode.c_str(); + return get_configData_string(CONFIGMODEL_ITEM_LANGUAGE_CODE); } - char *ConfigModel::Getimei() + std::string ConfigModel::Getimei() { - return imei_str; + return get_configData_string(CONFIGMODEL_ITEM_CAT1_IMEI); } - char *ConfigModel::GetpyVer() + std::string ConfigModel::GetpyVer() { - - return pyVer; + return get_configData_string(CONFIGMODEL_ITEM_CAT1_PYVER); } - char *ConfigModel::GetmoderVer() + std::string ConfigModel::GetmoderVer() { - - return moderVer; + return get_configData_string(CONFIGMODEL_ITEM_CAT1_MODEMVER); } 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 +582,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 +597,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,101 +606,106 @@ 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); } - /* ------------------------------ ImageAnimator ----------------------------- */ +/* ---------------------------------------------------------------------------- */ + int ConfigModel::get_configData_int(ConfigItem item) + { + return ReadJsonData_Int(GetcJSON(),get_config_name(item)); - ImageAnimator::ImageAnimator() + } + double ConfigModel::get_configData_double(ConfigItem item) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ImageAnimator::ImageAnimator"); + return ReadJsonData_Double(GetcJSON(),get_config_name(item)); + } + bool ConfigModel::get_configData_bool(ConfigItem item) + { + return ReadJsonData_Bool(GetcJSON(),get_config_name(item)); - ImageAnimator::~ImageAnimator() + } + std::string ConfigModel::get_configData_string(ConfigItem item) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ImageAnimator::~ImageAnimator"); + return ReadJsonData_String(GetcJSON(),get_config_name(item)); } - - /* - * @brief 创建并初始化图像路径数组 - * @param basePath 包含图片文件的基本路径 - * @param fileExtension 图片文件的扩展名 - * @param numImages 图片文件的数量 - * @return 返回包含图片文件路径的数组 - */ - const char **ImageAnimator::CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) + + void ConfigModel::set_condigData_Int(ConfigItem item, int data) { - const char **imagePaths = new const char *[numImages]; - char buffer[256]; - for (int i = 0; i < numImages; i++) - { - snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); - imagePaths[i] = strdup(buffer); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]); - } - return imagePaths; + WriteJsonData_Int(GetcJSON(),get_config_name(item),data); } - - /* - * @brief 初始化UIImageAnimatorView,并设置为GIF动画 - * 该函数用于使用提供的GIF图像和属性初始化UIImageAnimatorView - * @param imageAnimator 要初始化的UIImageAnimatorView对象的引用 - * @param imagePaths 图片路径 - * @param imageAnimatorInfo 图片映像的信息 - * @param imageAnimatorConfig 样式配置信息 - */ - void ImageAnimator::InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const char **imagePaths, const ImageAnimatorConfig &imageAnimatorConfig) + void ConfigModel::set_condigData_Double(ConfigItem item, double data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ImageAnimator::InitImageAnimatorSource"); - - if (imageAnimator == nullptr) - { - imageAnimator = new UIImageAnimatorView(); - } - imageAnimator->SetPosition(imageAnimatorConfig.x, imageAnimatorConfig.y, imageAnimatorConfig.w, imageAnimatorConfig.h); - imageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - imageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + WriteJsonData_Double(GetcJSON(),get_config_name(item),data); - imageAnimatorInfo = new ImageAnimatorInfo[imageAnimatorConfig.numFrames]; - for (int i = 0; i < imageAnimatorConfig.numFrames; i++) - { - imageAnimatorInfo[i].imagePath = imagePaths[i]; - imageAnimatorInfo[i].pos.x = imageAnimatorConfig.x; - imageAnimatorInfo[i].pos.y = imageAnimatorConfig.y; - imageAnimatorInfo[i].width = imageAnimatorConfig.w; - imageAnimatorInfo[i].height = imageAnimatorConfig.h; - imageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; - } + } + void ConfigModel::set_condigData_Bool(ConfigItem item, bool data) + { + WriteJsonData_Bool(GetcJSON(),get_config_name(item),data); - imageAnimator->SetImageAnimatorSrc(imageAnimatorInfo, imageAnimatorConfig.numFrames, imageAnimatorConfig.time); // 200 is the default delay time - imageAnimator->SetTimeOfPause(imageAnimatorConfig.time); - imageAnimator->SetRepeat(true); } - /* - * 释放图片文件路径数组占用的内存 - * @param imagePaths 图片文件路径数组 - * @param numImages 图片文件的数量 - */ - void ImageAnimator::FreeImagePathsArray(const char **imagePaths, const int numImages) + void ConfigModel::set_condigData_String(ConfigItem item, const char *data) { - for (int i = 0; i < numImages; i++) - { - delete imagePaths[i]; - imagePaths[i] = nullptr; - } + 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 ImageAnimator::DeleteImageAnimatorInfo(ImageAnimatorInfo *&imageAnimatorInfo) + } + void ConfigModel::set_condigData_VectorString(ConfigItem item, const std::vector &data) { - if (imageAnimatorInfo != nullptr) - { - // 由于 imageAnimatorInfo 是一个数组,我们需要使用 delete[] 来删除它 - delete[] imageAnimatorInfo; + WriteJsonData_VectorString(GetcJSON(),get_config_name(item),data); - // 重置指针防止悬空指针 - imageAnimatorInfo = nullptr; - } + } + 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); } +} -} \ 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) +{ + return OHOS::ConfigModel::GetInstance()->GetClassicBlueToothState(); +} +/*** + * Cat1服务是否开启 + */ +bool poweron_cat1_on_bootup_flag(void) +{ + return OHOS::ConfigModel::GetInstance()->GetCat1_4Gability(); +} +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/language/src/LanguageSwitchModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchModel.cpp index 0875e9a82..10932b2de 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchModel.cpp @@ -14,10 +14,10 @@ namespace OHOS LanguageSwitchModel::LanguageSwitchModel() { p_ConfigModel = ConfigModel::GetInstance(); - if (p_ConfigModel->GetLanguageCode() != nullptr) + // if (p_ConfigModel->GetLanguageCode().c_str() != nullptr) { //printf("%s\n", p_ConfigModel->GetLanguageCode()); - CurLanguageCode = const_cast(p_ConfigModel->GetLanguageCode()); + CurLanguageCode = const_cast(p_ConfigModel->GetLanguageCode().c_str()); } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp index 73d0eb79c..1effc9d51 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersView.cpp @@ -13,841 +13,929 @@ #include "PlayersModel.h" #include "PlayersCaseListAdapter.h" #include "MainViewSample.h" +#include "traing/training_card/include/TraingCardView.h" -namespace OHOS { -static PlayersView* g_pPlayersView = nullptr; +namespace OHOS +{ + static PlayersView *g_pPlayersView = nullptr; #define STEP_LABEL_X 166 #define STEP_LABEL_Y 30 #define TEXT_WIDTH 120 #define TEXT_HEIGHT 30 -PlayersView::PlayersView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView::PlayersView"); - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - g_pPlayersView = this; -} - -PlayersView::~PlayersView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView::~PlayersView"); - if (viewiInitStatus == true) { - state = GetPlayerButtonState(); - if (state == UICheckBox::UICheckBoxState::SELECTED) { - PlayersModel::GetInstance()->SetPlayButtonState(true); - } - RemoveAll(); - listGroup->RemoveAll(); - delete list; - list = nullptr; - delete playerlistener; - playerlistener = nullptr; - delete playerButton; - playerButton = nullptr; - delete soundlistener; - soundlistener = nullptr; - delete nextButton; - nextButton = nullptr; - delete nextlistener; - nextlistener = nullptr; - delete preButton; - preButton = nullptr; - TearDownView(); - delete adapterText; - adapterText = nullptr; - delete backGround; - delete titleLabel; - delete subTitleLabel; - delete MusciSourceLabel; - MusciSourceLabel = nullptr; - if(music_list_button != nullptr) - { - delete music_list_button; - music_list_button = nullptr; - } - if(PhoneMusicConnectStatusLabel != nullptr) - { - delete PhoneMusicConnectStatusLabel; - PhoneMusicConnectStatusLabel = nullptr; - } - backGround = nullptr; - titleLabel = nullptr; - subTitleLabel = nullptr; - delete playbackProgress; - playbackProgress = nullptr; - delete jumpView; - jumpView = nullptr; - delete playersPresenter; - playersPresenter = nullptr; - delete playerOnDragListener; - playerOnDragListener = nullptr; - } - g_pPlayersView = nullptr; -} + PlayersView::PlayersView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView::PlayersView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pPlayersView = this; + } -void PlayersView::TitleSetText(const char *text) -{ - titleLabel->SetText(text); - titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + PlayersView::~PlayersView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView::~PlayersView"); + if (viewiInitStatus == true) + { + state = GetPlayerButtonState(); + if (state == UICheckBox::UICheckBoxState::SELECTED) + { + PlayersModel::GetInstance()->SetPlayButtonState(true); + } + RemoveAll(); + listGroup->RemoveAll(); + delete list; + list = nullptr; + delete playerlistener; + playerlistener = nullptr; + delete playerButton; + playerButton = nullptr; + delete soundlistener; + soundlistener = nullptr; + delete nextButton; + nextButton = nullptr; + delete nextlistener; + nextlistener = nullptr; + delete preButton; + preButton = nullptr; + TearDownView(); + delete adapterText; + adapterText = nullptr; + delete backGround; + delete titleLabel; + delete subTitleLabel; + delete MusciSourceLabel; + MusciSourceLabel = nullptr; + if (music_list_button != nullptr) + { + delete music_list_button; + music_list_button = nullptr; + } + if (PhoneMusicConnectStatusLabel != nullptr) + { + delete PhoneMusicConnectStatusLabel; + PhoneMusicConnectStatusLabel = nullptr; + } + backGround = nullptr; + titleLabel = nullptr; + subTitleLabel = nullptr; + delete playbackProgress; + playbackProgress = nullptr; + delete jumpView; + jumpView = nullptr; + delete playersPresenter; + playersPresenter = nullptr; + delete playerOnDragListener; + playerOnDragListener = nullptr; + } + g_pPlayersView = nullptr; + } -} + void PlayersView::TitleSetText(const char *text) + { + titleLabel->SetText(text); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + } -void PlayersView::PlayerModelButtonSetSrc(uint32_t playMode) -{ - ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(playMode, PLAYER_IAMGES); - playerModelButton->SetSrc(image); -} + void PlayersView::PlayerModelButtonSetSrc(uint32_t playMode) + { + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(playMode, PLAYER_IAMGES); + playerModelButton->SetSrc(image); + } -int16_t PlayersView::GetVolumeRank(void) -{ - return volumeSet; -} + int16_t PlayersView::GetVolumeRank(void) + { + return volumeSet; + } -void PlayersView::SetVolumeRank(int16_t value) -{ - volumeSet = value; -} + void PlayersView::SetVolumeRank(int16_t value) + { + volumeSet = value; + } -void PlayersView::SetVolumeAddOne(void) -{ - volumeSet++; -} + void PlayersView::SetVolumeAddOne(void) + { + volumeSet++; + } -UIButton *PlayersView::GetPullButton(void) -{ - return pullButton; -} + UIButton *PlayersView::GetPullButton(void) + { + return pullButton; + } -UIButton *PlayersView::GetOptionsButton(void) -{ - return optionsButton; -} + UIButton *PlayersView::GetOptionsButton(void) + { + return optionsButton; + } -UIButton *PlayersView::GetPreButton(void) -{ - return preButton; -} + UIButton *PlayersView::GetPreButton(void) + { + return preButton; + } -UIButton *PlayersView::GetNextButton(void) -{ - return nextButton; -} + UIButton *PlayersView::GetNextButton(void) + { + return nextButton; + } -//获取音乐列表按钮 -UIButton *PlayersView::GetMusicListButton(void) -{ - return music_list_button; -} + // 获取音乐列表按钮 + UIButton *PlayersView::GetMusicListButton(void) + { + return music_list_button; + } -UILabel *PlayersView::GetTitleLabel(void) -{ - return titleLabel; -} + UILabel *PlayersView::GetTitleLabel(void) + { + return titleLabel; + } -//获取音乐来源标签 -UILabel *PlayersView::GetMusicSourceLabel(void) -{ - return MusciSourceLabel; -} + // 获取音乐来源标签 + UILabel *PlayersView::GetMusicSourceLabel(void) + { + return MusciSourceLabel; + } -//获手机音乐连接状态标签 -UILabel *PlayersView::GetPhoneMusicConnectStatusLabel(void) -{ - return PhoneMusicConnectStatusLabel; -} + // 获手机音乐连接状态标签 + UILabel *PlayersView::GetPhoneMusicConnectStatusLabel(void) + { + return PhoneMusicConnectStatusLabel; + } -UICheckBox *PlayersView::GetPlayerButton(void) -{ - return playerButton; -} + UICheckBox *PlayersView::GetPlayerButton(void) + { + return playerButton; + } -UIImageView *PlayersView::GetSoundButton(void) -{ - return soundButton; -} + UIImageView *PlayersView::GetSoundButton(void) + { + return soundButton; + } -UICircleProgress *PlayersView::GetPlaybackProgress(void) -{ - return playbackProgress; -} + UICircleProgress *PlayersView::GetPlaybackProgress(void) + { + return playbackProgress; + } -UIImageView *PlayersView::GetPlayerModelButton(void) -{ - return playerModelButton; -} + UIImageView *PlayersView::GetPlayerModelButton(void) + { + return playerModelButton; + } -UICheckBox::UICheckBoxState PlayersView::GetPlayerButtonState(void) -{ - return playerButton->GetState(); -} + UICheckBox::UICheckBoxState PlayersView::GetPlayerButtonState(void) + { + return playerButton->GetState(); + } -void PlayersView::SetPlayerButtonState(UICheckBox::UICheckBoxState state) -{ - if (playerButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::SetPlayerButtonState playerButton NULL"); - return; + void PlayersView::SetPlayerButtonState(UICheckBox::UICheckBoxState state) + { + if (playerButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::SetPlayerButtonState playerButton NULL"); + return; + } + return playerButton->SetState(state); } - return playerButton->SetState(state); -} -UIList *PlayersView::GetPlayerList(void) -{ - return list; -} -/// @brief 根据传入的status参数来控制歌曲列表组的显示与隐藏。 -/// @param status -void PlayersView::SetPlayerListGroupStatus(bool status) -{ - if (listGroup == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView listGroup is NULL"); - return; + UIList *PlayersView::GetPlayerList(void) + { + return list; } - UIView *vew = MainViewSample::GetInstance()->GetMainViewGroup(); - if (vew != nullptr) { - vew->SetVisible(!status); + /// @brief 根据传入的status参数来控制歌曲列表组的显示与隐藏。 + /// @param status + void PlayersView::SetPlayerListGroupStatus(bool status) + { + if (listGroup == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView listGroup is NULL"); + return; + } + UIView *vew = MainViewSample::GetInstance()->GetMainViewGroup(); + if (vew != nullptr) + { + vew->SetVisible(!status); + } + /*增加训练卡片控制*/ + UIView *cardview = TraingCardView::GetInstance()->GetTraingCrad(); + if (cardview != nullptr) + { + cardview->SetVisible(!status); + } + listGroup->SetVisible(status); + return; } - listGroup->SetVisible(status); - return; -} -/// @brief 根据传入的status参数来控制删除歌曲视图的显示与隐藏。 -/// @param status -void PlayersView::SetPlayerDelSongViewStatus(bool status) -{ - if (DelSongView == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView DelSongView is NULL"); + /// @brief 根据传入的status参数来控制删除歌曲视图的显示与隐藏。 + /// @param status + void PlayersView::SetPlayerDelSongViewStatus(bool status) + { + if (DelSongView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlayersView DelSongView is NULL"); + return; + } + UIView *vew = MainViewSample::GetInstance()->GetMainViewGroup(); + if (vew != nullptr) + { + vew->SetVisible(!status); + } + /*增加训练卡片控制*/ + UIView *cardview = TraingCardView::GetInstance()->GetTraingCrad(); + if (cardview != nullptr) + { + cardview->SetVisible(!status); + } + DelSongView->SetVisible(status); + RootView::GetInstance()->Invalidate(); return; } - UIView *vew = MainViewSample::GetInstance()->GetMainViewGroup(); - if (vew != nullptr) { - vew->SetVisible(!status); - } - DelSongView->SetVisible(status); - RootView::GetInstance()->Invalidate(); - return; - -} - -void PlayersView::SetPlayerCtrVolume(float leftVolume, float rightVolume) -{ - PlayersModel::GetInstance()->GetPlayerCtr()->SetVolume(leftVolume, rightVolume); -} - -void PlayersView::TearDownView() -{ - delete prelistener; - prelistener = nullptr; - delete playerModelButton; - playerModelButton = nullptr; - delete modellistener; - modellistener = nullptr; - delete soundButton; - soundButton = nullptr; - delete optionslistener; - optionslistener = nullptr; - delete optionsButton; - optionsButton = nullptr; - delete pullButton; - pullButton = nullptr; - delete listGroup; - listGroup = nullptr; -} -PlayersView* PlayersView::GetInstance(void) -{ - return g_pPlayersView; -} - -// 显示音乐列表 -void PlayersView::ShowUpListView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView"); - listGroup = new UIScrollView(); - if (listGroup == nullptr) { - return; + void PlayersView::SetPlayerCtrVolume(float leftVolume, float rightVolume) + { + PlayersModel::GetInstance()->GetPlayerCtr()->SetVolume(leftVolume, rightVolume); } - listGroup->SetPosition(0, 0); - listGroup->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); - listGroup->SetScrollBlankSize(20); - listGroup->SetReboundSize(50); - listGroup->SetDirection(1); - musicListTitle = new UILabel(); - if(musicListTitle ==nullptr) + void PlayersView::TearDownView() { - return; + delete prelistener; + prelistener = nullptr; + delete playerModelButton; + playerModelButton = nullptr; + delete modellistener; + modellistener = nullptr; + delete soundButton; + soundButton = nullptr; + delete optionslistener; + optionslistener = nullptr; + delete optionsButton; + optionsButton = nullptr; + delete pullButton; + pullButton = nullptr; + delete listGroup; + listGroup = nullptr; + } + + PlayersView *PlayersView::GetInstance(void) + { + return g_pPlayersView; } - musicListTitle->SetPosition(173, 52,120,35); - musicListTitle->SetStyle(STYLE_TEXT_FONT, 30); - musicListTitle->SetStyle(STYLE_LINE_HEIGHT, 36); - musicListTitle->SetText("音乐列表"); - musicListTitle->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - musicListTitle->SetTextColor(Color::GetColorFromRGBA(0xff, 0xf3, 0xff, 0xff)); - musicListTitle->SetRollSpeed(0); - musicListTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - listGroup->Add(musicListTitle); - - // list type - if (adapterText == nullptr) { - adapterText = new PlayersCaseListAdapter(); - if (adapterText == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "adapterText new fail"); + + // 显示音乐列表 + void PlayersView::ShowUpListView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView"); + listGroup = new UIScrollView(); + if (listGroup == nullptr) + { return; } - } - if (list == nullptr) { - list = new UIList(UIList::VERTICAL); - if (list == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail"); + listGroup->SetPosition(0, 0); + listGroup->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + listGroup->SetScrollBlankSize(20); + listGroup->SetReboundSize(50); + listGroup->SetDirection(1); + + musicListTitle = new UILabel(); + if (musicListTitle == nullptr) + { return; } - list->SetPosition(67, 138, 332, 500); - list->SetStartIndex(0); // 0 : list start index - list->SetAdapter(adapterText); - } - listGroup->Add(list); - RootView::GetInstance()->Add(listGroup); - UIView::OnDragListener *dragListener = (UIView::OnDragListener*)OHOS::PlayerOnDragListener::GetInstance(); - if (dragListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::OnDragListener fail"); - return; + musicListTitle->SetPosition(173, 52, 120, 35); + musicListTitle->SetStyle(STYLE_TEXT_FONT, 30); + musicListTitle->SetStyle(STYLE_LINE_HEIGHT, 36); + musicListTitle->SetText("音乐列表"); + musicListTitle->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + musicListTitle->SetTextColor(Color::GetColorFromRGBA(0xff, 0xf3, 0xff, 0xff)); + musicListTitle->SetRollSpeed(0); + musicListTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + listGroup->Add(musicListTitle); + + // list type + if (adapterText == nullptr) + { + adapterText = new PlayersCaseListAdapter(); + if (adapterText == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "adapterText new fail"); + return; + } + } + if (list == nullptr) + { + list = new UIList(UIList::VERTICAL); + if (list == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "list new fail"); + return; + } + list->SetPosition(67, 138, 332, 500); + list->SetStartIndex(0); // 0 : list start index + list->SetAdapter(adapterText); + } + listGroup->Add(list); + RootView::GetInstance()->Add(listGroup); + UIView::OnDragListener *dragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::OnDragListener fail"); + return; + } + listGroup->SetDraggable(true); + listGroup->SetTouchable(true); + listGroup->SetOnDragListener(dragListener); + listGroup->SetVisible(false); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView end"); } - listGroup->SetDraggable(true); - listGroup->SetTouchable(true); - listGroup->SetOnDragListener(dragListener); - listGroup->SetVisible(false); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpListView end"); -} -/// @brief 创建删除歌曲视图 -/// @param songName -void PlayersView::ShowUpDelSongView() -{ - if(p_PlayerListDelSongView == nullptr) + /// @brief 创建删除歌曲视图 + /// @param songName + void PlayersView::ShowUpDelSongView() { - p_PlayerListDelSongView = new PlayerListDelSongView(); + if (p_PlayerListDelSongView == nullptr) + { + p_PlayerListDelSongView = new PlayerListDelSongView(); + } + DelSongView = p_PlayerListDelSongView->InitDelSongView(); + RootView::GetInstance()->Add(DelSongView); + DelSongView->SetTouchable(true); + DelSongView->SetVisible(false); } - DelSongView = p_PlayerListDelSongView->InitDelSongView(); - RootView::GetInstance()->Add(DelSongView); - DelSongView->SetTouchable(true); - DelSongView->SetVisible(false); -} -//设置按钮的位置和监听 -void PlayersView::SetUpButton(UIButton *btn, const Point& point, - int16_t width, int16_t height, UIView::OnClickListener *listener) -{ - if (btn == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::SetUpButton nullptr"); - return; - } - Add(btn); - btn->SetPosition(point.x, point.y, width, height); - btn->SetOnClickListener(listener); -} -//复选框:选中播放未选中暂停 -int PlayersView::ShowUpCheckBoxButton() -{ - ImageInfo *ImagePlay; - ImageInfo *ImagerPause; - if (playerButton == nullptr) { - playerButton = new UICheckBox(); - } - if (soundButton == nullptr) { - soundButton = new UIImageView(); - } - if ((playerButton == nullptr) || (soundButton == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new fail"); - return OHOS_FAILURE; - } - playerlistener = new ButtonOnClickListener(reinterpret_cast(playerButton)); - if (playerlistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerlistener new fail"); - return OHOS_FAILURE; - } - playerButton->SetPosition(195, 195, 80, 80); // 140:x 139:y 172:width 172:height - playerButton->SetOnClickListener(playerlistener); - ImagePlay = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PLAY, PLAYER_IAMGES); //播放图片 - ImagerPause = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PAUSE, PLAYER_IAMGES);//暂停图片 - playerButton->SetImages(ImagePlay, ImagerPause); - Add(playerButton); - - soundlistener = new ButtonOnClickListener(reinterpret_cast(soundButton)); - if (soundlistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soundlistener new fail"); - return OHOS_FAILURE; - } - soundButton->SetTouchable(true); - soundButton->SetPosition(321, 321, 60, 60); - soundButton->SetOnClickListener(soundlistener); - if (LoadPlayerImage(soundButton, PLAYER_MUSIC_VOICE) == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerModelButton LoadPlayerImage fail"); - return false; + // 设置按钮的位置和监听 + void PlayersView::SetUpButton(UIButton *btn, const Point &point, + int16_t width, int16_t height, UIView::OnClickListener *listener) + { + if (btn == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::SetUpButton nullptr"); + return; + } + Add(btn); + btn->SetPosition(point.x, point.y, width, height); + btn->SetOnClickListener(listener); } - Add(soundButton); - return OHOS_SUCCESS; -} -//显示按钮:下一首,上一首,播放模式 -int PlayersView::ShowUpButton() -{ - struct Point pointBtn; - ImageInfo *image; - pointBtn.x = 366; // 366:x - pointBtn.y = 213; // 213:y - nextlistener = new ButtonOnClickListener(reinterpret_cast(nextButton)); - if (nextlistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "nextlistener new fail"); - return OHOS_FAILURE; - } - SetUpButton(nextButton, pointBtn, 60, 60, nextlistener); // 93:width 116:height - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_NEXT, PLAYER_IAMGES); - nextButton->SetImageSrc(image, image); - nextButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - nextButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - nextButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); - nextButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - nextButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - pointBtn.x = 60; // 60:x - pointBtn.y = 213; // 213:y - prelistener = new ButtonOnClickListener(reinterpret_cast(preButton)); - if (prelistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "prelistener new fail"); - return OHOS_FAILURE; - } - SetUpButton(preButton, pointBtn, 60, 60, prelistener); // 86:width 116:height - image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_PROVE, PLAYER_IAMGES); - preButton->SetImageSrc(image, image); - preButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - preButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - preButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); - preButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - preButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - pointBtn.x = 105; // 105:x - pointBtn.y = 321; // 321:y - modellistener = new ButtonOnClickListener(reinterpret_cast(playerModelButton)); - if (modellistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "modellistener new fail"); - return OHOS_FAILURE; - } - playerModelButton->SetTouchable(true); - playerModelButton->SetPosition(pointBtn.x, pointBtn.y, 60, 60); - playerModelButton->SetOnClickListener(modellistener); - if (ShowUpPlayerMode() == false) { - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerModel %d", PlayersModel::GetInstance()->GetPlayerModel()); - Add(playerModelButton); - - return OHOS_SUCCESS; -} -//显示音乐播放模式:LOOP 循环播放 SEQUENCE 循序播放 REPEATS 单曲循环 RANDOM 随机播放 -bool PlayersView::ShowUpPlayerMode() -{ - if (PlayersModel::GetInstance()->GetPlayerModel() == LOOP) { - if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_LOOP) == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYER_PLAYERSMODEL_LOOP fail"); - return false; + // 复选框:选中播放未选中暂停 + int PlayersView::ShowUpCheckBoxButton() + { + ImageInfo *ImagePlay; + ImageInfo *ImagerPause; + if (playerButton == nullptr) + { + playerButton = new UICheckBox(); } - } else if (PlayersModel::GetInstance()->GetPlayerModel() == SEQUENCE) { - if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_SEQUENCE) == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_SEQUENCE fail"); - return false; + if (soundButton == nullptr) + { + soundButton = new UIImageView(); } - } else if (PlayersModel::GetInstance()->GetPlayerModel() == REPEATS) { - if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_REPEATS) == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_REPEATS fail"); - return false; + if ((playerButton == nullptr) || (soundButton == nullptr)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new fail"); + return OHOS_FAILURE; + } + playerlistener = new ButtonOnClickListener(reinterpret_cast(playerButton)); + if (playerlistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerlistener new fail"); + return OHOS_FAILURE; } - } else if (PlayersModel::GetInstance()->GetPlayerModel() == RANDOM) { - if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_RANDOM) == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_RANDOM fail"); + playerButton->SetPosition(195, 195, 80, 80); // 140:x 139:y 172:width 172:height + playerButton->SetOnClickListener(playerlistener); + ImagePlay = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PLAY, PLAYER_IAMGES); // 播放图片 + ImagerPause = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_PAUSE, PLAYER_IAMGES); // 暂停图片 + playerButton->SetImages(ImagePlay, ImagerPause); + Add(playerButton); + + soundlistener = new ButtonOnClickListener(reinterpret_cast(soundButton)); + if (soundlistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "soundlistener new fail"); + return OHOS_FAILURE; + } + soundButton->SetTouchable(true); + soundButton->SetPosition(321, 321, 60, 60); + soundButton->SetOnClickListener(soundlistener); + if (LoadPlayerImage(soundButton, PLAYER_MUSIC_VOICE) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerModelButton LoadPlayerImage fail"); return false; } + Add(soundButton); + return OHOS_SUCCESS; } - return true; -} -//显示按钮视图 -int PlayersView::ShowUpButtonView() -{ - int ret; - ret = ShowUpCheckBoxButton(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; - } - if (nextButton == nullptr) { - nextButton = new UIButton(); - } - if (preButton == nullptr) { - preButton = new UIButton(); - } - if (optionsButton == nullptr) { - optionsButton = new UIButton(); - } - if (music_list_button == nullptr) { - music_list_button = new UIButton(); - } - if (pullButton == nullptr) { - pullButton = new UIButton(); - } - if (playerModelButton == nullptr) { - playerModelButton = new UIImageView(); - } - if ((nextButton == nullptr) || (preButton == nullptr) || (playerModelButton == nullptr) || (optionsButton == nullptr) || - (pullButton == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UIButton new fail"); - return OHOS_FAILURE; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpButtonView"); + // 显示按钮:下一首,上一首,播放模式 + int PlayersView::ShowUpButton() + { + struct Point pointBtn; + ImageInfo *image; + pointBtn.x = 366; // 366:x + pointBtn.y = 213; // 213:y + nextlistener = new ButtonOnClickListener(reinterpret_cast(nextButton)); + if (nextlistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "nextlistener new fail"); + return OHOS_FAILURE; + } + SetUpButton(nextButton, pointBtn, 60, 60, nextlistener); // 93:width 116:height + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_NEXT, PLAYER_IAMGES); + nextButton->SetImageSrc(image, image); + nextButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + nextButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + nextButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + nextButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + nextButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + pointBtn.x = 60; // 60:x + pointBtn.y = 213; // 213:y + prelistener = new ButtonOnClickListener(reinterpret_cast(preButton)); + if (prelistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "prelistener new fail"); + return OHOS_FAILURE; + } + SetUpButton(preButton, pointBtn, 60, 60, prelistener); // 86:width 116:height + image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_PROVE, PLAYER_IAMGES); + preButton->SetImageSrc(image, image); + preButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + preButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + preButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + preButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + preButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + pointBtn.x = 105; // 105:x + pointBtn.y = 321; // 321:y + modellistener = new ButtonOnClickListener(reinterpret_cast(playerModelButton)); + if (modellistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "modellistener new fail"); + return OHOS_FAILURE; + } + playerModelButton->SetTouchable(true); + playerModelButton->SetPosition(pointBtn.x, pointBtn.y, 60, 60); + playerModelButton->SetOnClickListener(modellistener); + if (ShowUpPlayerMode() == false) + { + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerModel %d", PlayersModel::GetInstance()->GetPlayerModel()); + Add(playerModelButton); - ret = ShowUpButton(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; - } - ret = ShowUpButtonOptions(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; - } - ret = ShowUpCircleProgress(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; + return OHOS_SUCCESS; } - ret = ShowUpMusicListbutton(); - if (ret == OHOS_FAILURE) { - return OHOS_FAILURE; + // 显示音乐播放模式:LOOP 循环播放 SEQUENCE 循序播放 REPEATS 单曲循环 RANDOM 随机播放 + bool PlayersView::ShowUpPlayerMode() + { + if (PlayersModel::GetInstance()->GetPlayerModel() == LOOP) + { + if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_LOOP) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYER_PLAYERSMODEL_LOOP fail"); + return false; + } + } + else if (PlayersModel::GetInstance()->GetPlayerModel() == SEQUENCE) + { + if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_SEQUENCE) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_SEQUENCE fail"); + return false; + } + } + else if (PlayersModel::GetInstance()->GetPlayerModel() == REPEATS) + { + if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_REPEATS) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_REPEATS fail"); + return false; + } + } + else if (PlayersModel::GetInstance()->GetPlayerModel() == RANDOM) + { + if (LoadPlayerImage(playerModelButton, PLAYER_PLAYERSMODEL_RANDOM) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "load PLAYERSMODEL_RANDOM fail"); + return false; + } + } + return true; } - return OHOS_SUCCESS; -} + // 显示按钮视图 + int PlayersView::ShowUpButtonView() + { + int ret; + ret = ShowUpCheckBoxButton(); + if (ret == OHOS_FAILURE) + { + return OHOS_FAILURE; + } + if (nextButton == nullptr) + { + nextButton = new UIButton(); + } + if (preButton == nullptr) + { + preButton = new UIButton(); + } + if (optionsButton == nullptr) + { + optionsButton = new UIButton(); + } + if (music_list_button == nullptr) + { + music_list_button = new UIButton(); + } + if (pullButton == nullptr) + { + pullButton = new UIButton(); + } + if (playerModelButton == nullptr) + { + playerModelButton = new UIImageView(); + } + if ((nextButton == nullptr) || (preButton == nullptr) || (playerModelButton == nullptr) || (optionsButton == nullptr) || + (pullButton == nullptr)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UIButton new fail"); + return OHOS_FAILURE; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShowUpButtonView"); -//显示音乐列表按钮 -int PlayersView::ShowUpMusicListbutton() -{ - struct Point pointBtn; - pointBtn.x = 213; - pointBtn.y = 35; - music_list_button_listener = new ButtonOnClickListener(reinterpret_cast(music_list_button)); - if (music_list_button_listener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "music_list_button_listener new fail"); - return OHOS_FAILURE; - } - SetUpButton(music_list_button, pointBtn, 60, 60, music_list_button_listener); // 75:width 76:height - ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_LIST, PLAYER_IAMGES); - music_list_button->SetImageSrc(image, image); - music_list_button->SetViewId("music_list_button"); - music_list_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - music_list_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - music_list_button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); - music_list_button->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - music_list_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - - return OHOS_SUCCESS; -} -/* - 创建了两个按钮:optionslistener:显示选项按钮,点击后里面有三种模式:1手机音乐,2本地音乐,3蓝牙耳机 - pullButton:上拉按钮上拉后显示歌单 -*/ -int PlayersView::ShowUpButtonOptions() -{ - struct Point pointBtn; - pointBtn.x = 213; - pointBtn.y = 366; - optionslistener = new ButtonOnClickListener(reinterpret_cast(optionsButton)); - if (optionslistener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "optionslistener new fail"); - return OHOS_FAILURE; - } - SetUpButton(optionsButton, pointBtn, 60, 60, optionslistener); // 75:width 76:height - ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_LOCAL_MUSIC_COLOR, PLAYER_IAMGES); - optionsButton->SetImageSrc(image, image); - optionsButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - optionsButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - optionsButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); - optionsButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - optionsButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - - pointBtn.x = 178; // 178:x - pointBtn.y = 394; // 394:y - SetUpButton(pullButton, pointBtn, 95, 48, nullptr); // 95:width 48:height - pullButton->SetImageSrc(PNG_PULLBUTTON_FACE_IMAGE, PNG_PULLBUTTON_FACE_IMAGE); - pullButton->SetVisible(false); - return OHOS_SUCCESS; -} -//显示播放进度条 -int PlayersView::ShowUpCircleProgress() -{ - if (playbackProgress == nullptr) { - playbackProgress = new UICircleProgress(); - if (playbackProgress == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playbackProgress new fail"); + ret = ShowUpButton(); + if (ret == OHOS_FAILURE) + { + return OHOS_FAILURE; + } + ret = ShowUpButtonOptions(); + if (ret == OHOS_FAILURE) + { return OHOS_FAILURE; } + ret = ShowUpCircleProgress(); + if (ret == OHOS_FAILURE) + { + return OHOS_FAILURE; + } + ret = ShowUpMusicListbutton(); + if (ret == OHOS_FAILURE) + { + return OHOS_FAILURE; + } + return OHOS_SUCCESS; } - playbackProgress->SetPosition(158, 158, 150, 150); - playbackProgress->SetCenterPosition(75, 75); - playbackProgress->SetRange(PLAY_PROGRESS_MAX, PLAY_PROGRESS_MIN); - playbackProgress->SetRadius(70); - playbackProgress->SetStartAngle(0); - playbackProgress->SetEndAngle(360); // 360: end angle - playbackProgress->SetValue(0); - playbackProgress->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - playbackProgress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - playbackProgress->SetBackgroundStyle(STYLE_LINE_COLOR, 0xfff61313); - playbackProgress->SetBackgroundStyle(STYLE_LINE_WIDTH, 0); - playbackProgress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xfffbfbfb); - playbackProgress->SetForegroundStyle(STYLE_BORDER_COLOR, 0xffffffff); - playbackProgress->SetForegroundStyle(STYLE_LINE_COLOR, 0xffffffff); - playbackProgress->SetForegroundStyle(STYLE_LINE_WIDTH, 6); // 6:width - Add(playbackProgress); - return OHOS_SUCCESS; -} -//创建跳转视图 -void PlayersView::CreateJumpView(void) -{ - if (jumpView == nullptr) { - jumpView = new JumpView(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView new fail"); - return; + + // 显示音乐列表按钮 + int PlayersView::ShowUpMusicListbutton() + { + struct Point pointBtn; + pointBtn.x = 213; + pointBtn.y = 35; + music_list_button_listener = new ButtonOnClickListener(reinterpret_cast(music_list_button)); + if (music_list_button_listener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "music_list_button_listener new fail"); + return OHOS_FAILURE; + } + SetUpButton(music_list_button, pointBtn, 60, 60, music_list_button_listener); // 75:width 76:height + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_MUSIC_LIST, PLAYER_IAMGES); + music_list_button->SetImageSrc(image, image); + music_list_button->SetViewId("music_list_button"); + music_list_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + music_list_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + music_list_button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + music_list_button->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + music_list_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + return OHOS_SUCCESS; + } + /* + 创建了两个按钮:optionslistener:显示选项按钮,点击后里面有三种模式:1手机音乐,2本地音乐,3蓝牙耳机 + pullButton:上拉按钮上拉后显示歌单 + */ + int PlayersView::ShowUpButtonOptions() + { + struct Point pointBtn; + pointBtn.x = 213; + pointBtn.y = 366; + optionslistener = new ButtonOnClickListener(reinterpret_cast(optionsButton)); + if (optionslistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "optionslistener new fail"); + return OHOS_FAILURE; + } + SetUpButton(optionsButton, pointBtn, 60, 60, optionslistener); // 75:width 76:height + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(PLAYER_LOCAL_MUSIC_COLOR, PLAYER_IAMGES); + optionsButton->SetImageSrc(image, image); + optionsButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + optionsButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + optionsButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + optionsButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + optionsButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + pointBtn.x = 178; // 178:x + pointBtn.y = 394; // 394:y + SetUpButton(pullButton, pointBtn, 95, 48, nullptr); // 95:width 48:height + pullButton->SetImageSrc(PNG_PULLBUTTON_FACE_IMAGE, PNG_PULLBUTTON_FACE_IMAGE); + pullButton->SetVisible(false); + return OHOS_SUCCESS; + } + // 显示播放进度条 + int PlayersView::ShowUpCircleProgress() + { + if (playbackProgress == nullptr) + { + playbackProgress = new UICircleProgress(); + if (playbackProgress == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playbackProgress new fail"); + return OHOS_FAILURE; + } + } + playbackProgress->SetPosition(158, 158, 150, 150); + playbackProgress->SetCenterPosition(75, 75); + playbackProgress->SetRange(PLAY_PROGRESS_MAX, PLAY_PROGRESS_MIN); + playbackProgress->SetRadius(70); + playbackProgress->SetStartAngle(0); + playbackProgress->SetEndAngle(360); // 360: end angle + playbackProgress->SetValue(0); + playbackProgress->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + playbackProgress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + playbackProgress->SetBackgroundStyle(STYLE_LINE_COLOR, 0xfff61313); + playbackProgress->SetBackgroundStyle(STYLE_LINE_WIDTH, 0); + playbackProgress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xfffbfbfb); + playbackProgress->SetForegroundStyle(STYLE_BORDER_COLOR, 0xffffffff); + playbackProgress->SetForegroundStyle(STYLE_LINE_COLOR, 0xffffffff); + playbackProgress->SetForegroundStyle(STYLE_LINE_WIDTH, 6); // 6:width + Add(playbackProgress); + return OHOS_SUCCESS; + } + // 创建跳转视图 + void PlayersView::CreateJumpView(void) + { + if (jumpView == nullptr) + { + jumpView = new JumpView(); + if (jumpView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView new fail"); + return; + } } } -} -//创建一个音乐播放器的逻辑层 -void PlayersView::CreatePlayersPresenter(void) -{ - if (playersPresenter == nullptr) { - playersPresenter = new PlayersPresenter(); - if (playersPresenter == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersPresenter new fail"); - return; + // 创建一个音乐播放器的逻辑层 + void PlayersView::CreatePlayersPresenter(void) + { + if (playersPresenter == nullptr) + { + playersPresenter = new PlayersPresenter(); + if (playersPresenter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersPresenter new fail"); + return; + } } } -} -//创建一个音乐播放器的拖拽监听 -void PlayersView::CreatePlayerOnDragListener(void) -{ - if (playerOnDragListener == nullptr) { - playerOnDragListener = new PlayerOnDragListener(); - if (playerOnDragListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerOnDragListener new fail"); - return; + // 创建一个音乐播放器的拖拽监听 + void PlayersView::CreatePlayerOnDragListener(void) + { + if (playerOnDragListener == nullptr) + { + playerOnDragListener = new PlayerOnDragListener(); + if (playerOnDragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerOnDragListener new fail"); + return; + } } } -} -//初始化背景图片 -bool PlayersView::InitBackGround(void) -{ - if (backGround == nullptr) { - backGround = new UIImageView(); - if (backGround == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGround new fail"); + // 初始化背景图片 + bool PlayersView::InitBackGround(void) + { + if (backGround == nullptr) + { + backGround = new UIImageView(); + if (backGround == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGround new fail"); + return false; + } + } + backGround->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + if (LoadPlayerImage(backGround, PLAYER_BACKGROUND) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGround LoadPlayerImage fail"); return false; } - } - backGround->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - if (LoadPlayerImage(backGround, PLAYER_BACKGROUND) == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backGround LoadPlayerImage fail"); - return false; - } - /* -------------------------------------------------------------------------- */ - if(elipse == nullptr){ - elipse = new UIImageView(); - if(elipse ==nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "elipse new fail"); + /* -------------------------------------------------------------------------- */ + if (elipse == nullptr) + { + elipse = new UIImageView(); + if (elipse == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "elipse new fail"); + return false; + } + } + elipse->SetPosition(173, 173, 120, 120); + if (LoadPlayerImage(elipse, PLAYER_ELLIPSE) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "elipse LoadPlayerImage fail"); return false; } + Add(backGround); + Add(elipse); + return true; } - elipse->SetPosition(173,173,120,120); - if (LoadPlayerImage(elipse, PLAYER_ELLIPSE) == false) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "elipse LoadPlayerImage fail"); - return false; - } - Add(backGround); - Add(elipse); - return true; -} -//创建音乐名,作者名 -void PlayersView::CreatePlayerMusicName() -{ - if (titleLabel == nullptr) { - titleLabel = new UILabel(); - if (titleLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail"); - return; + // 创建音乐名,作者名 + void PlayersView::CreatePlayerMusicName() + { + if (titleLabel == nullptr) + { + titleLabel = new UILabel(); + if (titleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail"); + return; + } } - } - titleLabel->SetPosition(127, 35, 200, 53); // 127:x 35:y 200:width 53:height - titleLabel->SetText("Music Name"); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); - Add(titleLabel); + titleLabel->SetPosition(127, 35, 200, 53); // 127:x 35:y 200:width 53:height + titleLabel->SetText("Music Name"); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); + Add(titleLabel); - if (subTitleLabel == nullptr) { - subTitleLabel = new UILabel(); - if (subTitleLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "subTitleLabel new fail"); - return; + if (subTitleLabel == nullptr) + { + subTitleLabel = new UILabel(); + if (subTitleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "subTitleLabel new fail"); + return; + } } + subTitleLabel->SetPosition(77, 92, 300, 38); // 77:x 92:y 300:width 38:height + subTitleLabel->SetText("Musical Authors"); + subTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30:font data + subTitleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + Add(subTitleLabel); + return; + } + // 拖拽监听:从下到上拖拽后显示音乐列表 + bool PlayersView::OnDragEvent(const DragEvent &event) + { + /* 300: y limit of drag start point */ + // if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > 300)) { + // PlayersPresenter::GetInstance()->ShowPlayerListGroup(); + // return true; + // } + return false; } - subTitleLabel->SetPosition(77, 92, 300, 38); // 77:x 92:y 300:width 38:height - subTitleLabel->SetText("Musical Authors"); - subTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30:font data - subTitleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - Add(subTitleLabel); - return; -} -//拖拽监听:从下到上拖拽后显示音乐列表 -bool PlayersView::OnDragEvent(const DragEvent& event) -{ - /* 300: y limit of drag start point */ - // if ((event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) && (event.GetStartPoint().y > 300)) { - // PlayersPresenter::GetInstance()->ShowPlayerListGroup(); - // return true; - // } - return false; -} -/// @brief 创建音乐来源标签 -/// @param -void PlayersView::CreateMusicSourceLabel(void) -{ - if (MusciSourceLabel == nullptr) { - MusciSourceLabel = new UILabel(); - if (MusciSourceLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MusciSourceLabel new fail"); - return; + /// @brief 创建音乐来源标签 + /// @param + void PlayersView::CreateMusicSourceLabel(void) + { + if (MusciSourceLabel == nullptr) + { + MusciSourceLabel = new UILabel(); + if (MusciSourceLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MusciSourceLabel new fail"); + return; + } } + MusciSourceLabel->SetPosition(163, 90, 140, 41); + MusciSourceLabel->SetText("本地音乐"); + MusciSourceLabel->SetStyle(STYLE_TEXT_FONT, 35); + MusciSourceLabel->SetStyle(STYLE_LINE_HEIGHT, 41); + MusciSourceLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + MusciSourceLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + MusciSourceLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35); + Add(MusciSourceLabel); + } + + /// @brief 设置音乐来源标签内容 + /// @param text 文本内容 + void PlayersView::MusicSourceLabelSetText(const char *text) + { + MusciSourceLabel->SetText(text); + MusciSourceLabel->Invalidate(); } - MusciSourceLabel->SetPosition(163, 90, 140, 41); - MusciSourceLabel->SetText("本地音乐"); - MusciSourceLabel->SetStyle(STYLE_TEXT_FONT, 35); - MusciSourceLabel->SetStyle(STYLE_LINE_HEIGHT, 41); - MusciSourceLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - MusciSourceLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - MusciSourceLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35); - Add(MusciSourceLabel); -} -/// @brief 设置音乐来源标签内容 -/// @param text 文本内容 -void PlayersView::MusicSourceLabelSetText(const char *text) -{ - MusciSourceLabel->SetText(text); - MusciSourceLabel->Invalidate(); -} - -/// @brief 创建手机音乐连接状态标签 -/// @param -void PlayersView::CreatePhoneMusicConnectStatusLabel(void) -{ - if (PhoneMusicConnectStatusLabel == nullptr) { - PhoneMusicConnectStatusLabel = new UILabel(); - if (PhoneMusicConnectStatusLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMusicConnectStatusLabel new fail"); - return; + /// @brief 创建手机音乐连接状态标签 + /// @param + void PlayersView::CreatePhoneMusicConnectStatusLabel(void) + { + if (PhoneMusicConnectStatusLabel == nullptr) + { + PhoneMusicConnectStatusLabel = new UILabel(); + if (PhoneMusicConnectStatusLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PhoneMusicConnectStatusLabel new fail"); + return; + } } + PhoneMusicConnectStatusLabel->SetPosition(188, 40, 90, 35); + PhoneMusicConnectStatusLabel->SetText("未连接"); + PhoneMusicConnectStatusLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); + PhoneMusicConnectStatusLabel->SetStyle(STYLE_TEXT_FONT, 30); + PhoneMusicConnectStatusLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + PhoneMusicConnectStatusLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + PhoneMusicConnectStatusLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + PhoneMusicConnectStatusLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + PhoneMusicConnectStatusLabel->SetVisible(false); + Add(PhoneMusicConnectStatusLabel); + } + + /// @brief 设置手机音乐连接状态标签内容 + /// @param text 文本内容 + void PlayersView::PhoneMusicConnectStatusLabelSetText(const char *text) + { + PhoneMusicConnectStatusLabel->SetText(text); + PhoneMusicConnectStatusLabel->Invalidate(); } - PhoneMusicConnectStatusLabel->SetPosition(188, 40, 90, 35); - PhoneMusicConnectStatusLabel->SetText("未连接"); - PhoneMusicConnectStatusLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); - PhoneMusicConnectStatusLabel->SetStyle(STYLE_TEXT_FONT, 30); - PhoneMusicConnectStatusLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - PhoneMusicConnectStatusLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - PhoneMusicConnectStatusLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - PhoneMusicConnectStatusLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - PhoneMusicConnectStatusLabel->SetVisible(false); - Add(PhoneMusicConnectStatusLabel); -} - -/// @brief 设置手机音乐连接状态标签内容 -/// @param text 文本内容 -void PlayersView::PhoneMusicConnectStatusLabelSetText(const char *text) -{ - PhoneMusicConnectStatusLabel->SetText(text); - PhoneMusicConnectStatusLabel->Invalidate(); -} - -/// @brief 设置手机连接状态标签是否可见 -/// @param status -void PlayersView::PhoneMusicConnectStatusLabelIsSetVisible(bool status) -{ - PhoneMusicConnectStatusLabel->SetVisible(status); -} - -/// @brief 设置音乐列表按钮是否可见 -/// @param status -void PlayersView::MusicListButtonIsSetVisible(bool status) -{ - music_list_button->SetVisible(status); -} -/// @brief 设置选项按钮的图片样式:点击该按钮后进入音乐来源视图,点击里面的按钮,改选项按钮会被替换相应图片 -/// @param image 图片信息 -void PlayersView::OptionsButtonSetImageStyle(ImageInfo *image) -{ - optionsButton->SetImageSrc(image, image); - optionsButton->Invalidate(); -} -//初始化音乐播放器主视图 -bool PlayersView::InitView(void) -{ - int ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " PlayersView InitView"); + /// @brief 设置手机连接状态标签是否可见 + /// @param status + void PlayersView::PhoneMusicConnectStatusLabelIsSetVisible(bool status) + { + PhoneMusicConnectStatusLabel->SetVisible(status); + } - if (InitBackGround() == false) { - return false; + /// @brief 设置音乐列表按钮是否可见 + /// @param status + void PlayersView::MusicListButtonIsSetVisible(bool status) + { + music_list_button->SetVisible(status); } - //CreatePlayerMusicName(); - CreatePhoneMusicConnectStatusLabel(); - CreateMusicSourceLabel(); - // changeView - CreateJumpView(); - // OnClick - CreatePlayersPresenter(); - // OnDrag - CreatePlayerOnDragListener(); - // 按键设置 - ret = ShowUpButtonView(); - if (ret == OHOS_FAILURE) { - return false; + /// @brief 设置选项按钮的图片样式:点击该按钮后进入音乐来源视图,点击里面的按钮,改选项按钮会被替换相应图片 + /// @param image 图片信息 + void PlayersView::OptionsButtonSetImageStyle(ImageInfo *image) + { + optionsButton->SetImageSrc(image, image); + optionsButton->Invalidate(); } - // 需要一个模拟信息,假装发生了按键点击,开始播放音乐 - // 调用 OnClick 回调函数来处理点击事件 - //playerButton.OnClick(,); - // 遍历文件名到list链表 - PlayersListGroup::GetInstance()->SetUpListCase(); - PlayersModel::GetInstance()->PlayerInit(); - ShowUpListView(); - ShowUpDelSongView(); - SetTouchable(true); - SetDraggable(true); - return true; -} + // 初始化音乐播放器主视图 + bool PlayersView::InitView(void) + { + int ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " PlayersView InitView"); -void PlayersView::PreLoad(void) -{ - if (!viewiInitStatus) { - if (InitView()) { - viewiInitStatus = true; + if (InitBackGround() == false) + { + return false; + } + + // CreatePlayerMusicName(); + CreatePhoneMusicConnectStatusLabel(); + CreateMusicSourceLabel(); + // changeView + CreateJumpView(); + // OnClick + CreatePlayersPresenter(); + // OnDrag + CreatePlayerOnDragListener(); + // 按键设置 + ret = ShowUpButtonView(); + if (ret == OHOS_FAILURE) + { + return false; + } + // 需要一个模拟信息,假装发生了按键点击,开始播放音乐 + // 调用 OnClick 回调函数来处理点击事件 + // playerButton.OnClick(,); + // 遍历文件名到list链表 + PlayersListGroup::GetInstance()->SetUpListCase(); + PlayersModel::GetInstance()->PlayerInit(); + ShowUpListView(); + ShowUpDelSongView(); + SetTouchable(true); + SetDraggable(true); + return true; + } + + void PlayersView::PreLoad(void) + { + if (!viewiInitStatus) + { + if (InitView()) + { + viewiInitStatus = true; + } } } -} -void PlayersView::UnLoad(void) -{ - // Players's usage scenes is complicated, so we do not release it's resources inner slice. -} -//加载音乐图片 -bool PlayersView::LoadPlayerImage(UIImageView *view, uint32_t resId) -{ - std::string file = PLAYER_IAMGES; - ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); - if (image == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::LoadPlayerImage %x fail", resId); - return false; + void PlayersView::UnLoad(void) + { + // Players's usage scenes is complicated, so we do not release it's resources inner slice. + } + // 加载音乐图片 + bool PlayersView::LoadPlayerImage(UIImageView *view, uint32_t resId) + { + std::string file = PLAYER_IAMGES; + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::LoadPlayerImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; } - view->SetSrc(image); - return true; -} } 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/SystemAboutTheWatchView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp index b8769e1b6..27c59e575 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp @@ -269,7 +269,12 @@ namespace OHOS .text = "", .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, }; - Config.text = ConfigModel::GetInstance()->Getimei(); + Config.text = const_cast(ConfigModel::GetInstance()->Getimei().c_str()); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Imei %s , %s \r\n",Config.text,ConfigModel::GetInstance()->Getimei().c_str()); + + + AlgorithmVersion = InitLabel(Config); if (AlgorithmVersion == nullptr) { @@ -299,7 +304,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ uint8_t btaddr[6] ={0}; uint8_t btaddr_str[64]={0}; - uint32_t len = 64; + uint32_t len = 6; errcode_t ret = uapi_get_nv_btaddr((uint8_t*)btaddr,&len); sprintf((char*)btaddr_str , "%02X:%02X:%02X:%02X:%02X:%02X",btaddr[0],btaddr[1],btaddr[2],btaddr[3],btaddr[4],btaddr[5]); @@ -344,8 +349,8 @@ namespace OHOS SystemAboutTheWatchScrollView->Add(LANAddressTitle); /* -------------------------------------------------------------------------- */ - uint8_t ble_name[20] = {0}; - uint32_t ble_name_len ; + uint8_t ble_name[20] = {0}; + uint32_t ble_name_len = sizeof(ble_name) ; ret = uapi_get_nv_btname(ble_name, &ble_name_len); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"get btname %s ,ret 0x%X\n",ble_name,ret); @@ -434,7 +439,9 @@ namespace OHOS .text = "HarmonyOS Sans", .lineBreakMode = UILabel::LINE_BREAK_WRAP, }; - Config.text=ConfigModel::GetInstance()->GetmoderVer(); + Config.text=const_cast(ConfigModel::GetInstance()->GetmoderVer().c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "modemver %s , %s \r\n",Config.text,ConfigModel::GetInstance()->GetmoderVer().c_str()); + CAT1mode = InitLabel(Config); if (CAT1mode == nullptr) { @@ -469,10 +476,12 @@ namespace OHOS .height = 30, .fontSize = 26, .lineHeigh = 30, - .text = "HarmonyOS Sans", + .text = "PyVer_3", .lineBreakMode = UILabel::LINE_BREAK_WRAP, }; - Config.text=ConfigModel::GetInstance()->GetpyVer(); + Config.text=const_cast(ConfigModel::GetInstance()->GetpyVer().c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "pyver %s , %s \r\n",Config.text,ConfigModel::GetInstance()->GetpyVer().c_str()); + pymode = InitLabel(Config); if (CAT1mode == nullptr) { 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..89b506d71 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); // } } @@ -396,8 +394,8 @@ namespace OHOS { if(is_new_cat1_version) { - char *imei_str= ConfigModel::GetInstance()->Getimei(); - char * version_buf=ConfigModel::GetInstance()->GetmoderVer(); + char *imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); + char * version_buf=const_cast(ConfigModel::GetInstance()->GetmoderVer().c_str()); sprintf((char *)uri,"http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver=%s&imei=%s",version_buf,imei_str); cat1_ota_update((char *)"0"); container_updating->SetVisible(true); @@ -455,8 +453,8 @@ namespace OHOS } - char *imei_str= ConfigModel::GetInstance()->Getimei(); - char * version_buf=ConfigModel::GetInstance()->GetmoderVer(); + char *imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); + char * version_buf=const_cast(ConfigModel::GetInstance()->GetmoderVer().c_str()); sprintf((char *)uri, "http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver=%s&imei=%s", version_buf,imei_str); @@ -812,7 +810,7 @@ namespace OHOS } display_api->set_screen_set_keepon_timeout(-1); memset(uri,0,256); - char *imei_str= ConfigModel::GetInstance()->Getimei(); + char *imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); sprintf((char *)uri,"http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver=%s&imei=%s",version_buf,imei_str); custom_start_ota_download_ui_1(uri,(uint8_t*)Path,true); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index 43be18705..87ef50174 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -92,7 +92,7 @@ extern "C" #if 0 switch (request->msgId) { - case TOPIC_EVENT_TREADMILL_UPDATE: + case TOPIC_EVENT_ACTIVITY_UPDATE: cyweeInfo = new cywee_activity_result_t(); // 在case块内分配内存 rets = memcpy_s(cyweeInfo, sizeof(cywee_activity_result_t), (cywee_activity_result_t *)request->data, request->len); if (rets != EOK) @@ -104,7 +104,7 @@ extern "C" } TraingModel::GetInstance()->AnalysisData(cyweeInfo); break; - case TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE: + case TOPIC_EVENT_INACTIVITY_UPDATE: cyweeInfo = new cywee_activity_result_t(); // 在case块内分配内存 rets = memcpy_s(cyweeInfo, sizeof(cywee_activity_result_t), (cywee_activity_result_t *)request->data, request->len); if (rets != EOK) @@ -116,42 +116,6 @@ extern "C" } TraingModel::GetInstance()->AnalysisData(cyweeInfo); break; - case TOPIC_EVENT_INDOOR_RUNNING_UPDATE: - cyweeInfo = new cywee_activity_result_t(); // 在case块内分配内存 - rets = memcpy_s(cyweeInfo, sizeof(cywee_activity_result_t), (cywee_activity_result_t *)request->data, request->len); - if (rets != EOK) - { - delete cyweeInfo; // 处理内存分配失败的情况 - cyweeInfo = NULL; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s cywee_activity_result_t fail! ret = %d", rets); - return; - } - TraingModel::GetInstance()->AnalysisData(cyweeInfo); - break; - case TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE: - cyweeInfo = new cywee_activity_result_t(); // 在case块内分配内存 - rets = memcpy_s(cyweeInfo, sizeof(cywee_activity_result_t), (cywee_activity_result_t *)request->data, request->len); - if (rets != EOK) - { - delete cyweeInfo; // 处理内存分配失败的情况 - cyweeInfo = NULL; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s cywee_activity_result_t fail! ret = %d", rets); - return; - } - TraingModel::GetInstance()->AnalysisData(cyweeInfo); - break; - case TOPIC_EVENT_FREE_TRAINING_UPDATE: - cyweeInfo = new cywee_activity_result_t(); // 在case块内分配内存 - rets = memcpy_s(cyweeInfo, sizeof(cywee_activity_result_t), (cywee_activity_result_t *)request->data, request->len); - if (rets != EOK) - { - delete cyweeInfo; // 处理内存分配失败的情况 - cyweeInfo = NULL; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s cywee_result_t fail! ret = %d", rets); - return; - } - TraingModel::GetInstance()->AnalysisData(cyweeInfo); - break; default: // 处理未知msgId的情况 break; @@ -196,14 +160,8 @@ namespace OHOS TraingModel ::~TraingModel() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::~TraingModel()"); -#if 0 // 取消订阅 - TraingUnsubscribeTopic(TOPIC_EVENT_TREADMILL_UPDATE); - TraingUnsubscribeTopic(TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE); - TraingUnsubscribeTopic(TOPIC_EVENT_INDOOR_RUNNING_UPDATE); - TraingUnsubscribeTopic(TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE); - TraingUnsubscribeTopic(TOPIC_EVENT_FREE_TRAINING_UPDATE); -#endif + TraingUnsubscribeTopic(TOPIC_EVENT_ACTIVITY_UPDATE); } TraingModel *TraingModel::GetInstance(void) { @@ -213,14 +171,8 @@ namespace OHOS void TraingModel ::Init() { -#if 0 // 进行消息订阅 - TraingSubscribeTopic(TOPIC_EVENT_TREADMILL_UPDATE); - TraingSubscribeTopic(TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE); - TraingSubscribeTopic(TOPIC_EVENT_INDOOR_RUNNING_UPDATE); - TraingSubscribeTopic(TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE); - TraingSubscribeTopic(TOPIC_EVENT_FREE_TRAINING_UPDATE); -#endif + TraingSubscribeTopic(TOPIC_EVENT_ACTIVITY_UPDATE); } /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h index ccc9ac931..a45a17ab8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h @@ -1,41 +1,38 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-12 16:22:24 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h + */ #ifndef Get_WEATHER_DATA_ERROR_VIEW_H #define Get_WEATHER_DATA_ERROR_VIEW_H #include "BaseView.h" #include "View.h" -#include "components/ui_view_group.h" #include "components/ui_scroll_view.h" #include "components/ui_label.h" #include "components/ui_label_ext.h" #include "components/ui_image_view.h" namespace OHOS { - class GetWeatherDataErrorPresenter; - class GetWeatherDataErrorView : public View + + static constexpr const char *GETWEATHERDATAERRORVIEW = "GetWeatherDataErrorView"; + class GetWeatherDataErrorView { public: GetWeatherDataErrorView(); virtual ~GetWeatherDataErrorView(); static GetWeatherDataErrorView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; + UIScrollView *GetWeatherDataErrorViewInit(void); private: - void InitView(void); - void DeInitView(void); - void PreLoad(void); + void ClearAll(); - private: - UIView::OnDragListener *draglistener{nullptr}; - UIViewGroup *container_ = nullptr; - UIScrollView *scrollView1_ = nullptr; - UILabel *label1_ = nullptr; - UIImageView *image1_ = nullptr; - bool viewInitStatus{false}; + UIScrollView *scrollView = nullptr; + UILabel *label = nullptr; + UIImageView *image = nullptr; }; -} // namespace OHOS -#endif // GetWeatherDataError_PRESENTER_H \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h index 5fab389cb..ecff30147 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-12 19:45:12 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h + */ #ifndef MAIN_WEATHER_VIEW_H #define MAIN_WEATHER_VIEW_H @@ -7,6 +14,7 @@ #include "weather/include/WeatherView.h" #include "weather/include/WeatherReportView.h" +#include "weather/include/GetWeatherDataErrorView.h" namespace OHOS { typedef enum @@ -40,7 +48,7 @@ namespace OHOS private: WeatherView *weatherView{nullptr}; WeatherReportView *weatherReportView{nullptr}; - + GetWeatherDataErrorView *g_GetWeatherDataErrorView{nullptr}; private: int16_t maxPage = MAX_WEATHERVIEW; UISwipeView *weatherSwipeViewList{nullptr}; // 天气滑动视图列表 diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h index 2ed852656..dcecff4b9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h @@ -2,71 +2,92 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:20 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-11 15:51:19 + * @LastEditTime: 2024-04-12 18:57:44 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h */ #ifndef WEATHER_MODEL_H #define WEATHER_MODEL_H #include "wearable_log.h" -#if __cplusplus -extern "C" +#include "iostream" +namespace OHOS { +#if __cplusplus + extern "C" + { #endif /* __cplusplus */ #include "string.h" - static int WEATHER_DATA_VALID = 0; //天气数据是否有效 - /*天气数据*/ - struct Weather_data - { - int humidity; // 湿度 - char windScale[16]; // 风速 - char textNight[16]; // 夜间天气文本 - int uvIndex; // 紫外线指数 - int temp; // 温度 - int iconNight; // 夜间天气图标 - }; - //"address": { "lat" : 225737664, "atm" : "1010", "city" : "深圳", "subLocality" : "宝安", "lon" : 1138535138 } - /*天气数据的地址信息*/ - struct Weather_data_address - { - int lat; // 纬度 - char atm[16]; // 大气压 - char city[32]; // 城市 - char subLocality[32]; // 子地区 - int lon; // 经纬度 - }; + static uint8_t WEATHER_DATA_VALID = 0; // 天气数据是否有效 + /*天气数据*/ + struct Weather_data + { + int humidity; // 湿度 + char windScale[16]; // 风速 + char textNight[16]; // 夜间天气文本 + int uvIndex; // 紫外线指数 + int temp; // 温度 + int iconNight; // 夜间天气图标 + }; + //"address": { "lat" : 225737664, "atm" : "1010", "city" : "深圳", "subLocality" : "宝安", "lon" : 1138535138 } + /*天气数据的地址信息*/ + struct Weather_data_address + { + int lat; // 纬度 + char atm[16]; // 大气压 + char city[32]; // 城市 + char subLocality[32]; // 子地区 + int lon; // 经纬度 + }; - //{"tempMin":22,"iconDay":6,"fxDate":1712505600,"textDay":"阵雨","tempMax":29}, - /*一天内天气数据*/ - struct ONE_DAY_DATA - { - int tempMin; // 最低温度 - int iconDay; // 白天天气图标 - int fxDate; // 日期 - char textDay[16]; // 白天天气文本 - int tempMax; // 最高温度 - }; - - extern Weather_data Weather_data_t_now; - extern Weather_data_address Weather_data_t_address; - extern ONE_DAY_DATA Weather_data_seven_data[]; + //{"tempMin":22,"iconDay":6,"fxDate":1712505600,"textDay":"阵雨","tempMax":29}, + /*一天内天气数据*/ + struct ONE_DAY_DATA + { + int tempMin; // 最低温度 + int iconDay; // 白天天气图标 + int fxDate; // 日期 + char textDay[16]; // 白天天气文本 + int tempMax; // 最高温度 + }; - void UI_set_weather_now_data(int humidity, char *windScale, char *textNight, int uvIndex, int temp, int iconNight); + void UI_set_weather_now_data(int humidity, char *windScale, char *textNight, int uvIndex, int temp, int iconNight); - void UI_set_weather_address_data(int lat, char *atm, char *city, char *subLocality, int lon); + void UI_set_weather_address_data(int lat, char *atm, char *city, char *subLocality, int lon); - void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t); + void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t); #if __cplusplus -} + } #endif /* __cplusplus */ -namespace OHOS -{ + + static constexpr const char *WeatherBackground = "WEATHER_BACKGROUND.bin"; // 天气背景 + static constexpr const char *weather130x130[] = + { + "/user/res/weather/weather130x130/WEATHER_CLEAR-CLOUDY.bin", + "/user/res/weather/weather130x130/WEATHER_CLEAR-SUNNY.bin", //晴 + "/user/res/weather/weather130x130/WEATHER_DUSTSTORM.bin", + "/user/res/weather/weather130x130/WEATHER_FOGGY.bin", + "/user/res/weather/weather130x130/WEATHER_HAZE.bin", + "/user/res/weather/weather130x130/WEATHER_OVERCAST.bin", + "/user/res/weather/weather130x130/WEATHER_RAIN.bin", + "/user/res/weather/weather130x130/WEATHER_SNOW.bin", + "/user/res/weather/weather130x130/WEATHER_SUNNY.bin", + "/user/res/weather/weather130x130/WEATHER_SUNNY-CLOUNDY.bin", + "/user/res/weather/weather130x130/WEATHER_THUNDERSHOWER.bin", + "/user/res/weather/weather130x130/WEATHER_UNKNOWN.bin", + }; + /* -------------------------------------------------------------------------- */ class WeatherModel { public: static WeatherModel &GetInstance(void); + std::string GetWeatherImage(); + std::string GetWeatherTemperature(); + std::string GetWeatherDescription(); + std::string GetWeatherArea(); + std::string GetWeatherMaxAndMinTemperature(); + private: WeatherModel(); WeatherModel(const WeatherModel &) = delete; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h index 07ef3b5f3..a06a92a72 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-12 16:41:27 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h + */ #ifndef WEATHER_REPORT_VIEW_H #define WEATHER_REPORT_VIEW_H @@ -7,7 +14,7 @@ #include "components/ui_view_group.h" #include "components/ui_scroll_view.h" #include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" +#include "language/font/ui_resource_string.h" #include "components/ui_image_animator.h" #include "config/include/ConfigModel.h" namespace OHOS @@ -39,6 +46,8 @@ namespace OHOS } private: + const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); + void FreeImagePathsArray(const char **imagePaths, const int numImages); UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 bool WeatherReportViewLabelInit(void); bool WeatherReportViewImageAnimatorViewInit(void); @@ -52,10 +61,7 @@ namespace OHOS UIImageAnimatorView *UVImageAnimatorView{nullptr}; // 紫外线动画 UIImageAnimatorView *WindSpeedImageAnimatorView{nullptr}; // 风速动画 UIImageAnimatorView *HumidityImageAnimatorView{nullptr}; // 湿度动画 - ImageAnimator *p_ImageAnimator{nullptr}; - ImageAnimatorInfo *UVimageAnimatorInfo{nullptr}; - ImageAnimatorInfo *WindSpeedimageAnimatorInfo{nullptr}; - ImageAnimatorInfo *HumidityimageAnimatorInfo{nullptr}; + const char **UVPathsArray{nullptr}; const char **WindSpeedPathsArray{nullptr}; const char **HumidityPathsArray{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h index 6f6931cf7..331cbcfba 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-12 15:06:35 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h + */ #ifndef WEATHER_VIEW_H #define WEATHER_VIEW_H @@ -13,26 +20,6 @@ #include "wearable_log.h" #include "AppGroupView.h" #include -#include "config/include/ConfigModel.h" - -namespace OHOS -{ - static constexpr char *WeatherBackground = "WEATHER_BACKGROUND.bin"; // 天气背景 - static constexpr const char *weather130x130[] = - { - "/user/res/weather/weather130x130/WEATHER_CLEAR-CLOUDY.bin", - "/user/res/weather/weather130x130/WEATHER_CLEAR-SUNNY.bin", - "/user/res/weather/weather130x130/WEATHER_DUSTSTORM.bin", - "/user/res/weather/weather130x130/WEATHER_FOGGY.bin", - "/user/res/weather/weather130x130/WEATHER_HAZE.bin", - "/user/res/weather/weather130x130/WEATHER_OVERCAST.bin", - "/user/res/weather/weather130x130/WEATHER_RAIN.bin", - "/user/res/weather/weather130x130/WEATHER_SNOW.bin", - "/user/res/weather/weather130x130/WEATHER_SUNNY.bin", - "/user/res/weather/weather130x130/WEATHER_SUNNY-CLOUNDY.bin", - "/user/res/weather/weather130x130/WEATHER_THUNDERSHOWER.bin", - "/user/res/weather/weather130x130/WEATHER_UNKNOWN.bin"}; -} namespace OHOS { @@ -53,13 +40,9 @@ namespace OHOS UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); private: - std::string GetTime(); - std::string GetWeatherImage(); - std::string GetWeatherTemperature(); - std::string GetWeatherDescription(); - std::string GetWeatherArea(); - std::string GetWeatherMaxAndMinTemperature(); - + const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); + void FreeImagePathsArray(const char **imagePaths, const int numImages); + void DumpWeatherInfo(); std::string WeatherImag; // 天气图片 std::string Temperature; // 温度 std::string WeatherDescription; // 天气描述 @@ -73,8 +56,6 @@ namespace OHOS UILabelExt *showWeatherAreaLabel{nullptr}; // 显示天气地区 UILabelExt *showMaxandMinTemperatureLabel{nullptr}; // 显示最高与最低气温 UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 - ImageAnimator *p_ImageAnimator{nullptr}; - ImageAnimatorInfo *PullUpimageAnimatorInfo{nullptr}; const char **PullUpPathsArray{nullptr}; bool viewInitStatus{false}; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp index 55a43f67c..c71b9135a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp @@ -1,6 +1,13 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-12 20:00:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp + */ #include "weather/include/GetWeatherDataErrorView.h" -#include "weather/include/GetWeatherDataErrorPresenter.h" -#include "UiConfig.h" +#include "wearable_log.h" +#include "weather/include/MainWeatherPresenter.h" /* 天气获取数据失败后会调用该视图*/ namespace OHOS @@ -10,153 +17,94 @@ namespace OHOS GetWeatherDataErrorView::GetWeatherDataErrorView() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetWeatherDataErrorView::GetWeatherDataErrorView"); g_pGetWeatherDataErrorView = this; } GetWeatherDataErrorView::~GetWeatherDataErrorView() { - if (viewInitStatus == true) - { - DeInitView(); - } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetWeatherDataErrorView::~GetWeatherDataErrorView"); + ClearAll(); g_pGetWeatherDataErrorView = nullptr; } GetWeatherDataErrorView *GetWeatherDataErrorView::GetInstance() { - return g_pGetWeatherDataErrorView; } - void GetWeatherDataErrorView::InitView() + UIScrollView *GetWeatherDataErrorView::GetWeatherDataErrorViewInit() { - // Add ScrollView to App - if (scrollView1_ == nullptr) - { - scrollView1_ = new UIScrollView(); - } - scrollView1_->SetPosition(0, 0); - scrollView1_->Resize(466, 466); - scrollView1_->SetViewId("scrollView1"); - scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - container_->Add(scrollView1_); - scrollView1_->SetVisible(true); - - // Add Label to App - if (label1_ == nullptr) + if (scrollView == nullptr) { - label1_ = new UILabel(); + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is new fail!!"); + return nullptr; + } + scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + scrollView->SetViewId(GETWEATHERDATAERRORVIEW); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + UIView::OnDragListener *listener = static_cast(MainWeatherPresenter::GetInstance()); + if (listener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "listener is nullptr!!"); + return nullptr; + } + scrollView->SetOnDragListener(listener); + /* -------------------------------------------------------------------------- */ + image = new UIImageView(); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image is new fail!!"); + return nullptr; + } + image->SetPosition(168, 127, 130, 130); + const char * ImgSr = "/user/res/weather/weather130x130/WEATHER_UNKNOWN.bin"; //天气数据获取失败 + image->SetSrc(ImgSr); + scrollView->Add(image); + /* -------------------------------------------------------------------------- */ + label = new UILabel(); + if (label == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is new fail!!"); + return nullptr; + } + label->SetPosition(33, 268, 400, 70); + label->SetStyle(STYLE_TEXT_FONT, 26); + label->SetStyle(STYLE_LINE_HEIGHT, 35); + label->SetText("未获取到天气信息\n请前往APP更新"); + label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(40); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + scrollView->Add(label); } - label1_->SetPosition(113, 268); - label1_->Resize(240, 70); - label1_->SetViewId("label1"); - label1_->SetStyle(STYLE_TEXT_FONT, 30); - label1_->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - label1_->SetText("未获取到天气信息\n请前往APP更新"); - label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label1_->SetRollSpeed(0); - label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to scrollView1 - scrollView1_->Add(label1_); - label1_->SetVisible(true); - - // Add ImageView to App - if (image1_ == nullptr) - { - image1_ = new UIImageView(); - } - image1_->SetPosition(168, 127); - image1_->Resize(130, 130); - image1_->SetViewId("image1"); - image1_->SetSrc("/user/res/weather/WEATHER_UNKNOWN.bin"); - - // Add to scrollView1 - scrollView1_->Add(image1_); - image1_->SetVisible(true); + return scrollView; } - void GetWeatherDataErrorView::DeInitView() - { - container_->RemoveAll(); - scrollView1_->RemoveAll(); - if (label1_ != nullptr) - { - delete label1_; - label1_ = nullptr; - } - if (image1_ != nullptr) - { - delete image1_; - image1_ = nullptr; - } - if (scrollView1_ != nullptr) - { - delete scrollView1_; - scrollView1_ = nullptr; - } - if (container_ != nullptr) - { - delete container_; - container_ = nullptr; - } - } - - void GetWeatherDataErrorView::PreLoad(void) + void GetWeatherDataErrorView::ClearAll() { - if (!viewInitStatus) + scrollView->RemoveAll(); + + if (label != nullptr) { - InitView(); - viewInitStatus = true; + delete label; + label = nullptr; } - } - void GetWeatherDataErrorView::OnStart() - { - container_ = new UIViewGroup(); - if (container_ == nullptr) + + if (image != nullptr) { - return; + delete image; + image = nullptr; } - // container_容器属性 扩展 - container_->SetPosition(0, 0); - container_->SetWidth(Screen::GetInstance().GetWidth()); - container_->SetHeight(Screen::GetInstance().GetHeight()); - draglistener = static_cast(GetWeatherDataErrorPresenter::GetInstance()); - if (draglistener == nullptr) + if (scrollView != nullptr) { - return; + delete scrollView; + scrollView = nullptr; } - container_->SetOnDragListener(draglistener); - container_->SetTouchable(true); - container_->SetDraggable(true); - PreLoad(); - RootView::GetInstance()->Add(container_); } - void GetWeatherDataErrorView::OnSetUpView() - { - - View::OnSetUpView(); - Draw(); - } - - void GetWeatherDataErrorView::OnTearDownView() - { - - View::OnTearDownView(); - return; - } - - void GetWeatherDataErrorView::OnStop() - { - - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; - } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp index 69311be7d..177ba4804 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp @@ -65,13 +65,16 @@ namespace OHOS bool MainWeatherPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - UNUSED(view); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); return true; } + if(strcmp(view.GetViewId(),GETWEATHERDATAERRORVIEW) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp index 8bb07596c..428ec38e9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp @@ -1,5 +1,6 @@ #include "weather/include/MainWeatherView.h" #include "weather/include/MainWeatherPresenter.h" +#include "weather/include/WeatherModel.h" namespace OHOS { static MainWeatherView *g_pMainWeatherView{nullptr}; @@ -23,20 +24,29 @@ namespace OHOS void MainWeatherView::ClearAll(void) { - for (int32_t i = 0; i < maxPage; i++) + if (weatherSwipeViewList != nullptr) { - recordCard[i] = nullptr; - } - weatherSwipeViewList->RemoveAll(); + for (int32_t i = 0; i < maxPage; i++) + { + recordCard[i] = nullptr; + } + weatherSwipeViewList->RemoveAll(); - delete weatherView; - weatherView = nullptr; + delete weatherView; + weatherView = nullptr; - delete weatherReportView; - weatherReportView = nullptr; + delete weatherReportView; + weatherReportView = nullptr; - delete weatherSwipeViewList; - weatherSwipeViewList = nullptr; + delete weatherSwipeViewList; + weatherSwipeViewList = nullptr; + } + + if (g_GetWeatherDataErrorView != nullptr) + { + delete g_GetWeatherDataErrorView; + g_GetWeatherDataErrorView = nullptr; + } } /* @@ -69,42 +79,57 @@ namespace OHOS recordCard[i]->InitView(this); weatherSwipeViewList->Add(recordCard[i]); } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView InitPage over!!"); - return weatherSwipeViewList; - } - - void MainWeatherView::OnStart() - { - View::OnStart(); - MainWeatherViewInit(); - + /* -------------------------------------------------------------------------- */ if (weatherSwipeViewList != nullptr) { UIView::OnClickListener *weatherOnClickListener = (UIView::OnClickListener *)OHOS::MainWeatherPresenter::GetInstance(); if (weatherOnClickListener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnClickListener new fail"); - return; + return nullptr; } UIView::OnDragListener *weatherOnDragListener = (UIView::OnDragListener *)OHOS::MainWeatherPresenter::GetInstance(); if (weatherOnDragListener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnDragListener new fail"); - return; + return nullptr; } UISwipeView::OnSwipeListener *weatherOnSwipeListener = (UISwipeView::OnSwipeListener *)OHOS::MainWeatherPresenter::GetInstance(); if (weatherOnSwipeListener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); - return; + return nullptr; } weatherSwipeViewList->SetOnClickListener(weatherOnClickListener); weatherSwipeViewList->SetOnDragListener(weatherOnDragListener); weatherSwipeViewList->SetOnSwipeListener(weatherOnSwipeListener); } + /* -------------------------------------------------------------------------- */ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView InitPage over!!"); + return weatherSwipeViewList; + } + + void MainWeatherView::OnStart() + { + View::OnStart(); + if (WEATHER_DATA_VALID) + { + MainWeatherViewInit(); + RootView::GetInstance()->Add(weatherSwipeViewList); + } + else + { + g_GetWeatherDataErrorView = new GetWeatherDataErrorView(); + if (g_GetWeatherDataErrorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_GetWeatherDataErrorView new fail!!"); + return; + } + RootView::GetInstance()->Add(g_GetWeatherDataErrorView->GetWeatherDataErrorViewInit()); + } RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainWeatherPresenter::GetInstance(); RootView::GetInstance()->SetOnKeyActListener(keyactListener); } @@ -112,7 +137,7 @@ namespace OHOS void MainWeatherView::OnSetUpView() { View::OnSetUpView(); - RootView::GetInstance()->Add(weatherSwipeViewList); + Draw(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp index f4039746f..035e28e42 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -2,90 +2,103 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:09 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-11 15:51:28 + * @LastEditTime: 2024-04-12 16:34:46 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp */ #include "weather/include/WeatherModel.h" -#if __cplusplus -extern "C" +namespace OHOS { -#endif /* __cplusplus */ - Weather_data Weather_data_t_now; - Weather_data_address Weather_data_t_address; - ONE_DAY_DATA Weather_data_seven_data[7]; - - /* - * @brief 设置当前天气数据 - * @param {int} humidity 湿度 - * @param {char} *windScale 风力 - * @param {char} *textNight 夜间天气文本 - * @param {int} uvIndex 紫外线指数 - * @param {int} temp 温度 - * @param {int} iconNight 夜间天气图标 - */ - void UI_set_weather_now_data(int humidity, char *windScale, char *textNight, int uvIndex, int temp, int iconNight) +#if __cplusplus + extern "C" { - Weather_data_t_now.humidity = humidity; - memset((void *)Weather_data_t_now.windScale, 0, 16); - strcpy(Weather_data_t_now.windScale, windScale); - memset((void *)Weather_data_t_now.textNight, 0, 16); - strcpy(Weather_data_t_now.textNight, textNight); - Weather_data_t_now.uvIndex = uvIndex; - Weather_data_t_now.temp = temp; - Weather_data_t_now.iconNight = iconNight; +#endif /* __cplusplus */ + static Weather_data Weather_data_t_now; + static Weather_data_address Weather_data_t_address; + static ONE_DAY_DATA Weather_data_seven_data[7]; - WEATHER_DATA_VALID = 1; - } + /* + * @brief 设置当前天气数据 + * @param {int} humidity 湿度 + * @param {char} *windScale 风力 + * @param {char} *textNight 夜间天气文本 + * @param {int} uvIndex 紫外线指数 + * @param {int} temp 温度 + * @param {int} iconNight 夜间天气图标 + */ + void UI_set_weather_now_data(int humidity, char *windScale, char *textNight, int uvIndex, int temp, int iconNight) + { + Weather_data_t_now.humidity = humidity; + memset((void *)Weather_data_t_now.windScale, 0, 16); + strcpy(Weather_data_t_now.windScale, windScale); + memset((void *)Weather_data_t_now.textNight, 0, 16); + strcpy(Weather_data_t_now.textNight, textNight); + Weather_data_t_now.uvIndex = uvIndex; + Weather_data_t_now.temp = temp; + Weather_data_t_now.iconNight = iconNight; - /* - * @brief 设置天气地址信息 - * @param {int} lat 纬度 - * @param {char} *atm 大气压 - * @param {char} *city 城市 - * @param {char} *subLocality 子地区 - * @param {int} lon 经度 - */ - void UI_set_weather_address_data(int lat, char *atm, char *city, char *subLocality, int lon) - { - Weather_data_t_address.lat = lat; - Weather_data_t_address.lon = lon; - memset((void *)Weather_data_t_address.atm, 0, 16); - strcpy(Weather_data_t_address.atm, atm); - memset((void *)Weather_data_t_address.city, 0, 32); - strcpy(Weather_data_t_address.city, city); - memset((void *)Weather_data_t_address.subLocality, 0, 32); - strcpy(Weather_data_t_address.subLocality, subLocality); + WEATHER_DATA_VALID = 1; + } - WEATHER_DATA_VALID = 1; - } + /* + * @brief 设置天气地址信息 + * @param {int} lat 纬度 + * @param {char} *atm 大气压 + * @param {char} *city 城市 + * @param {char} *subLocality 子地区 + * @param {int} lon 经度 + */ + void UI_set_weather_address_data(int lat, char *atm, char *city, char *subLocality, int lon) + { + Weather_data_t_address.lat = lat; + Weather_data_t_address.lon = lon; + memset((void *)Weather_data_t_address.atm, 0, 16); + strcpy(Weather_data_t_address.atm, atm); + memset((void *)Weather_data_t_address.city, 0, 32); + strcpy(Weather_data_t_address.city, city); + memset((void *)Weather_data_t_address.subLocality, 0, 32); + strcpy(Weather_data_t_address.subLocality, subLocality); + } - /* - * @brief 设置七天天气数据 - */ - void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t) - { - for (int i = 0; i < 7; i++) + /* + * @brief 设置七天天气数据 + */ + void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t) { - Weather_data_seven_data[i].fxDate = t[i].fxDate; - Weather_data_seven_data[i].iconDay = t[i].iconDay; - Weather_data_seven_data[i].tempMax = t[i].tempMax; - Weather_data_seven_data[i].tempMin = t[i].tempMin; - Weather_data_seven_data[i].fxDate = t[i].fxDate; - memset((void *)Weather_data_seven_data[i].textDay, 0, 16); - strcpy(Weather_data_seven_data[i].textDay, t[i].textDay); + for (int i = 0; i < 7; i++) + { + Weather_data_seven_data[i].fxDate = t[i].fxDate; + Weather_data_seven_data[i].iconDay = t[i].iconDay; + Weather_data_seven_data[i].tempMax = t[i].tempMax; + Weather_data_seven_data[i].tempMin = t[i].tempMin; + Weather_data_seven_data[i].fxDate = t[i].fxDate; + memset((void *)Weather_data_seven_data[i].textDay, 0, 16); + strcpy(Weather_data_seven_data[i].textDay, t[i].textDay); + } } - WEATHER_DATA_VALID = 1; - } + void jsonCheck_weather(uint8_t *buf); #if __cplusplus -} + } #endif /* __cplusplus */ -namespace OHOS -{ + + static constexpr const char json_data[] = + "{\"now\": {\"humidity\":89,\"windScale\":\"2\",\"textNight\":\"多云\",\"uvIndex\":3,\"temp\":24,\"iconNight\":4}," + "\"address\": {\"lat\":225737664,\"atm\":\"1010\",\"city\":\"深圳\",\"subLocality\":\"宝安\",\"lon\":1138535138}," + "\"daily\": [{\"tempMin\":22,\"iconDay\":6,\"fxDate\":1712505600,\"textDay\":\"阵雨\",\"tempMax\":29}," + "{\"tempMax\":27,\"textDay\":\"多云\",\"iconDay\":3,\"fxDate\":1712592000,\"tempMin\":22}," + "{\"tempMax\":29,\"fxDate\":1712678400,\"textDay\":\"多云\",\"iconDay\":3,\"tempMin\":22}," + "{\"tempMin\":23,\"textDay\":\"多云\",\"fxDate\":1712764800,\"tempMax\":30,\"iconDay\":3}," + "{\"fxDate\":1712851200,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":31,\"tempMin\":24}," + "{\"fxDate\":1712937600,\"iconDay\":3,\"tempMax\":31,\"tempMin\":24,\"textDay\":\"多云\"}," + "{\"fxDate\":1713024000,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":29,\"tempMin\":25}]," + "\"code\":1}"; + + /* -------------------------------------------------------------------------- */ WeatherModel::WeatherModel() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherModel::WeatherModel"); + jsonCheck_weather((uint8_t *)json_data); } WeatherModel::~WeatherModel() @@ -99,4 +112,42 @@ namespace OHOS return instance; } + // 获取天气图片 + std::string WeatherModel::GetWeatherImage() + { + int size = Weather_data_t_now.iconNight; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "iconNight:%d", size); + return weather130x130[size]; + } + + // 获取温度 + std::string WeatherModel::GetWeatherTemperature() + { + int temperature = Weather_data_t_now.temp; + return std::to_string(temperature) + "°"; + } + + // 获取天气描述 + std::string WeatherModel::GetWeatherDescription() + { + std::string WeatherDescription = Weather_data_t_now.textNight; + return WeatherDescription; + } + + // 获取天气地区 + std::string WeatherModel::GetWeatherArea() + { + std::string city = Weather_data_t_address.city; + std::string subLocality = Weather_data_t_address.city; + return (city + subLocality); + } + + // 获取最高气温和最低气温 + std::string WeatherModel::GetWeatherMaxAndMinTemperature() + { + int maxtemperature = Weather_data_seven_data[0].tempMax; + int mintemperature = Weather_data_seven_data[0].tempMin; + std::string MaxandMinTemperature = "最高" + std::to_string(maxtemperature) + "°" + " " + "最低" + std::to_string(mintemperature) + "°"; + return MaxandMinTemperature; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp index b0ade2c4a..702037ee5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp @@ -9,16 +9,19 @@ namespace OHOS static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_H = 60; static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 24; // 图片帧数 static constexpr int16_t UV_IMAGE_ANIMATOR_TIME = 100; // 图片更新间隔 + static ImageAnimatorInfo UVimageAnimatorInfo[UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; static constexpr int16_t WINDSPEED_IMAGE_ANIMATOR_VIEW_X = 203; static constexpr int16_t WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 24; // 图片帧数 + static ImageAnimatorInfo WindSpeedimageAnimatorInfo[WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; static constexpr int16_t HUMIDITY_IMAGE_ANIMATOR_VIEW_X = 353; static constexpr int16_t HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 20; // 图片帧数 + static ImageAnimatorInfo HumidityimageAnimatorInfo[HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; - static constexpr char *UVPaths = "/user/res/weather/weather60x60gif/UV/"; - static constexpr char *WindSpeedPaths = "/user/res/weather/weather60x60gif/WindSpeed/"; - static constexpr char *HumidityPaths = "/user/res/weather/weather60x60gif/Humidity/"; + static constexpr const char *UVPaths = "/user/res/weather/weather60x60gif/UV/"; + static constexpr const char *WindSpeedPaths = "/user/res/weather/weather60x60gif/WindSpeed/"; + static constexpr const char *HumidityPaths = "/user/res/weather/weather60x60gif/Humidity/"; static WeatherReportView *g_pWeatherReportView{nullptr}; @@ -80,20 +83,11 @@ namespace OHOS delete HumidityImageAnimatorView; HumidityImageAnimatorView = nullptr; - if (p_ImageAnimator != nullptr) - { - p_ImageAnimator->FreeImagePathsArray(UVPathsArray, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->DeleteImageAnimatorInfo(UVimageAnimatorInfo); - - p_ImageAnimator->FreeImagePathsArray(WindSpeedPathsArray, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->DeleteImageAnimatorInfo(WindSpeedimageAnimatorInfo); + FreeImagePathsArray(UVPathsArray, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->FreeImagePathsArray(HumidityPathsArray, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->DeleteImageAnimatorInfo(HumidityimageAnimatorInfo); + FreeImagePathsArray(WindSpeedPathsArray, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - delete p_ImageAnimator; - p_ImageAnimator = nullptr; - } + FreeImagePathsArray(HumidityPathsArray, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); } } @@ -211,7 +205,6 @@ namespace OHOS /* ----------------------------------- Add ---------------------------------- */ Add(title); - Add(UV_Number); Add(WindSpeed_Number); Add(Humidity_Number); @@ -226,37 +219,84 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WeatherReportViewImageAnimatorViewInit"); - p_ImageAnimator = new ImageAnimator(); - if (p_ImageAnimator == nullptr) + /* ----------------------------- UVImageAnimatorView---------------------------- */ + UVPathsArray = CreateImagePathsArray(UVPaths, "bin", UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (UVImageAnimatorView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_ImageAnimator new fail!!"); - return false; + UVImageAnimatorView = new UIImageAnimatorView(); + if (UVImageAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UVImageAnimatorView new fail"); + return false; + } + for (uint8_t i = 0; i < UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + UVimageAnimatorInfo[i].imagePath = (UVPathsArray[i]); + UVimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + UVimageAnimatorInfo[i].pos.x = UV_IMAGE_ANIMATOR_VIEW_X; + UVimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y; + UVimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W; + UVimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H; + } + UVImageAnimatorView->SetPosition(UV_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H); + UVImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + UVImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + UVImageAnimatorView->SetImageAnimatorSrc(UVimageAnimatorInfo, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME); + UVImageAnimatorView->SetRepeat(true); + UVImageAnimatorView->Start(); + } + /* ----------------------- WindSpeedImageAnimatorView ----------------------- */ + WindSpeedPathsArray = CreateImagePathsArray(WindSpeedPaths, "bin", WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (WindSpeedImageAnimatorView == nullptr) + { + WindSpeedImageAnimatorView = new UIImageAnimatorView(); + if (WindSpeedImageAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WindSpeedImageAnimatorView new fail"); + return false; + } + for (uint8_t i = 0; i < WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + WindSpeedimageAnimatorInfo[i].imagePath = (WindSpeedPathsArray[i]); + WindSpeedimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + WindSpeedimageAnimatorInfo[i].pos.x = WINDSPEED_IMAGE_ANIMATOR_VIEW_X; + WindSpeedimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y; + WindSpeedimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W; + WindSpeedimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H; + } + WindSpeedImageAnimatorView->SetPosition(WINDSPEED_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H); + WindSpeedImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + WindSpeedImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + WindSpeedImageAnimatorView->SetImageAnimatorSrc(WindSpeedimageAnimatorInfo, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME); + WindSpeedImageAnimatorView->SetRepeat(true); + WindSpeedImageAnimatorView->Start(); + } + /* ------------------------ HumidityImageAnimatorView ----------------------- */ + HumidityPathsArray = CreateImagePathsArray(HumidityPaths, "bin", HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (HumidityImageAnimatorView == nullptr) + { + HumidityImageAnimatorView = new UIImageAnimatorView(); + if (HumidityImageAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HumidityImageAnimatorView new fail"); + return false; + } + for (uint8_t i = 0; i < HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + HumidityimageAnimatorInfo[i].imagePath = (HumidityPathsArray[i]); + HumidityimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + HumidityimageAnimatorInfo[i].pos.x = HUMIDITY_IMAGE_ANIMATOR_VIEW_X; + HumidityimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y; + HumidityimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W; + HumidityimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H; + } + HumidityImageAnimatorView->SetPosition(HUMIDITY_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H); + HumidityImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + HumidityImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + HumidityImageAnimatorView->SetImageAnimatorSrc(HumidityimageAnimatorInfo, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME); + HumidityImageAnimatorView->SetRepeat(true); + HumidityImageAnimatorView->Start(); } - - p_ImageAnimator->imageAnimatorConfig = { - .x = UV_IMAGE_ANIMATOR_VIEW_X, - .y = UV_IMAGE_ANIMATOR_VIEW_Y, - .w = UV_IMAGE_ANIMATOR_VIEW_W, - .h = UV_IMAGE_ANIMATOR_VIEW_H, - .numFrames = UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, - .time = UV_IMAGE_ANIMATOR_TIME, - }; - UVPathsArray = p_ImageAnimator->CreateImagePathsArray(UVPaths, "bin", UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->InitImageAnimatorSource(UVImageAnimatorView, UVimageAnimatorInfo, UVPathsArray, p_ImageAnimator->imageAnimatorConfig); - - p_ImageAnimator->imageAnimatorConfig.x = WINDSPEED_IMAGE_ANIMATOR_VIEW_X; - WindSpeedPathsArray = p_ImageAnimator->CreateImagePathsArray(WindSpeedPaths, "bin", WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->InitImageAnimatorSource(WindSpeedImageAnimatorView, WindSpeedimageAnimatorInfo, WindSpeedPathsArray, p_ImageAnimator->imageAnimatorConfig); - - p_ImageAnimator->imageAnimatorConfig.x = HUMIDITY_IMAGE_ANIMATOR_VIEW_X; - p_ImageAnimator->imageAnimatorConfig.numFrames = HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; - HumidityPathsArray = p_ImageAnimator->CreateImagePathsArray(HumidityPaths, "bin", HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->InitImageAnimatorSource(HumidityImageAnimatorView, HumidityimageAnimatorInfo, HumidityPathsArray, p_ImageAnimator->imageAnimatorConfig); - - /* ---------------------------------- Start --------------------------------- */ - UVImageAnimatorView->Start(); - WindSpeedImageAnimatorView->Start(); - HumidityImageAnimatorView->Start(); /* ----------------------------------- Add ---------------------------------- */ Add(UVImageAnimatorView); Add(WindSpeedImageAnimatorView); @@ -294,4 +334,31 @@ namespace OHOS return true; } + const char **WeatherReportView::CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) + { + const char **imagePaths = new const char *[numImages]; + char buffer[256]; + for (int i = 0; i < numImages; i++) + { + snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); + imagePaths[i] = strdup(buffer); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]); + } + return imagePaths; + } + + /* + * @brief: 释放图片路径数组指针 + * @param {char} imagePaths 图片路径数组 + * @param {int} numImages 图片数量 + */ + void WeatherReportView::FreeImagePathsArray(const char **imagePaths, const int numImages) + { + for (int i = 0; i < numImages; i++) + { + delete imagePaths[i]; + imagePaths[i] = nullptr; + } + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp index 2e6692871..4bb5d2544 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp @@ -60,9 +60,10 @@ namespace OHOS static constexpr int16_t PULLUP_ANIMATOR_VIEW_Y = 400; static constexpr int16_t PULLUP_ANIMATOR_VIEW_W = 40; static constexpr int16_t PULLUP_ANIMATOR_VIEW_H = 40; - static constexpr int16_t PULLUP_ANIMATOR_VIEW_NUM_FRAMES = 74; - static constexpr int16_t PULLUP_ANIMATOR_VIEW_TIME = 50; - static constexpr char *PullUpPaths = "/user/res/weather/PullUp/PullUp_"; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_NUM_FRAMES = 70; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_TIME = 100; + ImageAnimatorInfo PullUpimageAnimatorInfo[PULLUP_ANIMATOR_VIEW_NUM_FRAMES]; + static constexpr const char *PullUpPaths = "/user/res/weather/PullUp/PullUp_"; static WeatherView *g_pWeatherView{nullptr}; WeatherView::WeatherView() @@ -70,11 +71,15 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::WeatherView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); SetViewIndex(0); // 视图索引 - WeatherImag = GetWeatherImage(); - Temperature = GetWeatherTemperature(); - WeatherDescription = GetWeatherDescription(); - WeatherArea = GetWeatherArea(); - MaxandMinTemperature = GetWeatherMaxAndMinTemperature(); + if (WEATHER_DATA_VALID) + { + WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); + WeatherImag = p_WeatherModel->GetWeatherImage(); + Temperature = p_WeatherModel->GetWeatherTemperature(); + WeatherDescription = p_WeatherModel->GetWeatherDescription(); + WeatherArea = p_WeatherModel->GetWeatherArea(); + MaxandMinTemperature = p_WeatherModel->GetWeatherMaxAndMinTemperature(); + } g_pWeatherView = this; } @@ -126,14 +131,8 @@ namespace OHOS delete PullUpAnimatorView; PullUpAnimatorView = nullptr; } - if (p_ImageAnimator != nullptr) - { - p_ImageAnimator->FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->DeleteImageAnimatorInfo(PullUpimageAnimatorInfo); - delete p_ImageAnimator; - p_ImageAnimator = nullptr; - } + FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); } } @@ -142,52 +141,6 @@ namespace OHOS return g_pWeatherView; } - // 获取天气图片 - std::string WeatherView::GetWeatherImage() - { - int size = sizeof(weather130x130) / sizeof(weather130x130[0]); - return weather130x130[8]; - } - // 获取温度 - - std::string WeatherView::GetWeatherTemperature() - { - // 使用系统时间作为种子 - srand(time(0)); - int temperature = rand() % 50; - return std::to_string(22) + "°"; - } - // 获取天气描述 - - std::string WeatherView::GetWeatherDescription() - { - srand(time(0)); - std::string area[] = {"晴", "雨夹雪", "雷阵雨伴有冰雹"}; - int num = rand() % (sizeof(area) / sizeof(area[0])); - return area[0]; - } - // 获取天气地区 - - std::string WeatherView::GetWeatherArea() - { - srand(time(0)); - std::string area[] = {"北京市东城区", "深圳市宝安区"}; - int num = rand() % (sizeof(area) / sizeof(area[0])); - return area[1]; - } - // 获取最高气温和最低气温 - - std::string WeatherView::GetWeatherMaxAndMinTemperature() - { - // 使用系统时间作为种子 - srand(time(0)); - // 生成随机数 - int maxtemperature = 20 + rand() % 40; // 最高气温:20°~60° - int mintemperature = -5 + rand() % 20; - std::string MaxandMinTemperature = "最高" + std::to_string(22) + "°" + " " + "最低" + std::to_string(18) + "°"; - return MaxandMinTemperature; - } - // 初始化标签 UILabelExt *WeatherView::InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight) { @@ -263,24 +216,31 @@ namespace OHOS } showMaxandMinTemperatureLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); /* -------------------------------------------------------------------------- */ - - p_ImageAnimator = new ImageAnimator(); - if (p_ImageAnimator == nullptr) + PullUpPathsArray = CreateImagePathsArray(PullUpPaths, "bin", PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + if (PullUpAnimatorView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_ImageAnimator new fail!!"); - return false; + PullUpAnimatorView = new UIImageAnimatorView(); + if (PullUpAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpAnimatorView new fail"); + return false; + } + for (uint8_t i = 0; i < PULLUP_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + PullUpimageAnimatorInfo[i].imagePath = (PullUpPathsArray[i]); + PullUpimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + PullUpimageAnimatorInfo[i].pos.x = PULLUP_ANIMATOR_VIEW_X; + PullUpimageAnimatorInfo[i].pos.y = PULLUP_ANIMATOR_VIEW_Y; + PullUpimageAnimatorInfo[i].width = PULLUP_ANIMATOR_VIEW_W; + PullUpimageAnimatorInfo[i].height = PULLUP_ANIMATOR_VIEW_H; + } + PullUpAnimatorView->SetPosition(PULLUP_ANIMATOR_VIEW_X, PULLUP_ANIMATOR_VIEW_Y, PULLUP_ANIMATOR_VIEW_W, PULLUP_ANIMATOR_VIEW_H); + PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + PullUpAnimatorView->SetImageAnimatorSrc(PullUpimageAnimatorInfo, PULLUP_ANIMATOR_VIEW_NUM_FRAMES, PULLUP_ANIMATOR_VIEW_TIME); + PullUpAnimatorView->SetRepeat(true); + PullUpAnimatorView->Start(); } - - p_ImageAnimator->imageAnimatorConfig.x = PULLUP_ANIMATOR_VIEW_X; - p_ImageAnimator->imageAnimatorConfig.y = PULLUP_ANIMATOR_VIEW_Y; - p_ImageAnimator->imageAnimatorConfig.w = PULLUP_ANIMATOR_VIEW_W; - p_ImageAnimator->imageAnimatorConfig.h = PULLUP_ANIMATOR_VIEW_H; - p_ImageAnimator->imageAnimatorConfig.numFrames = PULLUP_ANIMATOR_VIEW_NUM_FRAMES; - p_ImageAnimator->imageAnimatorConfig.time = PULLUP_ANIMATOR_VIEW_TIME; - PullUpPathsArray = p_ImageAnimator->CreateImagePathsArray(PullUpPaths, "bin", PULLUP_ANIMATOR_VIEW_NUM_FRAMES); - p_ImageAnimator->InitImageAnimatorSource(PullUpAnimatorView, PullUpimageAnimatorInfo, PullUpPathsArray, p_ImageAnimator->imageAnimatorConfig); - PullUpAnimatorView->Start(); - /* -------------------------------- 将组件添加到根视图 ------------------------------- */ Add(showWeatherImage); Add(showCurrentTimeLabel); @@ -333,4 +293,41 @@ namespace OHOS showCurrentTimeLabel->SetText(stringtime.c_str()); } } + + const char **WeatherView::CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) + { + const char **imagePaths = new const char *[numImages]; + char buffer[256]; + for (int i = 0; i < numImages; i++) + { + snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); + imagePaths[i] = strdup(buffer); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]); + } + return imagePaths; + } + + /* + * @brief: 释放图片路径数组指针 + * @param {char} imagePaths 图片路径数组 + * @param {int} numImages 图片数量 + */ + void WeatherView::FreeImagePathsArray(const char **imagePaths, const int numImages) + { + for (int i = 0; i < numImages; i++) + { + delete imagePaths[i]; + imagePaths[i] = nullptr; + } + } + + void WeatherView::DumpWeatherInfo() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherInfo:"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherImag:%s", WeatherImag.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Temperature:%s", Temperature.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherDescription:%s", WeatherDescription.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherArea:%s", WeatherArea.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaxandMinTemperature:%s\n", MaxandMinTemperature.c_str()); + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index cd98d98b5..d235a8803 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -75,12 +75,12 @@ void set_ble_falg(bool falg) void set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight) { - return UI_set_weather_now_data(humidity, windScale, textNight,uvIndex,temp,iconNight); + return OHOS::UI_set_weather_now_data(humidity, windScale, textNight,uvIndex,temp,iconNight); } void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon) { - return UI_set_weather_address_data(lat, atm, city,subLocality,lon); + return OHOS::UI_set_weather_address_data(lat, atm, city,subLocality,lon); } // struct ONE_DAY_DATA // { @@ -91,7 +91,7 @@ void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,i // int tempMax; // }; -static struct ONE_DAY_DATA data_t[7]; +static OHOS::ONE_DAY_DATA data_t[7]; void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char *textDay,int x) { data_t[x].tempMin=tempMin; diff --git a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h index c1cb6e73f..141ccf71f 100755 --- a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h @@ -46,15 +46,9 @@ typedef enum { TOPIC_EVENT_HFP_PHONE_TO_WATCH, TOPIC_EVENT_HFP_WATCH_TO_PHONE, #ifdef CYWEE_SPORT - TOPIC_EVENT_NORMAL_UPDATE, - TOPIC_EVENT_TREADMILL_UPDATE, - TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE, - TOPIC_EVENT_INDOOR_RUNNING_UPDATE, - TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE, - TOPIC_EVENT_FREE_TRAINING_UPDATE, + TOPIC_EVENT_ACTIVITY_UPDATE, + TOPIC_EVENT_INACTIVITY_UPDATE, #endif - TOPIC_EVENT_AR_ALERT_UPDATE, - TOPIC_EVENT_EXTRA_INFO_UPDATE, #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION TOPIC_EVENT_CHARGE_PLUG, TOPIC_EVENT_CHARGE_UNPLUG, @@ -91,7 +85,7 @@ typedef enum { /* topic数量 */ #ifndef MAX_BROACCAST_TOPIC_NUMBER -#define MAX_BROACCAST_TOPIC_NUMBER 32 +#define MAX_BROACCAST_TOPIC_NUMBER 64 #endif /* 每个topic 对应的bitmap长度 */ diff --git a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c index 2dc6498c6..eec2193aa 100755 --- a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c @@ -26,14 +26,8 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_STEPDATA_UPDATE, A_CORE_MASK, 1}, {TOPIC_EVENT_SHUTDOWN, A_CORE_MASK, 1}, {TOPIC_EVENT_HEARTRATE_UPDATA, A_CORE_MASK, 1}, - {TOPIC_EVENT_NORMAL_UPDATE, A_CORE_MASK, 1}, - {TOPIC_EVENT_TREADMILL_UPDATE, A_CORE_MASK, 1}, - {TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE, A_CORE_MASK, 1}, - {TOPIC_EVENT_INDOOR_RUNNING_UPDATE, A_CORE_MASK, 1}, - {TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE, A_CORE_MASK, 1}, - {TOPIC_EVENT_FREE_TRAINING_UPDATE, A_CORE_MASK, 1}, - {TOPIC_EVENT_AR_ALERT_UPDATE, A_CORE_MASK, 1}, - {TOPIC_EVENT_EXTRA_INFO_UPDATE, A_CORE_MASK, 1}, + {TOPIC_EVENT_ACTIVITY_UPDATE, A_CORE_MASK, 1}, + {TOPIC_EVENT_INACTIVITY_UPDATE, A_CORE_MASK, 1}, #ifdef SUPPORT_SPO2_NOTIFICATION {TOPIC_EVENT_SPO2_UPDATE, A_CORE_MASK, 1}, {TOPIC_EVENT_START_HRS_MONITORING, A_CORE_MASK, 1}, diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 75e543a82..bfe9013eb 100755 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -51,14 +51,8 @@ extern "C" { const PriorityMapper g_pri_mapper[] = { {TOPIC_EVENT_ALARM_RING, PRIORITY_TWO}, {TOPIC_EVENT_NEXTDAY_UPDATE, PRIORITY_TWO}, - {TOPIC_EVENT_NORMAL_UPDATE,PRIORITY_TWO}, - {TOPIC_EVENT_TREADMILL_UPDATE,PRIORITY_TWO}, - {TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE,PRIORITY_TWO}, - {TOPIC_EVENT_INDOOR_RUNNING_UPDATE,PRIORITY_TWO}, - {TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE,PRIORITY_TWO}, - {TOPIC_EVENT_FREE_TRAINING_UPDATE,PRIORITY_TWO}, - {TOPIC_EVENT_AR_ALERT_UPDATE,PRIORITY_TWO}, - {TOPIC_EVENT_EXTRA_INFO_UPDATE,PRIORITY_TWO}, + {TOPIC_EVENT_ACTIVITY_UPDATE,PRIORITY_TWO}, + {TOPIC_EVENT_INACTIVITY_UPDATE,PRIORITY_TWO}, #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION {TOPIC_EVENT_CHARGE_PLUG, PRIORITY_TWO}, {TOPIC_EVENT_CHARGE_UNPLUG, PRIORITY_TWO}, @@ -127,14 +121,9 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_PHONE_TO_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_WATCH_TO_PHONE); #ifdef CYWEE_SPORT - MsgCenterSubscribeTopic(TOPIC_EVENT_NORMAL_UPDATE); - MsgCenterSubscribeTopic(TOPIC_EVENT_TREADMILL_UPDATE); - MsgCenterSubscribeTopic(TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE); - MsgCenterSubscribeTopic(TOPIC_EVENT_INDOOR_RUNNING_UPDATE); - MsgCenterSubscribeTopic(TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE); - MsgCenterSubscribeTopic(TOPIC_EVENT_FREE_TRAINING_UPDATE); - MsgCenterSubscribeTopic(TOPIC_EVENT_AR_ALERT_UPDATE); - MsgCenterSubscribeTopic(TOPIC_EVENT_EXTRA_INFO_UPDATE); + MsgCenterSubscribeTopic(TOPIC_EVENT_ACTIVITY_UPDATE); + MsgCenterSubscribeTopic(TOPIC_EVENT_INACTIVITY_UPDATE); + #endif #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION MsgCenterSubscribeTopic(TOPIC_EVENT_CHARGE_PLUG); @@ -193,7 +182,6 @@ static OHOS::UIViewGroup* CalldialNotify(void) /*显示绑定通知*/ static OHOS::UIViewGroup* showDeviceBindingNotify(void) { - PairingViewEventListener::GetInstance().Pairing_StartTimer(); return OHOS::CreateDeviceBindingView(); } @@ -822,6 +810,16 @@ void MsgCenterNotifyCanCelFindWatchProc(const Topic topic, Request* req) } FindWatchViewEventListener::GetInstance().SetFindWatchNotifyFlag(false); } +void MsgCenterNotifyActivityProc(const Topic topic, Request* req) +{ + unused(topic); + unused(req); +} +void MsgCenterNotifyInactivityProc(const Topic topic, Request* req) +{ + unused(topic); + unused(req); +} /* 订阅事件通知逻辑可定制 */ static msg_center_notify_table_t g_msg_center_notify_table[] = { {TOPIC_EVENT_ALARM_RING, MsgCenterNotifyAlarmProc}, @@ -834,14 +832,8 @@ static msg_center_notify_table_t g_msg_center_notify_table[] = { {TOPIC_EVENT_HFP_PHONE_TO_WATCH, MsgCenterNotifyHfpWatchProc}, {TOPIC_EVENT_FIND_WATCH,MsgCenterNotifyFindWatchProc}, {TOPIC_EVENT_CANCEL_FIND_WATCH,MsgCenterNotifyCanCelFindWatchProc}, - {TOPIC_EVENT_NORMAL_UPDATE, MsgCenterNotifyNormalProc}, - {TOPIC_EVENT_TREADMILL_UPDATE, MsgCenterNotifyTreadmillProc}, - {TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE, MsgCenterNotifyOutdoorRunningProc}, - {TOPIC_EVENT_INDOOR_RUNNING_UPDATE, MsgCenterNotifyIndoorRunningProc}, - {TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE, MsgCenterNotifyFitnessPedometerProc}, - {TOPIC_EVENT_FREE_TRAINING_UPDATE, MsgCenterNotifyFreeTrainingProc}, - {TOPIC_EVENT_AR_ALERT_UPDATE, MsgCenterNotifyArAlertProc}, - {TOPIC_EVENT_EXTRA_INFO_UPDATE, MsgCenterNotifyExtraInfoProc}, + {TOPIC_EVENT_ACTIVITY_UPDATE, MsgCenterNotifyActivityProc}, + {TOPIC_EVENT_INACTIVITY_UPDATE, MsgCenterNotifyInactivityProc}, #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION {TOPIC_EVENT_CHARGE_PLUG, MsgCenterNotifyChargePlugProc}, {TOPIC_EVENT_CHARGE_UNPLUG, MsgCenterNotifyChargeUnPlugProc}, diff --git a/code/sdk/build/config/target_config/brandy/build_brandy_update.py b/code/sdk/build/config/target_config/brandy/build_brandy_update.py index 2c72c5c4f..46a1b1a65 100755 --- a/code/sdk/build/config/target_config/brandy/build_brandy_update.py +++ b/code/sdk/build/config/target_config/brandy/build_brandy_update.py @@ -86,10 +86,16 @@ def get_new_image(info): # image_list.append("=".join([info.nv_bin, "nv"])) # 资源文件 - + info.res_delfile = [] + # 多个文件删除例子 + # info.res_delfile = ["/user/userdata/ConfigModel.json","/user/res/APPLIST_COMPASS_IMAGE.bin"] + + info.res_rmdir = [] + # 删除路径例子 + # info.res_rmdir = ["/user/res/dials"] + if os.path.exists(info.res_dir) : - result = res_pack(info.res_dir, info.res_index, info.res_data) - #result = res_pack(info.res_dir, info.res_index, info.res_data,info.res_delfile,info.res_rmdir) + result = res_pack(info.res_dir, info.res_index, info.res_data,info.res_delfile,info.res_rmdir) if not result: sys.exit("[ERROR] resource file pack failed!!!") image_list.append("=".join([info.res_index, "res_index"])) diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h index 6075ca642..822ed8685 100755 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h @@ -176,12 +176,12 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { #else { HAL_PIO_FUNC_TE, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L22 MIPI TE #endif - { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_NONE, HAL_PIO_IE_DISABLE }, // S_AGPIO_L23 CAT_1_PWR_ON 控制CAT_1开机脚,或者控制 CAT1电源 拉高有效 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L23 CAT_1_PWR_ON 控制CAT_1开机脚,或者控制 CAT1电源 拉高有效 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L24 LCM_EN { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L25 //////////// audio pa reset { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L26 心率复位 PPG reset { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L27 LCM reset - { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_NONE, HAL_PIO_IE_DISABLE }, // S_AGPIO_L28 CAT_1复位 CAT1_RESET_N 拉低有效 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L28 CAT_1复位 CAT1_RESET_N 拉低有效 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L29 charge done info 检测是否充满电 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L30 KP_MKIN1 唤醒 CAT1 ,输出 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L31 KP_MKOUIT1 唤醒 蓝牙 ,输入 @@ -237,7 +237,9 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { */ -#define DEFAULT_POWERON_CAT1 0 +//默认开启Cat1 然后再根据配置决定是否关闭. +#define DEFAULT_POWERON_CAT1 1 + //需要配置默认输出的,以及需要配置默认输入中断函数的。 const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 8ed5e9e4d..3caaf8223 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -41,7 +41,9 @@ extern void CWM_OS_restoreData(uint8_t* data, uint32_t len); #define SPORT_ACTIVE_MODE_INDOOR_RUNNING 1006 // 室內跑步 indoor running 1006 #define SPORT_ACTIVE_MODE_FITNESS_PEDOMETERR 1008 // 防誤觸計步 fitness_pedometer 1008 #define SPORT_ACTIVE_MODE_FREE_TRAINING 5001 // 自由運動 FreeTraining 5001 -#define SPORT_ACTIVE_MODE_AR_ALERT 1001 // 長時間動作偵測 AR alert 1001 +//#define SPORT_ACTIVE_MODE_AR_ALERT 1001 // 長時間動作偵測 AR alert 1001 +#define SPORT_ACTIVE_MODE_AR_ALERT 102 // 長時間動作偵測 AR alert 1001 +#define SPORT_ACTIVE_MODE_EXTRA_INFO 100 // 额外信息 AR alert 1001 #define INACTIVITY_MODE_NOTHING 0 // 无作用 #define INACTIVITY_MODE_SEDENTARY 1 // 久坐和有效站立 @@ -49,6 +51,11 @@ extern void CWM_OS_restoreData(uint8_t* data, uint32_t len); #define INACTIVITY_MODE_SEDENTARY_AND_NAP 3 // 久坐、有效站立和小睡 #define INACTIVITY_MODE_NAP 4 // 小睡 +#define INACTIVITY_MODE_SEDENTARY_OUTPUT 20 // 久坐和有效站立 +#define INACTIVITY_MODE_SLEEPING_OUTPUT 21 // 睡眠 +#define INACTIVITY_MODE_SLEEPING_ACCUMULATE_TIME_OUTPUT 31 // 久坐、有效站立和小睡 +#define INACTIVITY_MODE_NAP_OUTPUT 22 // 小睡 +#define INACTIVITY_MODE_NAP_ACCUMULATE_TIME_OUTPUT 32 #pragma pack(1) @@ -438,10 +445,10 @@ typedef struct typedef struct { int activity_mode; - int calories; - int duration; int steps; int distance; + int calories; + int duration; int step_frequency; int step_length; int pace; @@ -454,6 +461,7 @@ typedef struct int max_pace; int ar_alert_type; int MHR_zone; + int hrs; }cywee_activity_result_t; typedef struct @@ -479,19 +487,10 @@ typedef struct #pragma pack() typedef enum{ - CYWEE_MSG_TYPE_NORMAL_UPDATE, - CYWEE_MSG_TYPE_TREADMILL_UPDATE, - CYWEE_MSG_TYPE_OUTDOOR_RUNNING_UPDATE, - CYWEE_MSG_TYPE_INDOOR_RUNNING_UPDATE, - CYWEE_MSG_TYPE_FITNESS_PEDOMETERR_UPDATE, - CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE, - CYWEE_MSG_TYPE_AR_ALERT_UPDATE, - CYWEE_MSG_TYPE_EXTRA_INFO_UPDATE, - CYWEE_MSG_TYPE_SEDENTARY_UPDATE, - CYWEE_MSG_TYPE_SLEEPING_UPDATE, - CYWEE_MSG_TYPE_SLEEPING_ACCUMULATE_TIME_UPDATE, - CYWEE_MSG_TYPE_NAP_UPDATE, - CYWEE_MSG_TYPE_NAP_ACCUMULATE_TIME_UPDATE + CYWEE_MSG_TYPE_ACTIVITY_UPDATE, + CYWEE_MSG_TYPE_ACTIVITY_EXTRA_INFO_UPDATE, + CYWEE_MSG_TYPE_INACTIVITY_UPDATE, + CYWEE_MSG_TYPE_INACTIVITY_EXTRA_INFO_UPDATE, } cywee_msg_type_t; diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c index d0c4b0e42..9f4abd43b 100644 --- a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -62,144 +62,133 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen PRINT("cywee_msg_callback\r\n"); cywee_activity_result_t c_activity_result_t; cywee_inactivity_result_t c_inactivity_result_t; - switch(msg_type) + + if(msg_type == CYWEE_MSG_TYPE_ACTIVITY_UPDATE) { - //一般模式 - case CYWEE_MSG_TYPE_NORMAL_UPDATE: - PRINT("CYWEE_MSG_TYPE_NORMAL_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", - c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, - c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_NORMAL_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //跑步机模式 - case CYWEE_MSG_TYPE_TREADMILL_UPDATE: - PRINT("CYWEE_MSG_TYPE_TREADMILL_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", - c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, - c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_TREADMILL_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //户外跑步模式 - case CYWEE_MSG_TYPE_OUTDOOR_RUNNING_UPDATE: - PRINT("CYWEE_MSG_TYPE_OUTDOOR_RUNNING_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", - c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, - c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //室内跑步模式 - case CYWEE_MSG_TYPE_INDOOR_RUNNING_UPDATE: - PRINT("CYWEE_MSG_TYPE_INDOOR_RUNNING_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", - c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, - c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_INDOOR_RUNNING_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //防误触计步模式 - case CYWEE_MSG_TYPE_FITNESS_PEDOMETERR_UPDATE: - PRINT("CYWEE_MSG_TYPE_FITNESS_PEDOMETERR_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", - c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, - c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //自由运动模式 - case CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE: - PRINT("CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("activit_mode[%d], calories[%d], duration[%d], MHR_zone[%d],len[%d]\n", - c_activity_result_t.activity_mode,c_activity_result_t.calories,c_activity_result_t.duration,c_activity_result_t.MHR_zone,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_FREE_TRAINING_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //长时间动作侦测模式 - case CYWEE_MSG_TYPE_AR_ALERT_UPDATE: - PRINT("CYWEE_MSG_TYPE_AR_ALERT_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("activit_mode[%d], ar alert type[%d], len[%d]\n", - c_activity_result_t.activity_mode,c_activity_result_t.ar_alert_type,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_AR_ALERT_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //额外信息 - case CYWEE_MSG_TYPE_EXTRA_INFO_UPDATE: - PRINT("CYWEE_MSG_TYPE_EXTRA_INFO_UPDATE\r\n"); - memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); - PRINT("average step frequency[%d], average step length[%d], average pace[%d], max step frequency[%d], max pace[%d], len[%d]\n", - c_activity_result_t.avg_step_freq,c_activity_result_t.avg_step_len,c_activity_result_t.avg_pace,c_activity_result_t.max_step_freq,c_activity_result_t.max_pace,sizeof(cywee_activity_result_t)); - CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //久坐 - case CYWEE_MSG_TYPE_SEDENTARY_UPDATE: - PRINT("CYWEE_MSG_TYPE_SEDENTARY_UPDATE\r\n"); - memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); - PRINT("inactivity_mode_number[%d], sedentary status[%d], stand freq[%d], len[%d]\n", - c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.sedentary_status, - c_inactivity_result_t.stand_freq,sizeof(cywee_inactivity_result_t)); - //CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //睡眠 - case CYWEE_MSG_TYPE_SLEEPING_UPDATE: - PRINT("CYWEE_MSG_TYPE_SLEEPING_UPDATE\r\n"); - memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); - PRINT("inactivity_mode_number[%d], sleep status[%d], month[%d], day[%d], hour[%d], min[%d], len[%d]\n", - c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.sleep_status, - c_inactivity_result_t.month,c_inactivity_result_t.day, - c_inactivity_result_t.hour,c_inactivity_result_t.minute, - sizeof(cywee_inactivity_result_t)); - //CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //睡眠累计 - case CYWEE_MSG_TYPE_SLEEPING_ACCUMULATE_TIME_UPDATE: - PRINT("CYWEE_MSG_TYPE_SLEEPING_ACCUMULATE_TIME_UPDATE\r\n"); - memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); - PRINT("inactivity_mode_number[%d], total sleep time[%d], total nap time[%d], total deep sleep time[%d], total wake time[%d], total rem sleep time[%d], len[%d]\n", - c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.total_sleep_time,c_inactivity_result_t.total_mild_sleep_time, - c_inactivity_result_t.total_deep_sleep_time,c_inactivity_result_t.total_wake_time,c_inactivity_result_t.total_rem_sleep_time, - c_inactivity_result_t.stand_freq,sizeof(cywee_inactivity_result_t)); - //CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - //小睡 - case CYWEE_MSG_TYPE_NAP_UPDATE: - PRINT("CYWEE_MSG_TYPE_NAP_UPDATE\r\n"); + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + switch (c_activity_result_t.activity_mode) + { + case SPORT_ACTIVE_MODE_NORMAL: + PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", + c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, + c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + case SPORT_ACTIVE_MODE_TREADMILL: + PRINT("CYWEE_MSG_TYPE_TREADMILL_UPDATE\r\n"); + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", + c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, + c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + case SPORT_ACTIVE_MODE_OUTDOOR_RUNNING: + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", + c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, + c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + case SPORT_ACTIVE_MODE_INDOOR_RUNNING: + PRINT("CYWEE_MSG_TYPE_INDOOR_RUNNING_UPDATE\r\n"); + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", + c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, + c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + case SPORT_ACTIVE_MODE_FITNESS_PEDOMETERR: + PRINT("CYWEE_MSG_TYPE_FITNESS_PEDOMETERR_UPDATE\r\n"); + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", + c_activity_result_t.activity_mode,c_activity_result_t.steps,c_activity_result_t.distance,c_activity_result_t.calories,c_activity_result_t.step_frequency, + c_activity_result_t.step_length,c_activity_result_t.pace,c_activity_result_t.BMR_calories,c_activity_result_t.is_pause,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + case SPORT_ACTIVE_MODE_FREE_TRAINING: + PRINT("CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE\r\n"); + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + PRINT("activit_mode[%d], calories[%d], duration[%d], MHR_zone[%d],len[%d]\n", + c_activity_result_t.activity_mode,c_activity_result_t.calories,c_activity_result_t.duration,c_activity_result_t.MHR_zone,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + + //长时间动作侦测 + case SPORT_ACTIVE_MODE_AR_ALERT: + PRINT("CYWEE_MSG_TYPE_AR_ALERT_UPDATE\r\n"); + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + PRINT("activit_mode[%d], ar alert type[%d], len[%d]\n", + c_activity_result_t.activity_mode,c_activity_result_t.ar_alert_type,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + + //额外信息 + case SPORT_ACTIVE_MODE_EXTRA_INFO: + PRINT("CYWEE_MSG_TYPE_EXTRA_INFO_UPDATE\r\n"); + memcpy(&c_activity_result_t, msg_data, sizeof(cywee_activity_result_t)); + PRINT("average step frequency[%d], average step length[%d], average pace[%d], max step frequency[%d], max pace[%d], len[%d]\n", + c_activity_result_t.avg_step_freq,c_activity_result_t.avg_step_len,c_activity_result_t.avg_pace,c_activity_result_t.max_step_freq,c_activity_result_t.max_pace,sizeof(cywee_activity_result_t)); + CustomEventPublish(TOPIC_EVENT_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + default: + break; + } + }else if(msg_type == CYWEE_MSG_TYPE_INACTIVITY_UPDATE){ memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); - PRINT("inactivity_mode_number[%d], nap status[%d], month[%d], day[%d], hour[%d], min[%d], len[%d]\n", - c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.nap_status,c_inactivity_result_t.month, - c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,sizeof(cywee_inactivity_result_t)); - //CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; + switch (c_inactivity_result_t.inactivity_mode) + { + //久坐 + case INACTIVITY_MODE_SEDENTARY_OUTPUT: + memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); + PRINT("inactivity_mode_number[%d], sedentary status[%d], stand freq[%d], len[%d]\n", + c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.sedentary_status, + c_inactivity_result_t.stand_freq,sizeof(cywee_inactivity_result_t)); + CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + + //睡眠 + case INACTIVITY_MODE_SLEEPING_OUTPUT: + memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); + PRINT("inactivity_mode_number[%d], sleep status[%d], month[%d], day[%d], hour[%d], min[%d], len[%d]\n", + c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.sleep_status, + c_inactivity_result_t.month,c_inactivity_result_t.day, + c_inactivity_result_t.hour,c_inactivity_result_t.minute, + sizeof(cywee_inactivity_result_t)); + CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + + //睡眠累计 + case INACTIVITY_MODE_SLEEPING_ACCUMULATE_TIME_OUTPUT: + memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); + PRINT("inactivity_mode_number[%d], total sleep time[%d], total nap time[%d], total deep sleep time[%d], total wake time[%d], total rem sleep time[%d], len[%d]\n", + c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.total_sleep_time,c_inactivity_result_t.total_mild_sleep_time, + c_inactivity_result_t.total_deep_sleep_time,c_inactivity_result_t.total_wake_time,c_inactivity_result_t.total_rem_sleep_time, + c_inactivity_result_t.stand_freq,sizeof(cywee_inactivity_result_t)); + CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + + //小睡 + case INACTIVITY_MODE_NAP_OUTPUT: + memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); + PRINT("inactivity_mode_number[%d], nap status[%d], month[%d], day[%d], hour[%d], min[%d], len[%d]\n", + c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.nap_status,c_inactivity_result_t.month, + c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,sizeof(cywee_inactivity_result_t)); + CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; - //小睡累计 - case CYWEE_MSG_TYPE_NAP_ACCUMULATE_TIME_UPDATE: - PRINT("CYWEE_MSG_TYPE_NAP_ACCUMULATE_TIME_UPDATE\r\n"); - memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); - PRINT("inactivity_mode_number[%d], total nap time[%d], total mild time[%d], total deep sleep time[%d], total wake time[%d], total rem sleep time[%d], len[%d]\n", - c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.total_nap_time,c_inactivity_result_t.total_mild_sleep_time, - c_inactivity_result_t.total_deep_sleep_time,c_inactivity_result_t.total_wake_time,c_inactivity_result_t.total_rem_sleep_time, - c_inactivity_result_t.stand_freq,sizeof(cywee_inactivity_result_t)); - //CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - default: - + //小睡累计 + case INACTIVITY_MODE_NAP_ACCUMULATE_TIME_OUTPUT: + memcpy(&c_inactivity_result_t, msg_data, sizeof(cywee_inactivity_result_t)); + PRINT("inactivity_mode_number[%d], total nap time[%d], total mild time[%d], total deep sleep time[%d], total wake time[%d], total rem sleep time[%d], len[%d]\n", + c_inactivity_result_t.inactivity_mode,c_inactivity_result_t.total_nap_time,c_inactivity_result_t.total_mild_sleep_time, + c_inactivity_result_t.total_deep_sleep_time,c_inactivity_result_t.total_wake_time,c_inactivity_result_t.total_rem_sleep_time, + c_inactivity_result_t.stand_freq,sizeof(cywee_inactivity_result_t)); + CustomEventPublish(TOPIC_EVENT_INACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + break; + } + } + else PRINT("Unknown sensor message type"); - break; - } } diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index 008b25def..851eba7af 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -76,16 +76,28 @@ int gpio_int_pin_init(void) } +// int CWM_setGpio(uint16_t sensortype, uint16_t sensorPin, uint16_t pintype) +// { + +// return ERRCODE_SUCC; +// } + +// int CWM_securityCodeWrite(uint32_t sensortype, uint8_t* data, uint32_t len) +// { +// return ERRCODE_SUCC; +// } + // int CWM_enableGpioIRQ(uint16_t sensorType, uint16_t sensorPin, PFN_IRQHANDLE callback) // { +// CWM_OS_dbgPrintf("CWM_enableGpioIRQ sensorType %d, sensorPin %d, callback 0x%X\n",sensorType,sensorPin,callback); -// return 1; +// return ERRCODE_SUCC; // } // int CWM_disableGpioIRQ(uint16_t sensorType, uint16_t sensorPin) // { - -// return 1; +// CWM_OS_dbgPrintf("CWM_disableGpioIRQ sensorType %d, sensorPin %d\n",sensorType,sensorPin); +// return ERRCODE_SUCC; // } @@ -316,10 +328,33 @@ int CWM_OS_dbgPrintf(const char * format,...) CWM_OS_dbgOutput(InputBuff); return 0; } - +#define CWM_DATA_PATH "/system/cyweedata" void CWM_OS_saveData(uint8_t* data, uint32_t len){ - + + FILE * fp = fopen(CWM_DATA_PATH,"wb"); + if(fp==NULL) + { + CWM_OS_dbgPrintf("open fail\n"); + return; + } + int ret =fwrite(data,1,len,fp); + if(ret==0) + { + CWM_OS_dbgPrintf("fwrite failed %d\n",ret); + } + fclose(fp); } void CWM_OS_restoreData(uint8_t* data, uint32_t len){ - + FILE * fp = fopen(CWM_DATA_PATH,"rb"); + if(fp==NULL) + { + CWM_OS_dbgPrintf("open fail\n"); + return; + } + int ret =fread(data,1,len,fp); + if(ret==0) + { + CWM_OS_dbgPrintf("fread failed %d\n",ret); + } + fclose(fp); } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 70bfb785b..3134adc71 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -47,6 +47,21 @@ static osTimerId_t g_cywee_oncharging_timer; CustomSensorData csd; +static uint8_t hrs = 0; +static uint8_t wearstatus = 0; + +void set_user_info(int age,int gender,double weight,int height,int wearing_method) +{ + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = age; + scl.iData[2] = weight; + scl.iData[3] = (int)weight; + scl.iData[4] = weight; + scl.iData[5] = wearing_method; + CWM_SettingControl(SCL_USER_INFO, &scl); +} + void time_sync(void) { time_t rawtime; @@ -59,8 +74,8 @@ void time_sync(void) memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; - scl.iData[1] = timeinfo->tm_year; - scl.iData[2] = timeinfo->tm_mon; + scl.iData[1] = timeinfo->tm_year + 1900; + scl.iData[2] = timeinfo->tm_mon + 1; scl.iData[3] = timeinfo->tm_mday; scl.iData[4] = timeinfo->tm_hour; scl.iData[5] = timeinfo->tm_min; @@ -70,7 +85,6 @@ void time_sync(void) void cywee_hrs_check_timer_callback(void) { - uint8_t hrs,wearstatus; get_hrs_wearstatus(&hrs,&wearstatus); CWM_OS_dbgPrintf("hrs : %d,wearstatus : %d \r\n",hrs,wearstatus); memset(&csd, 0, sizeof(CUSTOM_HEARTRATE)); @@ -194,6 +208,14 @@ void cyw_inactivity_mode_change(int mode) //久坐和有效站立 case INACTIVITY_MODE_SEDENTARY: + PRINT("INACTIVITY_MODE_SEDENTARY\r\n"); + //training_mode_init(); + //配置久坐相关参数 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[2] = 1; + scl.iData[3] = 1; + CWM_SettingControl(SCL_SEDENTARY, &scl); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = 1; @@ -210,6 +232,17 @@ void cyw_inactivity_mode_change(int mode) //久坐、有效站立和小睡 case INACTIVITY_MODE_SEDENTARY_AND_NAP: + /* + SCL_REQ_SLEEPING_DATA + int[0] = 1 + int[1] = terminate_sleep + (0: 立刻輸出狀態,但不中止此段睡眠偵測, + 1: 立刻輸出狀態,並中止此段睡眠偵測) + */ + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 1; + CWM_SettingControl(SCL_REQ_SLEEPING_DATA, &scl); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = 3; @@ -438,7 +471,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_result_t.inactivity_mode = (int)sensorEVT->fData[15]; c_inactivity_result_t.sedentary_status = (int)sensorEVT->fData[2]; c_inactivity_result_t.stand_freq = (int)sensorEVT->fData[3]; - cywee_func(CYWEE_MSG_TYPE_SEDENTARY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); + cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); }else if((int)sensorEVT->fData[0] == 21){ CWM_OS_dbgPrintf("inactivity_mode_number[%d], sleep status[%d], month[%d], day[%d], hour[%d], min[%d]\n", @@ -455,7 +488,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_result_t.day = (int)sensorEVT->fData[4]; c_inactivity_result_t.hour = (int)sensorEVT->fData[5]; c_inactivity_result_t.minute = (int)sensorEVT->fData[6]; - cywee_func(CYWEE_MSG_TYPE_SLEEPING_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); + cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); }else if((int)sensorEVT->fData[0] == 31){ CWM_OS_dbgPrintf("inactivity_mode_number[%d], total sleep time[%d], total mild time[%d], total deep sleep time[%d], total wake time[%d], total rem sleep time[%d]\n", @@ -472,7 +505,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_result_t.total_deep_sleep_time = (int)sensorEVT->fData[3]; c_inactivity_result_t.total_wake_time = (int)sensorEVT->fData[4]; c_inactivity_result_t.total_rem_sleep_time = (int)sensorEVT->fData[5]; - cywee_func(CYWEE_MSG_TYPE_SLEEPING_ACCUMULATE_TIME_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); + cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); }else if((int)sensorEVT->fData[0] == 22){ CWM_OS_dbgPrintf("inactivity_mode_number[%d], nap status[%d], month[%d], day[%d], hour[%d], min[%d]\n", @@ -489,7 +522,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_result_t.day = (int)sensorEVT->fData[4]; c_inactivity_result_t.hour = (int)sensorEVT->fData[5]; c_inactivity_result_t.minute = (int)sensorEVT->fData[6]; - cywee_func(CYWEE_MSG_TYPE_NAP_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); + cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); }else if((int)sensorEVT->fData[0] == 32){ CWM_OS_dbgPrintf("inactivity_mode_number[%d], total nap time[%d], total mild time[%d], total deep sleep time[%d], total wake time[%d], total rem sleep time[%d]\n", @@ -506,7 +539,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_result_t.total_deep_sleep_time = (int)sensorEVT->fData[3]; c_inactivity_result_t.total_wake_time = (int)sensorEVT->fData[4]; c_inactivity_result_t.total_rem_sleep_time = (int)sensorEVT->fData[5]; - cywee_func(CYWEE_MSG_TYPE_NAP_ACCUMULATE_TIME_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); + cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); } break; case IDX_ALGO_ACTIVITY_OUTPUT: @@ -521,12 +554,14 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { (int)sensorEVT->fData[5]); memset(&c_activity_result_t,0,sizeof(cywee_activity_result_t)); + c_activity_result_t.activity_mode = (int)sensorEVT->fData[0]; c_activity_result_t.avg_step_freq = (int)sensorEVT->fData[1]; c_activity_result_t.avg_step_len = (int)sensorEVT->fData[2]; c_activity_result_t.avg_pace = (int)sensorEVT->fData[3]; c_activity_result_t.max_step_freq = (int)sensorEVT->fData[4]; c_activity_result_t.max_pace = (int)sensorEVT->fData[5]; - cywee_func(CYWEE_MSG_TYPE_EXTRA_INFO_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + c_activity_result_t.hrs = hrs; + cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); }else if((int)sensorEVT->fData[0] == 5001) { @@ -540,7 +575,8 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_activity_result_t.calories = (int)sensorEVT->fData[1]; c_activity_result_t.duration = (int)sensorEVT->fData[5]; c_activity_result_t.MHR_zone = (int)sensorEVT->fData[6]; - cywee_func(CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + c_activity_result_t.hrs = hrs; + cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); }else if((int)sensorEVT->fData[0] == 102) { @@ -549,7 +585,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { memset(&c_activity_result_t,0,sizeof(cywee_activity_result_t)); c_activity_result_t.activity_mode = (int)sensorEVT->fData[0]; c_activity_result_t.ar_alert_type = (int)sensorEVT->fData[1]; - cywee_func(CYWEE_MSG_TYPE_AR_ALERT_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); + cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); }else{ CWM_OS_dbgPrintf("activity_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d]\n", @@ -573,36 +609,13 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_activity_result_t.pace = (int)sensorEVT->fData[7]; c_activity_result_t.BMR_calories = (int)sensorEVT->fData[8]; c_activity_result_t.is_pause = (int)sensorEVT->fData[14]; - - switch ((int)sensorEVT->fData[0]) - { - case SPORT_ACTIVE_MODE_NORMAL: - cywee_func(CYWEE_MSG_TYPE_NORMAL_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - case SPORT_ACTIVE_MODE_TREADMILL: - cywee_func(CYWEE_MSG_TYPE_TREADMILL_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - case SPORT_ACTIVE_MODE_OUTDOOR_RUNNING: - cywee_func(CYWEE_MSG_TYPE_OUTDOOR_RUNNING_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - case SPORT_ACTIVE_MODE_INDOOR_RUNNING: - cywee_func(CYWEE_MSG_TYPE_INDOOR_RUNNING_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - case SPORT_ACTIVE_MODE_FITNESS_PEDOMETERR: - cywee_func(CYWEE_MSG_TYPE_FITNESS_PEDOMETERR_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); - break; - - default: - break; - } + c_activity_result_t.hrs = hrs; + cywee_func(CYWEE_MSG_TYPE_ACTIVITY_UPDATE,&c_activity_result_t,sizeof(cywee_activity_result_t)); CustomEventPublish(TOPIC_EVENT_STEPDATA_UPDATE,&stepcount,sizeof(int)); } break; + case IDX_ALGO_ANY_MOTION: CWM_OS_dbgPrintf("IDX_ALGO_ANY_MOTION\n"); diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 819e1c14e..2a48240a0 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -427,11 +427,12 @@ uint16_t hx3695_read_fifo_data(int32_t *buf, uint8_t phase_num, uint8_t sig) hx3695_brust_read_reg(0x22, databuf, 3); read_fifo_first_flg = 0; } - hx3695_brust_read_reg(0x22, fifo_data_buf, fifo_read_bytes); -// for(ii=0; ii touch_cnt: %d, notouch_cnt: %d, wear status: %d, \r\n", touch_cnt, notouch_cnt, hx3695_wear_status); -// PRINT("hx3695_wear_ppg_Int_handle wearstatus = %d\r\n", hrsresult.wearstatus); - -// for(int i=0;i<*count;i++) -// { -// DEBUG_PRINTF("%d,%d,%d,%d,%d,%d\r\n",1+i,*count,ir_buf[i],ppg_s_data.s_buf[i*2],ppg_s_data.s_buf[i*2+1],hx3695_wear_status); -// } + PRINT("hx3695_wear_ppg_Int_handle wearstatus = %d\r\n", hrsresult.wearstatus); + PRINT("count : %d \r\n",*count); + for(int i=0;i<*count;i++) + { + PRINT("%d,%d,%d,%d,%d,%d\r\n",1+i,*count,ir_buf[i],ppg_s_data.s_buf[i*2],ppg_s_data.s_buf[i*2+1],hx3695_wear_status); + } } #endif diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c index ea1817a75..c4b2e4d50 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_check_touch.c @@ -148,6 +148,7 @@ uint8_t hx3695_check_touch_read(ppg_sensor_data_t *s_dat) // if (size && size <= 256) // { fifo_out_size = hx3695_read_fifo_data(s_buf,hrs_phase_num,2); + PRINT("fifo_out_size : %d\r\n",fifo_out_size); s_dat->count = fifo_out_size; for (i=0; icheck_mode_wear_thre) { notouch_cnt = 0; diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c index 749efac90..944aa79a7 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-03-13 15:08:38 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-03-29 10:51:50 + * @LastEditTime: 2024-04-12 20:23:58 * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c * @Description: * @@ -56,6 +56,8 @@ void ppg_send_cmd_to_driver(char* mode, uint8_t enable) md = FT_GRAY_CARD_MODE; } else if (strcmp(mode, "ledoff") == 0) { md = FT_LED_OFF_MODE; + } else if (strcmp(mode, "wear") == 0) { + md = WEAR_MODE; } diff --git a/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp b/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp index bd72fc928..fa7e7d85a 100644 --- a/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp +++ b/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp @@ -305,7 +305,7 @@ static void ppg_service_check_task(void *arg) cmd = "leaklight"; enable = 1; }else if (mail == PPG_SERVICE_CMD_TYPE_DO_GRAYCARD_TEST){ - cmd = "graycard"; + cmd = "wear"; enable = 1; }else if (mail == PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST){ diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp index 0da45797b..4ff317831 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp @@ -80,21 +80,21 @@ void uapi_cat1_stop_volte_voice(void) void uapi_cat1_remove_audio_vote(void) { - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_AUDIO); + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_CAT1); if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_AUDIO); + uapi_pm_remove_sleep_veto(PM_ID_CAT1); } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has delete pm_id_audio vote\r\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has delete pm_id_cat1 vote\r\n"); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"\r\nCAT1 SERVICE MCU SLEEP SUCCESS\r\n"); } void uapi_cat1_add_audio_vote(void) { - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_AUDIO); + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_CAT1); if (cnt == 0) { - uapi_pm_add_sleep_veto(PM_ID_AUDIO); + uapi_pm_add_sleep_veto(PM_ID_CAT1); } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_audio vote\r\n"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"\r\nCAT1 SERVICE MCU WAKEUP SUCCESS\r\n"); } diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp index 69c9fd0a8..04f9297b5 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..891d41e2d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -110,17 +110,86 @@ 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; +} + +void startup_post_init_task(void) +{ + + PRINT("startup_post_init_task !\r\n"); + + LOS_Msleep(5000); + if ( poweron_cat1_on_bootup_flag() ) + { + PRINT("PowerOn Cat1 !\r\n"); + + uapi_cat1_power_on(1); + uapi_cat1_reset(0); + }else{ + PRINT("PowerOff Cat1 !\r\n"); + + uapi_cat1_power_on(0); + uapi_cat1_reset(1); + } + +} + +void startup_post_init(void) +{ + PRINT("startup_post_init !\r\n"); + app_task_definition_t taskcfg={0}; + taskcfg.create_queue_handle = NULL; + taskcfg.attr.name="startup_post_init_task"; + taskcfg.attr.priority = osPriorityNormal; + taskcfg.attr.stack_size = 0x1000; + taskcfg.func = startup_post_init_task; + 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); + + } +} #include "upg.h" #include "upg_porting.h" @@ -572,7 +641,6 @@ errcode_t init_btaddr_btname(void) { errcode_t ret ; - srand(time(0)); uint8_t bd_addr[BD_ADDR_LEN]={0}; uint8_t name[BTSDK_DEVNAME_LEN]={0}; uint32_t addrlen = sizeof(bd_addr); @@ -582,6 +650,7 @@ errcode_t init_btaddr_btname(void) printf("uapi_get_nv_btaddr failed ret %d , addrlen %d\n",ret,addrlen); return ERRCODE_FAIL; } + //如果 281106856959 if ( bd_addr[5] == 0x59 && bd_addr[4] == 0x69 && @@ -590,11 +659,25 @@ errcode_t init_btaddr_btname(void) bd_addr[1] == 0x11 && bd_addr[0] == 0x28 ) { + + uint8_t soc_id[20]; // 20 is soc id length + uapi_soc_read_id(soc_id, 20); // 20 is soc id length + uint16_t sum = 0x0; + printf("[soc id:]\r\n"); + for (uint8_t i = 0; i < 20; i += 2) { // 20 is soc id length, 2 means use 16bits + uint16_t ptmp16= *((uint16_t *)&soc_id[i]); + sum += ptmp16; + printf("0x%04X ", ptmp16); + if ((i + 2) % 8 == 0) { printf("\r\n"); } // 2&8 will word wrap + } + printf("get socid sum 0x%04X\r\n",sum); + srand(sum); //默认是:281106856959 printf("是默认值,修改地址\n"); - bd_addr[5] = rand() % 0xFF; - bd_addr[4] = rand() % 0xFF; bd_addr[3] = rand() % 0xFF; + bd_addr[4] = rand() % 0xFF; + bd_addr[5] = rand() % 0xFF; + printf("uapi_set_nv_btaddr : ******%02x%02x%02x\n", bd_addr[3], bd_addr[4], bd_addr[5]); ret = uapi_set_nv_btaddr(bd_addr, addrlen); @@ -606,7 +689,8 @@ errcode_t init_btaddr_btname(void) } - + +#if 0 uint32_t namelen = sizeof(name); ret = uapi_get_nv_btname(name,&namelen); if (ret != ERRCODE_SUCC) { @@ -614,7 +698,6 @@ errcode_t init_btaddr_btname(void) printf("uapi_get_nv_btname failed ret %d , namelen %d\n",ret,namelen); return ERRCODE_FAIL; } - if ( strcmp((char*)name,"WatchSoar") == 0) { //默认是:WatchSoar @@ -628,6 +711,7 @@ errcode_t init_btaddr_btname(void) return ERRCODE_FAIL; } } +#endif return ERRCODE_SUCC; } 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 */ diff --git a/code/sdk/middleware/chips/brandy/nv/nv_config/cfg/acore/app.json b/code/sdk/middleware/chips/brandy/nv/nv_config/cfg/acore/app.json index 52dc09067..1e6fff5e1 100755 --- a/code/sdk/middleware/chips/brandy/nv/nv_config/cfg/acore/app.json +++ b/code/sdk/middleware/chips/brandy/nv/nv_config/cfg/acore/app.json @@ -41,7 +41,7 @@ "key_status": "alive", "structure_type": "btsrv_local_device_info_t", "attributions": 1, - "value": [[40,17,6,133,105, 89],0,0,["W","a","t","c","h","S","o","a","r",0]] + "value": [[40,17,6,133,105, 89],0,0,["W","a","t","c","h","D","e","m","o",0]] }, "btsrv_paired_device_info":{ "key_id": "0x2102", diff --git a/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h b/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h index bc2d0d9f0..16c84a7e4 100755 --- a/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h +++ b/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h @@ -42,6 +42,7 @@ typedef enum { PM_ID_HEART,//新增,心率芯片 PM_ID_MOTOR,//新增,马达 PM_ID_GSENSOR,//新增,加速计 + PM_ID_CAT1,//Cat1 communication PM_ID_MAX, } pm_id_t; diff --git a/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image b/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image index 086d8c50f..f953a69ae 100755 Binary files a/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image and b/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image differ diff --git a/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image.c b/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image.c index 0ef54bf84..66e2a0f60 100755 --- a/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image.c +++ b/code/sdk/tools/bin/platform_tool/mkyaffs2image/mkyaffs2image.c @@ -942,6 +942,7 @@ int main(int argc, char *argv[]) chunkSize = get_pagesize(g_pagetype); spareSize = sel_oob_info->oobsize; + printf("chunkSize %d spareSize %d\n",chunkSize,spareSize); printf("Processing directory %s into image file %s\n",argv[1],argv[2]);