[RVB2601 Creative Application Development] Transplant U8g2 Graphics Library + LCD Weather Display
[Copy link]
1. Transplant the u8g2 graphics library, reference link: [Pingtou Ge RVB2601 Creative Application Development] Practice 2-Transplant U8g2 Graphics Library https://en.eeworld.com/bbs/thread-1198007-1-1.html, thanks to this blogger!
The process of transplantation took a long time. Finally, the project tree was not displayed, but the actual project was there. I used vscode and integrated development environment cdk in combination. I used vscode to edit the code, and cdk to compile and download the code.
2. Code writing: (According to the last WiFi weather acquisition)
The code does not take any robustness into consideration. The overall functionality is adjusted first and then optimized.
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. Display results
|