Added partial update clock example

This commit is contained in:
Larry Bank
2024-11-03 13:49:31 +00:00
parent 6e2819bbd3
commit b6739e131c
4 changed files with 184 additions and 0 deletions
@@ -0,0 +1,16 @@
CFLAGS=-D_LINUX_ -Wall -O2 -I../../
LIBS=-lgpiod
all: pu_clock
pu_clock: main.o bb_epaper.o
$(CXX) main.o bb_epaper.o $(LIBS) -o pu_clock
main.o: main.cpp
$(CXX) $(CFLAGS) -c main.cpp
bb_epaper.o: ../../../src/bb_epaper.cpp ../../../src/bb_epaper.h
$(CXX) $(CFLAGS) -c ../../../src/bb_epaper.cpp
clean:
rm -rf *.o pu_clock
@@ -0,0 +1,90 @@
// Created with image_to_c
// https://github.com/bitbank2/image_to_c
//
// Roboto_Black_78
// Data size = 1262 bytes
//
// for non-Arduino builds...
#ifndef PROGMEM
#define PROGMEM
#endif
const uint8_t Roboto_Black_78[] PROGMEM = {
0xff,0xbb,0x30,0x00,0x3a,0x00,0xb3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4b,0x59,
0x70,0x00,0x07,0x00,0x93,0xff,0x6a,0x00,0x32,0x59,0x6d,0x00,0x0c,0x00,0x94,0xff,
0xa7,0x00,0x4e,0x59,0x6e,0x00,0x05,0x00,0x93,0xff,0x12,0x01,0x4f,0x59,0x70,0x00,
0x04,0x00,0x93,0xff,0x95,0x01,0x4f,0x59,0x6d,0x00,0x05,0x00,0x94,0xff,0xe9,0x01,
0x4c,0x59,0x6f,0x00,0x06,0x00,0x94,0xff,0x5d,0x02,0x4f,0x59,0x70,0x00,0x06,0x00,
0x93,0xff,0xe6,0x02,0x4e,0x59,0x6d,0x00,0x04,0x00,0x94,0xff,0x2c,0x03,0x4c,0x59,
0x70,0x00,0x06,0x00,0x93,0xff,0xb7,0x03,0x4c,0x59,0x70,0x00,0x06,0x00,0x93,0xff,
0x3b,0x04,0x1c,0x2e,0x55,0x00,0x09,0x00,0xad,0xff,0x28,0x3c,0x71,0xc9,0x27,0x34,
0x5f,0x04,0x0f,0x04,0x0f,0x09,0xe8,0x3c,0x20,0xf4,0xf4,0xf4,0xf4,0xf4,0xf4,0xf4,
0xff,0x4f,0x4f,0xf4,0xf9,0x8e,0xfe,0x82,0x0d,0xf0,0x83,0xe9,0x3f,0xdf,0x4f,0xa5,
0x7e,0xff,0xe9,0x3f,0xdf,0xff,0xf5,0xc6,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf5,0x20,0x35,0xef,0xff,0xff,0xad,
0xb5,0xff,0xd7,0x6e,0xbb,0x5f,0xf6,0xd2,0xe1,0x85,0xd8,0x61,0x2e,0x3d,0xaf,0xda,
0xda,0xfd,0xad,0xad,0xad,0xad,0xad,0xad,0xac,0x30,0xb6,0xb0,0xc2,0xc1,0x82,0xc1,
0x82,0xce,0x7c,0x74,0x28,0xbf,0x05,0x82,0xc1,0x60,0xb0,0xb0,0x58,0x2c,0x16,0x0b,
0x0b,0x05,0x82,0xc1,0x60,0xb0,0xb0,0x51,0xff,0xf3,0x2c,0xe0,0xb0,0x59,0xcc,0x36,
0x0b,0x05,0x95,0x2f,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x28,0x40,0x71,0xe8,0x67,0x36,0x67,0x04,0x0f,0x04,0x0f,0x08,0x3c,0x20,0xf4,
0xf0,0x83,0xd3,0xd3,0xd3,0xd3,0xd3,0xd7,0x4f,0x5d,0x3f,0xd3,0xe7,0x3c,0x23,0xa0,
0x83,0x7d,0x3e,0x93,0xf4,0xfd,0x3e,0x95,0xfb,0xff,0x15,0xfd,0x3f,0xff,0xff,0xca,
0x18,0xfa,0xfd,0x7f,0xad,0x7f,0x4b,0x5f,0xd2,0xd7,0xad,0x2d,0x74,0xba,0xd7,0x4b,
0x4b,0x5d,0x2d,0x2d,0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x61,0x61,0xac,0x30,0x58,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x74,0xa7,0x08,0x1e,0x13,0xd0,0x7a,0x7a,0xe9,
0xf7,0x1f,0xf6,0xbf,0x90,0x1f,0x5b,0x5b,0xed,0x6c,0x2c,0x35,0x86,0x0a};
@@ -0,0 +1,78 @@
//
// C++ example for bb_epaper library
// written by Larry Bank (bitbank@pobox.com)
// This example shows how to do partial updates for any type of
// black and white epaper display even if the original pixels are
// lost (e.g. deep deep sleep or power failure)
// The target display is a 400x300 4.2" B/W UC8151
// You can easily select a different display by adjusting the
// coordinates and using a different font size
//
// Project started 9/23/2024
// Copyright (c) 2024 BitBank Software, Inc.
//
#include "../../../src/bb_epaper.h"
#include "Roboto_Black_78.h"
#include <time.h>
BBEPAPER bbep(EPD42_400x300); // 4.2" UC81xx controller
// BCM GPIO numbers used by Pimoroni e-paper "HATs"
#define PIN_DC 22
#define PIN_RST 27
#define PIN_BUSY 17
#define PIN_CS 8
#define SPI_BUS 0
struct tm myTime;
time_t t;
int iFrame = 0;
void UpdateDisplay(int iFrame)
{
char szTemp[16];
bbep.fillScreen(BBEP_WHITE);
bbep.setFont(Roboto_Black_78);
bbep.setTextColor(BBEP_BLACK);
if (iFrame & 0xf) { // partial updates for 15 out of 16 frames
// write the old pixels (old time) into the old 1-bit plane
bbep.setPlane(PLANE_1);
sprintf(szTemp, "%02d:%02d", myTime.tm_hour, myTime.tm_min);
bbep.drawString(szTemp, 0, 200);
bbep.writePlane(PLANE_1);
bbep.setPlane(PLANE_0);
bbep.fillScreen(BBEP_WHITE);
t = time(NULL);
myTime = *localtime(&t);
sprintf(szTemp, "%02d:%02d", myTime.tm_hour, myTime.tm_min);
bbep.drawString(szTemp, 0, 200);
bbep.writePlane(PLANE_0); // write the new pixels
bbep.refresh(REFRESH_PARTIAL);
} else { // full update, just display the current time
t = time(NULL);
myTime = *localtime(&t);
sprintf(szTemp, "%02d:%02d", myTime.tm_hour, myTime.tm_min);
bbep.drawString(szTemp, 0, 200);
bbep.writePlane();
bbep.refresh(REFRESH_FULL);
}
bbep.sleep(DEEP_SLEEP); // extends the life of the display
} /* UpdateDisplay() */
int main(int argc, const char * argv[]) {
bbep.initIO(PIN_DC, PIN_RST, PIN_BUSY, PIN_CS, SPI_BUS, 8000000);
bbep.allocBuffer(); // Use RAM since we have plenty
while (1) { // loop forever
time_t tt;
struct tm testTime;
UpdateDisplay(iFrame++); // show the latest time
testTime.tm_min = myTime.tm_min;
// On a system with power saving features, you would sleep here
while (testTime.tm_min == myTime.tm_min) { // wait for minute to change
tt = time(NULL);
testTime = *localtime(&tt);
}
}
return 0; // it never gets here
} /* main() */