1
0
Fork 0

LCD: Introduce LCD display and animations

Add support for the LCD and using it for displaying animations.
Animations are automatically played if available for the ID of the
detected tag.

The code should support adding other kind of animations, for tags being
removed or for other UI interactions for example.
This commit is contained in:
Teo-CD 2023-10-21 22:01:10 +01:00
parent e21123538b
commit 69909851c2
4 changed files with 127 additions and 3 deletions

65
src/LCD.cpp Normal file
View file

@ -0,0 +1,65 @@
//
// Created by Teo-CD on 17/10/23.
//
#include "LCD.h"
uint8_t LCD::bitmap[528] = {};
void LCD::init() {
lcd.begin(60, 4);
lcd.clearDisplay();
lastFrameTime = millis();
/* Needed to keep the display clean at boot. */
lcd.display();
/* TODO: JIN splash welcome ? */
}
void LCD::startNewAnim(int8_t ID) {
char directoryPath[15];
uint8_t rawID = getRawId(ID);
if (!SD.mediaPresent()) {
Com::sendComment("SD Card not present, cannot play animation");
return;
}
if (!isValidId(ID)) {
Com::sendComment("Unknown ID for animation : %d", rawID);
return;
}
/* Interrupt previous running animation if there's one. */
if (animDir)
animDir.close();
/* TODO: If adding remove animation, change path + check isIdGone */
snprintf(directoryPath, 15, "%s/ANIM",
(isIdCharacter(ID) ? charDirs : promoDirs)[rawID]);
animDir = SD.open(directoryPath);
if (!animDir) {
Com::sendComment("Could not open directory %s for ID %d", directoryPath, rawID);
return;
}
checkAndDisplay();
}
bool LCD::checkAndDisplay() {
if (!animDir || millis() - lastFrameTime < frameTarget)
return false;
File frame = animDir.openNextFile();
if (!frame) {
/* There are no frames anymore, the animation is complete. */
animDir.close();
return false;
}
frame.read(bitmap, 528);
frame.close();
lcd.clearDisplay();
lcd.drawBitmap(0, 0, bitmap, 84, 48, 1);
lcd.display();
lastFrameTime = millis();
return true;
}

View file

@ -3,6 +3,7 @@
#include "Pinout.h"
#include "Com.h"
#include "LCD.h"
#include "RFID.h"
__attribute__((noreturn)) int main() {
@ -44,15 +45,27 @@ __attribute__((noreturn)) int main() {
digitalWrite(pin_NFC1_RST, HIGH);
rfid.init();
if (!SD.begin(BUILTIN_SDCARD))
Com::sendComment("Could not use the SD Card.");
LCD lcd;
digitalWrite(pin_LCD_RST, HIGH);
lcd.init();
/* Main loop */
while (true) {
int8_t tagEvent;
/* Display first, in case the RFID communication delays it too much. */
lcd.checkAndDisplay();
tagEvent = rfid.checkTags();
if (tagEvent) {
Com::sendFigUpdate(tagEvent);
lcd.startNewAnim(tagEvent);
}
delay(100);
/* TODO: Drop delay, WFE+timer interrupt(s) ? */
delay(25);
}
}