【平头哥RVB2601创意应用开发】移植U8g2图形库+LCD显示天气
[复制链接]
1、移植u8g2图形库,参考的链接:【平头哥RVB2601创意应用开发】实践2-移植U8g2图形库 https://bbs.eeworld.com.cn/thread-1198007-1-1.html,感谢这位博主!
移植的过程,折腾了好久,最终弄完是,工程树形里面不显示,但是实际的工程有。本人是使用vscode和集成开发环境cdk组合使用的。用vscode编辑代码,cdk编译、下载代码。
2、代码的编写:(按照上次WiFi获取天气进行)
代码没有做任何鲁棒性考虑,先把整体功能调通,最终再优化。
void w800_data_receive_callback(int linkid, void *data, size_t len, char remote_ip[16], uint16_t remote_ports)
{
uint8_t *buf;
buf = (uint8_t *)data;
if(len == 0)
{
return;
}
if(buf == NULL)
{
return;
}
printf("Receive data len: %d\r\n",len);
printf("Receive data:");
for(uint16_t i = 0; i < len; i++)
{
// printf("%02X ",buf);
printf("%c",buf);
}
printf("\r\n\r\n");
cJSON *body = NULL;
uint8_t *cjson_buf = NULL;
char buffer_temp[100];
body = cJSON_Parse(buf);
cjson_buf = cJSON_Print(body);
printf("%s\r\r\n",cjson_buf);
cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
cJSON *cjson_data = NULL;
cJSON *cjson_cityName = NULL;
cJSON *cjson_lastUpdate = NULL;
cJSON *cjson_fl = NULL;
cJSON *cjson_fx = NULL;
cJSON *cjson_qw = NULL;
printf("\r\n\r\n");
cjson_data = cJSON_GetObjectItem(body,"data");
cjson_cityName = cJSON_GetObjectItem(cjson_data,"cityName");
cjson_buf = cJSON_Print(cjson_cityName);
printf("%s\r\r\n",cjson_buf);
memset(buffer_temp,0,sizeof(buffer_temp));
strcat(buffer_temp,"cityName:");
strcat(buffer_temp,cjson_buf);
u8g2_DrawUTF8(&u8g2, 0, 12, buffer_temp);
u8g2_SendBuffer(&u8g2);
cjson_lastUpdate = cJSON_GetObjectItem(cjson_data,"lastUpdate");
cjson_buf = cJSON_Print(cjson_lastUpdate);
printf("%s\r\r\n",cjson_buf);
memset(buffer_temp,0,sizeof(buffer_temp));
//strcat(buffer_temp,"lastUpdate:");
strcat(buffer_temp,cjson_buf);
u8g2_DrawUTF8(&u8g2, 0, 24, buffer_temp);
u8g2_SendBuffer(&u8g2);
cjson_fl = cJSON_GetObjectItem(cjson_data,"fl");
cjson_buf = cJSON_Print(cjson_fl);
printf("%s\r\r\n",cjson_buf);
memset(buffer_temp,0,sizeof(buffer_temp));
strcat(buffer_temp,"fl:");
strcat(buffer_temp,cjson_buf);
u8g2_DrawUTF8(&u8g2, 0, 36, buffer_temp);
u8g2_SendBuffer(&u8g2);
cjson_fx = cJSON_GetObjectItem(cjson_data,"fx");
cjson_buf = cJSON_Print(cjson_fx);
printf("%s\r\r\n",cjson_buf);
memset(buffer_temp,0,sizeof(buffer_temp));
strcat(buffer_temp,"fx:");
strcat(buffer_temp,cjson_buf);
u8g2_DrawUTF8(&u8g2, 0, 48, buffer_temp);
u8g2_SendBuffer(&u8g2);
cjson_qw = cJSON_GetObjectItem(cjson_data,"qw");
cjson_buf = cJSON_Print(cjson_qw);
printf("%s\r\r\n",cjson_buf);
memset(buffer_temp,0,sizeof(buffer_temp));
strcat(buffer_temp,"qw:");
strcat(buffer_temp,cjson_buf);
u8g2_DrawUTF8(&u8g2, 0, 60, buffer_temp);
u8g2_SendBuffer(&u8g2);
}
3、显示结果
|