alignment, refresh only if necessary

This commit is contained in:
Stefan Ostermann 2021-09-19 14:27:42 +02:00
parent 5056994b96
commit 43cb919898
3 changed files with 49 additions and 8 deletions

View File

@ -57,10 +57,17 @@ void printStringWithWait(char *s, int delayTime, LedControl lc)
}
}
void printString(char *s, LedControl lc)
/**
* Careful: manipulates *s!
* */
void printString(char *s, LedControl lc, int offset)
{
int offset = 0;
int display = 0;
for (int i=0;i<lc.getDeviceCount();i++) {
lc.clearDisplay(i);
}
while (*s != 0)
{
if (*s < 32)
@ -71,7 +78,7 @@ void printString(char *s, LedControl lc)
{
if (i+offset>7) {
offset = offset-8;
display++;
display++;
}
lc.setRow(display, i + offset, reverse(buffer[i + 2]));
}

View File

@ -14,7 +14,7 @@ void printStringWithShift(char* s, int delayTime, LedControl lc);
void printStringWithWait(char* s, int delayTime, LedControl lc);
void printString(char* s, LedControl lc);
void printString(char* s, LedControl lc, int offset);
void fadeOut(int max, int time, LedControl lc);
@ -44,7 +44,7 @@ PROGMEM const unsigned char CH[] = {
2, 8, B1100000, B1100000, B0000000, B0000000, B0000000, // .
4, 8, B1100000, B0011000, B0000110, B0000001, B0000000, // /
4, 8, B0111110, B1000001, B1000001, B0111110, B0000000, // 0
3, 8, B1000010, B1111111, B1000000, B0000000, B0000000, // 1
4, 8, B1000010, B1111111, B1000000, B0000000, B0000000, // 1
4, 8, B1100010, B1010001, B1001001, B1000110, B0000000, // 2
4, 8, B0100010, B1000001, B1001001, B0110110, B0000000, // 3
4, 8, B0011000, B0010100, B0010010, B1111111, B0000000, // 4

View File

@ -13,6 +13,8 @@
#include <FS.h> // Use the SPIFFS library for the filesystem
#include <LittleFS.h>
#include <time.h> // time() ctime()
#include "disp.h"
/*
@ -36,6 +38,9 @@ int iteration = 0;
RTC_DS1307 rtc;
DateTime now;
time_t tnow; // this is the epoch
tm stm; // the structure tm holds time information in a more convient way
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
@ -48,13 +53,21 @@ DateTime now;
#define MAX_CS D6
#define MAX_DIN D7
/* Configuration of NTP */
#define MY_NTP_SERVER "de.pool.ntp.org"
#define MY_TZ "CET-1CEST,M3.5.0/02,M10.5.0/03"
LedControl lc = LedControl(MAX_DIN, MAX_CLK, MAX_CS, 3);
/* we always wait a bit between updates of the display */
unsigned long delaytime = 500;
char str[24];
unsigned long last_ntp = 0;
#define NTP_INTERVAL 100000
char str[24] = "\0";
char prev_str[24] = "\0";
void configModeCallback(AsyncWiFiManager *myWiFiManager);
AsyncWebServer server(80);
@ -129,6 +142,8 @@ void setup()
Serial.println("Wifi connected.");
}
configTime(MY_TZ, MY_NTP_SERVER); // ntp
//server.on("/", handleRoot);
// Route for root / web page
@ -179,8 +194,27 @@ void configModeCallback(AsyncWiFiManager *myWiFiManager)
void loop()
{
if (millis() - last_ntp > NTP_INTERVAL)
{
time(&tnow); // read the current time
localtime_r(&tnow, &stm); // update the structure tm with the current time
last_ntp = millis();
Serial.printf("ntp time: %02d:%02d\n", stm.tm_hour, stm.tm_min);
rtc.adjust(DateTime(stm.tm_year, stm.tm_mon, stm.tm_mday, stm.tm_hour, stm.tm_min, stm.tm_sec));
}
setTime(str);
printString(str, lc);
if (strcmp(str,prev_str)!=0) {
Serial.printf("%s %s",prev_str,str);
strcpy(prev_str, str);
printString(str, lc,2);
}
delay(500);
}
void setTime(char *timeStr)