262 lines
6.9 KiB
C
262 lines
6.9 KiB
C
#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 enum {
|
||
CAMERA_SHOW_DISCONNECT = 0x00,
|
||
CAMERA_SHOW_BACKSTAGE,
|
||
CAMERA_SHOW_PHOTO,
|
||
} camera_show_e;
|
||
|
||
typedef struct f_camera_t_ {
|
||
camera_show_e get_sta;
|
||
} f_camera_t;
|
||
|
||
enum {
|
||
COMPO_ID_BTN_CAMERA = 1,
|
||
};
|
||
|
||
/* 拍照界面亮屏最小时间 */
|
||
#define FUNC_CAMERA_SHOW_MIN_TIME 600 /* unit:100ms */
|
||
static u32 camera_temp_sleep_time = 0;
|
||
|
||
/* APP未连接 */
|
||
static void func_camera_show_disconnect(compo_form_t *frm)
|
||
{
|
||
compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME);
|
||
compo_form_set_title(frm, i18n[STR_CAMERA]);
|
||
|
||
compo_picturebox_t *pic = compo_picturebox_create(frm, UI_BUF_WORLD_CLOCK_ERROR_BIN);
|
||
compo_picturebox_set_pos(pic, 116, 120);
|
||
|
||
compo_textbox_t *acquiring_txt = compo_textbox_create(frm, 50);
|
||
compo_textbox_set_location(acquiring_txt, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 53, 200, 30);
|
||
compo_textbox_set(acquiring_txt, i18n[STR_CONNECT_APP]);
|
||
}
|
||
|
||
/* APP位于后台 */
|
||
static void func_camera_show_backstage(compo_form_t *frm)
|
||
{
|
||
compo_form_add_image(frm, UI_BUF_CAMERA_ICON_CAMERA_BIN, GUI_SCREEN_CENTER_X - 10, GUI_SCREEN_CENTER_Y - 25);
|
||
|
||
compo_textbox_t *txt = compo_textbox_create(frm, 110);
|
||
compo_textbox_set_multiline(txt, true);
|
||
compo_textbox_set_location(txt, GUI_SCREEN_CENTER_X, 216, 200, 60);
|
||
compo_textbox_set(txt, i18n[STR_APP_OPEN_PHOTO]);
|
||
}
|
||
|
||
/* 显示拍照页面 */
|
||
static void func_camera_show_photo(compo_form_t *frm)
|
||
{
|
||
compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME);
|
||
compo_form_set_title(frm, i18n[STR_CAMERA]);
|
||
|
||
compo_form_add_image(frm, UI_BUF_CAMERA_CAMERA_BIN, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 25);
|
||
|
||
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 + 25, 100, 100);
|
||
}
|
||
|
||
//创建相机窗体,创建窗体中不要使用功能结构体 func_cb.f_cb
|
||
compo_form_t *func_camera_form_create(void)
|
||
{
|
||
/* 新建窗体 */
|
||
compo_form_t *frm = compo_form_create(true);
|
||
|
||
if (!ble_is_connected())
|
||
{
|
||
/* 显示未连接APP提示 */
|
||
func_camera_show_disconnect(frm);
|
||
}
|
||
else
|
||
{
|
||
if (SysVariable.app_active)
|
||
{
|
||
/* APP处于前台显示拍照界面 */
|
||
func_camera_show_photo(frm);
|
||
}
|
||
else
|
||
{
|
||
/* APP未在前台提示 */
|
||
func_camera_show_backstage(frm);
|
||
}
|
||
}
|
||
|
||
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() && SysVariable.app_active)
|
||
{
|
||
printf("COMPO_ID_BTN_CAMERA");
|
||
sys_cb.motor_flag = 1;
|
||
set_func_motor(80, 2, 2, 1);
|
||
PROTOCOL_TaskPhoto_Start();
|
||
}
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/* 获取拍照当前显示状态 */
|
||
static camera_show_e func_camera_show_state_get(void)
|
||
{
|
||
if (!ble_is_connected()) {
|
||
/* 显示未连接APP提示 */
|
||
return CAMERA_SHOW_DISCONNECT;
|
||
} else {
|
||
if (SysVariable.app_active) {
|
||
/* APP处于前台显示拍照界面 */
|
||
return CAMERA_SHOW_PHOTO;
|
||
} else {
|
||
/* APP未在前台提示 */
|
||
return CAMERA_SHOW_BACKSTAGE;
|
||
}
|
||
}
|
||
}
|
||
|
||
//相机功能事件处理
|
||
static void func_camera_process(void)
|
||
{
|
||
f_camera_t *f_camera = (f_camera_t *)func_cb.f_cb;
|
||
|
||
camera_show_e state = func_camera_show_state_get();
|
||
if (f_camera->get_sta != state)
|
||
{
|
||
/* 销毁窗体 - 刷新 */
|
||
if (func_cb.frm_main != NULL) {
|
||
compo_form_destroy(func_cb.frm_main);
|
||
}
|
||
|
||
func_cb.frm_main = func_camera_form_create();
|
||
|
||
if (ble_is_connected() && SysVariable.app_active) {
|
||
SysVariable.rockFlag = true;
|
||
DeviveControlAppOpenCamera(DEV_CAMERA_OPEN);
|
||
}
|
||
}
|
||
f_camera->get_sta = state;
|
||
|
||
func_process();
|
||
}
|
||
|
||
/* 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();
|
||
|
||
if (ble_is_connected() && SysVariable.app_active) {
|
||
SysVariable.rockFlag = true;
|
||
DeviveControlAppOpenCamera(DEV_CAMERA_OPEN);
|
||
}
|
||
|
||
f_camera_t *f_camera = (f_camera_t *)func_cb.f_cb;
|
||
f_camera->get_sta = func_camera_show_state_get();
|
||
}
|
||
|
||
//退出相机功能
|
||
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();
|
||
}
|