Compare commits
No commits in common. "a7c2856ef67b0eb33c8e3402306cc8dd847fed71" and "69909851c217f0a18df8184f3848e4ee115a643d" have entirely different histories.
a7c2856ef6
...
69909851c2
9 changed files with 9 additions and 127 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
.pio
|
||||
**/.idea
|
||||
.idea
|
||||
|
|
10
README.md
10
README.md
|
@ -45,7 +45,7 @@ se synchroniser avec le firmware et potentiellement le mettre à jour.
|
|||
- [x] LCD (base)
|
||||
- [x] LCD (animations)
|
||||
- [ ] LCD (UI)
|
||||
- [x] Audio (sons de figurines)
|
||||
- [ ] Audio (sons de figurines)
|
||||
- [ ] Audio (sons d'UI)
|
||||
- [ ] Audio (gain ?)
|
||||
- [ ] Communication avec logiciel
|
||||
|
@ -81,7 +81,7 @@ détaillés ici.
|
|||
|
||||
## Structure de fichiers
|
||||
|
||||
Les fichiers sur la carte SD sont structurés comme suit (**notez les majuscules**) :
|
||||
Les fichiers sur la carte SD sont structurés comme suit :
|
||||
```
|
||||
/
|
||||
├── RANDONNEE/
|
||||
|
@ -91,16 +91,16 @@ Les fichiers sur la carte SD sont structurés comme suit (**notez les majuscules
|
|||
│ │ ├── 02
|
||||
│ │ ├── ..
|
||||
│ │ └── XX
|
||||
│ └── ENTRY.WAV
|
||||
│ └── audio.wav
|
||||
├── RESTO/
|
||||
│ ├── ANIM/
|
||||
│ │ └── ..
|
||||
│ └── ENTRY.WAV
|
||||
│ └── audio.wav
|
||||
├── .../
|
||||
└── SYS/
|
||||
├── ANIM*/
|
||||
├── ../
|
||||
└── *.WAV
|
||||
└── *.wav
|
||||
```
|
||||
|
||||
Tous les fichiers liés à une figurine en particulier doivent être placés dans un
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
namespace Com {
|
||||
void sendFigUpdate(int8_t event);
|
||||
void sendComment(const char message[62], ...);
|
||||
void sendComment(const char* message, ...);
|
||||
}
|
||||
|
||||
#endif //JIN_BARBAPAPA_COM_H
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include <Adafruit_PCD8544.h>
|
||||
|
||||
#include "Audio.h"
|
||||
#include "Com.h"
|
||||
#include "IDs.h"
|
||||
#include "Pinout.h"
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
//
|
||||
// Created by Teo-CD on 22/10/23.
|
||||
//
|
||||
|
||||
#ifndef JIN_BARBAPAPA_SPEAKER_H
|
||||
#define JIN_BARBAPAPA_SPEAKER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Audio.h>
|
||||
#include <SerialFlash.h>
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Com.h"
|
||||
#include "IDs.h"
|
||||
#include "Pinout.h"
|
||||
|
||||
static constexpr uint8_t audioMemReservation = 10;
|
||||
|
||||
class Speaker {
|
||||
public:
|
||||
Speaker() : sd(SD) {};
|
||||
static void init();
|
||||
|
||||
/** Play the entry sound for a specific tag ID. */
|
||||
void playNewSound(int8_t ID);
|
||||
|
||||
/** Check if a sound and playing an disable the amp if not anymore. */
|
||||
bool checkPlayingAndDisable();
|
||||
private:
|
||||
SDClass &sd;
|
||||
|
||||
/*
|
||||
* Below are members needed to set up the audio pipeline.
|
||||
* We need an input, output, and to connect them to one another.
|
||||
* We also need some specially reserved memory to store the data to playback.
|
||||
*/
|
||||
static audio_block_t audioMemory[audioMemReservation];
|
||||
static bool memoryInitialized;
|
||||
AudioPlaySdWav sdWavSource;
|
||||
AudioOutputI2S i2sOut;
|
||||
AudioConnection connectLeftChannels{sdWavSource, 0, i2sOut, 0};
|
||||
AudioConnection connectRightChannels{sdWavSource, 1, i2sOut, 1};
|
||||
};
|
||||
|
||||
|
||||
#endif //JIN_BARBAPAPA_SPEAKER_H
|
|
@ -28,7 +28,7 @@ namespace Com {
|
|||
flushBuffer();
|
||||
}
|
||||
|
||||
void sendComment(const char message[62], ...) {
|
||||
void sendComment(const char *message, ...) {
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
buffer[0] = '#';
|
||||
|
|
|
@ -47,23 +47,14 @@ bool LCD::checkAndDisplay() {
|
|||
if (!animDir || millis() - lastFrameTime < frameTarget)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Audio playback is controlled by interrupts, so it can happen anytime.
|
||||
* Prevent a potential conflict when reading a frame of animation from the
|
||||
* SD card and being interrupted by the audio library, which will try to
|
||||
* read audio data from the SD card at the same time.
|
||||
*/
|
||||
AudioNoInterrupts();
|
||||
File frame = animDir.openNextFile();
|
||||
if (!frame) {
|
||||
/* There are no frames anymore, the animation is complete. */
|
||||
animDir.close();
|
||||
AudioInterrupts();
|
||||
return false;
|
||||
}
|
||||
frame.read(bitmap, 528);
|
||||
frame.close();
|
||||
AudioInterrupts();
|
||||
|
||||
lcd.clearDisplay();
|
||||
lcd.drawBitmap(0, 0, bitmap, 84, 48, 1);
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
//
|
||||
// Created by Teo-CD on 22/10/23.
|
||||
//
|
||||
|
||||
#include "Speaker.h"
|
||||
|
||||
DMAMEM audio_block_t Speaker::audioMemory[audioMemReservation];
|
||||
bool Speaker::memoryInitialized = false;
|
||||
|
||||
void Speaker::init() {
|
||||
if (memoryInitialized)
|
||||
return;
|
||||
AudioStream::initialize_memory(audioMemory, audioMemReservation);
|
||||
memoryInitialized = true;
|
||||
}
|
||||
|
||||
void Speaker::playNewSound(int8_t ID) {
|
||||
char filePath[20];
|
||||
uint8_t rawID = getRawId(ID);
|
||||
|
||||
if (!SD.mediaPresent()) {
|
||||
Com::sendComment("SD Card not present, cannot play sound");
|
||||
return;
|
||||
}
|
||||
if (!isValidId(ID)) {
|
||||
Com::sendComment("Unknown ID for sound : %d", rawID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sdWavSource.isPlaying())
|
||||
sdWavSource.stop();
|
||||
|
||||
snprintf(filePath, 20, "%s/ENTRY.WAV",
|
||||
(isIdCharacter(ID) ? charDirs : promoDirs)[rawID]);
|
||||
|
||||
if (!sd.exists(filePath)) {
|
||||
Com::sendComment("File %s not present, cannot play sound.", filePath);
|
||||
return;
|
||||
}
|
||||
digitalWrite(pin_Audio_Amp_enable, HIGH);
|
||||
sdWavSource.play(filePath);
|
||||
}
|
||||
|
||||
bool Speaker::checkPlayingAndDisable() {
|
||||
bool isPlaying = sdWavSource.isPlaying();
|
||||
if (!isPlaying)
|
||||
digitalWrite(pin_Audio_Amp_enable, LOW);
|
||||
return isPlaying;
|
||||
}
|
13
src/main.cpp
13
src/main.cpp
|
@ -5,7 +5,6 @@
|
|||
#include "Com.h"
|
||||
#include "LCD.h"
|
||||
#include "RFID.h"
|
||||
#include "Speaker.h"
|
||||
|
||||
__attribute__((noreturn)) int main() {
|
||||
pinMode(pin_DBG_LED_1, OUTPUT);
|
||||
|
@ -41,6 +40,7 @@ __attribute__((noreturn)) int main() {
|
|||
Serial.begin(115200);
|
||||
Com::sendComment("System is powered up, running set-up.");
|
||||
|
||||
/* TODO: Setups once module structure is up. */
|
||||
RFID rfid;
|
||||
digitalWrite(pin_NFC1_RST, HIGH);
|
||||
rfid.init();
|
||||
|
@ -52,28 +52,17 @@ __attribute__((noreturn)) int main() {
|
|||
digitalWrite(pin_LCD_RST, HIGH);
|
||||
lcd.init();
|
||||
|
||||
/* Don't enable the amp here, only do it when playing to save some power. */
|
||||
Speaker::init();
|
||||
Speaker speaker;
|
||||
|
||||
Com::sendComment("All modules initialized, entering main loop.");
|
||||
|
||||
/* Main loop */
|
||||
while (true) {
|
||||
int8_t tagEvent;
|
||||
|
||||
/* Display first, in case the RFID communication delays it too much. */
|
||||
lcd.checkAndDisplay();
|
||||
speaker.checkPlayingAndDisable();
|
||||
|
||||
tagEvent = rfid.checkTags();
|
||||
if (tagEvent) {
|
||||
tagEvent = 4;
|
||||
Com::sendFigUpdate(tagEvent);
|
||||
/* Start the audio first because of the possible WAV parsing delay. */
|
||||
speaker.playNewSound(tagEvent);
|
||||
lcd.startNewAnim(tagEvent);
|
||||
|
||||
}
|
||||
|
||||
/* TODO: Drop delay, WFE+timer interrupt(s) ? */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue