#include "include.h" #include "func.h" #include "m_sportInfo.h" #include "api.h" #include "ancs_msg.h" #include "m_storage.h" #include "app_variable.h" #if TRACE_EN #define TRACE(...) printf(__VA_ARGS__) #else #define TRACE(...) #endif typedef struct f_camera_t_ { bool sta; u32 enter_tick; } f_camera_t; enum { COMPO_ID_BTN_CAMERA = 1, }; /* 拍照界面亮屏最小时间 */ #define FUNC_CAMERA_SHOW_MIN_TIME 600 // 60s static u32 camera_temp_sleep_time = 0; //创建相机窗体,创建窗体中不要使用功能结构体 func_cb.f_cb compo_form_t *func_camera_form_create(void) { //新建窗体和背景 compo_form_t *frm = compo_form_create(true); compo_shape_t *shape; //设置标题栏 compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME); compo_form_set_title(frm, i18n[STR_CAMERA]); if((SysVariable.ble_state == TRUE)) { // compo_form_add_image(frm, UI_BUF_CAMERA_CAMERA_BIN, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y); //创建圆形 shape = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE,40); compo_shape_set_color(shape, make_color(102, 102, 102)); compo_shape_set_location(shape, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, 80, 80); shape = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE,36); compo_shape_set_color(shape, COLOR_BLACK); compo_shape_set_location(shape, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, 72, 72); shape = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE,27); compo_shape_set_color(shape, COLOR_WHITE); compo_shape_set_location(shape, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, 54, 54); } else{ compo_form_add_image(frm, UI_BUF_CAMERA_ICON_CAMERA_BIN, GUI_SCREEN_CENTER_X-10, 47 + 67); //创建文本 compo_textbox_t *txt = compo_textbox_create(frm, 110); // compo_textbox_set_align_center(txt, true); compo_textbox_set_multiline(txt, TRUE); compo_textbox_set_location(txt, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 70, GUI_SCREEN_WIDTH - 80, 60); compo_textbox_set_autoroll_mode(txt, TEXT_AUTOROLL_MODE_SROLL_CIRC); compo_textbox_set(txt, i18n[STR_CAMERA_REMIND]);//STR_CAMERA_DISCONNECTION } //创建按钮 compo_button_t *btn = compo_button_create(frm); compo_setid(btn, COMPO_ID_BTN_CAMERA); compo_button_set_location(btn, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, 100, 100); // //新建按钮 // compo_button_t *btn; // btn = compo_button_create_by_image(frm, UI_BUF_COMMON_BUTTON_BIN); // compo_button_set_pos(btn, 160, 336); //创建文本 // compo_textbox_t *txt = compo_textbox_create(frm, 110); // // compo_textbox_set_align_center(txt, true); // compo_textbox_set_multiline(txt, false); // compo_textbox_set_location(txt, 120, 216,100,20); // compo_textbox_set_autosize(txt, false); // compo_textbox_set_autoroll_mode(txt, TEXT_AUTOROLL_MODE_SROLL_CIRC); // compo_textbox_set(txt, i18n[STR_CAMERA_DISCONNECTION]); return frm; } //按键事件处理 static void func_camera_click(void) { int id = compo_get_button_id(); switch (id) { case COMPO_ID_BTN_CAMERA: if(ble_is_connected()){ printf("COMPO_ID_BTN_CAMERA"); sys_cb.motor_flag = 1; set_func_motor(80,2,2,1); PROTOCOL_TaskPhoto_Start(); } break; default: break; } } //界面刷新 static void func_camera_interface(void) { f_camera_t *f_camera = (f_camera_t *)func_cb.f_cb; if ((SysVariable.ble_state == TRUE) &&(f_camera->sta == false)) { //销毁窗体 if (func_cb.frm_main != NULL) { compo_form_destroy(func_cb.frm_main); } func_cb.frm_main = func_camera_form_create(); f_camera->sta = true; } } // static void func_camera_animation(void) // { // f_camera_t *f_logo_switching = (f_camera_t *)func_cb.f_cb; // if(tick_check_expire(func_cb.enter_tick, 5000)) { // func_cb.sta = FUNC_CLOCK; // } // } //相机功能事件处理 static void func_camera_process(void) { // func_camera_animation(); func_process(); func_camera_interface(); } /* true:公共处理占用中,false:空闲 */ volatile bool camera_event_state = false; volatile bool func_camera_sta_get(void) { return camera_event_state; } //相机功能消息处理 static void func_camera_message(size_msg_t msg) { switch (msg) { case MSG_CTP_CLICK: func_camera_click(); break; case MSG_CTP_SHORT_UP: break; case MSG_CTP_SHORT_DOWN: break; case MSG_CTP_LONG: break; case KU_BACK: camera_event_state = true; func_back_to(); camera_event_state = false; break; case MSG_CTP_SHORT_LEFT: case MSG_CTP_SHORT_RIGHT: camera_event_state = true; func_message(msg); camera_event_state = false; break; default: func_message(msg); break; } } //进入相机功能 static void func_camera_enter(void) { func_cb.f_cb = func_zalloc(sizeof(f_camera_t)); func_cb.frm_main = func_camera_form_create(); // func_cb.enter_tick = tick_get(); if(ble_is_connected()){ SysVariable.rockFlag = true; DeviveControlAppOpenCamera(DEV_CAMERA_OPEN); } } //退出相机功能 static void func_camera_exit(void) { SysVariable.rockFlag = false; /* 临时更改过亮屏时间,恢复原本时间 */ if (camera_temp_sleep_time) { SysVariable.sleep_time = camera_temp_sleep_time; SysVariable.guioff_delay = SysVariable.sleep_time; SysVariable.sleep_delay = SysVariable.sleep_time; } DeviveControlAppOpenCamera(DEV_CAMERA_CLOSE); func_cb.last = FUNC_CAMERA; camera_event_state = false; bsp_motor_stop(MOTOR_PORT); } //相机功能 void func_camera(void) { printf("%s\n", __func__); func_camera_enter(); /* 如果亮屏时间小于一分钟,临时改成亮屏至少一分钟 */ if (SysVariable.sleep_time < FUNC_CAMERA_SHOW_MIN_TIME) { camera_temp_sleep_time = SysVariable.sleep_time; SysVariable.sleep_time = FUNC_CAMERA_SHOW_MIN_TIME; SysVariable.guioff_delay = SysVariable.sleep_time; SysVariable.sleep_delay = SysVariable.sleep_time; } else { camera_temp_sleep_time = 0; } while (func_cb.sta == FUNC_CAMERA) { func_camera_process(); func_camera_message(msg_dequeue()); } func_camera_exit(); }