update FlipDotDrv and add scrolling text feature
This commit is contained in:
parent
453cf8094c
commit
a457006614
|
|
@ -21,15 +21,13 @@ private:
|
|||
uint16_t FrameDataLength;
|
||||
uint16_t bufferLength;
|
||||
|
||||
GFXcanvas1 myCanvas;
|
||||
|
||||
public:
|
||||
FlipDotDrv(uint8_t width, uint8_t height, uint8_t address);
|
||||
~FlipDotDrv();
|
||||
|
||||
void sendRaw(const uint8_t* bmp, uint16_t length);
|
||||
|
||||
void printText(const char* txt, uint8_t multiplier = 1);
|
||||
void printText(const char* txt, uint8_t x, uint8_t y, uint8_t multiplier = 1);
|
||||
void sendCanvas(const GFXcanvas1 * canv);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@ framework = arduino
|
|||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
witnessmenow/UniversalTelegramBot @ ^1.3.0
|
||||
adafruit/Adafruit GFX Library @ ^1.11.11
|
||||
adafruit/Adafruit GFX Library @ 1.12.3
|
||||
build_flags=-DTELEGRAM_DEBUG
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
|
||||
FlipDotDrv::FlipDotDrv(uint8_t width, uint8_t height, uint8_t address)
|
||||
: myCanvas{width, height}
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
|
@ -80,36 +79,23 @@ void FlipDotDrv::sendRaw(const uint8_t* bmp, uint16_t length)
|
|||
|
||||
}
|
||||
|
||||
|
||||
void FlipDotDrv::printText(const char* txt, uint8_t multiplier)
|
||||
void FlipDotDrv::sendCanvas(const GFXcanvas1 * canv)
|
||||
{
|
||||
printText(txt, 0, 0, multiplier);
|
||||
}
|
||||
|
||||
void FlipDotDrv::printText(const char* txt, uint8_t x, uint8_t y, uint8_t multiplier)
|
||||
{
|
||||
myCanvas.fillScreen(0);
|
||||
|
||||
// myCanvas.setFont(&FreeSans9pt7b);
|
||||
myCanvas.setFont(NULL);
|
||||
myCanvas.setTextSize(multiplier);
|
||||
|
||||
myCanvas.setCursor(x, y);
|
||||
myCanvas.print(txt);
|
||||
|
||||
uint8_t rawBuff[192] = {};
|
||||
GFXcanvas1 localCanvas(width, height, true);
|
||||
memcpy(localCanvas.getBuffer(), canv->getBuffer(), width * height / 8);
|
||||
|
||||
uint8_t displayBuffer[width * height / 8] = {};
|
||||
for (int i = 0; i < (this->width * this->height / 8); ++i)
|
||||
{
|
||||
rawBuff[i] = (myCanvas.getPixel(i / 2, ((i % 2) * 8) + 0) << 0|
|
||||
myCanvas.getPixel(i / 2, ((i % 2) * 8) + 1) << 1|
|
||||
myCanvas.getPixel(i / 2, ((i % 2) * 8) + 2) << 2|
|
||||
myCanvas.getPixel(i / 2, ((i % 2) * 8) + 3) << 3|
|
||||
myCanvas.getPixel(i / 2, ((i % 2) * 8) + 4) << 4|
|
||||
myCanvas.getPixel(i / 2, ((i % 2) * 8) + 5) << 5|
|
||||
myCanvas.getPixel(i / 2, ((i % 2) * 8) + 6) << 6|
|
||||
myCanvas.getPixel(i / 2, ((i % 2) * 8) + 7) << 7 );
|
||||
displayBuffer[i] = (localCanvas.getPixel(i / 2, ((i % 2) * 8) + 0) << 0|
|
||||
localCanvas.getPixel(i / 2, ((i % 2) * 8) + 1) << 1|
|
||||
localCanvas.getPixel(i / 2, ((i % 2) * 8) + 2) << 2|
|
||||
localCanvas.getPixel(i / 2, ((i % 2) * 8) + 3) << 3|
|
||||
localCanvas.getPixel(i / 2, ((i % 2) * 8) + 4) << 4|
|
||||
localCanvas.getPixel(i / 2, ((i % 2) * 8) + 5) << 5|
|
||||
localCanvas.getPixel(i / 2, ((i % 2) * 8) + 6) << 6|
|
||||
localCanvas.getPixel(i / 2, ((i % 2) * 8) + 7) << 7 );
|
||||
}
|
||||
|
||||
this->sendRaw(rawBuff, sizeof(rawBuff));
|
||||
this->sendRaw(displayBuffer, sizeof(displayBuffer));
|
||||
}
|
||||
123
src/main.cpp
123
src/main.cpp
|
|
@ -2,6 +2,7 @@
|
|||
#include <WiFi.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Telegram.h"
|
||||
#include "FlipDotDrv.h"
|
||||
|
|
@ -16,16 +17,26 @@ void onOTAStart() {
|
|||
WiFiClientSecure secured_client;
|
||||
bool Start = false;
|
||||
|
||||
FlipDotDrv flip(96, 16, 1);
|
||||
#define WIDTH 96
|
||||
#define HEIGHT 16
|
||||
#define ROTATION 0 // 0 or 2 for 0 degrees or 180 degrees
|
||||
#define MAX_CHAR_PER_LINE WIDTH/6
|
||||
|
||||
FlipDotDrv flip(WIDTH, HEIGHT, 0);
|
||||
GFXcanvas1 canvas(WIDTH, HEIGHT);
|
||||
|
||||
void displayText(const char* text, bool background, int16_t x = -1, int16_t y = -1);
|
||||
|
||||
String Text = "";
|
||||
|
||||
void printOpen(String Args)
|
||||
{
|
||||
flip.printText("offen", 18, 0, 2);
|
||||
Text = "offen";
|
||||
}
|
||||
|
||||
void printClose(String Args)
|
||||
{
|
||||
flip.printText("geschlossen", 15, 4, 1);
|
||||
Text = "geschlossen";
|
||||
}
|
||||
|
||||
void printText(String Args)
|
||||
|
|
@ -33,7 +44,7 @@ void printText(String Args)
|
|||
Serial.print("Display would show '");
|
||||
Serial.print(Args);
|
||||
Serial.println("'");
|
||||
flip.printText(Args.c_str());
|
||||
Text = Args;
|
||||
}
|
||||
|
||||
TelegramCommand myCmdList[] {
|
||||
|
|
@ -46,19 +57,21 @@ uint32_t myCmdListCnt = sizeof(myCmdList) / sizeof(myCmdList[0]);
|
|||
|
||||
Telegram tele(secured_client, myCmdList, myCmdListCnt);
|
||||
|
||||
uint8_t rawBuff[192] = {};
|
||||
|
||||
void setup()
|
||||
{
|
||||
uint8_t rawBuff[192] = {};
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
|
||||
|
||||
//rotate the Canvas so it is displayed in the correct orientation on the FlipDotDisplay
|
||||
canvas.setRotation(ROTATION);
|
||||
|
||||
Serial.println("Initializing Display");
|
||||
flip.sendRaw(rawBuff, sizeof(rawBuff));
|
||||
|
||||
delay(500);
|
||||
delay(1000);
|
||||
Serial.println("draw checker");
|
||||
memset(rawBuff, 0xAA, 192);
|
||||
for (int i = 0; i < 192; ++i)
|
||||
|
|
@ -69,7 +82,8 @@ void setup()
|
|||
rawBuff[i] = 0x55;
|
||||
}
|
||||
flip.sendRaw(rawBuff, sizeof(rawBuff));
|
||||
delay(500);
|
||||
|
||||
delay(1000);
|
||||
Serial.println("bigger checker");
|
||||
for (int i = 0; i < 192; ++i)
|
||||
{
|
||||
|
|
@ -79,7 +93,8 @@ void setup()
|
|||
rawBuff[i] = 0xCC;
|
||||
}
|
||||
flip.sendRaw(rawBuff, sizeof(rawBuff));
|
||||
delay(500);
|
||||
|
||||
delay(1000);
|
||||
Serial.println("largest checker");
|
||||
for (int i = 0; i < 192; ++i)
|
||||
{
|
||||
|
|
@ -104,6 +119,7 @@ void setup()
|
|||
|
||||
Serial.print("Retrieving time: ");
|
||||
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
|
||||
// configTzTime("CET-1CEST,M3.5.0,M10.5.0/3", "pool.ntp.org");
|
||||
time_t now = time(nullptr);
|
||||
while (now < 24 * 3600)
|
||||
{
|
||||
|
|
@ -120,7 +136,94 @@ void setup()
|
|||
void loop()
|
||||
{
|
||||
unsigned long now = millis();
|
||||
static unsigned long lastDisplayRefresh = now;
|
||||
|
||||
tele.cyclic(now);
|
||||
yield();
|
||||
}
|
||||
|
||||
if ((now - lastDisplayRefresh) > 3000)
|
||||
{
|
||||
//fill canvas with black pixels
|
||||
canvas.fillScreen(0);
|
||||
|
||||
//if textlength is larger than possible on the display we need to scroll
|
||||
uint32_t TextLength = Text.length();
|
||||
if (TextLength > (MAX_CHAR_PER_LINE - 6))
|
||||
{
|
||||
static uint32_t offset = 0;
|
||||
|
||||
//get the substring ffor this iteration
|
||||
String SubText = Text.substring(offset, offset + MAX_CHAR_PER_LINE);
|
||||
|
||||
//increase the offset and reset it at the end of the scrol
|
||||
offset++;
|
||||
if (offset + MAX_CHAR_PER_LINE > TextLength)
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
//write substring to canvas
|
||||
displayText(SubText.c_str(), true, 15, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
//display current time on the left
|
||||
tm timeinfo;
|
||||
char buffer [6] {0};
|
||||
if(getLocalTime(&timeinfo))
|
||||
{
|
||||
strftime(buffer, 6, "%R", &timeinfo);
|
||||
return;
|
||||
}
|
||||
displayText(buffer, true, 0, 4);
|
||||
|
||||
//display text on the right centered
|
||||
displayText(Text.c_str(), true, (6 + (MAX_CHAR_PER_LINE - 6 - TextLength) / 2) * 6, 4);
|
||||
}
|
||||
|
||||
//send canvas to display
|
||||
flip.sendCanvas(&canvas);
|
||||
}
|
||||
}
|
||||
|
||||
void displayText(const char* text, bool background, int16_t x, int16_t y)
|
||||
{
|
||||
// canvas.fillScreen(0);
|
||||
canvas.setFont(NULL);
|
||||
canvas.setTextSize(1);
|
||||
canvas.setTextColor(1);
|
||||
|
||||
int16_t cursor_x, cursor_y;
|
||||
int16_t bounds_x, bounds_y;
|
||||
uint16_t bounds_w, bounds_h;
|
||||
canvas.getTextBounds(text, 0, 0, &bounds_x, &bounds_y, &bounds_w, &bounds_h);
|
||||
|
||||
if (x == -1)
|
||||
{
|
||||
// Zentriert
|
||||
cursor_x = (WIDTH - bounds_w) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
cursor_x = x;
|
||||
}
|
||||
if (y == -1)
|
||||
{
|
||||
// Zentriert
|
||||
cursor_y = (HEIGHT - bounds_h) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
cursor_y = y;
|
||||
}
|
||||
|
||||
if (background)
|
||||
{
|
||||
canvas.fillRect(cursor_x - 1, cursor_y - 1, bounds_w + 1, bounds_h + 1, 0);
|
||||
}
|
||||
|
||||
canvas.setCursor(cursor_x, cursor_y);
|
||||
canvas.print(text);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user