228 lines
7.9 KiB
C++
228 lines
7.9 KiB
C++
#include "TjdUiAppCameraPresenter.h"
|
|
#include "NativeAbility.h"
|
|
#include "TjdUiAppCameraModel.h"
|
|
#include "TjdUiAppCameraView.h"
|
|
#include "TjdUiAppIds.h"
|
|
#include "TjdUiMsgCenter.h"
|
|
#include "TjdUiRegisterManager.h"
|
|
#include "broadcast_feature.h"
|
|
#include "common/key_code.h"
|
|
#include "components/ui_view_group.h"
|
|
#include "dock/input_device.h"
|
|
#include "los_typedef.h"
|
|
#include "notification_manager.h"
|
|
#include "sys_config.h"
|
|
#include <stdio.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include "ble_api.h"
|
|
#include "ble_port_protocol.h"
|
|
|
|
static uint8_t g_camera_server_id;
|
|
static uint16_t g_camera_server_conn_id;
|
|
static uint16_t g_camera_server_handle;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
using namespace OHOS;
|
|
|
|
#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 {
|
|
|
|
TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_CAMERA, TjdUiAppCameraView, TjdUiAppCameraPresenter, IMG_MENU_LIST_MENU_CAMERA,
|
|
STR_ID_19);
|
|
|
|
static OHOS::UIScrollView *g_messageCameraView = nullptr;
|
|
|
|
void gatts_send_to_app(void)
|
|
{
|
|
tjd_get_gatt_server_conn_handle_id(&g_camera_server_id, &g_camera_server_conn_id, &g_camera_server_handle);
|
|
gatts_ntf_ind_t param = {0};
|
|
param.attr_handle = g_camera_server_handle;
|
|
uint8_t send_data[5] = {0x5a, 0x05, 0x0d, 0x03, 0x9d};
|
|
param.value = send_data;
|
|
param.value_len = sizeof(send_data);
|
|
errcode_t ret = gatts_notify_indicate(g_camera_server_id, g_camera_server_conn_id, ¶m);
|
|
if (ret != ERRCODE_SUCC) {
|
|
static_print_error("gatts_notify_indicate faile ret(errcode_t): %x", ret);
|
|
}
|
|
static_print_debug("gatts_notify_indicate success ret(errcode_t): %x", ret);
|
|
}
|
|
|
|
static void camera_shark_task(void *argument)
|
|
{
|
|
TjdUiAppCameraModel &model = TjdUiAppCameraModel::GetInstance();
|
|
while (1) {
|
|
if (model.isGiveShake() && model.CanUploadTakePhotoCmd()) {
|
|
static_print_info("isGiveShake take_photo");
|
|
uint8 pack_head = PROTOCOL_RES_FRAME_HEAD;
|
|
uint8_t data = 0x00;
|
|
tjd_ble_protocol_send_lefun_data(&pack_head, &data, sizeof(uint8_t), 0x0e);
|
|
}
|
|
// // 等待2秒
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
|
}
|
|
}
|
|
|
|
static TjdUiAppCameraPresenter *g_pv_AppCameraPresenter = nullptr;
|
|
|
|
OHOS::GraphicTimer *timerToClick_{nullptr};
|
|
|
|
TjdUiAppCameraPresenter::TjdUiAppCameraPresenter(KeyType type)
|
|
{
|
|
type_ = type;
|
|
g_pv_AppCameraPresenter = this;
|
|
}
|
|
|
|
TjdUiAppCameraPresenter::~TjdUiAppCameraPresenter()
|
|
{
|
|
g_pv_AppCameraPresenter = nullptr;
|
|
if (timerToClick_ != nullptr) {
|
|
delete timerToClick_;
|
|
timerToClick_ = nullptr;
|
|
}
|
|
osThreadTerminate(camera_shark_task_id);
|
|
}
|
|
|
|
TjdUiAppCameraPresenter &TjdUiAppCameraPresenter::GetInstance(void) { return *g_pv_AppCameraPresenter; }
|
|
|
|
void TjdUiAppCameraPresenter::OnStart()
|
|
{
|
|
if (type_ == KeyType::KEY_SLICE)
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
else if (type_ == KeyType::KEY_POPUPWINDOW)
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::SYS_KEY_TYPE);
|
|
osThreadAttr_t task_attr = {"mg_game_task", 0, NULL, 0, NULL, 0x700, (osPriority_t)17, 0, 0};
|
|
task_attr.stack_mem = memalign(16, task_attr.stack_size); // add
|
|
camera_shark_task_id = osThreadNew(camera_shark_task, NULL, &task_attr);
|
|
if (camera_shark_task_id == NULL) {
|
|
static_print_error("create camera shark task failed");
|
|
return;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppCameraPresenter::OnStop()
|
|
{
|
|
if (type_ == KeyType::KEY_SLICE)
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
else if (type_ == KeyType::KEY_POPUPWINDOW)
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::SYS_KEY_TYPE);
|
|
|
|
osThreadTerminate(camera_shark_task_id);
|
|
}
|
|
|
|
bool TjdUiAppCameraPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
printf("TjdUiAppCameraPresenter::OnKeyAct\n");
|
|
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) {
|
|
return true;
|
|
}
|
|
if (type_ == KeyType::KEY_SLICE)
|
|
ExitCameraView();
|
|
else if (type_ == KeyType::KEY_POPUPWINDOW) {
|
|
gatts_send_to_app();
|
|
NotificationManager::GetInstance()->StopNotify();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void TjdUiAppCameraPresenter::ExitCameraView(void)
|
|
{
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
gatts_send_to_app();
|
|
}
|
|
|
|
static void TimerCallbackToClick_(void *param)
|
|
{
|
|
UIView *view = (UIView *)param;
|
|
const Vector2<float> &scale1 = {1.0, 1.0};
|
|
Vector2<float> pivot = {100, 100};
|
|
view->Scale(scale1, pivot);
|
|
view->Invalidate();
|
|
|
|
timerToClick_->Stop();
|
|
delete timerToClick_;
|
|
timerToClick_ = nullptr;
|
|
}
|
|
|
|
bool TjdUiAppCameraPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
printf("line = %d, TjdUiAppCameraView::CameraOnClickedListener::OnClick", __LINE__);
|
|
if (view.GetViewId() == "take_photo") {
|
|
// OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MENU_LIST);
|
|
// OHOS::NativeAbility::GetInstance().ChangePreSlice(OHOS::TransitionType::TRANSITION_ZOOM);
|
|
const Vector2<float> &scale = {0.8, 0.8};
|
|
Vector2<float> pivot = {100, 100};
|
|
view.Scale(scale, pivot);
|
|
view.Invalidate();
|
|
|
|
if (timerToClick_ == nullptr) {
|
|
timerToClick_ = new OHOS::GraphicTimer(150, TimerCallbackToClick_, &view, false);
|
|
}
|
|
timerToClick_->Start();
|
|
static_print_info("TjdUiAppCameraView::CameraOnClickedListener::OnClick take_photo");
|
|
if (TjdUiAppCameraModel::GetInstance().CanUploadTakePhotoCmd()) {
|
|
uint8 pack_head = PROTOCOL_RES_FRAME_HEAD;
|
|
uint8_t data = 0x00;
|
|
tjd_ble_protocol_send_lefun_data(&pack_head, &data, sizeof(uint8_t), 0x0e);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void TjdUiCameraMsgCenterMessageProc(const Topic topic, Request *req) // 相机弹窗消息处理
|
|
{
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic));
|
|
OHOS::NotificationManager::GetInstance()->ShowNotify(
|
|
[]() -> OHOS::UIViewGroup * {
|
|
g_pv_AppCameraPresenter = new TjdUiAppCameraPresenter(KeyType::KEY_POPUPWINDOW);
|
|
|
|
if (g_messageCameraView == nullptr) {
|
|
g_messageCameraView = new CameraPopupWindow();
|
|
}
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(g_pv_AppCameraPresenter,
|
|
KeyModelType::SYS_KEY_TYPE);
|
|
OHOS::NotificationManager::GetInstance()->RegisterNotifyCleanupFunction([]() {
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST);
|
|
static_print_info("TjdUiShutdownMsgCenterMessageProc RegisterNotifyCleanupFunction");
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::SYS_KEY_TYPE);
|
|
if (timerToClick_ != nullptr) {
|
|
delete timerToClick_;
|
|
timerToClick_ = nullptr;
|
|
}
|
|
OHOS::RootView::GetInstance()->Remove(g_messageCameraView);
|
|
delete g_messageCameraView;
|
|
delete g_pv_AppCameraPresenter;
|
|
g_messageCameraView = nullptr;
|
|
g_pv_AppCameraPresenter = nullptr;
|
|
RunPopOutPageCallback();
|
|
});
|
|
return g_messageCameraView;
|
|
},
|
|
static_cast<uint16_t>(topic), true
|
|
|
|
);
|
|
}
|
|
|
|
} // namespace TJD
|