add log state -- active||inactive

This commit is contained in:
milang 2019-09-28 14:28:05 +02:00
parent 1f04e55306
commit 4f48257422
2 changed files with 44 additions and 35 deletions

View File

@ -42,9 +42,21 @@ static log_line first_line=
0,
0
};
static log_line* current_line=&first_line;
static int state;
void ll_set_state(int s)
{
state = s;
}
int ll_get_state()
{
return state;
}
static log_line* add_line()
{
current_line->next = malloc(sizeof(log_line));
@ -89,29 +101,32 @@ static void append_character(char 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(&current_line->text[0])>396-7)
{
add_line();
}
#endif
}
if (current_line->cursor == MAX_LENGHT-1)
add_line();
current_line->text[current_line->cursor] = '\0';
#ifdef FXCG50
if (dsize(&current_line->text[0])>396-7)
{
add_line();
}
#endif
}
// log something
void ll_send(const char * txt)
{
char c=1;
int i=0;
while (c)
if (state)
{
c=txt[i];
append_character(c);
i++;
char c=1;
int i=0;
while (c)
{
c=txt[i];
append_character(c);
i++;
}
}
}
@ -167,26 +182,11 @@ void ll_pause()
GNORETURN void ll_panic(uint32_t code)
{
char str[10];
sprintf(str, "\nException occured : %d", code);
sprintf(str, "\nException !\n>> LogState=%d\n>> ErrCode=%d", state, code);
ll_set_state(1);
ll_send(str);
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;
}
}
ll_pause();
}
void ll_set_panic()

View File

@ -1,6 +1,15 @@
#ifndef LLOG
#define LLOG
// Enables or disable the log state
// It increases performances and then you can choose to enable && disable logging during execution
// s==1 => enabled
// s==0 => disabled
void ll_set_state(int s);
// With this function you can copy the state somewhere, and restore it after modifications
int ll_get_state();
// Display a message in the log stream
// you can add \n to start an new line ^^
void ll_send(const char * txt);