//电机开关机的回调
void power_handle(lv_obj_t *obj, lv_event_t event)
{
static bool power_flag = true;
static uint8_t light_value;
if (event == LV_EVENT_SHORT_CLICKED)
{
if(power_flag)
{
board_backlight_control(50);
lv_obj_set_click(image_sub_app,false);
lv_obj_set_click(image_sub_mode,false);
lv_obj_set_click(image_sub_set,false);
lv_obj_set_click(image_sub_wind,false);
lv_obj_set_click(bar_huiwind,false);
lv_obj_set_click(bar_wind,false);
lv_obj_set_click(image_partition,false);
sys_info.power_close = 1;
store_data.power_flag = 1;
}
else
{
qmsd_storage_get_u8("set_screen","backlight_value",&light_value);
board_backlight_control(light_value);
lv_obj_set_click(image_sub_app,true);
lv_obj_set_click(image_sub_mode,true);
lv_obj_set_click(image_sub_set,true);
lv_obj_set_click(image_sub_wind,true);
lv_obj_set_click(bar_huiwind,true);
lv_obj_set_click(bar_wind,true);
lv_obj_set_click(image_partition,true);
sys_info.power_open = 1;
sys_info.bar_songfeng = 1;
sys_info.bar_huifeng = 1;
store_data.power_flag = 0;
}
power_flag = !power_flag;
START_STORE_TIME();
}
}
void sub_mode_handle(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_SHORT_CLICKED)
{
lv_obj_set_hidden(image_mode_pop_make,!lv_obj_get_hidden(image_mode_pop_make));
lv_task_reset(task_mode_pop);
}
}
void sub_set_handle(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_SHORT_CLICKED)
{
screen_main_delete();
lv_obj_set_hidden(all_top_info,true);
screen_set_show();
ESP_LOGI(TAG, "Clicked");
printf("set scr in boot malloc %d, out malloc %d\n", heap_caps_get_free_size(MALLOC_CAP_INTERNAL), heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
}
}
static void my_wind_level_func(int *fan1, int *fan2,int level)
{
if( *fan1 > level && *fan2 > level)
{
*fan1 = 1;
*fan2 = 1;
}
else if(*fan1 > level)
{
*fan1 = level;
}
else if(*fan2 > level)
{
*fan2 = level;
}
}
extern int g_image_wind_value;
//点风扇
void sub_wind_handle(lv_obj_t *obj, lv_event_t event)
{
static int fan1_value;
static int fan2_value;
int wind_value = g_image_wind_value;
if (event == LV_EVENT_SHORT_CLICKED)
{
fan1_value = lv_slider_get_value(bar_wind);
fan2_value = lv_slider_get_value(bar_huiwind);
if(store_data.mode_flag == 2){
store_data.mode_flag = 1;
lv_obj_set_click(bar_huiwind,true);
lv_obj_set_click(bar_wind,true);
lv_img_set_src(hand_mode_pop,&img_main_mode_pop_on);
lv_img_set_src(auto_mode_pop,&img_main_mode_pop_off);
lv_img_set_src(sleep_mode_pop,&img_main_mode_pop_off);
}
fan1_value++;
if(sys_info.paifeng_change == 1){
fan2_value = 1;
}else{
fan2_value++;
}
START_STORE_TIME();
my_wind_level_func(&fan1_value, &fan2_value, wind_value);
lv_slider_set_value(bar_wind, fan1_value,LV_ANIM_OFF);
lv_slider_set_value(bar_huiwind, fan2_value,LV_ANIM_OFF);
lv_event_send(bar_wind,LV_EVENT_VALUE_CHANGED,NULL);
lv_event_send(bar_huiwind,LV_EVENT_VALUE_CHANGED,NULL);
}
}
void sub_app_handle(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_SHORT_CLICKED)
{
lv_task_reset(task_app_pop);
lv_obj_set_hidden(image_app_pop_make,!lv_obj_get_hidden(image_app_pop_make));
}
}
void set_return_handle(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_SHORT_CLICKED)
{
lv_obj_set_hidden(all_top_info,false);
screen_set_delete();
screen_main_show();
}
}
void part_control_handle(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_SHORT_CLICKED)
{
screen_main_delete();
screen_part0_show();
}
}
//点模式后面的回调函数
void mode_pop_handle(lv_obj_t *obj, lv_event_t event)
{
int x1, x2;
if (event == LV_EVENT_SHORT_CLICKED)
{
lv_task_reset(task_mode_pop);
uint8_t light_value;
if(!strcmp(obj->qmsd_id,"hand_mode_pop"))
{
lv_img_set_src(hand_mode_pop,&img_main_mode_pop_on);
lv_img_set_src(auto_mode_pop,&img_main_mode_pop_off);
lv_img_set_src(sleep_mode_pop,&img_main_mode_pop_off);
qmsd_storage_get_u8("set_screen","backlight_value",&light_value);
board_backlight_control(light_value);
if(store_data.mode_flag == 2)
{
int16_t songfeng = 1, huifeng = 1;
qmsd_storage_get_i16("main_screen","songfeng",&songfeng);
qmsd_storage_get_i16("main_screen","huifeng",&huifeng);
lv_slider_set_value(bar_wind,songfeng,LV_ANIM_OFF);
lv_slider_set_value(bar_huiwind,huifeng,LV_ANIM_OFF);
lv_event_send(bar_wind,LV_EVENT_VALUE_CHANGED,NULL);
lv_event_send(bar_huiwind,LV_EVENT_VALUE_CHANGED,NULL);
}
lv_obj_set_click(bar_huiwind,true);
lv_obj_set_click(bar_wind,true);
store_data.mode_flag = 1;
sys_info.sleep_mode_flag = 0;
}
else if(!strcmp(obj->qmsd_id,"auto_mode_pop"))
{
lv_img_set_src(hand_mode_pop,&img_main_mode_pop_off);
lv_img_set_src(auto_mode_pop,&img_main_mode_pop_on);
lv_img_set_src(sleep_mode_pop,&img_main_mode_pop_off);
qmsd_storage_get_u8("set_screen","backlight_value",&light_value);
board_backlight_control(light_value);
if(store_data.mode_flag == 1)
{
qmsd_storage_set_i16("main_screen","songfeng",lv_slider_get_value(bar_wind));
qmsd_storage_set_i16("main_screen","huifeng",lv_slider_get_value(bar_huiwind));
}
lv_slider_set_value(bar_wind,sys_value.sf_dangwei,LV_ANIM_OFF);
lv_slider_set_value(bar_huiwind,sys_value.hf_dangwei,LV_ANIM_OFF);
lv_event_send(bar_wind,LV_EVENT_VALUE_CHANGED,NULL);
lv_event_send(bar_huiwind,LV_EVENT_VALUE_CHANGED,NULL);
lv_obj_set_click(bar_huiwind,false);
lv_obj_set_click(bar_wind,false);
store_data.mode_flag = 2;
sys_info.sleep_mode_flag = 0;
}
else if(!strcmp(obj->qmsd_id,"sleep_mode_pop"))
{
lv_img_set_src(hand_mode_pop,&img_main_mode_pop_off);
lv_img_set_src(auto_mode_pop,&img_main_mode_pop_off);
lv_img_set_src(sleep_mode_pop,&img_main_mode_pop_on);
sys_info.sleep_mode_flag = 1;
store_data.mode_flag = 3;
}
else
{
ESP_LOGI(TAG,"obj = %s",obj->qmsd_id);
}
START_STORE_TIME();
}
}
//送风回风值发送改变的回调
void wind_slider_hadle(lv_obj_t *obj, lv_event_t event)
{
uint16_t value;
int x1, x2;
if (event == LV_EVENT_VALUE_CHANGED)
{
value = lv_slider_get_value(obj);
if((value > 1) && (store_data.mode_flag == 3) )
{
lv_event_send(hand_mode_pop,LV_EVENT_SHORT_CLICKED,NULL);
}
if (!strcmp(obj->qmsd_id, "bar_wind1"))
{
lv_label_set_text_fmt(wind_level1, "%d档", value);
x1 = (bar_wind->coords.x2 - bar_wind->coords.x1 + 1) * lv_slider_get_value(bar_wind) / (lv_slider_get_max_value(obj)) ;
lv_obj_align_origo(songfengwind_img, bar_wind, LV_ALIGN_IN_LEFT_MID, x1, 0);
//printf("wind_slider_hadle...songfeng...value:%d\n",value);
sys_info.bar_songfeng = 1;
store_data.sf_dangwei = value;
}
else if(!strcmp(obj->qmsd_id,"bar_wind2"))
{
if(sys_info.paifeng_change == 1){
value = 1;
}else{
value = lv_slider_get_value(obj);
}
//printf("wind_slider_hadle...huifeng...value:%d\n",value);
lv_label_set_text_fmt(main_wind_level2, "%d档", value);
x2 = (bar_huiwind->coords.x2 - bar_huiwind->coords.x1 + 1) * value / (lv_slider_get_max_value(obj)) ;
lv_obj_align_origo(huifengwind_img, bar_huiwind, LV_ALIGN_IN_LEFT_MID, x2, 0);
sys_info.bar_huifeng = 1;
store_data.hf_dangwei = value;
}
START_STORE_TIME();
}
}
//内循环,外循环,混风的点击事件
void app_pop_choose_handler(lv_obj_t *obj, lv_event_t event)
{
static int slider_value;
if (event == LV_EVENT_VALUE_CHANGED) {
lv_task_reset(task_app_pop);
slider_value = lv_slider_get_value(obj);
switch (slider_value)
{
case 0:
lv_obj_set_style_local_text_color(app_pop_neixunhuan, 0, 0, LV_COLOR_MAKE(0x10,0x10,0x10));
lv_obj_set_style_local_text_color(app_pop_hunfeng, 0, 0, LV_COLOR_MAKE(0x8E,0x8E,0x8E));
lv_obj_set_style_local_text_color(app_pop_waixunhuan, 0, 0, LV_COLOR_MAKE(0x8E,0x8E,0x8E));
printf("neixunhuan...\n");
sys_info.paifeng_change = 1;
sys_info.s_neixunhuan = 1;
store_data.pre_xunhuan = NEIXUNHUAN;
break;
case 1:
lv_obj_set_style_local_text_color(app_pop_neixunhuan, 0, 0, LV_COLOR_MAKE(0x8E,0x8E,0x8E));
lv_obj_set_style_local_text_color(app_pop_hunfeng, 0, 0, LV_COLOR_MAKE( 0x8E,0x8E,0x8E));
lv_obj_set_style_local_text_color(app_pop_waixunhuan, 0, 0, LV_COLOR_MAKE(0x10,0x10,0x10));
printf("waixunhuan...\n");
sys_info.paifeng_change = 0;
sys_info.s_waixunhuan = 1;
store_data.pre_xunhuan = WAIXUNHUAN;
break;
case 2:
lv_obj_set_style_local_text_color(app_pop_neixunhuan, 0, 0, LV_COLOR_MAKE(0x8E,0x8E,0x8E));
lv_obj_set_style_local_text_color(app_pop_hunfeng, 0, 0, LV_COLOR_MAKE(0x10,0x10,0x10 ));
lv_obj_set_style_local_text_color(app_pop_waixunhuan, 0, 0, LV_COLOR_MAKE(0x8E,0x8E,0x8E));
printf("hunfeng...\n");
sys_info.paifeng_change = 1;
sys_info.s_hunfeng=1;
store_data.pre_xunhuan = HUNFENG;
break;
default:
break;
}
START_STORE_TIME();
//切换手动模式
if(store_data.mode_flag == 2){
store_data.mode_flag = 1;
lv_obj_set_click(bar_huiwind,true);
lv_obj_set_click(bar_wind,true);
lv_img_set_src(hand_mode_pop,&img_main_mode_pop_on);
lv_img_set_src(auto_mode_pop,&img_main_mode_pop_off);
lv_img_set_src(sleep_mode_pop,&img_main_mode_pop_off);
}
}
}
/**
* @brief 设置界面回调函数
*
* @param obj wifi配置回调
* @param event
*/
lv_obj_t *wifi_config_make;
lv_obj_t * wifi_config_ta;
lv_obj_t * wifi_config_kb;
char cur_ssid[30];
static void kb_event_cb(lv_obj_t * keyboard, lv_event_t e)
{
lv_keyboard_def_event_cb(wifi_config_kb, e);
if(e == LV_EVENT_CANCEL) {
lv_keyboard_set_textarea(wifi_config_kb, NULL);
lv_obj_del(wifi_config_kb);
wifi_config_kb = NULL;
}
if(e == LV_EVENT_APPLY)
{
printf("ssid = %s\t password = %s\n",cur_ssid,lv_textarea_get_text(wifi_config_ta));
qmsd_wifi_sta_config(cur_ssid, lv_textarea_get_text(wifi_config_ta), NULL);
lv_obj_t *parent = lv_obj_get_parent(keyboard);
lv_obj_del(parent);
wifi_config_kb = NULL;
parent = NULL;
}
}
static void wifi_config_kb_create(void)
{
wifi_config_kb = lv_keyboard_create(wifi_config_make, NULL);
lv_keyboard_set_cursor_manage(wifi_config_kb, true);
lv_obj_set_event_cb(wifi_config_kb, kb_event_cb);
lv_keyboard_set_textarea(wifi_config_kb, wifi_config_ta);
}
static void ta_event_cb(lv_obj_t * ta_local, lv_event_t e)
{
if(e == LV_EVENT_CLICKED && wifi_config_kb == NULL) {
wifi_config_kb_create();
}
}
void wifi_config_return_handle(lv_obj_t * obj, lv_event_t e)
{
if(e == LV_EVENT_SHORT_CLICKED)
{
lv_obj_t *parent = lv_obj_get_parent(obj);
lv_obj_del(parent);
wifi_config_kb = NULL;
parent = NULL;
}
}
void wifi_connect_handle(lv_obj_t * obj, lv_event_t event)
{
if (event == LV_EVENT_SHORT_CLICKED) //LV_EVENT_LONG_PRESSED
{
wifi_config_make = lv_obj_create(screen_set,NULL);
lv_obj_set_size(wifi_config_make,480,480);
lv_obj_set_style_local_bg_opa(wifi_config_make, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_90);
lv_obj_set_style_local_border_opa(wifi_config_make, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 0);
lv_obj_set_style_local_bg_color(wifi_config_make, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,LV_COLOR_BLACK);
lv_obj_t *chooseed_ssid = lv_label_create(wifi_config_make,NULL);
strcpy(cur_ssid,lv_label_get_text(obj));
// cur_ssid = lv_label_get_text(obj);
lv_label_set_text_fmt(chooseed_ssid,"SSID :%s",cur_ssid);
lv_obj_set_style_local_text_font(chooseed_ssid,0,0,&ali_font_16);
lv_obj_set_style_local_text_color(chooseed_ssid,0,0,LV_COLOR_WHITE);
lv_obj_align_origo(chooseed_ssid, wifi_config_make, LV_ALIGN_IN_TOP_MID, 0, 40);
lv_obj_t *label_guide = lv_label_create(wifi_config_make,NULL);
lv_label_set_text(label_guide,"input wifi password");
lv_obj_set_style_local_text_font(label_guide,0,0,&ali_font_16);
lv_obj_set_style_local_text_color(label_guide,0,0,LV_COLOR_WHITE);
lv_obj_align_origo(label_guide, wifi_config_make, LV_ALIGN_IN_TOP_MID, 0, 80);
lv_obj_t *wifi_config_return = lv_img_create(wifi_config_make,NULL);
lv_img_set_src(wifi_config_return, &imgreturn_png);
lv_obj_set_pos(wifi_config_return, 20, 18);
lv_obj_set_click(wifi_config_return,true);
lv_obj_set_style_local_image_recolor(wifi_config_return,LV_IMG_PART_MAIN,LV_STATE_PRESSED,LV_COLOR_BLACK);
lv_obj_set_style_local_image_recolor_opa(wifi_config_return,LV_IMG_PART_MAIN,LV_STATE_PRESSED,60);
lv_obj_set_event_cb(wifi_config_return, wifi_config_return_handle);
lv_obj_set_ext_click_area(wifi_config_return,30,30,30,30);
wifi_config_ta = lv_textarea_create(wifi_config_make, NULL);
lv_obj_set_size(wifi_config_ta,183,40);
lv_obj_align_origo(wifi_config_ta, wifi_config_make, LV_ALIGN_IN_TOP_MID, 0, 150);
lv_obj_set_event_cb(wifi_config_ta, ta_event_cb);
lv_textarea_set_text(wifi_config_ta, "");
lv_obj_set_style_local_text_font(wifi_config_ta, 0, 0, &ali_font_20);
int max_h = LV_VER_RES / 2 - LV_DPI / 8;
if(lv_obj_get_height(wifi_config_ta) > max_h) lv_obj_set_height(wifi_config_ta, max_h);
wifi_config_kb_create();
}
}