-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_weather.c
214 lines (194 loc) · 6.62 KB
/
app_weather.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* Copyright (c) 2020 Rockchip Electronics Co., Ltd
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <rtthread.h>
#include <stdio.h>
#include <math.h>
#include <dfs_posix.h>
#include "drv_heap.h"
#include "drv_display.h"
#include "hal_base.h"
#include "image_info.h"
#include "display.h"
#include "app_main.h"
#include "lib_imageprocess.h"
extern lv_font_t lv_font_simhei_36;
extern lv_font_t lv_font_simhei_72;
/*
**************************************************************************************************
*
* Weather design callback
*
**************************************************************************************************
*/
static rt_uint8_t update_all = 1;
static rt_uint8_t sunnys_num = 0;
static image_info_t weather_bg;
static image_info_t watch_sunnys_info[5];
static struct image_st target;
rt_err_t app_weather_init(void *param)
{
struct image_st *par = (struct image_st *)param;
rt_uint16_t i;
img_load_info_t img_load_info;
char img_name[64];
target = *par;
// backup
rt_memset(&weather_bg, 0, sizeof(image_info_t));
weather_bg.type = IMG_TYPE_RAW;
weather_bg.pixel = RTGRAPHIC_PIXEL_FORMAT_RGB565;
weather_bg.x = 0;
weather_bg.y = 0;
weather_bg.w = WEATHER_WIN_XRES;
weather_bg.h = WEATHER_WIN_YRES;
weather_bg.size = weather_bg.w * weather_bg.h * (WEATHER_WIN_COLOR_DEPTH >> 3),
weather_bg.data = (rt_uint8_t *)rt_malloc_psram(weather_bg.size);
RT_ASSERT(weather_bg.data != RT_NULL);
img_load_info.w = weather_bg.w;
img_load_info.h = weather_bg.h;
img_load_info.name = WEATHER_PATH"/weather_bkg.dta";
app_load_img(&img_load_info, weather_bg.data, weather_bg.w, weather_bg.h, 0, (WEATHER_WIN_COLOR_DEPTH >> 3));
//large numbers
for (i = 0; i < 5; i++)
{
rt_memset(&watch_sunnys_info[i], 0, sizeof(image_info_t));
watch_sunnys_info[i].type = IMG_TYPE_RAW;
watch_sunnys_info[i].pixel = RTGRAPHIC_PIXEL_FORMAT_RGB565;
watch_sunnys_info[i].x = 0;
watch_sunnys_info[i].y = 0;
watch_sunnys_info[i].w = 96;
watch_sunnys_info[i].h = 96;
watch_sunnys_info[i].size = watch_sunnys_info[i].w * watch_sunnys_info[i].h * 2;
watch_sunnys_info[i].data = (rt_uint8_t *)rt_malloc_psram(watch_sunnys_info[i].size);
RT_ASSERT(watch_sunnys_info[i].data != RT_NULL);
rt_memset(img_name, 0, sizeof(img_name));
snprintf(img_name, sizeof(img_name), WEATHER_PATH"/dynamic_icon_sunny_%01d.dta", i);
img_load_info.w = watch_sunnys_info[i].w;
img_load_info.h = watch_sunnys_info[i].h;
img_load_info.name = (const char *)&img_name;
app_load_img(&img_load_info, watch_sunnys_info[i].data, watch_sunnys_info[i].w, watch_sunnys_info[i].h, 0, 2);
}
return RT_EOK;
}
rt_err_t app_weather_design(void *param)
{
struct image_st *par = ⌖
rt_uint8_t *fb = par->pdata;
rt_uint32_t vir_w = par->stride / format2depth[par->format];
rt_uint16_t startx = 0;
rt_uint16_t starty = 0;
image_info_t *img_info = NULL;
rt_err_t ret;
if (update_all)
{
if (app_lvgl_init_check() == 0)
return -RT_ERROR;
//backup
img_info = &weather_bg;
rt_display_img_fill(img_info, fb, vir_w, startx, starty);
struct app_lvgl_label_design label;
label.ping_pong = 0;
label.font = &lv_font_simhei_36;
label.align = LV_LABEL_ALIGN_CENTER;
label.fmt = RTGRAPHIC_PIXEL_FORMAT_RGB565;
label.img[0] = *par;
//region
startx = 0;
starty = 40;
label.txt = "鼓楼区";
label.img[0].width = CLOCK_WIN_XRES;
label.img[0].height = lv_font_simhei_36.line_height;
label.img[0].pdata = fb + (startx + starty * vir_w) * format2depth[par->format];
ret = app_lv_label_design(&label);
if (ret != RT_EOK)
{
return -RT_ERROR;
}
//air quality
startx = 176;
starty = 192;
label.txt = "晴";
label.align = LV_LABEL_ALIGN_LEFT;
label.img[0].width = 40;
label.img[0].height = lv_font_simhei_36.line_height;
label.img[0].pdata = fb + (startx + starty * vir_w) * format2depth[par->format];
app_lv_label_design(&label);
if (ret != RT_EOK)
{
return -RT_ERROR;
}
startx = 256;
starty = 192;
label.txt = "优";
label.img[0].width = 40;
label.img[0].height = lv_font_simhei_36.line_height;
label.img[0].pdata = fb + (startx + starty * vir_w) * format2depth[par->format];
app_lv_label_design(&label);
if (ret != RT_EOK)
{
return -RT_ERROR;
}
startx = 290;
starty = 192;
label.txt = "12";
label.img[0].width = 60;
label.img[0].height = lv_font_simhei_36.line_height;
label.img[0].pdata = fb + (startx + starty * vir_w) * format2depth[par->format];
app_lv_label_design(&label);
if (ret != RT_EOK)
{
return -RT_ERROR;
}
//temperature
startx = 0;
starty = 260;
label.align = LV_LABEL_ALIGN_CENTER;
label.txt = "27℃/18℃";
label.img[0].width = CLOCK_WIN_XRES;
label.img[0].height = lv_font_simhei_36.line_height;
label.img[0].pdata = fb + (startx + starty * vir_w) * format2depth[par->format];
app_lv_label_design(&label);
if (ret != RT_EOK)
{
return -RT_ERROR;
}
//update time
startx = 0;
starty = 380;
label.txt = "更新时间 10:26";
label.img[0].width = CLOCK_WIN_XRES;
label.img[0].height = lv_font_simhei_36.line_height;
label.img[0].pdata = fb + (startx + starty * vir_w) * format2depth[par->format];
app_lv_label_design(&label);
if (ret != RT_EOK)
{
return -RT_ERROR;
}
//temperature large
startx = 176;
starty = 118;
label.txt = "26℃";
label.font = &lv_font_simhei_72;
label.img[0].width = 156;
label.img[0].height = lv_font_simhei_72.line_height;
label.img[0].pdata = fb + (startx + starty * vir_w) * format2depth[par->format];
app_lv_label_design(&label);
if (ret != RT_EOK)
{
return -RT_ERROR;
}
}
update_all = 0;
//sunnys
startx = 30;
starty = 118;
img_info = &watch_sunnys_info[sunnys_num];
if (++sunnys_num >= 5)
{
sunnys_num = 0;
}
rt_display_img_fill(img_info, fb, vir_w, startx, starty);
return RT_EOK;
}