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:
parent
e21123538b
commit
69909851c2
4 changed files with 127 additions and 3 deletions
|
@ -42,8 +42,8 @@ se synchroniser avec le firmware et potentiellement le mettre à jour.
|
||||||
- [ ] Contrôle des modules
|
- [ ] Contrôle des modules
|
||||||
- [x] RFID (base)
|
- [x] RFID (base)
|
||||||
- [ ] RFID (avancé, écriture des tags)
|
- [ ] RFID (avancé, écriture des tags)
|
||||||
- [ ] LCD (base)
|
- [x] LCD (base)
|
||||||
- [ ] LCD (animations)
|
- [x] LCD (animations)
|
||||||
- [ ] LCD (UI)
|
- [ ] LCD (UI)
|
||||||
- [ ] Audio (sons de figurines)
|
- [ ] Audio (sons de figurines)
|
||||||
- [ ] Audio (sons d'UI)
|
- [ ] Audio (sons d'UI)
|
||||||
|
|
46
include/LCD.h
Normal file
46
include/LCD.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
//
|
||||||
|
// Created by Teo-CD on 17/10/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef JIN_BARBAPAPA_LCD_H
|
||||||
|
#define JIN_BARBAPAPA_LCD_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <SD.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#include <Adafruit_PCD8544.h>
|
||||||
|
|
||||||
|
#include "Com.h"
|
||||||
|
#include "IDs.h"
|
||||||
|
#include "Pinout.h"
|
||||||
|
|
||||||
|
class LCD {
|
||||||
|
public:
|
||||||
|
LCD() : sd(SD) {};
|
||||||
|
void init();
|
||||||
|
/***
|
||||||
|
* Check if time has passed and we should display a new frame.
|
||||||
|
* @return True if a new frame was displayed.
|
||||||
|
*/
|
||||||
|
bool checkAndDisplay();
|
||||||
|
void startNewAnim(int8_t ID);
|
||||||
|
private:
|
||||||
|
Adafruit_PCD8544 lcd{pin_LCD_DC, pin_LCD_CS, pin_LCD_RST};
|
||||||
|
|
||||||
|
SDClass &sd;
|
||||||
|
/* Directory where the current animation frames are stored. */
|
||||||
|
File animDir;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Array storing the bitmap that will be passed to the LCD.
|
||||||
|
* The LCD is 84x48 so that should be 504 bytes, but the row length (84)
|
||||||
|
* is not byte aligned. Thus, the last byte is padded, giving 88x48 = 528.
|
||||||
|
*/
|
||||||
|
static uint8_t bitmap[528];
|
||||||
|
uint32_t lastFrameTime = 0;
|
||||||
|
/* Delay between two frames, in milliseconds. Above 10 FPS is mushy, avoid. */
|
||||||
|
static constexpr uint32_t frameTarget = 1000 / 7;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //JIN_BARBAPAPA_LCD_H
|
65
src/LCD.cpp
Normal file
65
src/LCD.cpp
Normal 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;
|
||||||
|
}
|
15
src/main.cpp
15
src/main.cpp
|
@ -3,6 +3,7 @@
|
||||||
#include "Pinout.h"
|
#include "Pinout.h"
|
||||||
|
|
||||||
#include "Com.h"
|
#include "Com.h"
|
||||||
|
#include "LCD.h"
|
||||||
#include "RFID.h"
|
#include "RFID.h"
|
||||||
|
|
||||||
__attribute__((noreturn)) int main() {
|
__attribute__((noreturn)) int main() {
|
||||||
|
@ -44,15 +45,27 @@ __attribute__((noreturn)) int main() {
|
||||||
digitalWrite(pin_NFC1_RST, HIGH);
|
digitalWrite(pin_NFC1_RST, HIGH);
|
||||||
rfid.init();
|
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 */
|
/* Main loop */
|
||||||
while (true) {
|
while (true) {
|
||||||
int8_t tagEvent;
|
int8_t tagEvent;
|
||||||
|
|
||||||
|
/* Display first, in case the RFID communication delays it too much. */
|
||||||
|
lcd.checkAndDisplay();
|
||||||
|
|
||||||
tagEvent = rfid.checkTags();
|
tagEvent = rfid.checkTags();
|
||||||
if (tagEvent) {
|
if (tagEvent) {
|
||||||
Com::sendFigUpdate(tagEvent);
|
Com::sendFigUpdate(tagEvent);
|
||||||
|
lcd.startNewAnim(tagEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(100);
|
/* TODO: Drop delay, WFE+timer interrupt(s) ? */
|
||||||
|
delay(25);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue