38 #define STACKSIZE_TASK ( 256 ) 39 #define PRIORITY_TASK ( 3 ) 43 #define DISPLAY_LINES 30 44 #define DISPLAY_CHARS 64 58 static uint8_t last_given_id = 0;
59 static QueueHandle_t display_queue;
60 static SemaphoreHandle_t display_id_mutex;
76 va_start (args, fmtstr);
77 vsprintf(msg.
message,fmtstr, args);
80 msg.
taskname = pcTaskGetName(xTaskGetCurrentTaskHandle());
86 xSemaphoreTake(display_id_mutex,portMAX_DELAY);
89 newId = ++last_given_id;
90 if(last_given_id == 0xFF) {
96 xSemaphoreGive(display_id_mutex);
102 xQueueSend(display_queue, &msg, portMAX_DELAY );
116 static void display_print_message(uint8_t line,
log_message_t* msg)
121 LCD_SetTextColor(GUI_COLOR_LIGHT_GRAY);
122 const char* charPtr = msg->
taskname;
124 LCD_DisplayCharLine(line,x++,*charPtr++);
126 LCD_DisplayCharLine(line,x++,
':');
127 LCD_DisplayCharLine(line,x++,
' ');
130 LCD_SetTextColor(GUI_COLOR_WHITE);
133 LCD_DisplayCharLine(line,x++,*charPtr++);
137 LCD_DisplayCharLine(line,x++,
' ');
152 static void display_task()
159 xQueueReceive(display_queue,&tmp_message,portMAX_DELAY);
160 uint8_t new_id = tmp_message.id;
163 if((top_id <= bottom_id && new_id >= top_id && new_id <= bottom_id) ||
164 (top_id > bottom_id && new_id >= top_id)) {
167 memcpy(&message_buffer[replace_buffer_index],&tmp_message,
sizeof(
log_message_t));
168 display_print_message(new_id-top_id, &message_buffer[replace_buffer_index]);
169 }
else if(top_id > bottom_id && new_id <= bottom_id ) {
172 memcpy(&message_buffer[replace_buffer_index],&tmp_message,
sizeof(
log_message_t));
173 display_print_message(
visible_messages -1 - (bottom_id-new_id), &message_buffer[replace_buffer_index]);
179 uint8_t buffer_index = (buffer_offset + i) % DISPLAY_LINES;
180 display_print_message(i,&message_buffer[buffer_index]);
184 memcpy(&message_buffer[buffer_index],&tmp_message,
sizeof(
log_message_t));
202 LCD_Clear(GUI_COLOR_BLACK);
203 xTaskCreate(display_task,
211 display_id_mutex = xSemaphoreCreateMutex();
#define QUEUE_SIZE
Size of the message queue.
const char * taskname
Name of the task that wrote the message.
#define STACKSIZE_TASK
Stack size of the display task.
uint8_t buffer_offset
Offset in the message_buffer to get to the top message.
char message[DISPLAY_CHARS+1]
Message (formatted)
#define DISPLAY_CHARS
Number of horizontal characters that can be displayed.
uint8_t id
Id that was assigned to the task.
#define PRIORITY_TASK
Priority of the Display task (low priority number denotes low priority task)
void display_init()
Initializes the display and starts the display task global.
uint8_t visible_messages
Number of currently visible messages.
log_message_t message_buffer[DISPLAY_LINES]
buffer of all visible messages (ring buffer!)
uint8_t display_log(uint8_t id, const char *fmtstr,...)
Logs a message to the display global.
#define DISPLAY_LINES
Number of lines that fit on the display (vertically)
Structure to describe a log message.