From 8057e659a3f914eeb7893eb36f5022ae6545f8e2 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Fri, 13 Aug 2021 06:05:55 +0200 Subject: [PATCH] add centered text --- main/hello_world_main.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main/hello_world_main.c b/main/hello_world_main.c index 535c410..c6a5aca 100644 --- a/main/hello_world_main.c +++ b/main/hello_world_main.c @@ -184,6 +184,22 @@ void put_line(uint8_t line, char *str, uint8_t spacing, uint8_t size){ pos++; } } + +void put_line_center(uint8_t line, char *str, uint8_t spacing, uint8_t size){ + uint8_t pos = 0; + uint8_t txt_length = 0; + + while(str[pos] != 0){ + txt_length += (check_chr_width(font[str[pos]-0x20]) + 1 + spacing)*size; + pos++; + } + pos=0; + + uint8_t disp_pos = 65-(txt_length/2); + + while(str[pos] != 0){ + put_chr(line, disp_pos, font[str[pos]-0x20], size); + disp_pos += (check_chr_width(font[str[pos]-0x20]) + 1 + spacing)*size; pos++; } } @@ -202,8 +218,7 @@ void app_main(void) { printf("Hello world!\n"); - put_line(0, "429 Amalienplatz"); - put_line(1, "0123abcd"); + put_line(2, "429 Amalienplatz", 1, 1); gpio_config_t io_conf; //disable interrupt