#include "include.h" #include "func.h" #include "app_variable.h" #if TRACE_EN #define TRACE(...) printf(__VA_ARGS__) #else #define TRACE(...) #endif #define OFFSET(x) ((x)<127?(x):(x-256) ) typedef struct f_weather_t_ { bool sta; s16 cur_temp; s16 n1day_temp; s16 n2day_temp; s16 cur_temp_low; s16 cur_temp_hig; } f_weather_t; enum{ //文字 COMPO_ID_TXT_CUR_TEMP = 1, COMPO_ID_TXT_TIME, COMPO_ID_PIC_BIG, COMPO_ID_PIC_SMALL_LEF, COMPO_ID_PIC_SMALL_CEN, COMPO_ID_PIC_SMALL_RIG, COMPO_ID_TXT_TODAY_TEMP_BIG, COMPO_ID_TXT_GET_WEATHER_TIME, COMPO_ID_TXT_TODAY_TEMP_SMALL, COMPO_ID_TXT_TOMORROW_TEMP, COMPO_ID_TXT_3THDAY_TEMP, COMPO_ID_TXT_WEEK_1, }; //连上了蓝牙 static void func_weather_show_connect_ble_detail(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_WEATHER]); f_weather_t *f_weather = (f_weather_t *)func_cb.f_cb; char week_en_text[][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; char week_ch_text[][12] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; //创建蓝色矩形框 背景1 compo_shape_t *blue_btn_bg ; blue_btn_bg = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE,16); compo_shape_set_color(blue_btn_bg, make_color(60, 134, 244)); compo_shape_set_location(blue_btn_bg, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, GUI_SCREEN_WIDTH, GUI_SCREEN_HEIGHT); //创建白色矩形框 compo_shape_t *white_btn_lef ; white_btn_lef = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE,26); compo_shape_set_color(white_btn_lef, COLOR_WHITE); compo_shape_set_location(white_btn_lef, GUI_SCREEN_CENTER_X - 78, 220 , 56, 110); compo_shape_set_alpha(white_btn_lef, 165); compo_shape_t *white_btn_cen ; white_btn_cen = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE,26); compo_shape_set_color(white_btn_cen, COLOR_WHITE); compo_shape_set_location(white_btn_cen, GUI_SCREEN_CENTER_X, 220 , 56, 110); compo_shape_set_alpha(white_btn_cen, 165); compo_shape_t *white_btn_rig ; white_btn_rig = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE,26); compo_shape_set_color(white_btn_rig, COLOR_WHITE); compo_shape_set_location(white_btn_rig, GUI_SCREEN_CENTER_X + 78, 220 , 56, 110); compo_shape_set_alpha(white_btn_rig, 165); //创建 左边标题文本框 compo_textbox_t *txt_sex = compo_textbox_create(frm, 50); compo_textbox_set_align_center(txt_sex,FALSE); compo_textbox_set_location(txt_sex, 32, 9, GUI_SCREEN_CENTER_X, 30); compo_textbox_set_autoroll_mode(txt_sex, TEXT_AUTOROLL_MODE_SROLL_CIRC); compo_textbox_set(txt_sex, i18n[STR_WEATHER]); //右上角时间 char buf_time[10] = {0}; if (SysVariable.deviceInfo.timeType == TIME_TYPE_12_HOUR) sprintf(buf_time, "%02d:%02d%s", get_autoformat_hour(SysVariable.Rtc.hour), SysVariable.Rtc.min, SysVariable.Rtc.hour >= 12 ? "PM" : "AM"); else sprintf(buf_time, "%02d:%02d", SysVariable.Rtc.hour, SysVariable.Rtc.min); compo_textbox_t *txt_time = compo_textbox_create(frm, 8); compo_setid(txt_time, COMPO_ID_TXT_TIME); compo_textbox_set_location(txt_time, 180, 16, 0, 0); compo_textbox_set_autosize(txt_time, true); compo_textbox_set(txt_time, buf_time); compo_textbox_set_visible(txt_time, true); //创建天气图片 compo_picturebox_t *pic = compo_picturebox_create(frm, UI_BUF_WEATHER_LIST_BIN); compo_setid(pic,COMPO_ID_PIC_BIG); compo_picturebox_cut(pic, SysVariable.weather.type, WEATHER_CNT); compo_picturebox_set_pos(pic, 30+24, 54+20); // compo_bonddata(pic, COMPO_BOND_WEATHER); compo_picturebox_t *pic_lef = compo_picturebox_create(frm, UI_BUF_WEATHER_LIST_BIN); compo_setid(pic,COMPO_ID_PIC_SMALL_LEF); compo_picturebox_cut(pic_lef, SysVariable.weather.type, WEATHER_CNT); compo_picturebox_set_size(pic_lef,28,30); compo_picturebox_set_pos(pic_lef, GUI_SCREEN_CENTER_X - 78, 184); // compo_bonddata(pic_lef, COMPO_BOND_WEATHER); compo_picturebox_t *pic_cen = compo_picturebox_create(frm, UI_BUF_WEATHER_LIST_BIN); compo_setid(pic,COMPO_ID_PIC_SMALL_CEN); compo_picturebox_cut(pic_cen, SysVariable.weather.n1day_type, WEATHER_CNT); compo_picturebox_set_size(pic_cen,28,30); compo_picturebox_set_pos(pic_cen, GUI_SCREEN_CENTER_X, 184); // compo_bonddata(pic_cen, COMPO_BOND_WEATHER); compo_picturebox_t *pic_rig = compo_picturebox_create(frm, UI_BUF_WEATHER_LIST_BIN); compo_setid(pic,COMPO_ID_PIC_SMALL_RIG); compo_picturebox_cut(pic_rig, SysVariable.weather.n2day_type, WEATHER_CNT); compo_picturebox_set_size(pic_rig,28,30); compo_picturebox_set_pos(pic_rig, GUI_SCREEN_CENTER_X + 78, 184); // compo_bonddata(pic_rig, COMPO_BOND_WEATHER); //创建天气 当前温度 数字 compo_textbox_t *txt_cur_temp = compo_textbox_create(frm, 6); compo_textbox_set_font(txt_cur_temp,UI_BUF_0FONT_FONT_NUM_24_BIN); compo_setid(txt_cur_temp,COMPO_ID_TXT_CUR_TEMP); compo_textbox_set_align_center(txt_cur_temp,FALSE); compo_textbox_set_pos(txt_cur_temp, 25, 103); // compo_textbox_set(txt_cur_temp, "30℃"); // compo_bonddata(txt_cur_temp, COMPO_BOND_TEMPERATURE); // compo_textbox_set(txt_height, i18n[STR_PER_HEIGHT]); //创建天气 当天温度范围 数字 compo_textbox_t *txt_today_temp_big = compo_textbox_create(frm, 12); compo_textbox_set_font(txt_today_temp_big,UI_BUF_0FONT_FONT_NUM_24_BIN); compo_setid(txt_today_temp_big,COMPO_ID_TXT_TODAY_TEMP_BIG); compo_textbox_set_location(txt_today_temp_big, 158, 83,180,40); //新建图片 获取时间图标 // compo_form_add_image(frm, UI_BUF_WEATHER_ICON_REFRESH_BIN, 142, 112); //创建天气 获取时间 数字 // compo_textbox_t *txt_get_time = compo_textbox_create(frm, 7); // compo_textbox_set_align_center(txt_get_time,FALSE); // compo_setid(txt_get_time,COMPO_ID_TXT_GET_WEATHER_TIME); // compo_textbox_set_pos(txt_get_time, 153, 105); // compo_textbox_set(txt_get_time, "20:36pm"); // 获取 当天天气 温度范围 【当天温度】 compo_textbox_t *txt_today_temp_small = compo_textbox_create(frm, 11); compo_textbox_set_font(txt_today_temp_small,UI_BUF_0FONT_FONT_WEATHER_BIN); compo_setid(txt_today_temp_small,COMPO_ID_TXT_TODAY_TEMP_SMALL); compo_textbox_set_autoroll_mode(txt_today_temp_small, TEXT_AUTOROLL_MODE_SROLL_CIRC); // compo_textbox_set_multiline(txt_today_temp_small,true); compo_textbox_set_location(txt_today_temp_small, GUI_SCREEN_CENTER_X - 78, 220,50,30); //获取 明天天气 温度范围 compo_textbox_t *txt_tomorrow_temp = compo_textbox_create(frm, 11); compo_textbox_set_font(txt_tomorrow_temp,UI_BUF_0FONT_FONT_WEATHER_BIN); compo_setid(txt_tomorrow_temp,COMPO_ID_TXT_TOMORROW_TEMP); compo_textbox_set_autoroll_mode(txt_tomorrow_temp, TEXT_AUTOROLL_MODE_SROLL_CIRC); // compo_textbox_set_multiline(txt_tomorrow_temp,true); compo_textbox_set_location(txt_tomorrow_temp, GUI_SCREEN_CENTER_X, 220,50,30); //获取 后天天气 温度范围 compo_textbox_t *txt_thrday_temp = compo_textbox_create(frm, 11); compo_textbox_set_font(txt_thrday_temp,UI_BUF_0FONT_FONT_WEATHER_BIN); compo_setid(txt_thrday_temp,COMPO_ID_TXT_3THDAY_TEMP); compo_textbox_set_autoroll_mode(txt_tomorrow_temp, TEXT_AUTOROLL_MODE_SROLL_CIRC); // compo_textbox_set_multiline(txt_thrday_temp,true); compo_textbox_set_location(txt_thrday_temp, GUI_SCREEN_CENTER_X + 78, 220,50,30); //星期 compo_textbox_t *txt_today = compo_textbox_create(frm, 4); compo_textbox_set_font(txt_today,UI_BUF_0FONT_FONT_BIN); compo_textbox_set_location(txt_today, GUI_SCREEN_CENTER_X-78, 254, 44, 30); compo_textbox_set_autoroll_mode(txt_today, TEXT_AUTOROLL_MODE_SROLL_CIRC); if (SysVariable.deviceInfo.language == LANGUAGE_TYPE_Chinese) compo_textbox_set(txt_today, week_ch_text[SysVariable.Rtc.weekday]); else compo_textbox_set(txt_today, week_en_text[SysVariable.Rtc.weekday]); compo_textbox_t *txt_week2 = compo_textbox_create(frm, 4); compo_textbox_set_font(txt_week2, UI_BUF_0FONT_FONT_BIN); compo_textbox_set_location(txt_week2, GUI_SCREEN_CENTER_X, 254, 44, 30); compo_textbox_set_autoroll_mode(txt_week2, TEXT_AUTOROLL_MODE_SROLL_CIRC); if (SysVariable.deviceInfo.language == LANGUAGE_TYPE_Chinese) compo_textbox_set(txt_week2, week_ch_text[(SysVariable.Rtc.weekday + 1) % 7]); else compo_textbox_set(txt_week2, week_en_text[(SysVariable.Rtc.weekday + 1) % 7]); compo_textbox_t *txt_week3 = compo_textbox_create(frm, 4); compo_textbox_set_font(txt_week3, UI_BUF_0FONT_FONT_BIN); compo_textbox_set_location(txt_week3, GUI_SCREEN_CENTER_X + 78, 254, 44, 30); compo_textbox_set_autoroll_mode(txt_week3, TEXT_AUTOROLL_MODE_SROLL_CIRC); if (SysVariable.deviceInfo.language == LANGUAGE_TYPE_Chinese) compo_textbox_set(txt_week3, week_ch_text[(SysVariable.Rtc.weekday + 2) % 7]); else compo_textbox_set(txt_week3, week_en_text[(SysVariable.Rtc.weekday + 2) % 7]); } //未连接蓝牙或者未获取天气 static void func_weather_show_disconnect_ble_detail(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_WEATHER]); //提示语 compo_textbox_t *txt_remind = compo_textbox_create(frm, 150); // compo_textbox_set_align_center(txt_today,FALSE); compo_textbox_set_multiline(txt_remind,true); compo_textbox_set_location(txt_remind, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y +20, GUI_SCREEN_WIDTH - 20, 80); // compo_textbox_set_forecolor(txt_remind,make_color(60,134,244)); compo_textbox_set_autoroll_mode(txt_remind, TEXT_AUTOROLL_MODE_SROLL_CIRC); compo_textbox_set(txt_remind, i18n[STR_SYNC_WEATHER_REMIND]); } //创建天气窗体,创建窗体中不要使用功能结构体 func_cb.f_cb compo_form_t *func_weather_form_create(void) { //新建窗体和背景 compo_form_t *frm = compo_form_create(true); if(SysVariable.weather.getFlag==true){ func_weather_show_connect_ble_detail(frm); } else{ func_weather_show_disconnect_ble_detail(frm); } return frm; } //天气界面刷新 static void func_weather_refresh(void) { compo_picturebox_t *pic = NULL; compo_textbox_t *txt = NULL; f_weather_t *f_weather = (f_weather_t *)func_cb.f_cb; f_weather->cur_temp = SysVariable.weather.temperature; f_weather->cur_temp_low = SysVariable.weather.minTemp; f_weather->cur_temp_hig = SysVariable.weather.maxTemp; f_weather->n1day_temp = SysVariable.weather.n1day_temperature; f_weather->n2day_temp = SysVariable.weather.n2day_temperature; f_weather->cur_temp = weather_temperature_transform(OFFSET(f_weather->cur_temp))/100; f_weather->cur_temp_low = weather_temperature_transform(OFFSET(f_weather->cur_temp_low))/100; f_weather->cur_temp_hig = weather_temperature_transform(OFFSET(f_weather->cur_temp_hig))/100; f_weather->n1day_temp = weather_temperature_transform(OFFSET(f_weather->n1day_temp))/100; f_weather->n2day_temp = weather_temperature_transform(OFFSET(f_weather->n2day_temp))/100; char buf[16]; memset(buf, 0, sizeof(buf)); if(SysVariable.weather.getFlag==true) { pic = (compo_picturebox_t *)compo_getobj_byid(COMPO_ID_PIC_BIG); if(pic) compo_picturebox_cut(pic, SysVariable.weather.type, WEATHER_CNT); pic = (compo_picturebox_t *)compo_getobj_byid(COMPO_ID_PIC_SMALL_LEF); if(pic) compo_picturebox_cut(pic, SysVariable.weather.type, WEATHER_CNT); pic = (compo_picturebox_t *)compo_getobj_byid(COMPO_ID_PIC_SMALL_CEN); if(pic) compo_picturebox_cut(pic, SysVariable.weather.n1day_type, WEATHER_CNT); pic = (compo_picturebox_t *)compo_getobj_byid(COMPO_ID_PIC_SMALL_RIG); if(pic) compo_picturebox_cut(pic, SysVariable.weather.n2day_type, WEATHER_CNT); //获取时的当前天气温度 txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_TXT_CUR_TEMP); if(SysVariable.deviceInfo.distanceUnit == UNIT_TYPE_INCH){ snprintf(buf, sizeof(buf), "%d℉", f_weather->cur_temp); } else{ snprintf(buf, sizeof(buf), "%d℃", f_weather->cur_temp); } compo_textbox_set(txt, buf); //获取时的时间 // txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_TXT_GET_WEATHER_TIME); // snprintf(buf, sizeof(buf), "%d℉", (SysVariable.weather.temperature*9/5+ 32)); // compo_textbox_set(txt, buf); //获取当天 天气温度范围 txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_TXT_TODAY_TEMP_BIG); if(SysVariable.deviceInfo.distanceUnit == UNIT_TYPE_INCH){ snprintf(buf, sizeof(buf), "%d℉/%d℉", f_weather->cur_temp_low,f_weather->cur_temp_hig); } else{ snprintf(buf, sizeof(buf), "%d℃/%d℃", f_weather->cur_temp_low,f_weather->cur_temp_hig); } compo_textbox_set(txt, buf); //获取当天 天气温度范围 txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_TXT_TODAY_TEMP_SMALL); if(SysVariable.deviceInfo.distanceUnit == UNIT_TYPE_INCH){ // snprintf(buf, sizeof(buf), "%d~%d℉", (SysVariable.weather.minTemp*9/5+ 32),(SysVariable.weather.maxTemp*9/5+ 32)); snprintf(buf, sizeof(buf), "%d℉", f_weather->cur_temp); } else{ // snprintf(buf, sizeof(buf), "%d~%d℃", SysVariable.weather.minTemp,SysVariable.weather.maxTemp); snprintf(buf, sizeof(buf), "%d℃", f_weather->cur_temp); } compo_textbox_set(txt, buf); //获取明天 天气温度范围 txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_TXT_TOMORROW_TEMP); if(SysVariable.deviceInfo.distanceUnit == UNIT_TYPE_INCH){ // snprintf(buf, sizeof(buf), "%d~%d℉", (SysVariable.weather.n1day_minTemp*9/5+ 32),(SysVariable.weather.n1day_maxTemp*9/5+ 32)); snprintf(buf, sizeof(buf), "%d℉", f_weather->n1day_temp); } else{ // snprintf(buf, sizeof(buf), "%d~%d℃", SysVariable.weather.n1day_minTemp,SysVariable.weather.n1day_maxTemp); snprintf(buf, sizeof(buf), "%d℃", f_weather->n1day_temp); } compo_textbox_set(txt, buf); //获取后天 天气温度范围 txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_TXT_3THDAY_TEMP); if(SysVariable.deviceInfo.distanceUnit == UNIT_TYPE_INCH){ // snprintf(buf, sizeof(buf), "%d~%d℉", (SysVariable.weather.n2day_minTemp*9/5+ 32),(SysVariable.weather.n2day_maxTemp*9/5+ 32)); snprintf(buf, sizeof(buf), "%d℉", f_weather->n2day_temp); } else{ // snprintf(buf, sizeof(buf), "%d~%d℃", SysVariable.weather.n2day_minTemp,SysVariable.weather.n2day_maxTemp); snprintf(buf, sizeof(buf), "%d℃", f_weather->n2day_temp); } compo_textbox_set(txt, buf); } else{ SysVariable.weather.n1day_type = 0; SysVariable.weather.n2day_type = 0; } } static void func_weather_interface(void) { f_weather_t *f_weather = (f_weather_t *)func_cb.f_cb; if ((SysVariable.weather.getFlag == true) &&(f_weather->sta == false)) { //销毁窗体 if (func_cb.frm_main != NULL) { compo_form_destroy(func_cb.frm_main); } func_cb.frm_main = func_weather_form_create(); f_weather->sta = true; } } //天气功能事件处理 static void func_weather_process(void) { compo_textbox_t *txt_time = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_TXT_TIME); char buf_time[10] = {0}; static u32 tick = 0; if (tick_check_expire(tick, 500)) { if(txt_time){ tick = tick_get(); if (SysVariable.deviceInfo.timeType == TIME_TYPE_12_HOUR) sprintf(buf_time, "%02d:%02d%s", get_autoformat_hour(SysVariable.Rtc.hour), SysVariable.Rtc.min, SysVariable.Rtc.hour >= 12 ? "PM" : "AM"); else sprintf(buf_time, "%02d:%02d", SysVariable.Rtc.hour, SysVariable.Rtc.min); compo_textbox_set(txt_time, buf_time); } } if(SysVariable.weather.getFlag == true) { func_weather_refresh(); } func_process(); func_weather_interface(); } //天气功能消息处理 static void func_weather_message(size_msg_t msg) { switch (msg) { case MSG_CTP_CLICK: // sys_cb.weather_idx = (sys_cb.weather_idx + 1) % WEATHER_CNT; //test // printf("sys_cb.weather_idx=%d\n", sys_cb.weather_idx); break; case MSG_CTP_SHORT_UP: break; case MSG_CTP_SHORT_DOWN: break; case MSG_CTP_LONG: break; default: func_message(msg); break; } } //进入天气功能 static void func_weather_enter(void) { func_cb.f_cb = func_zalloc(sizeof(f_weather_t)); func_cb.frm_main = func_weather_form_create(); f_weather_t *f_weather = (f_weather_t *)func_cb.f_cb; f_weather->sta = false; func_weather_refresh(); } //退出天气功能 static void func_weather_exit(void) { func_cb.last = FUNC_WEATHER; } //天气功能 void func_weather(void) { printf("%s\n", __func__); func_weather_enter(); while (func_cb.sta == FUNC_WEATHER) { func_weather_process(); func_weather_message(msg_dequeue()); } func_weather_exit(); }