show statistics on second screen

This commit is contained in:
2020-11-20 12:20:30 +01:00
parent 3807e2fa9f
commit 206e371d48
8 changed files with 72 additions and 54 deletions

View File

@ -17,13 +17,12 @@
#include <stm32f1xx_hal.h>
#include <logger.h>
#include <PontCoopScheduler.h>
#define HIGH GPIO_PIN_SET
#define LOW GPIO_PIN_RESET
static void __LEDPIN_RST(GPIO_PinState v) {
HAL_GPIO_WritePin(Display_RES_GPIO_Port, Display_RES_Pin, v);
}
@ -312,7 +311,7 @@ static void oled_P6x8Char(unsigned char x,unsigned char y,unsigned char ch)
static void oled_P6x8Str(unsigned char x,unsigned char y,char ch[])
{
coloredMsg(LOG_BLUE, false, "OLED: %d %d %s", x, y, ch);
// coloredMsg(LOG_BLUE, false, "OLED: %d %d %s", x, y, ch);
unsigned char c=0,i=0,j=0;
while (ch[j]!='\0')
@ -401,9 +400,11 @@ static void oled_Cursor(unsigned char cursor_column, unsigned char cursor_row)
#define MAX_LINES 8
#define MAX_CHARS 21
#define NUM_OF_SCREENS 2
static uint8_t currentLine = 0;
static char lines[MAX_LINES+1][MAX_CHARS+1];
static char lines[NUM_OF_SCREENS][MAX_LINES+1][MAX_CHARS+1];
static oledScreen_t activeScreen = OLED_SCREEN0;
void oledClear() {
oled_CLS();
@ -411,32 +412,42 @@ void oledClear() {
currentLine = 0;
}
void oledPrint(char msg[]) {
void oledPrint(oledScreen_t screen, char msg[]) {
if (currentLine < MAX_LINES) {
memset(lines[currentLine], 0, MAX_CHARS);
strncpy(lines[currentLine], msg, MAX_CHARS);
memset(lines[currentLine] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
lines[currentLine][MAX_CHARS - 1] = 0;
oled_P6x8Str(1, currentLine, lines[currentLine]);
strncpy(lines[screen][currentLine], msg, MAX_CHARS);
memset(lines[screen][currentLine] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
lines[screen][currentLine][MAX_CHARS - 1] = 0;
currentLine++;
} else {
for (uint8_t i = 1; i < MAX_LINES; i++) {
memcpy(lines[i-1], lines[i], MAX_CHARS);
oled_P6x8Str(1, i-1, lines[i-1]);
memcpy(lines[screen][i-1], lines[screen][i], MAX_CHARS);
}
strncpy(lines[MAX_LINES - 1], msg, MAX_CHARS);
memset(lines[MAX_LINES - 1] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
lines[MAX_LINES - 1][MAX_CHARS - 1] = 0;
oled_P6x8Str(1, MAX_LINES - 1, lines[MAX_LINES - 1]);
strncpy(lines[screen][MAX_LINES - 1], msg, MAX_CHARS);
memset(lines[screen][MAX_LINES - 1] + strlen(msg), ' ', MAX_CHARS - strlen(msg) - 1);
lines[screen][MAX_LINES - 1][MAX_CHARS - 1] = 0;
}
for (uint8_t line = 0; line < MAX_LINES; line++) {
oled_P6x8Str(1, line, lines[activeScreen][line]);
}
}
static void oledSwitchBackToScreen0(void *handle) {
oledSetActiveScreen(OLED_SCREEN0);
}
void oledPrintf(const char *format, ...) {
void oledSetActiveScreen(oledScreen_t screen) {
activeScreen = screen;
if (screen == OLED_SCREEN1) {
schAdd(oledSwitchBackToScreen0, NULL, 10000, 0);
}
}
void oledPrintf(oledScreen_t screen, const char *format, ...) {
va_list vl;
va_start(vl, format);
char buf[MAX_CHARS+1];
vsnprintf(buf, MAX_CHARS, format, vl);
va_end(vl);
oledPrint(buf);
oledPrint(screen, buf);
}