oled stuff

This commit is contained in:
2020-11-19 20:03:37 +01:00
parent 5605a3d1d5
commit 33fcf6c080
6 changed files with 61 additions and 3 deletions

View File

@ -7,10 +7,14 @@
#include <main.h>
#include <spi.h>
#include <stdint.h>
#include <string.h>
#include <oled.h>
#include <oled-fonts.h>
#include <stm32f1xx_hal.h>
#include <logger.h>
#define HIGH GPIO_PIN_SET
@ -296,6 +300,8 @@ void oled_P6x8Char(unsigned char x,unsigned char y,unsigned char ch)
void oled_P6x8Str(unsigned char x,unsigned char y,char ch[])
{
coloredMsg(LOG_BLUE, false, "OLED: %d %d %s", x, y, ch);
unsigned char c=0,i=0,j=0;
while (ch[j]!='\0')
{
@ -524,3 +530,35 @@ void loop()
oled_P8x16Str(20,4,"Prototyping");
}
#endif
#define MAX_LINES 8
#define MAX_CHARS 21
static uint8_t currentLine = 0;
static char lines[MAX_LINES+1][MAX_CHARS+1];
void oledClear() {
oled_CLS();
memset(lines, 0, sizeof(lines));
currentLine = 0;
}
void oledPrint(char msg[]) {
if (currentLine < MAX_LINES) {
memset(lines[currentLine], 0, MAX_CHARS);
strncpy(lines[currentLine], msg, MAX_CHARS);
oled_P6x8Str(1, currentLine, lines[currentLine]);
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]);
}
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]);
}
}