From 1f04e55306f7b820b7e7a954b3f808fc41bd3ae2 Mon Sep 17 00:00:00 2001 From: milang Date: Sat, 21 Sep 2019 12:48:06 +0200 Subject: [PATCH] don't automatically add new lines at each message add ll_pause function --- liblog.c | 91 +++++++++++++++++++++++++++++++++++++------------------- liblog.h | 9 +++++- 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/liblog.c b/liblog.c index ce9cb43..4af9081 100644 --- a/liblog.c +++ b/liblog.c @@ -2,18 +2,20 @@ #include #include #include +#include #include #include +#include #ifdef FX9860G -#define MAX_LENGHT 21 +#define MAX_LENGHT 22 #define WIDTH 8 #endif #ifdef FXCG50 -#define MAX_LENGHT 150 +#define MAX_LENGHT 132 #define WIDTH 17 #endif @@ -29,13 +31,15 @@ typedef struct log_line char text[MAX_LENGHT]; #endif void* next; + int cursor; } log_line; static log_line first_line= { 0, - "", + "", + 0, 0 }; @@ -48,10 +52,13 @@ static log_line* add_line() current_line = current_line->next; current_line->previous=previous; current_line->next=0; - current_line->text[0]=' '; + current_line->cursor=0; + for (int i=0; itext[i]='\0'; + return current_line; } -static void clear_log() +void ll_clear() { while (current_line->previous) { @@ -59,6 +66,10 @@ static void clear_log() free(current_line); current_line=next; } + current_line->next=0; + current_line->cursor=0; + for (int i=0; itext[i]='\0'; } static void show_line(const log_line* l, int y) @@ -66,52 +77,47 @@ static void show_line(const log_line* l, int y) dtext(1, y, &l->text[0], C_BLACK, C_NONE); } -static void set_character(char c, int x) +static void append_character(char c) { - if (c=='\0' || c=='\n') + if (c=='\n') { - current_line->text[x]= '\0'; + current_line->text[current_line->cursor]= '\0'; add_line(); } else { - current_line->text[x] = c; + current_line->text[current_line->cursor] = c; + current_line->cursor ++; + + if (current_line->cursor == MAX_LENGHT-1) + add_line(); + current_line->text[current_line->cursor] = '\0'; +#ifdef FXCG50 + if (dsize(¤t_line->text[0])>396-7) + { + add_line(); + } +#endif } } // log something void ll_send(const char * txt) { - add_line(); char c=1; int i=0; - int p=0; while (c) { c=txt[i]; - set_character(c,p); - p++; - if (c=='\0' || c=='\n') - p=0; - if (p==MAX_LENGHT-1) - { - set_character('\0', p); - p=0; - } -#ifdef FXCG50 - if (dsize(¤t_line->text[0])>396-3) - { - set_character('\0', p); - p=0; - } -#endif + append_character(c); i++; } } void ll_display_custom(log_line* line) { + dfont(NULL); dclear(C_WHITE); for (int i=0; i<8; i++) { @@ -134,10 +140,35 @@ void ll_display() ll_display_custom(current_line); } - - -GNORETURN void ll_panic() +void ll_pause() { + log_line* line=current_line; + while (1) + { + ll_display_custom(line); + int key = getkey().key; + if (key==KEY_UP) + { + log_line* linet=line->previous; + if (linet) + line=linet; + } + if (key==KEY_DOWN) + { + log_line* linet=line->next; + if (linet) + line=linet; + } + if (key==KEY_EXIT) + break; + } +} + +GNORETURN void ll_panic(uint32_t code) +{ + char str[10]; + sprintf(str, "\nException occured : %d", code); + ll_send(str); log_line* line=current_line; while (1) { diff --git a/liblog.h b/liblog.h index 455ee68..7507303 100644 --- a/liblog.h +++ b/liblog.h @@ -2,12 +2,19 @@ #define LLOG // Display a message in the log stream +// you can add \n to start an new line ^^ void ll_send(const char * txt); -// Puts the 8 last lines of the stream +// Put the 8 last lines of the stream void ll_display(); +// Enable log displaying on panic void ll_set_panic(); +// Display log, enable scrolling, and waits the user to press Exit +void ll_pause(); + +// Clear log +void ll_clear(); #endif