changes ive found here

This commit is contained in:
2025-01-07 02:54:19 +01:00
parent 6a9ee38a99
commit 0e8b867323
3 changed files with 151 additions and 116 deletions

View File

@@ -54,8 +54,8 @@ static void https_request_task(void *pvparameters){
void get_json_string(char* buf, char* name, char* dest){
char* element = strstr(buf, name);
char *ptr= element;
while(*ptr != ':') ptr++;
while(*ptr != '"') ptr++;
while(*ptr != ':' && *ptr != 0) ptr++;
while(*ptr != '"' && *ptr != 0) ptr++;
ptr++;
char *end=ptr;
@@ -88,8 +88,14 @@ static void json_parse_task(void *pvparameters){
char countdown[10] ;
get_json_string(item, "countdown", countdown);
if(atoi(countdown)>=60){
uint8_t h = atoi(countdown) / 60;
uint8_t m = atoi(countdown) % 60;
sprintf(countdown, "%d:%02d", h, m);
}
if(line < 6){
sprintf(txt[line], " %.3s", countdown);
sprintf(txt[line], " %.4s", countdown);
put_line(fb, line, txt[line], 1, 1);
sprintf(txt[line], " %.20s", direction);
@@ -146,70 +152,70 @@ void app_main(void)
put_line(fb, 2, "wifi", 1, 1);
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
xTaskCreate(&https_request_task, "https_get_task", 8192, NULL, 5, NULL);
while (!buf_ok) {
vTaskDelay(1);
}
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
ESP_LOGI("bsvg", "got from https server:");
for(uint32_t i=0; i<sizeof(bsvg_buf); i++){
putchar(bsvg_buf[i]);
if(i%1000==0)
vTaskDelay(1);
}
putchar('\n');
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
put_line(fb, 3, "https", 1, 1);
xTaskCreate(&json_parse_task, "json_parse_task", 8192, NULL, 5, NULL);
ESP_LOGI("bsvg", "Parsing JSON...");
while (!json_ok) {
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
vTaskDelay(1);
}
ESP_LOGI("bsvg", "Done");
//if (departureList == NULL)
//{
// ESP_LOGI("bsvg", "did not get list");
// const char *error_ptr = cJSON_GetErrorPtr();
// heap_caps_print_heap_info(MALLOC_CAP_DEFAULT);
// if (error_ptr != NULL)
// {
// fprintf(stderr, "Error at %ld: %.10s\n", (uint32_t)error_ptr-(uint32_t)bsvg_buf, error_ptr);
// fprintf(stderr, "%.100s%.100s\n", error_ptr-100, error_ptr);
// fprintf(stderr, " ^\n");
// }
// else {
// fprintf(stderr, "did not get err ptr\n");
// }
//}else{
// ESP_LOGI("bsvg", "got list");
// printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
// ESP_LOGI("bsvg", "type: %d", departureList->type);
// ESP_LOGI("bsvg", "child: %ld", (uint32_t)departureList->child);
// if(cJSON_IsArray(departureList)){
// ESP_LOGI("bsvg", "is Array");
// const cJSON *departure = NULL;
// cJSON_ArrayForEach(departure, departureList){
// cJSON *number = cJSON_GetObjectItemCaseSensitive(cJSON_GetObjectItemCaseSensitive(departure, "servingLine"), "number");;
// if(number == NULL)
// ESP_LOGI("bsvg", "cant get number");
// else if(cJSON_IsNumber(number))
// ESP_LOGI("bsvg", "number (int): %d\n", number->valueint);
// else if(cJSON_IsString(number))
// ESP_LOGI("bsvg", "number (str): %.3s\n", number->valuestring);
// else
// ESP_LOGI("bsvg", "cant get number value");
// }
// }
//}
for (;;) {
vTaskDelay(1);
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
xTaskCreate(&https_request_task, "https_get_task", 8192, NULL, 5, NULL);
while (!buf_ok) {
vTaskDelay(1);
}
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
ESP_LOGI("bsvg", "got from https server:");
for(uint32_t i=0; i<sizeof(bsvg_buf); i++){
putchar(bsvg_buf[i]);
if(i%1000==0)
vTaskDelay(1);
}
putchar('\n');
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
put_line(fb, 3, "https", 1, 1);
xTaskCreate(&json_parse_task, "json_parse_task", 8192, NULL, 5, NULL);
ESP_LOGI("bsvg", "Parsing JSON...");
while (!json_ok) {
printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
vTaskDelay(1);
}
ESP_LOGI("bsvg", "Done");
//if (departureList == NULL)
//{
// ESP_LOGI("bsvg", "did not get list");
// const char *error_ptr = cJSON_GetErrorPtr();
// heap_caps_print_heap_info(MALLOC_CAP_DEFAULT);
// if (error_ptr != NULL)
// {
// fprintf(stderr, "Error at %ld: %.10s\n", (uint32_t)error_ptr-(uint32_t)bsvg_buf, error_ptr);
// fprintf(stderr, "%.100s%.100s\n", error_ptr-100, error_ptr);
// fprintf(stderr, " ^\n");
// }
// else {
// fprintf(stderr, "did not get err ptr\n");
// }
//}else{
// ESP_LOGI("bsvg", "got list");
// printf("free heap: %d\n", heap_caps_get_free_size( MALLOC_CAP_DEFAULT) );
// ESP_LOGI("bsvg", "type: %d", departureList->type);
// ESP_LOGI("bsvg", "child: %ld", (uint32_t)departureList->child);
// if(cJSON_IsArray(departureList)){
// ESP_LOGI("bsvg", "is Array");
// const cJSON *departure = NULL;
// cJSON_ArrayForEach(departure, departureList){
// cJSON *number = cJSON_GetObjectItemCaseSensitive(cJSON_GetObjectItemCaseSensitive(departure, "servingLine"), "number");;
// if(number == NULL)
// ESP_LOGI("bsvg", "cant get number");
// else if(cJSON_IsNumber(number))
// ESP_LOGI("bsvg", "number (int): %d\n", number->valueint);
// else if(cJSON_IsString(number))
// ESP_LOGI("bsvg", "number (str): %.3s\n", number->valuestring);
// else
// ESP_LOGI("bsvg", "cant get number value");
// }
// }
//}
vTaskDelay(6000);
}
}

View File

@@ -1,4 +1,5 @@
#include <stdint.h>
#include <stdio.h>
#include "text.h"
uint8_t check_chr_width(const uint8_t chr[]){
@@ -26,6 +27,7 @@ void put_line(uint8_t framebuffer[DISPLAY_HEIGHT][DISPLAY_WIDTH][3], uint8_t lin
if((str[pos]&0xE0) == 0xC0 && (str[pos+1]&0xC0) == 0x80){
code = (str[pos] & 0x1F) << 6;
code |= (str[pos+1] & 0x3F);
printf("mbc: %x\n", font[code][0]);
pos++;
}else{
code = str[pos];