#include "TjdUiAppCameraModel.h" #include "TjdUiAppCameraPresenter.h" #include "ble_api.h" #include "hal_tick.h" #include "power_display_service.h" #include "service_gsensor.h" #include "sys_config.h" #define ENABLE_PRINT_INFO 1 #if ENABLE_PRINT_INFO #define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制 #define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开 #define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开 #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印一般常开 #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif namespace TJD { GsensorData &TjdUiAppCameraModel::GetGsensorData(void) { gsensor_xyz_info xyzInfo = {}; uint8_t count = tjd_service_gs_get_fifo_count(GSEN_SERVICE_PRODUCTION); if (count == 0) { return data_; } tjd_service_gs_get_xyz_fifo(GSEN_SERVICE_PRODUCTION, &xyzInfo, 1); data_.x = xyzInfo.gsensor_x.raw_data; data_.y = xyzInfo.gsensor_y.raw_data; data_.z = xyzInfo.gsensor_z.raw_data; return data_; }; bool TjdUiAppCameraModel::isGiveShake(void) { //判断是否触发一次摇一摇 //记录当前陀螺仪数据 GsensorData initialData = GetGsensorData(); // 等待1秒 std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // 再次获取陀螺仪数据 GsensorData finalData = GetGsensorData(); // 计算加速度变化 int deltaX = finalData.x - initialData.x; int deltaY = finalData.y - initialData.y; int deltaZ = finalData.z - initialData.z; // 计算总加速度变化 double totalDelta = std::sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); // 设置阈值,例如1000 const int threshold = 1000; // 判断是否触发摇一摇 if (totalDelta > threshold) { return true; } return false; } bool TjdUiAppCameraModel::CanUploadTakePhotoCmd(void) { uint64_t curTime = OHOS::HALTick::GetInstance().GetTime(); if (curTime - lastShakeTime_ < 2000) { return false; } lastShakeTime_ = curTime; return true; } void TjdUiAppCameraModel::CloseAutoScreenOff(void) { const power_display_svr_api_t *handle = power_display_svr_get_api(); if (handle->get_screen_state() != SCREEN_ON) { handle->turn_on_screen(); } handle->set_screen_set_keepon_timeout(1000 * 60); } void TjdUiAppCameraModel::OpenAutoScreenOff(void) { const power_display_svr_api_t *handle = power_display_svr_get_api(); handle->set_screen_set_keepon_timeout(0); // handle->set_screen_set_keepon_timeout(sql_setting_get_close_screen_time() * 1000); } } // namespace TJD