Skip to content

Commit 70df3c8

Browse files
committed
Add WAV playback during battery test
1 parent a299a38 commit 70df3c8

22 files changed

+87
-3
lines changed

BoxBattery.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void BoxBattery::startBatteryTest() {
143143
file.writeString("Comments");
144144
file.writeString("\r\n");
145145
file.writeString("0;;;;;;");
146-
sprintf(output, "vFactor=%u, vChargerFactor=%u;", _batteryVoltageFactor, _batteryVoltageChargerFactor);
146+
sprintf(output, "vFactor=%u, vChargerFactor=%u;v2-wav", _batteryVoltageFactor, _batteryVoltageChargerFactor);
147147
file.writeString(output);
148148
file.writeString("\r\n");
149149
file.close();

BoxDAC.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,75 @@ void BoxDAC::loop(uint16_t timeoutMs) {
200200
} else {
201201
generateZeroAudio(timeoutMs);
202202
}
203+
batteryTestLoop();
204+
}
205+
206+
void BoxDAC::batteryTestLoop() {
207+
if (Box.boxBattery.batteryTestActive()) {
208+
if (current_volume != VOL_TEST)
209+
setVolume(VOL_TEST);
210+
/*
211+
uint8_t midiId = (_batteryTestBeepState % 60) + 36; //36-96
212+
uint16_t lengthMs = (midiId % 20)*10; //+ 250;
213+
beepMidi(midiId, lengthMs, true);
214+
215+
if (_batteryTestBeepState<255) {
216+
_batteryTestBeepState++;
217+
} else {
218+
_batteryTestBeepState = 0;
219+
}*/
220+
221+
if (!audioPlaying) {
222+
if (!hasStopped()/*audioSource && audioSource->isOpen()*/) {
223+
Log.info("BatteryTest continue pause...");
224+
play(); //continue
225+
} else {
226+
//next
227+
DirFs dir;
228+
uint8_t selectedFileId = 0;
229+
uint8_t fileCount = 0;
230+
if (dir.openDir("/revvox/audio")) {
231+
while (dir.nextFile()) {
232+
if (dir.isDir())
233+
continue;
234+
fileCount++;
235+
}
236+
dir.rewind();
237+
if (fileCount <= _batteryTestFileId)
238+
_batteryTestFileId = 0;
239+
240+
while (dir.nextFile()) {
241+
if (dir.isDir())
242+
continue;
243+
244+
if (_batteryTestFileId == selectedFileId) {
245+
Log.info("BatteryTest next song id %i...", _batteryTestFileId);
246+
char fullpath[strlen("/revvox/audio/")+strlen((const char*)dir.fileName())+1];
247+
sprintf(fullpath,"%s%s","/revvox/audio/", (const char*)dir.fileName());
248+
if (!playFile(fullpath)) {
249+
Log.error("BatteryTest file %s invalid...", fullpath);
250+
Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Red, 4);
251+
Box.boxBattery.stopBatteryTest();
252+
}
253+
break;
254+
}
255+
selectedFileId++;
256+
}
257+
_batteryTestFileId++;
258+
dir.closeDir();
259+
if (fileCount == 0) {
260+
Log.error("BatteryTest dir /revvox/audio/ empty...");
261+
Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Red, 4);
262+
Box.boxBattery.stopBatteryTest();
263+
}
264+
} else {
265+
Log.error("BatteryTest dir /revvox/audio/ not found...");
266+
Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Red, 3);
267+
Box.boxBattery.stopBatteryTest();
268+
}
269+
}
270+
}
271+
}
203272
}
204273

205274
void BoxDAC::play() {

BoxDAC.h

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class BoxDAC : public EnhancedThread {
4040
void samSay(const char *text, enum ESP8266SAM::SAMVoice voice = ESP8266SAM::SAMVoice::VOICE_SAM, uint8_t speed = 0, uint8_t pitch = 0, uint8_t throat = 0, uint8_t mouth = 0, bool sing = false, bool phoentic = false);
4141

4242
void dmaPingPingComplete();
43+
44+
void batteryTestLoop();
45+
4346
BoxAudioBufferTriple audioBuffer;
4447
unsigned long dmaIRQcount = 0;
4548
unsigned long lastDmaIRQcount = 0xFFFF;
@@ -79,6 +82,7 @@ class BoxDAC : public EnhancedThread {
7982
const static uint8_t VOL_MIN = 0xB0+0x7F; //0xB0=-40.0dB /min allowed value 0x81=-63.5dB
8083
const static uint8_t VOL_MAX = 0x0A+0x7F; //0x0A=+04.0dB /max allowed value 0x30=+24.0dB
8184
const static uint8_t VOL_STEP = 0x06; //3dB
85+
const static uint8_t VOL_TEST = VOL_MIN + 6*VOL_STEP;
8286
uint8_t current_volume;
8387

8488
//const static uint8_t VOL_BEEP_MIN = 0x2A; //0x2A=-40dB /min allowed value 0x3F=-61dB
@@ -115,6 +119,8 @@ class BoxDAC : public EnhancedThread {
115119
bool hasStopped();
116120

117121
private:
122+
uint8_t _batteryTestFileId;
123+
118124
enum class PAGE {
119125
SERIAL_IO = 0x00,
120126
DAC_OUT_VOL = 0x01,

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The custom bootloader is fully functional. The hackiebox custom firmware itself
1212
- Hardware drivers (WiFi, AMP/DAC, RFID reader, accelleration sensor, battery/charger, SD, LEDs)
1313
- Webinterface with basic CLI and file upload/download
1414
- JSON configuration file
15-
- Battery stamina test with csv log
15+
- Battery stamina test with WAV-playback with csv log
1616
- Tonie file header decoder
1717
- WAV player (with cli + by wav file in /rCONTENT/<UIDREV>/)
1818
### Todo
@@ -57,7 +57,7 @@ Open hackiebox_cfw.ino with energia and build the cfw. Remember the path where t
5757
### Preface
5858
It is recommended to have a second copy of the cfw to be able to load the working image and update a broken cfw image over your backup cfw.
5959
### Copy to sd
60-
First of all you need to create "/revvox/web" on your sd card (subdir revvox should be already there if you have successfully installed the sd bootloader) and copy over the content of the /web/ directory of this repository. In addition you have to copy your cfw image to your selected slot(s) on the sd card. (ex. "/revvox/boot/pre-img1.bin")
60+
First of all you need to create "/revvox/web" on your sd card (subdir revvox should be already there if you have successfully installed the sd bootloader) and copy over the content of the /web/ directory of this repository. The same applies to the "/revvox/audio" directory for WAV-playback during the battery test. In addition you have to copy your cfw image to your selected slot(s) on the sd card. (ex. "/revvox/boot/pre-img1.bin")
6161
### First boot
6262
Reinsert the sd card and run the cfw once. Then shutdown the box again (put the box onto the front where the speaker/tonie logo is and press both ears for 10s). Then remove the sd card again and add your wifi credentials to the created "/revvox/hackiebox.config.json" config file.
6363
## Firmware updates

audio/both-of-us-14037.wav

5.14 MB
Binary file not shown.
3.88 MB
Binary file not shown.
3.38 MB
Binary file not shown.

audio/into-the-night-20928.wav

4.29 MB
Binary file not shown.

audio/melody-of-nature-main-6672.wav

5.55 MB
Binary file not shown.
6.9 MB
Binary file not shown.

audio/source/both-of-us-14037.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/schlagt-both-of-us-14037/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/uberschrift-cinematic-fairy-tale-story-main-8697/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/schlagt-electronic-rock-king-around-here-15045/

audio/source/into-the-night-20928.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/schlagt-into-the-night-20928/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/schone-stucke-melody-of-nature-main-6672/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/akustische-gruppe-nightlife-michael-kobrin-95bpm-3783/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/solo-gitarre-the-cradle-of-your-soul-15700/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/schlagt-trailer-sport-stylish-16073/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://pixabay.com/de/music/schlagt-yesterday-extended-version-14197/
5.42 MB
Binary file not shown.

audio/trailer-sport-stylish-16073.wav

5.54 MB
Binary file not shown.
8.22 MB
Binary file not shown.

0 commit comments

Comments
 (0)