fork from github
This commit is contained in:
68
examples/MixerSample/MixerSample.ino
Normal file
68
examples/MixerSample/MixerSample.ino
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioGeneratorWAV.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
#include "AudioOutputMixer.h"
|
||||
|
||||
// VIOLA sample taken from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
|
||||
#include "viola.h"
|
||||
|
||||
AudioGeneratorWAV *wav[2];
|
||||
AudioFileSourcePROGMEM *file[2];
|
||||
AudioOutputI2S *out;
|
||||
AudioOutputMixer *mixer;
|
||||
AudioOutputMixerStub *stub[2];
|
||||
|
||||
void setup()
|
||||
{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.printf("WAV start\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file[0] = new AudioFileSourcePROGMEM( viola, sizeof(viola) );
|
||||
out = new AudioOutputI2S();
|
||||
mixer = new AudioOutputMixer(32, out);
|
||||
stub[0] = mixer->NewInput();
|
||||
stub[0]->SetGain(0.3);
|
||||
wav[0] = new AudioGeneratorWAV();
|
||||
wav[0]->begin(file[0], stub[0]);
|
||||
// Begin wav[1] later in loop()
|
||||
Serial.printf("starting 1\n");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static uint32_t start = 0;
|
||||
static bool go = false;
|
||||
|
||||
if (!start) start = millis();
|
||||
|
||||
if (wav[0]->isRunning()) {
|
||||
if (!wav[0]->loop()) { wav[0]->stop(); stub[0]->stop(); Serial.printf("stopping 1\n"); }
|
||||
}
|
||||
|
||||
if (millis()-start > 3000) {
|
||||
if (!go) {
|
||||
Serial.printf("starting 2\n");
|
||||
stub[1] = mixer->NewInput();
|
||||
stub[1]->SetGain(0.4);
|
||||
wav[1] = new AudioGeneratorWAV();
|
||||
file[1] = new AudioFileSourcePROGMEM( viola, sizeof(viola) );
|
||||
wav[1]->begin(file[1], stub[1]);
|
||||
go = true;
|
||||
}
|
||||
if (wav[1]->isRunning()) {
|
||||
if (!wav[1]->loop()) { wav[1]->stop(); stub[1]->stop(); Serial.printf("stopping 2\n");}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
49898
examples/MixerSample/viola.h
Normal file
49898
examples/MixerSample/viola.h
Normal file
File diff suppressed because it is too large
Load Diff
33
examples/PlayAACFromPROGMEM/PlayAACFromPROGMEM.ino
Normal file
33
examples/PlayAACFromPROGMEM/PlayAACFromPROGMEM.ino
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <Arduino.h>
|
||||
#include "AudioGeneratorAAC.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "sampleaac.h"
|
||||
|
||||
AudioFileSourcePROGMEM *in;
|
||||
AudioGeneratorAAC *aac;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
audioLogger = &Serial;
|
||||
in = new AudioFileSourcePROGMEM(sampleaac, sizeof(sampleaac));
|
||||
aac = new AudioGeneratorAAC();
|
||||
out = new AudioOutputI2S();
|
||||
|
||||
aac->begin(in, out);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (aac->isRunning()) {
|
||||
aac->loop();
|
||||
} else {
|
||||
Serial.printf("AAC done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
examples/PlayAACFromPROGMEM/homer.aac
Normal file
BIN
examples/PlayAACFromPROGMEM/homer.aac
Normal file
Binary file not shown.
2812
examples/PlayAACFromPROGMEM/sampleaac.h
Normal file
2812
examples/PlayAACFromPROGMEM/sampleaac.h
Normal file
File diff suppressed because it is too large
Load Diff
68
examples/PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino
Normal file
68
examples/PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <Arduino.h>
|
||||
#include "AudioFileSourceSD.h"
|
||||
#include "AudioOutputSPDIF.h"
|
||||
#include "AudioGeneratorFLAC.h"
|
||||
|
||||
// For this sketch, you need connected SD card with '.flac' music files in the root
|
||||
// directory. Some samples with various sampling rates are available from i.e.
|
||||
// Espressif Audio Development Framework at:
|
||||
// https://docs.espressif.com/projects/esp-adf/en/latest/design-guide/audio-samples.html
|
||||
//
|
||||
// On ESP8266 you might need to reencode FLAC files with max '-2' compression level
|
||||
// (i.e. 1152 maximum block size) or you will run out of memory. FLAC files will be
|
||||
// slightly bigger but you don't loose audio quality with reencoding (lossles codec).
|
||||
|
||||
// You may need a fast SD card. Set this as high as it will work (40MHz max).
|
||||
#define SPI_SPEED SD_SCK_MHZ(40)
|
||||
|
||||
// On ESP32 you can adjust the SPDIF_OUT_PIN (GPIO number).
|
||||
// On ESP8266 it is fixed to GPIO3/RX0 and this setting has no effect
|
||||
#define SPDIF_OUT_PIN 27
|
||||
|
||||
File dir;
|
||||
AudioFileSourceSD *source = NULL;
|
||||
AudioOutputSPDIF *output = NULL;
|
||||
AudioGeneratorFLAC *decoder = NULL;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
|
||||
audioLogger = &Serial;
|
||||
source = new AudioFileSourceSD();
|
||||
output = new AudioOutputSPDIF(SPDIF_OUT_PIN);
|
||||
decoder = new AudioGeneratorFLAC();
|
||||
|
||||
// NOTE: SD.begin(...) should be called AFTER AudioOutputSPDIF()
|
||||
// to takover the the SPI pins if they share some with I2S
|
||||
// (i.e. D8 on Wemos D1 mini is both I2S BCK and SPI SS)
|
||||
#if defined(ESP8266)
|
||||
SD.begin(SS, SPI_SPEED);
|
||||
#else
|
||||
SD.begin();
|
||||
#endif
|
||||
dir = SD.open("/");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if ((decoder) && (decoder->isRunning())) {
|
||||
if (!decoder->loop()) decoder->stop();
|
||||
} else {
|
||||
File file = dir.openNextFile();
|
||||
if (file) {
|
||||
if (String(file.name()).endsWith(".flac")) {
|
||||
source->close();
|
||||
if (source->open(file.name())) {
|
||||
Serial.printf_P(PSTR("Playing '%s' from SD card...\n"), file.name());
|
||||
decoder->begin(source, output);
|
||||
} else {
|
||||
Serial.printf_P(PSTR("Error opening '%s'\n"), file.name());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Serial.println(F("Playback form SD card done\n"));
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <Arduino.h>
|
||||
#include <AudioOutputI2S.h>
|
||||
#include <AudioFileSourcePROGMEM.h>
|
||||
#include <AudioGeneratorFLAC.h>
|
||||
|
||||
#include "sample.h"
|
||||
|
||||
AudioOutputI2S *out;
|
||||
AudioFileSourcePROGMEM *file;
|
||||
AudioGeneratorFLAC *flac;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting up...\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourcePROGMEM( sample_flac, sizeof(sample_flac) );
|
||||
out = new AudioOutputI2S();
|
||||
flac = new AudioGeneratorFLAC();
|
||||
flac->begin(file, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (flac->isRunning()) {
|
||||
if (!flac->loop()) flac->stop();
|
||||
} else {
|
||||
Serial.printf("FLAC done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
5707
examples/PlayFLACFromPROGMEMToDAC/sample.h
Normal file
5707
examples/PlayFLACFromPROGMEMToDAC/sample.h
Normal file
File diff suppressed because it is too large
Load Diff
54
examples/PlayMIDIFromLittleFS/PlayMIDIFromLittleFS.ino
Normal file
54
examples/PlayMIDIFromLittleFS/PlayMIDIFromLittleFS.ino
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.printf("ERROR - ESP32 does not support LittleFS\n");
|
||||
}
|
||||
void loop() {}
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <AudioOutputI2S.h>
|
||||
#include <AudioGeneratorMIDI.h>
|
||||
#include <AudioFileSourceLittleFS.h>
|
||||
|
||||
AudioFileSourceLittleFS *sf2;
|
||||
AudioFileSourceLittleFS *mid;
|
||||
AudioOutputI2S *dac;
|
||||
AudioGeneratorMIDI *midi;
|
||||
|
||||
void setup()
|
||||
{
|
||||
const char *soundfont = "/1mgm.sf2";
|
||||
const char *midifile = "/furelise.mid";
|
||||
|
||||
WiFi.mode(WIFI_OFF);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting up...\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
sf2 = new AudioFileSourceLittleFS(soundfont);
|
||||
mid = new AudioFileSourceLittleFS(midifile);
|
||||
|
||||
dac = new AudioOutputI2S();
|
||||
midi = new AudioGeneratorMIDI();
|
||||
midi->SetSoundfont(sf2);
|
||||
midi->SetSampleRate(22050);
|
||||
Serial.printf("BEGIN...\n");
|
||||
midi->begin(mid, dac);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (midi->isRunning()) {
|
||||
if (!midi->loop()) {
|
||||
uint32_t e = millis();
|
||||
midi->stop();
|
||||
}
|
||||
} else {
|
||||
Serial.printf("MIDI done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
BIN
examples/PlayMIDIFromLittleFS/data/1mgm.sf2
Normal file
BIN
examples/PlayMIDIFromLittleFS/data/1mgm.sf2
Normal file
Binary file not shown.
BIN
examples/PlayMIDIFromLittleFS/data/furelise.mid
Normal file
BIN
examples/PlayMIDIFromLittleFS/data/furelise.mid
Normal file
Binary file not shown.
55
examples/PlayMIDIFromSPIFFS/PlayMIDIFromSPIFFS.ino
Normal file
55
examples/PlayMIDIFromSPIFFS/PlayMIDIFromSPIFFS.ino
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#include "SPIFFS.h"
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <AudioOutputNull.h>
|
||||
#include <AudioOutputI2S.h>
|
||||
#include <AudioGeneratorMIDI.h>
|
||||
#include <AudioFileSourceSPIFFS.h>
|
||||
|
||||
AudioFileSourceSPIFFS *sf2;
|
||||
AudioFileSourceSPIFFS *mid;
|
||||
AudioOutputI2S *dac;
|
||||
AudioGeneratorMIDI *midi;
|
||||
|
||||
void setup()
|
||||
{
|
||||
const char *soundfont = "/1mgm.sf2";
|
||||
const char *midifile = "/furelise.mid";
|
||||
|
||||
WiFi.mode(WIFI_OFF);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting up...\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
sf2 = new AudioFileSourceSPIFFS(soundfont);
|
||||
mid = new AudioFileSourceSPIFFS(midifile);
|
||||
|
||||
dac = new AudioOutputI2S();
|
||||
midi = new AudioGeneratorMIDI();
|
||||
midi->SetSoundfont(sf2);
|
||||
midi->SetSampleRate(22050);
|
||||
Serial.printf("BEGIN...\n");
|
||||
midi->begin(mid, dac);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (midi->isRunning()) {
|
||||
if (!midi->loop()) {
|
||||
uint32_t e = millis();
|
||||
midi->stop();
|
||||
}
|
||||
} else {
|
||||
Serial.printf("MIDI done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
examples/PlayMIDIFromSPIFFS/data/1mgm.sf2
Normal file
BIN
examples/PlayMIDIFromSPIFFS/data/1mgm.sf2
Normal file
Binary file not shown.
BIN
examples/PlayMIDIFromSPIFFS/data/furelise.mid
Normal file
BIN
examples/PlayMIDIFromSPIFFS/data/furelise.mid
Normal file
Binary file not shown.
44
examples/PlayMODFromPROGMEMToDAC/PlayMODFromPROGMEMToDAC.ino
Normal file
44
examples/PlayMODFromPROGMEMToDAC/PlayMODFromPROGMEMToDAC.ino
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <Arduino.h>
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioGeneratorMOD.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
// enigma.mod sample from the mod archive: https://modarchive.org/index.php?request=view_by_moduleid&query=42146
|
||||
#include "enigma.h"
|
||||
|
||||
AudioGeneratorMOD *mod;
|
||||
AudioFileSourcePROGMEM *file;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
void setup()
|
||||
{
|
||||
WiFi.mode(WIFI_OFF); //WiFi.forceSleepBegin();
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourcePROGMEM( enigma_mod, sizeof(enigma_mod) );
|
||||
// out = new AudioOutputI2S(0, 1); Uncomment this line, comment the next one to use the internal DAC channel 1 (pin25) on ESP32
|
||||
out = new AudioOutputI2S();
|
||||
mod = new AudioGeneratorMOD();
|
||||
mod->SetBufferSize(3*1024);
|
||||
mod->SetSampleRate(44100);
|
||||
mod->SetStereoSeparation(32);
|
||||
mod->begin(file, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (mod->isRunning()) {
|
||||
if (!mod->loop()) mod->stop();
|
||||
} else {
|
||||
Serial.printf("MOD done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
15587
examples/PlayMODFromPROGMEMToDAC/enigma.h
Normal file
15587
examples/PlayMODFromPROGMEMToDAC/enigma.h
Normal file
File diff suppressed because it is too large
Load Diff
72
examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino
Normal file
72
examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#include "SPIFFS.h"
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceSPIFFS.h"
|
||||
#include "AudioFileSourceID3.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
// To run, set your ESP8266 build to 160MHz, and include a SPIFFS of 512KB or greater.
|
||||
// Use the "Tools->ESP8266/ESP32 Sketch Data Upload" menu to write the MP3 to SPIFFS
|
||||
// Then upload the sketch normally.
|
||||
|
||||
// pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
|
||||
|
||||
AudioGeneratorMP3 *mp3;
|
||||
AudioFileSourceSPIFFS *file;
|
||||
AudioOutputI2SNoDAC *out;
|
||||
AudioFileSourceID3 *id3;
|
||||
|
||||
|
||||
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||
{
|
||||
(void)cbData;
|
||||
Serial.printf("ID3 callback for: %s = '", type);
|
||||
|
||||
if (isUnicode) {
|
||||
string += 2;
|
||||
}
|
||||
|
||||
while (*string) {
|
||||
char a = *(string++);
|
||||
if (isUnicode) {
|
||||
string++;
|
||||
}
|
||||
Serial.printf("%c", a);
|
||||
}
|
||||
Serial.printf("'\n");
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
SPIFFS.begin();
|
||||
Serial.printf("Sample MP3 playback begins...\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourceSPIFFS("/pno-cs.mp3");
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->RegisterMetadataCB(MDCallback, (void*)"ID3TAG");
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->begin(id3, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (mp3->isRunning()) {
|
||||
if (!mp3->loop()) mp3->stop();
|
||||
} else {
|
||||
Serial.printf("MP3 done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
99
examples/PlayMP3ToSPDIF/PlayMP3ToSPDIF.ino
Normal file
99
examples/PlayMP3ToSPDIF/PlayMP3ToSPDIF.ino
Normal file
@@ -0,0 +1,99 @@
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include "SPIFFS.h"
|
||||
#endif
|
||||
#include "AudioFileSourceSPIFFS.h"
|
||||
#include "AudioFileSourceID3.h"
|
||||
#include "AudioOutputSPDIF.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
|
||||
// To run, set your ESP8266 build to 160MHz, and include a SPIFFS partition
|
||||
// big enough to hold your MP3 file. Find suitable MP3 file from i.e.
|
||||
// https://docs.espressif.com/projects/esp-adf/en/latest/design-guide/audio-samples.html
|
||||
// and download it into 'data' directory. Use the "Tools->ESP8266/ESP32 Sketch Data Upload"
|
||||
// menu to write the MP3 to SPIFFS. Then upload the sketch normally.
|
||||
|
||||
AudioFileSourceSPIFFS *file;
|
||||
AudioFileSourceID3 *id3;
|
||||
AudioOutputSPDIF *out;
|
||||
AudioGeneratorMP3 *mp3;
|
||||
|
||||
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||
{
|
||||
(void)cbData;
|
||||
Serial.printf("ID3 callback for: %s = '", type);
|
||||
|
||||
if (isUnicode) {
|
||||
string += 2;
|
||||
}
|
||||
|
||||
while (*string) {
|
||||
char a = *(string++);
|
||||
if (isUnicode) {
|
||||
string++;
|
||||
}
|
||||
Serial.printf("%c", a);
|
||||
}
|
||||
Serial.printf("'\n");
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println();
|
||||
audioLogger = &Serial;
|
||||
SPIFFS.begin();
|
||||
file = new AudioFileSourceSPIFFS();
|
||||
id3 = NULL;
|
||||
out = new AudioOutputSPDIF();
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
String fileName = "";
|
||||
|
||||
// Find first MP3 file in SPIFF and play it
|
||||
|
||||
#ifdef ESP32
|
||||
File dir, root = SPIFFS.open("/");
|
||||
while ((dir = root.openNextFile())) {
|
||||
if (String(dir.name()).endsWith(".mp3")) {
|
||||
if (file->open(dir.name())) {
|
||||
fileName = String(dir.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
dir = root.openNextFile();
|
||||
}
|
||||
#else
|
||||
Dir dir = SPIFFS.openDir("");
|
||||
while (dir.next()) {
|
||||
if (dir.fileName().endsWith(".mp3")) {
|
||||
if (file->open(dir.fileName().c_str())) {
|
||||
fileName = dir.fileName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fileName.length() > 0) {
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->RegisterMetadataCB(MDCallback, (void*)"ID3TAG");
|
||||
mp3->begin(id3, out);
|
||||
Serial.printf("Playback of '%s' begins...\n", fileName.c_str());
|
||||
} else {
|
||||
Serial.println("Can't find .mp3 file in SPIFFS");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (mp3->isRunning()) {
|
||||
if (!mp3->loop()) mp3->stop();
|
||||
} else {
|
||||
Serial.println("MP3 done");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
41
examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino
Normal file
41
examples/PlayOpusFromSPIFFS/PlayOpusFromSPIFFS.ino
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#include "SPIFFS.h"
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceSPIFFS.h"
|
||||
#include "AudioGeneratorOpus.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
|
||||
// The includes OPUS file is from Kevin MacLeod (incompetech.com), Licensed under Creative Commons: By Attribution 3.0, http://creativecommons.org/licenses/by/3.0/
|
||||
|
||||
AudioGeneratorOpus *opus;
|
||||
AudioFileSourceSPIFFS *file;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
void setup()
|
||||
{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
SPIFFS.begin();
|
||||
Serial.printf("Sample Opus playback begins...\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourceSPIFFS("/gs-16b-2c-44100hz.opus");
|
||||
out = new AudioOutputI2S();
|
||||
opus = new AudioGeneratorOpus();
|
||||
opus->begin(file, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (opus->isRunning()) {
|
||||
if (!opus->loop()) opus->stop();
|
||||
} else {
|
||||
Serial.printf("Opus done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
BIN
examples/PlayOpusFromSPIFFS/data/gs-16b-2c-44100hz.opus
Normal file
BIN
examples/PlayOpusFromSPIFFS/data/gs-16b-2c-44100hz.opus
Normal file
Binary file not shown.
36
examples/PlayRTTTLToI2SDAC/PlayRTTTLToI2SDAC.ino
Normal file
36
examples/PlayRTTTLToI2SDAC/PlayRTTTLToI2SDAC.ino
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioGeneratorRTTTL.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
|
||||
const char rudolph[] PROGMEM =
|
||||
"Rudolph the Red Nosed Raindeer:d=8,o=5,b=250:g,4a,g,4e,4c6,4a,2g.,g,a,g,a,4g,4c6,2b.,4p,f,4g,f,4d,4b,4a,2g.,g,a,g,a,4g,4a,2e.,4p,g,4a,a,4e,4c6,4a,2g.,g,a,g,a,4g,4c6,2b.,4p,f,4g,f,4d,4b,4a,2g.,g,a,g,a,4g,4d6,2c.6,4p,4a,4a,4c6,4a,4g,4e,2g,4d,4e,4g,4a,4b,4b,2b,4c6,4c6,4b,4a,4g,4f,2d,g,4a,g,4e,4c6,4a,2g.,g,a,g,a,4g,4c6,2b.,4p,f,4g,f,4d,4b,4a,2g.,4g,4a,4g,4a,2g,2d6,1c.6.";
|
||||
// Plenty more at: http://mines.lumpylumpy.com/Electronics/Computers/Software/Cpp/MFC/RingTones.RTTTL
|
||||
|
||||
AudioGeneratorRTTTL *rtttl;
|
||||
AudioFileSourcePROGMEM *file;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
Serial.printf("RTTTL start\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourcePROGMEM( rudolph, strlen_P(rudolph) );
|
||||
out = new AudioOutputI2S();
|
||||
rtttl = new AudioGeneratorRTTTL();
|
||||
rtttl->begin(file, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (rtttl->isRunning()) {
|
||||
if (!rtttl->loop()) rtttl->stop();
|
||||
} else {
|
||||
Serial.printf("RTTTL done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
78
examples/PlayWAVFromFunction/PlayWAVFromFunction.ino
Normal file
78
examples/PlayWAVFromFunction/PlayWAVFromFunction.ino
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <Arduino.h>
|
||||
#include "AudioFileSourceFunction.h"
|
||||
#include "AudioGeneratorWAV.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
float hz = 440.f;
|
||||
|
||||
// pre-defined function can also be used to generate the wave
|
||||
float sine_wave(const float time) {
|
||||
float v = sin(TWO_PI * hz * time); // C
|
||||
v *= fmod(time, 1.f); // change linear
|
||||
v *= 0.5; // scale
|
||||
return v;
|
||||
};
|
||||
|
||||
AudioGeneratorWAV* wav;
|
||||
AudioFileSourceFunction* file;
|
||||
AudioOutputI2SNoDAC* out;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
// ===== create instance with length of song in [sec] =====
|
||||
file = new AudioFileSourceFunction(8.);
|
||||
//
|
||||
// you can set (sec, channels, hz, bit/sample) but you should care about
|
||||
// the trade-off between performance and the audio quality
|
||||
//
|
||||
// file = new AudioFileSourceFunction(sec, channels, hz, bit/sample);
|
||||
// channels : default = 1
|
||||
// hz : default = 8000 (8000, 11025, 22050, 44100, 48000, etc.)
|
||||
// bit/sample : default = 16 (8, 16, 32)
|
||||
|
||||
// ===== set your sound function =====
|
||||
file->addAudioGenerators([&](const float time) {
|
||||
float v = sin(TWO_PI * hz * time); // generate sine wave
|
||||
v *= fmod(time, 1.f); // change linear
|
||||
v *= 0.5; // scale
|
||||
return v;
|
||||
});
|
||||
//
|
||||
// sound function should have one argument(float) and one return(float)
|
||||
// param : float (current time [sec] of the song)
|
||||
// return : float (the amplitude of sound which varies from -1.f to +1.f)
|
||||
//
|
||||
// sound function can be registerd only one or the same number with channels
|
||||
// if the channels > 1 && the number of function == 1,
|
||||
// same function are used to generate the sound in every channel
|
||||
//
|
||||
// file = new AudioFileSourceFunction(8., 2);
|
||||
// file->addAudioGenerators(
|
||||
// // L (channel 0)
|
||||
// [](const float time) {
|
||||
// return 0.25 * sin(TWO_PI * 440.f * time) * fmod(time, 1.f); // C
|
||||
// },
|
||||
// // R (channel 1)
|
||||
// [](const float time) {
|
||||
// return 0.25 * sin(TWO_PI * 550.f * time) * fmod(time, 1.f); // E
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// you can also use the pre-defined function
|
||||
// file->addAudioGenerators(sine_wave);
|
||||
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
wav = new AudioGeneratorWAV();
|
||||
wav->begin(file, out);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (wav->isRunning()) {
|
||||
if (!wav->loop()) wav->stop();
|
||||
} else {
|
||||
Serial.println("function done!");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
36
examples/PlayWAVFromPROGMEM/PlayWAVFromPROGMEM.ino
Normal file
36
examples/PlayWAVFromPROGMEM/PlayWAVFromPROGMEM.ino
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioGeneratorWAV.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
// VIOLA sample taken from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
|
||||
#include "viola.h"
|
||||
|
||||
AudioGeneratorWAV *wav;
|
||||
AudioFileSourcePROGMEM *file;
|
||||
AudioOutputI2SNoDAC *out;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.printf("WAV start\n");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourcePROGMEM( viola, sizeof(viola) );
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
wav = new AudioGeneratorWAV();
|
||||
wav->begin(file, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (wav->isRunning()) {
|
||||
if (!wav->loop()) wav->stop();
|
||||
} else {
|
||||
Serial.printf("WAV done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
49898
examples/PlayWAVFromPROGMEM/viola.h
Normal file
49898
examples/PlayWAVFromPROGMEM/viola.h
Normal file
File diff suppressed because it is too large
Load Diff
107
examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino
Normal file
107
examples/StreamMP3FromHTTP/StreamMP3FromHTTP.ino
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
|
||||
|
||||
// Enter your WiFi setup here:
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
// Randomly picked URL
|
||||
const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
|
||||
|
||||
AudioGeneratorMP3 *mp3;
|
||||
AudioFileSourceICYStream *file;
|
||||
AudioFileSourceBuffer *buff;
|
||||
AudioOutputI2SNoDAC *out;
|
||||
|
||||
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
(void) isUnicode; // Punt this ball for now
|
||||
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
|
||||
char s1[32], s2[64];
|
||||
strncpy_P(s1, type, sizeof(s1));
|
||||
s1[sizeof(s1)-1]=0;
|
||||
strncpy_P(s2, string, sizeof(s2));
|
||||
s2[sizeof(s2)-1]=0;
|
||||
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
|
||||
void StatusCallback(void *cbData, int code, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
// Note that the string may be in PROGMEM, so copy it to RAM for printf
|
||||
char s1[64];
|
||||
strncpy_P(s1, string, sizeof(s1));
|
||||
s1[sizeof(s1)-1]=0;
|
||||
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("Connecting to WiFi");
|
||||
|
||||
WiFi.disconnect();
|
||||
WiFi.softAPdisconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
// Try forever
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.println("...Connecting to WiFi");
|
||||
delay(1000);
|
||||
}
|
||||
Serial.println("Connected");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourceICYStream(URL);
|
||||
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
|
||||
buff = new AudioFileSourceBuffer(file, 2048);
|
||||
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
||||
mp3->begin(buff, out);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int lastms = 0;
|
||||
|
||||
if (mp3->isRunning()) {
|
||||
if (millis()-lastms > 1000) {
|
||||
lastms = millis();
|
||||
Serial.printf("Running for %d ms...\n", lastms);
|
||||
Serial.flush();
|
||||
}
|
||||
if (!mp3->loop()) mp3->stop();
|
||||
} else {
|
||||
Serial.printf("MP3 done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
104
examples/StreamMP3FromHTTP_SPIRAM/StreamMP3FromHTTP_SPIRAM.ino
Normal file
104
examples/StreamMP3FromHTTP_SPIRAM/StreamMP3FromHTTP_SPIRAM.ino
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceSPIRAMBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioOutputI2SNoDAC.h"
|
||||
|
||||
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
|
||||
|
||||
// Enter your WiFi setup here:
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
// Randomly picked URL
|
||||
const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
|
||||
|
||||
AudioGeneratorMP3 *mp3;
|
||||
AudioFileSourceICYStream *file;
|
||||
AudioFileSourceSPIRAMBuffer *buff;
|
||||
AudioOutputI2SNoDAC *out;
|
||||
|
||||
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
(void) isUnicode; // Punt this ball for now
|
||||
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
|
||||
Serial.printf_P(PSTR("METADATA(%s) '%s' = '%s'\n"), ptr, type, string);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
|
||||
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
|
||||
void StatusCallback(void *cbData, int code, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
static uint32_t lastTime = 0;
|
||||
static int lastCode = -99999;
|
||||
uint32_t now = millis();
|
||||
if ((lastCode != code) || (now - lastTime > 1000)) {
|
||||
Serial.printf_P(PSTR("STATUS(%s) '%d' = '%s'\n"), ptr, code, string);
|
||||
Serial.flush();
|
||||
lastTime = now;
|
||||
lastCode = code;
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("Connecting to WiFi");
|
||||
|
||||
WiFi.disconnect();
|
||||
WiFi.softAPdisconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
// Try forever
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.println("...Connecting to WiFi");
|
||||
delay(1000);
|
||||
}
|
||||
Serial.println("Connected");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourceICYStream(URL);
|
||||
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
|
||||
// Initialize 23LC1024 SPI RAM buffer with chip select ion GPIO4 and ram size of 128KByte
|
||||
buff = new AudioFileSourceSPIRAMBuffer(file, 4, 128*1024);
|
||||
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
||||
mp3->begin(buff, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int lastms = 0;
|
||||
|
||||
if (mp3->isRunning()) {
|
||||
if (millis()-lastms > 1000) {
|
||||
lastms = millis();
|
||||
Serial.printf("Running for %d ms...\n", lastms);
|
||||
Serial.flush();
|
||||
}
|
||||
if (!mp3->loop()) mp3->stop();
|
||||
} else {
|
||||
Serial.printf("MP3 done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
118
examples/StreamOnHost/AudioOutputLinuxDSP.h
Normal file
118
examples/StreamOnHost/AudioOutputLinuxDSP.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
AudioOutput
|
||||
Base class of an audio output player
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _AUDIOOUTPUTNULLSLOW_H
|
||||
#define _AUDIOOUTPUTNULLSLOW_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/soundcard.h>
|
||||
|
||||
#include "AudioOutput.h"
|
||||
|
||||
class AudioOutputNullSlow : public AudioOutput
|
||||
{
|
||||
public:
|
||||
AudioOutputNullSlow() { };
|
||||
~AudioOutputNullSlow() {};
|
||||
virtual bool begin() { samples = 0; startms = millis(); return true; }
|
||||
|
||||
virtual bool ConsumeSample(int16_t sample[2]) {
|
||||
|
||||
if (fd < 0) {
|
||||
fd = open("/dev/dsp", O_RDWR);
|
||||
if (fd < 0) {
|
||||
perror("open of /dev/dsp failed (Try with 'padsp this-exec')");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (channels && lastchannels != channels) {
|
||||
Serial.printf("CHANNELS=%d\n", channels);
|
||||
int arg = channels; /* mono or stereo */
|
||||
int status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
|
||||
if (status == -1) {
|
||||
perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
|
||||
exit(1);
|
||||
} else if (arg != channels) {
|
||||
perror("unable to set number of channels");
|
||||
exit(1);
|
||||
}
|
||||
lastchannels = channels;
|
||||
}
|
||||
|
||||
if (lastchannels > 0 && hertz && lasthertz != hertz) {
|
||||
Serial.printf("FREQ=%d\n", hertz);
|
||||
int arg = hertz*4/lastchannels; /* sampling rate */
|
||||
int status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
|
||||
if (status == -1) {
|
||||
perror("SOUND_PCM_WRITE_RATE ioctl failed");
|
||||
exit(1);
|
||||
}
|
||||
lasthertz = hertz;
|
||||
}
|
||||
|
||||
if (bps && lastbps != bps) {
|
||||
Serial.printf("BPS=%d\n", bps);
|
||||
int arg = bps; /* sample size */
|
||||
int status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
|
||||
if (status == -1) {
|
||||
perror("SOUND_PCM_WRITE_BITS ioctl failed");
|
||||
exit(1);
|
||||
} else if (arg != bps) {
|
||||
perror("unable to set sample size");
|
||||
exit(1);
|
||||
}
|
||||
lastbps = bps;
|
||||
}
|
||||
|
||||
if ((++samples & ((1<<9)-1)) == 0) {
|
||||
// let the main loop a chance to run
|
||||
return false;
|
||||
}
|
||||
|
||||
if (write(fd, sample, sizeof(sample)) != sizeof(sample)) {
|
||||
perror("doing sound");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool stop() { endms = millis(); return true; };
|
||||
unsigned long GetMilliseconds() { return endms - startms; }
|
||||
int GetSamples() { return samples; }
|
||||
int GetFrequency() { return hertz; }
|
||||
|
||||
protected:
|
||||
unsigned long startms;
|
||||
unsigned long endms;
|
||||
int samples;
|
||||
int lastchannels = -1;
|
||||
int lasthertz = -1;
|
||||
int lastbps = -1;
|
||||
int fd = -1;
|
||||
};
|
||||
|
||||
#endif
|
||||
57
examples/StreamOnHost/AudioOutputNullSlow.h
Normal file
57
examples/StreamOnHost/AudioOutputNullSlow.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
AudioOutput
|
||||
Base class of an audio output player
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _AUDIOOUTPUTNULLSLOW_H
|
||||
#define _AUDIOOUTPUTNULLSLOW_H
|
||||
|
||||
#include "AudioOutput.h"
|
||||
|
||||
class AudioOutputNullSlow : public AudioOutput
|
||||
{
|
||||
public:
|
||||
AudioOutputNullSlow() { };
|
||||
~AudioOutputNullSlow() {};
|
||||
virtual bool begin() { samples = 0; startms = millis(); return true; }
|
||||
virtual bool ConsumeSample(int16_t sample[2]) {
|
||||
// return false (= output buffer full)
|
||||
// sometimes to let the main loop running
|
||||
constexpr int everylog2 = 10;
|
||||
if ((++samples & ((1<<everylog2)-1)) == 0) {
|
||||
if (hertz > 0) {
|
||||
// simulate real time
|
||||
delay(1000/(hertz >> everylog2));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool stop() { endms = millis(); return true; };
|
||||
unsigned long GetMilliseconds() { return endms - startms; }
|
||||
int GetSamples() { return samples; }
|
||||
int GetFrequency() { return hertz; }
|
||||
|
||||
protected:
|
||||
unsigned long startms;
|
||||
unsigned long endms;
|
||||
int samples;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
118
examples/StreamOnHost/StreamOnHost.ino
Normal file
118
examples/StreamOnHost/StreamOnHost.ino
Normal file
@@ -0,0 +1,118 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#if AUDIO
|
||||
#pragma message("Outputting audio")
|
||||
#include "AudioOutputLinuxDSP.h"
|
||||
#else
|
||||
#pragma message("No audio")
|
||||
#include "AudioOutputNullSlow.h"
|
||||
#endif
|
||||
|
||||
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
|
||||
|
||||
// Enter your WiFi setup here:
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
// Randomly picked URL
|
||||
//const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
|
||||
//const char *URL="http://stream2.pvpjamz.com:8706/stream";
|
||||
// that one is not well decoded:
|
||||
const char *URL="http://icecast.radiofrance.fr/franceinter-lofi.mp3";
|
||||
|
||||
AudioGeneratorMP3 *mp3;
|
||||
AudioFileSourceICYStream *file;
|
||||
AudioFileSourceBuffer *buff;
|
||||
AudioOutputNullSlow *out;
|
||||
|
||||
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
(void) isUnicode; // Punt this ball for now
|
||||
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
|
||||
char s1[32], s2[64];
|
||||
strncpy_P(s1, type, sizeof(s1));
|
||||
s1[sizeof(s1)-1]=0;
|
||||
strncpy_P(s2, string, sizeof(s2));
|
||||
s2[sizeof(s2)-1]=0;
|
||||
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
|
||||
void StatusCallback(void *cbData, int code, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
// Note that the string may be in PROGMEM, so copy it to RAM for printf
|
||||
char s1[64];
|
||||
strncpy_P(s1, string, sizeof(s1));
|
||||
s1[sizeof(s1)-1]=0;
|
||||
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("Connecting to WiFi");
|
||||
|
||||
WiFi.disconnect();
|
||||
WiFi.softAPdisconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
// Try forever
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.println("...Connecting to WiFi");
|
||||
delay(1000);
|
||||
}
|
||||
Serial.println("Connected");
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = new AudioFileSourceICYStream();
|
||||
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
|
||||
file->useHTTP10();
|
||||
file->open(URL);
|
||||
buff = new AudioFileSourceBuffer(file, 2048);
|
||||
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
|
||||
out = new AudioOutputNullSlow();
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
||||
mp3->begin(buff, out);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int lastms = 0;
|
||||
|
||||
if (mp3->isRunning()) {
|
||||
if (millis()-lastms > 1000) {
|
||||
lastms = millis();
|
||||
Serial.printf("Running for %d ms...\n", lastms);
|
||||
Serial.flush();
|
||||
}
|
||||
if (!mp3->loop()) mp3->stop();
|
||||
} else {
|
||||
Serial.printf("MP3 done\n");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
66
examples/StreamOnHost/onHost
Executable file
66
examples/StreamOnHost/onHost
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
ino=${PWD##*/}
|
||||
|
||||
if [ ! -d "${ESP8266ARDUINO}/tests/host" ]; then
|
||||
echo "\${ESP8266ARDUINO} should point to ESP8266 Arduino core directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
THISLIB=$(pwd)/../..
|
||||
MAD=$(ls ${THISLIB}/src/libmad/*.c)
|
||||
PAGER=${PAGER:-less}
|
||||
|
||||
cd ${ESP8266ARDUINO}/tests/host
|
||||
|
||||
if [ "$1" = "clean" ]; then
|
||||
make clean
|
||||
cd ${THISLIB}
|
||||
rm -f src/*.o src/libmad/*.o
|
||||
exit 0
|
||||
elif [ "$1" = diff ]; then
|
||||
cd ${THISLIB}/examples
|
||||
diff -u StreamMP3FromHTTP/StreamMP3FromHTTP.ino ${ino}/${ino}.ino | ${PAGER}
|
||||
exit 0
|
||||
else
|
||||
echo ""
|
||||
echo "usage:"
|
||||
echo " $0"
|
||||
echo " $0 clean"
|
||||
echo " $0 diff"
|
||||
echo " AUDIO=a VALGRIND=v FORCE32=f $0"
|
||||
echo " a=1 play sound (use padsp, open /dev/dsp)"
|
||||
echo " v=1 run in native mode (FORCE32=0) with valgrind"
|
||||
echo " f=1 run in 32 bits mode (if gcc-multilib is installed)"
|
||||
echo "variable ESP8266ARDUINO must point to esp8266 Arduino core directory"
|
||||
echo ""
|
||||
[ "$1" = "-h" ] && exit 0
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
run=""
|
||||
|
||||
[ -z "${FORCE32}" ] && FORCE32=0
|
||||
[ -z "${AUDIO}" ] && AUDIO=1
|
||||
|
||||
if [ "${AUDIO}" = 1 ]; then
|
||||
run="${run} padsp"
|
||||
fi
|
||||
|
||||
if [ "${VALGRIND}" = 1 ]; then
|
||||
FORCE32=0
|
||||
run="$run valgrind"
|
||||
fi
|
||||
|
||||
touch ${THISLIB}/examples/${ino}/${ino}.ino # rebuild
|
||||
|
||||
eval make FORCE32=${FORCE32} -j \
|
||||
USERCSOURCES=\"${MAD}\" \
|
||||
USERCXXSOURCES=\"${THISLIB}/src/AudioFileSourceBuffer.cpp ${THISLIB}/src/AudioLogger.cpp ${THISLIB}/src/AudioGeneratorMP3.cpp ${THISLIB}/src/AudioFileSourceICYStream.cpp ${THISLIB}/src/AudioFileSourceHTTPStream.cpp\" \
|
||||
USERCFLAGS=\"-I${THISLIB}/src/ -DAUDIO=${AUDIO}\" \
|
||||
${THISLIB}/examples/${ino}/${ino}
|
||||
|
||||
set -x
|
||||
|
||||
$run ./bin/${ino}/${ino} "$@"
|
||||
stty sane
|
||||
185
examples/TalkingClockI2S/TalkingClockI2S.ino
Normal file
185
examples/TalkingClockI2S/TalkingClockI2S.ino
Normal file
@@ -0,0 +1,185 @@
|
||||
// Talking Clock example, with speech taken from
|
||||
// https://github.com/going-digital/Talkie/blob/master/Talkie/examples/Vocab_US_Clock/Vocab_US_Clock.ino
|
||||
// Released under GPL v2
|
||||
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include "AudioFileSourcePROGMEM.h"
|
||||
#include "AudioGeneratorTalkie.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "NOBABIES"
|
||||
#define STAPSK "ElephantsAreGreat"
|
||||
#endif
|
||||
|
||||
const char *ssid = STASSID;
|
||||
const char *pass = STAPSK;
|
||||
|
||||
long timezone = 2;
|
||||
byte daysavetime = 1;
|
||||
|
||||
uint8_t spTHE[] PROGMEM = {0x08,0xE8,0x3E,0x55,0x01,0xC3,0x86,0x27,0xAF,0x72,0x0D,0x4D,0x97,0xD5,0xBC,0x64,0x3C,0xF2,0x5C,0x51,0xF1,0x93,0x36,0x8F,0x4F,0x59,0x2A,0x42,0x7A,0x32,0xC3,0x64,0xFF,0x3F};
|
||||
uint8_t spTIME[] PROGMEM = {0x0E,0x28,0xAC,0x2D,0x01,0x5D,0xB6,0x0D,0x33,0xF3,0x54,0xB3,0x60,0xBA,0x8C,0x54,0x5C,0xCD,0x2D,0xD4,0x32,0x73,0x0F,0x8E,0x34,0x33,0xCB,0x4A,0x25,0xD4,0x25,0x83,0x2C,0x2B,0xD5,0x50,0x97,0x08,0x32,0xEC,0xD4,0xDC,0x4C,0x33,0xC8,0x70,0x73,0x0F,0x33,0xCD,0x20,0xC3,0xCB,0x43,0xDD,0x3C,0xCD,0x8C,0x20,0x77,0x89,0xF4,0x94,0xB2,0xE2,0xE2,0x35,0x22,0x5D,0xD6,0x4A,0x8A,0x96,0xCC,0x36,0x25,0x2D,0xC9,0x9A,0x7B,0xC2,0x18,0x87,0x24,0x4B,0x1C,0xC9,0x50,0x19,0x92,0x2C,0x71,0x34,0x4B,0x45,0x8A,0x8B,0xC4,0x96,0xB6,0x5A,0x29,0x2A,0x92,0x5A,0xCA,0x53,0x96,0x20,0x05,0x09,0xF5,0x92,0x5D,0xBC,0xE8,0x58,0x4A,0xDD,0xAE,0x73,0xBD,0x65,0x4B,0x8D,0x78,0xCA,0x2B,0x4E,0xD8,0xD9,0xED,0x22,0x20,0x06,0x75,0x00,0x00,0x80,0xFF,0x07};
|
||||
uint8_t spIS[] PROGMEM = {0x21,0x18,0x96,0x38,0xB7,0x14,0x8D,0x60,0x3A,0xA6,0xE8,0x51,0xB4,0xDC,0x2E,0x48,0x7B,0x5A,0xF1,0x70,0x1B,0xA3,0xEC,0x09,0xC6,0xCB,0xEB,0x92,0x3D,0xA7,0x69,0x1F,0xAF,0x71,0x89,0x9C,0xA2,0xB3,0xFC,0xCA,0x35,0x72,0x9A,0xD1,0xF0,0xAB,0x12,0xB3,0x2B,0xC6,0xCD,0x4F,0xCC,0x32,0x26,0x19,0x07,0xDF,0x0B,0x8F,0xB8,0xA4,0xED,0x7C,0xCF,0x23,0x62,0x8B,0x8E,0xF1,0x23,0x0A,0x8B,0x6E,0xCB,0xCE,0xEF,0x54,0x44,0x3C,0xDC,0x08,0x60,0x0B,0x37,0x01,0x1C,0x53,0x26,0x80,0x15,0x4E,0x14,0xB0,0x54,0x2B,0x02,0xA4,0x69,0xFF,0x7F};
|
||||
uint8_t spA_M_[] PROGMEM = {0xCD,0xEF,0x86,0xAB,0x57,0x6D,0x0F,0xAF,0x71,0xAD,0x49,0x55,0x3C,0xFC,0x2E,0xC5,0xB7,0x5C,0xF1,0xF2,0x87,0x66,0xDD,0x4E,0xC5,0xC3,0xEF,0x92,0xE2,0x3A,0x65,0xB7,0xA0,0x09,0xAA,0x1B,0x97,0x54,0x82,0x2E,0x28,0x77,0x5C,0x52,0x09,0x1A,0xA3,0xB8,0x76,0x49,0x25,0x68,0x8C,0x73,0xDB,0x24,0x95,0xA0,0x32,0xA9,0x6B,0xA7,0xD9,0x82,0x26,0xA9,0x76,0x42,0xD6,0x08,0xBA,0xE1,0xE8,0x0E,0x5A,0x2B,0xEA,0x9E,0x3D,0x27,0x18,0xAD,0xA8,0x07,0xF1,0x98,0x90,0x35,0xA2,0x96,0x44,0xA3,0x5D,0x66,0x8B,0x6B,0x12,0xCD,0x32,0x85,0x25,0xC9,0x81,0x2D,0xC3,0x64,0x85,0x34,0x58,0x89,0x94,0x52,0x1C,0x52,0x2F,0x35,0xDA,0xC7,0x51,0x48,0x23,0x97,0xCC,0x2C,0x97,0x2E,0xF3,0x5C,0xF3,0xA2,0x14,0xBA,0x2C,0x48,0xCE,0xCA,0x76,0xE8,0x32,0x2F,0x34,0xB2,0xDB,0x85,0xC9,0x83,0x90,0xA8,0x2C,0x57,0x26,0x8F,0x9C,0xBD,0xA2,0x53,0xD9,0xC2,0x54,0x59,0x28,0x99,0x4B,0x2C,0x5D,0xFF,0x3F};
|
||||
uint8_t spP_M_[] PROGMEM = {0x0E,0x98,0x41,0x54,0x00,0x43,0xA0,0x05,0xAB,0x42,0x8E,0x1D,0xA3,0x15,0xEC,0x4E,0x58,0xF7,0x92,0x66,0x70,0x1B,0x66,0xDB,0x73,0x99,0xC1,0xEB,0x98,0xED,0xD6,0x25,0x25,0x6F,0x70,0x92,0xDD,0x64,0xD8,0xFC,0x61,0xD0,0x66,0x83,0xD6,0x0A,0x86,0x23,0xAB,0x69,0xDA,0x2B,0x18,0x9E,0x3D,0x37,0x69,0x9D,0xA8,0x07,0x71,0x9F,0xA0,0xBD,0xA2,0x16,0xD5,0x7C,0x54,0xF6,0x88,0x6B,0x54,0x8B,0x34,0x49,0x2D,0x29,0x49,0x3C,0x34,0x64,0xA5,0x24,0x1B,0x36,0xD7,0x72,0x13,0x92,0xA4,0xC4,0x2D,0xC3,0xB3,0x4B,0xA3,0x62,0x0F,0x2B,0x37,0x6E,0x8B,0x5A,0xD4,0x3D,0xDD,0x9A,0x2D,0x50,0x93,0xF6,0x4C,0xAA,0xB6,0xC4,0x85,0x3B,0xB2,0xB1,0xD8,0x93,0x20,0x4D,0x8F,0x24,0xFF,0x0F};
|
||||
uint8_t spOH[] PROGMEM = {0xC6,0xC9,0x71,0x5A,0xA2,0x92,0x14,0x2F,0x6E,0x97,0x9C,0x46,0x9D,0xDC,0xB0,0x4D,0x62,0x1B,0x55,0x70,0xDD,0x55,0xBE,0x0E,0x36,0xC1,0x33,0x37,0xA9,0xA7,0x51,0x1B,0xCF,0x3C,0xA5,0x9E,0x44,0xAC,0x3C,0x7D,0x98,0x7B,0x52,0x96,0x72,0x65,0x4B,0xF6,0x1A,0xD9,0xCA,0xF5,0x91,0x2D,0xA2,0x2A,0x4B,0xF7,0xFF,0x01};
|
||||
uint8_t spOCLOCK[] PROGMEM = {0x21,0x4E,0x3D,0xB8,0x2B,0x19,0xBB,0x24,0x0E,0xE5,0xEC,0x60,0xE4,0xF2,0x90,0x13,0xD4,0x2A,0x11,0x80,0x00,0x42,0x69,0x26,0x40,0xD0,0x2B,0x04,0x68,0xE0,0x4D,0x00,0x3A,0x35,0x35,0x33,0xB6,0x51,0xD9,0x64,0x34,0x82,0xB4,0x9A,0x63,0x92,0x55,0x89,0x52,0x5B,0xCA,0x2E,0x34,0x25,0x4E,0x63,0x28,0x3A,0x50,0x95,0x26,0x8D,0xE6,0xAA,0x64,0x58,0xEA,0x92,0xCE,0xC2,0x46,0x15,0x9B,0x86,0xCD,0x2A,0x2E,0x37,0x00,0x00,0x00,0x0C,0xC8,0xDD,0x05,0x01,0xB9,0x33,0x21,0xA0,0x74,0xD7,0xFF,0x07};
|
||||
uint8_t spONE[] PROGMEM = {0xCC,0x67,0x75,0x42,0x59,0x5D,0x3A,0x4F,0x9D,0x36,0x63,0xB7,0x59,0xDC,0x30,0x5B,0x5C,0x23,0x61,0xF3,0xE2,0x1C,0xF1,0xF0,0x98,0xC3,0x4B,0x7D,0x39,0xCA,0x1D,0x2C,0x2F,0xB7,0x15,0xEF,0x70,0x79,0xBC,0xD2,0x46,0x7C,0x52,0xE5,0xF1,0x4A,0x6A,0xB3,0x71,0x47,0xC3,0x2D,0x39,0x34,0x4B,0x23,0x35,0xB7,0x7A,0x55,0x33,0x8F,0x59,0xDC,0xA2,0x44,0xB5,0xBC,0x66,0x72,0x8B,0x64,0xF5,0xF6,0x98,0xC1,0x4D,0x42,0xD4,0x27,0x62,0x38,0x2F,0x4A,0xB6,0x9C,0x88,0x68,0xBC,0xA6,0x95,0xF8,0x5C,0xA1,0x09,0x86,0x77,0x91,0x11,0x5B,0xFF,0x0F};
|
||||
uint8_t spTWO[] PROGMEM = {0x0E,0x38,0x6E,0x25,0x00,0xA3,0x0D,0x3A,0xA0,0x37,0xC5,0xA0,0x05,0x9E,0x56,0x35,0x86,0xAA,0x5E,0x8C,0xA4,0x82,0xB2,0xD7,0x74,0x31,0x22,0x69,0xAD,0x1C,0xD3,0xC1,0xD0,0xFA,0x28,0x2B,0x2D,0x47,0xC3,0x1B,0xC2,0xC4,0xAE,0xC6,0xCD,0x9C,0x48,0x53,0x9A,0xFF,0x0F};
|
||||
uint8_t spTHREE[] PROGMEM = {0x02,0xD8,0x2E,0x9C,0x01,0xDB,0xA6,0x33,0x60,0xFB,0x30,0x01,0xEC,0x20,0x12,0x8C,0xE4,0xD8,0xCA,0x32,0x96,0x73,0x63,0x41,0x39,0x89,0x98,0xC1,0x4D,0x0D,0xED,0xB0,0x2A,0x05,0x37,0x0F,0xB4,0xA5,0xAE,0x5C,0xDC,0x36,0xD0,0x83,0x2F,0x4A,0x71,0x7B,0x03,0xF7,0x38,0x59,0xCD,0xED,0x1E,0xB4,0x6B,0x14,0x35,0xB7,0x6B,0x94,0x99,0x91,0xD5,0xDC,0x26,0x48,0x77,0x4B,0x66,0x71,0x1B,0x21,0xDB,0x2D,0x8A,0xC9,0x6D,0x88,0xFC,0x26,0x28,0x3A,0xB7,0x21,0xF4,0x1F,0xA3,0x65,0xBC,0x02,0x38,0xBB,0x3D,0x8E,0xF0,0x2B,0xE2,0x08,0xB7,0x34,0xFF,0x0F};
|
||||
uint8_t spFOUR[] PROGMEM = {0x0C,0x18,0xB6,0x9A,0x01,0xC3,0x75,0x09,0x60,0xD8,0x0E,0x09,0x30,0xA0,0x9B,0xB6,0xA0,0xBB,0xB0,0xAA,0x16,0x4E,0x82,0xEB,0xEA,0xA9,0xFA,0x59,0x49,0x9E,0x59,0x23,0x9A,0x27,0x3B,0x78,0x66,0xAE,0x4A,0x9C,0x9C,0xE0,0x99,0xD3,0x2A,0xBD,0x72,0x92,0xEF,0xE6,0x88,0xE4,0x45,0x4D,0x7E,0x98,0x2D,0x62,0x67,0x37,0xF9,0xA1,0x37,0xA7,0x6C,0x94,0xE4,0xC7,0x1E,0xDC,0x3C,0xA5,0x83,0x1F,0x8B,0xEB,0x52,0x0E,0x0E,0x7E,0x2E,0x4E,0xC7,0x31,0xD2,0x79,0xA5,0x3A,0x0D,0xD9,0xC4,0xFF,0x07};
|
||||
uint8_t spFIVE[] PROGMEM = {0x02,0xE8,0x3E,0x8C,0x01,0xDD,0x65,0x08,0x60,0x98,0x4C,0x06,0x34,0x93,0xCE,0x80,0xE6,0xDA,0x9A,0x14,0x6B,0xAA,0x47,0xD1,0x5E,0x56,0xAA,0x6D,0x56,0xCD,0x78,0xD9,0xA9,0x1C,0x67,0x05,0x83,0xE1,0xA4,0xBA,0x38,0xEE,0x16,0x86,0x9B,0xFA,0x60,0x87,0x5B,0x18,0x6E,0xEE,0x8B,0x1D,0x6E,0x61,0xB9,0x69,0x36,0x65,0xBA,0x8D,0xE5,0xE5,0x3E,0x1C,0xE9,0x0E,0x96,0x9B,0x5B,0xAB,0x95,0x2B,0x58,0x6E,0xCE,0xE5,0x3A,0x6A,0xF3,0xB8,0x35,0x84,0x7B,0x05,0xA3,0xE3,0x36,0xEF,0x92,0x19,0xB4,0x86,0xDB,0xB4,0x69,0xB4,0xD1,0x2A,0x4E,0x65,0x9A,0x99,0xCE,0x28,0xD9,0x85,0x71,0x4C,0x18,0x6D,0x67,0x47,0xC6,0x5E,0x53,0x4A,0x9C,0xB5,0xE2,0x85,0x45,0x26,0xFE,0x7F};
|
||||
uint8_t spSIX[] PROGMEM = {0x0E,0xD8,0xAE,0xDD,0x03,0x0E,0x38,0xA6,0xD2,0x01,0xD3,0xB4,0x2C,0xAD,0x6A,0x35,0x9D,0xB1,0x7D,0xDC,0xEE,0xC4,0x65,0xD7,0xF1,0x72,0x47,0x24,0xB3,0x19,0xD9,0xD9,0x05,0x70,0x40,0x49,0xEA,0x02,0x98,0xBE,0x42,0x01,0xDF,0xA4,0x69,0x40,0x00,0xDF,0x95,0xFC,0x3F};
|
||||
uint8_t spSEVEN[] PROGMEM = {0x02,0xB8,0x3A,0x8C,0x01,0xDF,0xA4,0x73,0x40,0x01,0x47,0xB9,0x2F,0x33,0x3B,0x73,0x5F,0x53,0x7C,0xEC,0x9A,0xC5,0x63,0xD5,0xD1,0x75,0xAE,0x5B,0xFC,0x64,0x5C,0x35,0x87,0x91,0xF1,0x83,0x36,0xB5,0x68,0x55,0xC5,0x6F,0xDA,0x45,0x2D,0x1C,0x2D,0xB7,0x38,0x37,0x9F,0x60,0x3C,0xBC,0x9A,0x85,0xA3,0x25,0x66,0xF7,0x8A,0x57,0x1C,0xA9,0x67,0x56,0xCA,0x5E,0xF0,0xB2,0x16,0xB2,0xF1,0x89,0xCE,0x8B,0x92,0x25,0xC7,0x2B,0x33,0xCF,0x48,0xB1,0x99,0xB4,0xF3,0xFF};
|
||||
uint8_t spEIGHT[] PROGMEM = {0xC3,0x6C,0x86,0xB3,0x27,0x6D,0x0F,0xA7,0x48,0x99,0x4E,0x55,0x3C,0xBC,0x22,0x65,0x36,0x4D,0xD1,0xF0,0x32,0xD3,0xBE,0x34,0xDA,0xC3,0xEB,0x82,0xE2,0xDA,0x65,0x35,0xAF,0x31,0xF2,0x6B,0x97,0x95,0xBC,0x86,0xD8,0x6F,0x82,0xA6,0x73,0x0B,0xC6,0x9E,0x72,0x99,0xCC,0xCB,0x02,0xAD,0x3C,0x9A,0x10,0x60,0xAB,0x62,0x05,0x2C,0x37,0x84,0x00,0xA9,0x73,0x00,0x00,0xFE,0x1F};
|
||||
uint8_t spNINE[] PROGMEM = {0xCC,0xA1,0x26,0xBB,0x83,0x93,0x18,0xCF,0x4A,0xAD,0x2E,0x31,0xED,0x3C,0xA7,0x24,0x26,0xC3,0x54,0xF1,0x92,0x64,0x8B,0x8A,0x98,0xCB,0x2B,0x2E,0x34,0x53,0x2D,0x0E,0x2F,0x57,0xB3,0x0C,0x0D,0x3C,0xBC,0x3C,0x4C,0x4B,0xCA,0xF4,0xF0,0x72,0x0F,0x6E,0x49,0x53,0xCD,0xCB,0x53,0x2D,0x35,0x4D,0x0F,0x2F,0x0F,0xD7,0x0C,0x0D,0x3D,0xBC,0xDC,0x4D,0xD3,0xDD,0xC2,0xF0,0x72,0x52,0x4F,0x57,0x9B,0xC3,0xAB,0x89,0xBD,0x42,0x2D,0x0F,0xAF,0x5A,0xD1,0x71,0x91,0x55,0xBC,0x2C,0xC5,0x3B,0xD8,0x65,0xF2,0x82,0x94,0x18,0x4E,0x3B,0xC1,0x73,0x42,0x32,0x33,0x15,0x45,0x4F,0x79,0x52,0x6A,0x55,0xA6,0xA3,0xFF,0x07};
|
||||
uint8_t spTEN[] PROGMEM = {0x0E,0xD8,0xB1,0xDD,0x01,0x3D,0xA8,0x24,0x7B,0x04,0x27,0x76,0x77,0xDC,0xEC,0xC2,0xC5,0x23,0x84,0xCD,0x72,0x9A,0x51,0xF7,0x62,0x45,0xC7,0xEB,0x4E,0x35,0x4A,0x14,0x2D,0xBF,0x45,0xB6,0x0A,0x75,0xB8,0xFC,0x16,0xD9,0x2A,0xD9,0xD6,0x0A,0x5A,0x10,0xCD,0xA2,0x48,0x23,0xA8,0x81,0x35,0x4B,0x2C,0xA7,0x20,0x69,0x0A,0xAF,0xB6,0x15,0x82,0xA4,0x29,0x3C,0xC7,0x52,0x08,0xA2,0x22,0xCF,0x68,0x4B,0x2E,0xF0,0x8A,0xBD,0xA3,0x2C,0xAB,0x40,0x1B,0xCE,0xAA,0xB2,0x6C,0x82,0x40,0x4D,0x7D,0xC2,0x89,0x88,0x8A,0x61,0xCC,0x74,0xD5,0xFF,0x0F};
|
||||
uint8_t spELEVEN[] PROGMEM = {0xC3,0xCD,0x76,0x5C,0xAE,0x14,0x0F,0x37,0x9B,0x71,0xDE,0x92,0x55,0xBC,0x2C,0x27,0x70,0xD3,0x76,0xF0,0x83,0x5E,0xA3,0x5E,0x5A,0xC1,0xF7,0x61,0x58,0xA7,0x19,0x35,0x3F,0x99,0x31,0xDE,0x52,0x74,0xFC,0xA2,0x26,0x64,0x4B,0xD1,0xF1,0xAB,0xAE,0xD0,0x2D,0xC5,0xC7,0x2F,0x36,0xDD,0x27,0x15,0x0F,0x3F,0xD9,0x08,0x9F,0x62,0xE4,0xC2,0x2C,0xD4,0xD8,0xD3,0x89,0x0B,0x1B,0x57,0x11,0x0B,0x3B,0xC5,0xCF,0xD6,0xCC,0xC6,0x64,0x35,0xAF,0x18,0x73,0x1F,0xA1,0x5D,0xBC,0x62,0x45,0xB3,0x45,0x51,0xF0,0xA2,0x62,0xAB,0x4A,0x5B,0xC9,0x4B,0x8A,0x2D,0xB3,0x6C,0x06,0x2F,0x29,0xB2,0xAC,0x8A,0x18,0xBC,0x28,0xD9,0xAA,0xD2,0x92,0xF1,0xBC,0xE0,0x98,0x8C,0x48,0xCC,0x17,0x52,0xA3,0x27,0x6D,0x93,0xD0,0x4B,0x8E,0x0E,0x77,0x02,0x00,0xFF,0x0F};
|
||||
uint8_t spTWELVE[] PROGMEM = {0x06,0x28,0x46,0xD3,0x01,0x25,0x06,0x13,0x20,0xBA,0x70,0x70,0xB6,0x79,0xCA,0x36,0xAE,0x28,0x38,0xE1,0x29,0xC5,0x35,0xA3,0xE6,0xC4,0x16,0x6A,0x53,0x8C,0x97,0x9B,0x72,0x86,0x4F,0x28,0x1A,0x6E,0x0A,0x59,0x36,0xAE,0x68,0xF8,0x29,0x67,0xFA,0x06,0xA3,0x16,0xC4,0x96,0xE6,0x53,0xAC,0x5A,0x9C,0x56,0x72,0x77,0x31,0x4E,0x49,0x5C,0x8D,0x5B,0x29,0x3B,0x24,0x61,0x1E,0x6C,0x9B,0x6C,0x97,0xF8,0xA7,0x34,0x19,0x92,0x4C,0x62,0x9E,0x72,0x65,0x58,0x12,0xB1,0x7E,0x09,0xD5,0x2E,0x53,0xC5,0xBA,0x36,0x6B,0xB9,0x2D,0x17,0x05,0xEE,0x9A,0x6E,0x8E,0x05,0x50,0x6C,0x19,0x07,0x18,0x50,0xBD,0x3B,0x01,0x92,0x08,0x41,0x40,0x10,0xA6,0xFF,0x0F};
|
||||
uint8_t spTHIRTEEN[] PROGMEM = {0x08,0xE8,0x2C,0x15,0x01,0x43,0x07,0x13,0xE0,0x98,0xB4,0xA6,0x35,0xA9,0x1E,0xDE,0x56,0x8E,0x53,0x9C,0x7A,0xE7,0xCA,0x5E,0x76,0x8D,0x94,0xE5,0x2B,0xAB,0xD9,0xB5,0x62,0xA4,0x9C,0xE4,0xE6,0xB4,0x41,0x1E,0x7C,0xB6,0x93,0xD7,0x16,0x99,0x5A,0xCD,0x61,0x76,0x55,0xC2,0x91,0x61,0x1B,0xC0,0x01,0x5D,0x85,0x05,0xE0,0x68,0x51,0x07,0x1C,0xA9,0x64,0x80,0x1D,0x4C,0x9C,0x95,0x88,0xD4,0x04,0x3B,0x4D,0x4E,0x21,0x5C,0x93,0xA8,0x26,0xB9,0x05,0x4B,0x6E,0xA0,0xE2,0xE4,0x57,0xC2,0xB9,0xC1,0xB2,0x93,0x5F,0x09,0xD7,0x24,0xCB,0x4E,0x41,0x25,0x54,0x1D,0x62,0x3B,0x05,0x8D,0x52,0x57,0xAA,0xAD,0x10,0x24,0x26,0xE3,0xE1,0x36,0x5D,0x10,0x85,0xB4,0x97,0x85,0x72,0x41,0x14,0x52,0x5E,0x1A,0xCA,0xF9,0x91,0x6B,0x7A,0x5B,0xC4,0xE0,0x17,0x2D,0x54,0x1D,0x92,0x8C,0x1F,0x25,0x4B,0x8F,0xB2,0x16,0x41,0xA1,0x4A,0x3E,0xE6,0xFA,0xFF,0x01};
|
||||
uint8_t spFOURTEEN[] PROGMEM = {0x0C,0x58,0xAE,0x5C,0x01,0xD9,0x87,0x07,0x51,0xB7,0x25,0xB3,0x8A,0x15,0x2C,0xF7,0x1C,0x35,0x87,0x4D,0xB2,0xDD,0x53,0xCE,0x28,0x2B,0xC9,0x0E,0x97,0x2D,0xBD,0x2A,0x17,0x27,0x76,0x8E,0xD2,0x9A,0x6C,0x80,0x94,0x71,0x00,0x00,0x02,0xB0,0x58,0x58,0x00,0x9E,0x0B,0x0A,0xC0,0xB2,0xCE,0xC1,0xC8,0x98,0x7A,0x52,0x95,0x24,0x2B,0x11,0xED,0x36,0xD4,0x92,0xDC,0x4C,0xB5,0xC7,0xC8,0x53,0xF1,0x2A,0xE5,0x1A,0x17,0x55,0xC5,0xAF,0x94,0xBB,0xCD,0x1C,0x26,0xBF,0x52,0x9A,0x72,0x53,0x98,0xFC,0xC2,0x68,0xD2,0x4D,0x61,0xF0,0xA3,0x90,0xB6,0xD6,0x50,0xC1,0x8F,0x42,0xDA,0x4A,0x43,0x39,0x3F,0x48,0x2D,0x6B,0x33,0xF9,0xFF};
|
||||
uint8_t spFIFTEEN[] PROGMEM = {0x08,0xE8,0x2A,0x0D,0x01,0xDD,0xBA,0x31,0x60,0x6A,0xF7,0xA0,0xAE,0x54,0xAA,0x5A,0x76,0x97,0xD9,0x34,0x69,0xEF,0x32,0x1E,0x66,0xE1,0xE2,0xB3,0x43,0xA9,0x18,0x55,0x92,0x4E,0x37,0x2D,0x67,0x6F,0xDF,0xA2,0x5A,0xB6,0x04,0x30,0x55,0xA8,0x00,0x86,0x09,0xE7,0x00,0x01,0x16,0x17,0x05,0x70,0x40,0x57,0xE5,0x01,0xF8,0x21,0x34,0x00,0xD3,0x19,0x33,0x80,0x89,0x9A,0x62,0x34,0x4C,0xD5,0x49,0xAE,0x8B,0x53,0x09,0xF7,0x26,0xD9,0x6A,0x7E,0x23,0x5C,0x13,0x12,0xB3,0x04,0x9D,0x50,0x4F,0xB1,0xAD,0x14,0x15,0xC2,0xD3,0xA1,0xB6,0x42,0x94,0xA8,0x8C,0x87,0xDB,0x74,0xB1,0x70,0x59,0xE1,0x2E,0xC9,0xC5,0x81,0x5B,0x55,0xA4,0x4C,0x17,0x47,0xC1,0x6D,0xE3,0x81,0x53,0x9C,0x84,0x6A,0x46,0xD9,0x4C,0x51,0x31,0x42,0xD9,0x66,0xC9,0x44,0x85,0x29,0x6A,0x9B,0xAD,0xFF,0x07};
|
||||
uint8_t spSIXTEEN[] PROGMEM = {0x0A,0x58,0x5A,0x5D,0x00,0x93,0x97,0x0B,0x60,0xA9,0x48,0x05,0x0C,0x15,0xAE,0x80,0xAD,0x3D,0x14,0x30,0x7D,0xD9,0x50,0x92,0x92,0xAC,0x0D,0xC5,0xCD,0x2A,0x82,0xAA,0x3B,0x98,0x04,0xB3,0x4A,0xC8,0x9A,0x90,0x05,0x09,0x68,0x51,0xD4,0x01,0x23,0x9F,0x1A,0x60,0xA9,0x12,0x03,0xDC,0x50,0x81,0x80,0x22,0xDC,0x20,0x00,0xCB,0x06,0x3A,0x60,0x16,0xE3,0x64,0x64,0x42,0xDD,0xCD,0x6A,0x8A,0x5D,0x28,0x75,0x07,0xA9,0x2A,0x5E,0x65,0x34,0xED,0x64,0xBB,0xF8,0x85,0xF2,0x94,0x8B,0xAD,0xE4,0x37,0x4A,0x5B,0x21,0xB6,0x52,0x50,0x19,0xAD,0xA7,0xD8,0x4A,0x41,0x14,0xDA,0x5E,0x12,0x3A,0x04,0x91,0x4B,0x7B,0x69,0xA8,0x10,0x24,0x2E,0xE5,0xA3,0x81,0x52,0x90,0x94,0x5A,0x55,0x98,0x32,0x41,0x50,0xCC,0x93,0x2E,0x47,0x85,0x89,0x1B,0x5B,0x5A,0x62,0x04,0x44,0xE3,0x02,0x80,0x80,0x64,0xDD,0xFF,0x1F};
|
||||
uint8_t spSEVENTEEN[] PROGMEM = {0x02,0x98,0x3A,0x42,0x00,0x5B,0xA6,0x09,0x60,0xDB,0x52,0x06,0x1C,0x93,0x29,0x80,0xA9,0x52,0x87,0x9A,0xB5,0x99,0x4F,0xC8,0x3E,0x46,0xD6,0x5E,0x7E,0x66,0xFB,0x98,0xC5,0x5A,0xC6,0x9A,0x9C,0x63,0x15,0x6B,0x11,0x13,0x8A,0x9C,0x97,0xB9,0x9A,0x5A,0x39,0x71,0xEE,0xD2,0x29,0xC2,0xA6,0xB8,0x58,0x59,0x99,0x56,0x14,0xA3,0xE1,0x26,0x19,0x19,0xE3,0x8C,0x93,0x17,0xB4,0x46,0xB5,0x88,0x71,0x9E,0x97,0x9E,0xB1,0x2C,0xC5,0xF8,0x56,0xC4,0x58,0xA3,0x1C,0xE1,0x33,0x9D,0x13,0x41,0x8A,0x43,0x58,0xAD,0x95,0xA9,0xDB,0x36,0xC0,0xD1,0xC9,0x0E,0x58,0x4E,0x45,0x01,0x23,0xA9,0x04,0x37,0x13,0xAE,0x4D,0x65,0x52,0x82,0xCA,0xA9,0x37,0x99,0x4D,0x89,0xBA,0xC0,0xBC,0x14,0x36,0x25,0xEA,0x1C,0x73,0x52,0x1D,0x97,0xB8,0x33,0xAC,0x0E,0x75,0x9C,0xE2,0xCE,0xB0,0xDA,0xC3,0x51,0x4A,0x1A,0xA5,0xCA,0x70,0x5B,0x21,0xCE,0x4C,0x26,0xD2,0x6C,0xBA,0x38,0x71,0x2E,0x1F,0x2D,0xED,0xE2,0x24,0xB8,0xBC,0x3D,0x52,0x88,0xAB,0x50,0x8E,0xA8,0x48,0x22,0x4E,0x42,0xA0,0x26,0x55,0xFD,0x3F};
|
||||
uint8_t spEIGHTEEN[] PROGMEM = {0x2E,0x9C,0xD1,0x4D,0x54,0xEC,0x2C,0xBF,0x1B,0x8A,0x99,0x70,0x7C,0xFC,0x2E,0x29,0x6F,0x52,0xF6,0xF1,0xBA,0x20,0xBF,0x36,0xD9,0xCD,0xED,0x0C,0xF3,0x27,0x64,0x17,0x73,0x2B,0xA2,0x99,0x90,0x65,0xEC,0xED,0x40,0x73,0x32,0x12,0xB1,0xAF,0x30,0x35,0x0B,0xC7,0x00,0xE0,0x80,0xAE,0xDD,0x1C,0x70,0x43,0xAA,0x03,0x86,0x51,0x36,0xC0,0x30,0x64,0xCE,0x4C,0x98,0xFB,0x5C,0x65,0x07,0xAF,0x10,0xEA,0x0B,0x66,0x1B,0xFC,0x46,0xA8,0x3E,0x09,0x4D,0x08,0x2A,0xA6,0x3E,0x67,0x36,0x21,0x2A,0x98,0x67,0x9D,0x15,0xA7,0xA8,0x60,0xEE,0xB6,0x94,0x99,0xA2,0x4A,0x78,0x22,0xC2,0xA6,0x8B,0x8C,0x8E,0xCC,0x4C,0x8A,0x2E,0x8A,0x4C,0xD3,0x57,0x03,0x87,0x28,0x71,0x09,0x1F,0x2B,0xE4,0xA2,0xC4,0xC5,0x6D,0xAD,0x54,0x88,0xB2,0x63,0xC9,0xF2,0x50,0x2E,0x8A,0x4A,0x38,0x4A,0xEC,0x88,0x28,0x08,0xE3,0x28,0x49,0xF3,0xFF};
|
||||
uint8_t spNINETEEN[] PROGMEM = {0xC2,0xEA,0x8A,0x95,0x2B,0x6A,0x05,0x3F,0x71,0x71,0x5F,0x0D,0x12,0xFC,0x28,0x25,0x62,0x35,0xF0,0xF0,0xB3,0x48,0x1E,0x0F,0xC9,0xCB,0x2F,0x45,0x7C,0x2C,0x25,0x1F,0xBF,0x14,0xB3,0x2C,0xB5,0x75,0xFC,0x5A,0x5C,0xA3,0x5D,0xE1,0xF1,0x7A,0x76,0xB3,0x4E,0x45,0xC7,0xED,0x96,0x23,0x3B,0x18,0x37,0x7B,0x18,0xCC,0x09,0x51,0x13,0x4C,0xAB,0x6C,0x4C,0x4B,0x96,0xD2,0x49,0xAA,0x36,0x0B,0xC5,0xC2,0x20,0x26,0x27,0x35,0x63,0x09,0x3D,0x30,0x8B,0xF0,0x48,0x5C,0xCA,0x61,0xDD,0xCB,0xCD,0x91,0x03,0x8E,0x4B,0x76,0xC0,0xCC,0x4D,0x06,0x98,0x31,0x31,0x98,0x99,0x70,0x6D,0x2A,0xA3,0xE4,0x16,0xCA,0xBD,0xCE,0x5C,0x92,0x57,0x28,0xCF,0x09,0x69,0x2E,0x7E,0xA5,0x3C,0x63,0xA2,0x30,0x05,0x95,0xD2,0x74,0x98,0xCD,0x14,0x54,0xCA,0x53,0xA9,0x96,0x52,0x50,0x28,0x6F,0xBA,0xCB,0x0C,0x41,0x50,0xDE,0x65,0x2E,0xD3,0x05,0x89,0x4B,0x7B,0x6B,0x20,0x17,0x44,0xAE,0xED,0x23,0x81,0x52,0x90,0x85,0x73,0x57,0xD0,0x72,0x41,0xB1,0x02,0xDE,0x2E,0xDB,0x04,0x89,0x05,0x79,0xBB,0x62,0xE5,0x76,0x11,0xCA,0x61,0x0E,0xFF,0x1F};
|
||||
uint8_t spTWENTY[] PROGMEM = {0x01,0x98,0xD1,0xC2,0x00,0xCD,0xA4,0x32,0x20,0x79,0x13,0x04,0x28,0xE7,0x92,0xDC,0x70,0xCC,0x5D,0xDB,0x76,0xF3,0xD2,0x32,0x0B,0x0B,0x5B,0xC3,0x2B,0xCD,0xD4,0xDD,0x23,0x35,0xAF,0x44,0xE1,0xF0,0xB0,0x6D,0x3C,0xA9,0xAD,0x3D,0x35,0x0E,0xF1,0x0C,0x8B,0x28,0xF7,0x34,0x01,0x68,0x22,0xCD,0x00,0xC7,0xA4,0x04,0xBB,0x32,0xD6,0xAC,0x56,0x9C,0xDC,0xCA,0x28,0x66,0x53,0x51,0x70,0x2B,0xA5,0xBC,0x0D,0x9A,0xC1,0xEB,0x14,0x73,0x37,0x29,0x19,0xAF,0x33,0x8C,0x3B,0xA7,0x24,0xBC,0x42,0xB0,0xB7,0x59,0x09,0x09,0x3C,0x96,0xE9,0xF4,0x58,0xFF,0x0F};
|
||||
uint8_t spTHIRTY[] PROGMEM = {0x08,0x98,0xD6,0x15,0x01,0x43,0xBB,0x0A,0x20,0x1B,0x8B,0xE5,0x16,0xA3,0x1E,0xB6,0xB6,0x96,0x97,0x3C,0x57,0xD4,0x2A,0x5E,0x7E,0x4E,0xD8,0xE1,0x6B,0x7B,0xF8,0x39,0x63,0x0D,0x9F,0x95,0xE1,0xE7,0x4C,0x76,0xBC,0x91,0x5B,0x90,0x13,0xC6,0x68,0x57,0x4E,0x41,0x8B,0x10,0x5E,0x1D,0xA9,0x44,0xD3,0xBA,0x47,0xB8,0xDD,0xE4,0x35,0x86,0x11,0x93,0x94,0x92,0x5F,0x29,0xC7,0x4C,0x30,0x0C,0x41,0xC5,0x1C,0x3B,0x2E,0xD3,0x05,0x15,0x53,0x6C,0x07,0x4D,0x15,0x14,0x8C,0xB5,0xC9,0x6A,0x44,0x90,0x10,0x4E,0x9A,0xB6,0x21,0x81,0x23,0x3A,0x91,0x91,0xE8,0xFF,0x01};
|
||||
uint8_t spFOURTY[] PROGMEM = {0x04,0x18,0xB6,0x4C,0x00,0xC3,0x56,0x30,0xA0,0xE8,0xF4,0xA0,0x98,0x99,0x62,0x91,0xAE,0x83,0x6B,0x77,0x89,0x78,0x3B,0x09,0xAE,0xBD,0xA6,0x1E,0x63,0x3B,0x79,0x7E,0x71,0x5A,0x8F,0x95,0xE6,0xA5,0x4A,0x69,0xB9,0x4E,0x8A,0x5F,0x12,0x56,0xE4,0x58,0x69,0xE1,0x36,0xA1,0x69,0x2E,0x2B,0xF9,0x95,0x93,0x55,0x17,0xED,0xE4,0x37,0xC6,0xBA,0x93,0xB2,0x92,0xDF,0x19,0xD9,0x6E,0xC8,0x0A,0xFE,0x60,0xE8,0x37,0x21,0xC9,0xF9,0x8D,0x61,0x5F,0x32,0x13,0xE7,0x17,0x4C,0xD3,0xC6,0xB1,0x94,0x97,0x10,0x8F,0x8B,0xAD,0x11,0x7E,0xA1,0x9A,0x26,0x92,0xF6,0xFF,0x01};
|
||||
uint8_t spFIFTY[] PROGMEM = {0x08,0xE8,0x2E,0x84,0x00,0x23,0x84,0x13,0x60,0x38,0x95,0xA5,0x0F,0xCF,0xE2,0x79,0x8A,0x8F,0x37,0x02,0xB3,0xD5,0x2A,0x6E,0x5E,0x93,0x94,0x79,0x45,0xD9,0x05,0x5D,0x0A,0xB9,0x97,0x63,0x02,0x74,0xA7,0x82,0x80,0xEE,0xC3,0x10,0xD0,0x7D,0x28,0x03,0x6E,0x14,0x06,0x70,0xE6,0x0A,0xC9,0x9A,0x4E,0x37,0xD9,0x95,0x51,0xCE,0xBA,0xA2,0x14,0x0C,0x81,0x36,0x1B,0xB2,0x5C,0x30,0x38,0xFA,0x9C,0xC9,0x32,0x41,0xA7,0x18,0x3B,0xA2,0x48,0x04,0x05,0x51,0x4F,0x91,0x6D,0x12,0x04,0x20,0x9B,0x61,0x89,0xFF,0x1F};
|
||||
uint8_t spGOOD[] PROGMEM = {0x0A,0x28,0xCD,0x34,0x20,0xD9,0x1A,0x45,0x74,0xE4,0x66,0x24,0xAD,0xBA,0xB1,0x8C,0x9B,0x91,0xA5,0x64,0xE6,0x98,0x21,0x16,0x0B,0x96,0x9B,0x4C,0xE5,0xFF,0x01};
|
||||
uint8_t spMORNING[] PROGMEM = {0xCE,0x08,0x52,0x2A,0x35,0x5D,0x39,0x53,0x29,0x5B,0xB7,0x0A,0x15,0x0C,0xEE,0x2A,0x42,0x56,0x66,0xD2,0x55,0x2E,0x37,0x2F,0xD9,0x45,0xB3,0xD3,0xC5,0xCA,0x6D,0x27,0xD5,0xEE,0x50,0xF5,0x50,0x94,0x14,0x77,0x2D,0xD8,0x5D,0x49,0x92,0xFD,0xB1,0x64,0x2F,0xA9,0x49,0x0C,0x93,0x4B,0xAD,0x19,0x17,0x3E,0x66,0x1E,0xF1,0xA2,0x5B,0x84,0xE2,0x29,0x8F,0x8B,0x72,0x10,0xB5,0xB1,0x2E,0x4B,0xD4,0x45,0x89,0x4A,0xEC,0x5C,0x95,0x14,0x2B,0x8A,0x9C,0x34,0x52,0x5D,0xBC,0xCC,0xB5,0x3B,0x49,0x69,0x89,0x87,0xC1,0x98,0x56,0x3A,0x21,0x2B,0x82,0x67,0xCC,0x5C,0x85,0xB5,0x4A,0x8A,0xF6,0x64,0xA9,0x96,0xC4,0x69,0x3C,0x52,0x81,0x58,0x1C,0x97,0xF6,0x0E,0x1B,0xCC,0x0D,0x42,0x32,0xAA,0x65,0x12,0x67,0xD4,0x6A,0x61,0x52,0xFC,0xFF};
|
||||
uint8_t spAFTERNOON[] PROGMEM = {0xC7,0xCE,0xCE,0x3A,0xCB,0x58,0x1F,0x3B,0x07,0x9D,0x28,0x71,0xB4,0xAC,0x9C,0x74,0x5A,0x42,0x55,0x33,0xB2,0x93,0x0A,0x09,0xD4,0xC5,0x9A,0xD6,0x44,0x45,0xE3,0x38,0x60,0x9A,0x32,0x05,0xF4,0x18,0x01,0x09,0xD8,0xA9,0xC2,0x00,0x5E,0xCA,0x24,0xD5,0x5B,0x9D,0x4A,0x95,0xEA,0x34,0xEE,0x63,0x92,0x5C,0x4D,0xD0,0xA4,0xEE,0x58,0x0C,0xB9,0x4D,0xCD,0x42,0xA2,0x3A,0x24,0x37,0x25,0x8A,0xA8,0x8E,0xA0,0x53,0xE4,0x28,0x23,0x26,0x13,0x72,0x91,0xA2,0x76,0xBB,0x72,0x38,0x45,0x0A,0x46,0x63,0xCA,0x69,0x27,0x39,0x58,0xB1,0x8D,0x60,0x1C,0x34,0x1B,0x34,0xC3,0x55,0x8E,0x73,0x45,0x2D,0x4F,0x4A,0x3A,0x26,0x10,0xA1,0xCA,0x2D,0xE9,0x98,0x24,0x0A,0x1E,0x6D,0x97,0x29,0xD2,0xCC,0x71,0xA2,0xDC,0x86,0xC8,0x12,0xA7,0x8E,0x08,0x85,0x22,0x8D,0x9C,0x43,0xA7,0x12,0xB2,0x2E,0x50,0x09,0xEF,0x51,0xC5,0xBA,0x28,0x58,0xAD,0xDB,0xE1,0xFF,0x03};
|
||||
uint8_t spEVENING[] PROGMEM = {0xCD,0x6D,0x98,0x73,0x47,0x65,0x0D,0x6D,0x10,0xB2,0x5D,0x93,0x35,0x94,0xC1,0xD0,0x76,0x4D,0x66,0x93,0xA7,0x04,0xBD,0x71,0xD9,0x45,0xAE,0x92,0xD5,0xAC,0x53,0x07,0x6D,0xA5,0x76,0x63,0x51,0x92,0xD4,0xA1,0x83,0xD4,0xCB,0xB2,0x51,0x88,0xCD,0xF5,0x50,0x45,0xCE,0xA2,0x2E,0x27,0x28,0x54,0x15,0x37,0x0A,0xCF,0x75,0x61,0x5D,0xA2,0xC4,0xB5,0xC7,0x44,0x55,0x8A,0x0B,0xA3,0x6E,0x17,0x95,0x21,0xA9,0x0C,0x37,0xCD,0x15,0xBA,0xD4,0x2B,0x6F,0xB3,0x54,0xE4,0xD2,0xC8,0x64,0xBC,0x4C,0x91,0x49,0x12,0xE7,0xB2,0xB1,0xD0,0x22,0x0D,0x9C,0xDD,0xAB,0x62,0xA9,0x38,0x53,0x11,0xA9,0x74,0x2C,0xD2,0xCA,0x59,0x34,0xA3,0xE5,0xFF,0x03};
|
||||
uint8_t spPAUSE1[] PROGMEM = {0x00,0x00,0x00,0x00,0xFF,0x0F};
|
||||
|
||||
void sayTime(int hour, int minutes, AudioGeneratorTalkie *talkie)
|
||||
{
|
||||
bool pm = (hour >= 12);
|
||||
uint8_t *spHour[] = { spTWELVE, spONE, spTWO, spTHREE, spFOUR, spFIVE, spSIX,
|
||||
spSEVEN, spEIGHT, spNINE, spTEN, spELEVEN };
|
||||
size_t spHourLen[] = { sizeof(spTWELVE), sizeof(spONE), sizeof(spTWO),
|
||||
sizeof(spTHREE), sizeof(spFOUR), sizeof(spFIVE),
|
||||
sizeof(spSIX), sizeof(spSEVEN), sizeof(spEIGHT),
|
||||
sizeof(spNINE), sizeof(spTEN), sizeof(spELEVEN) };
|
||||
uint8_t *spMinDec[] = { spOH, spTEN, spTWENTY, spTHIRTY, spFOURTY, spFIFTY };
|
||||
size_t spMinDecLen[] = { sizeof(spOH), sizeof(spTEN), sizeof(spTWENTY),
|
||||
sizeof(spTHIRTY), sizeof(spFOURTY), sizeof(spFIFTY) };
|
||||
uint8_t *spMinSpecial[] = { spELEVEN, spTWELVE, spTHIRTEEN, spFOURTEEN,
|
||||
spFIFTEEN, spSIXTEEN, spSEVENTEEN, spEIGHTEEN,
|
||||
spNINETEEN };
|
||||
size_t spMinSpecialLen[] = { sizeof(spELEVEN), sizeof(spTWELVE),
|
||||
sizeof(spTHIRTEEN), sizeof(spFOURTEEN),
|
||||
sizeof(spFIFTEEN), sizeof(spSIXTEEN),
|
||||
sizeof(spSEVENTEEN), sizeof(spEIGHTEEN),
|
||||
sizeof(spNINETEEN) };
|
||||
uint8_t *spMinLow[] = { spONE, spTWO, spTHREE, spFOUR, spFIVE, spSIX,
|
||||
spSEVEN, spEIGHT, spNINE };
|
||||
size_t spMinLowLen[] = { sizeof(spONE), sizeof(spTWO), sizeof(spTHREE),
|
||||
sizeof(spFOUR), sizeof(spFIVE), sizeof(spSIX),
|
||||
sizeof(spSEVEN), sizeof(spEIGHT), sizeof(spNINE) };
|
||||
|
||||
talkie->say(spTHE, sizeof(spTHE));
|
||||
talkie->say(spTIME, sizeof(spTIME));
|
||||
talkie->say(spIS, sizeof(spIS));
|
||||
|
||||
hour = hour % 12;
|
||||
talkie->say(spHour[hour], spHourLen[hour]);
|
||||
if (minutes==0) {
|
||||
talkie->say(spOCLOCK, sizeof(spOCLOCK));
|
||||
} else if (minutes<=10 || minutes >=20) {
|
||||
talkie->say(spMinDec[minutes / 10], spMinDecLen[minutes /10]);
|
||||
if (minutes % 10) {
|
||||
talkie->say(spMinLow[(minutes % 10) - 1], spMinLowLen[(minutes % 10) - 1]);
|
||||
}
|
||||
} else {
|
||||
talkie->say(spMinSpecial[minutes - 11], spMinSpecialLen[minutes - 11]);
|
||||
}
|
||||
if (pm) {
|
||||
talkie->say(spP_M_, sizeof(spP_M_));
|
||||
} else {
|
||||
talkie->say(spA_M_, sizeof(spA_M_));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AudioGeneratorTalkie *talkie;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
|
||||
bool GetLocalTime(struct tm * info, uint32_t ms) {
|
||||
uint32_t count = ms / 10;
|
||||
time_t now;
|
||||
|
||||
time(&now);
|
||||
localtime_r(&now, info);
|
||||
|
||||
if (info->tm_year > (2016 - 1900)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
while (count--) {
|
||||
delay(10);
|
||||
time(&now);
|
||||
localtime_r(&now, info);
|
||||
if (info->tm_year > (2016 - 1900)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
// We start by connecting to a WiFi network
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println("Contacting Time Server");
|
||||
configTime(3600 * timezone, daysavetime * 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
|
||||
struct tm tmstruct ;
|
||||
do {
|
||||
tmstruct.tm_year = 0;
|
||||
Serial.printf(".");
|
||||
GetLocalTime(&tmstruct, 5000);
|
||||
delay(100);
|
||||
} while (tmstruct.tm_year < 100);
|
||||
|
||||
audioLogger = &Serial;
|
||||
out = new AudioOutputI2S();
|
||||
talkie = new AudioGeneratorTalkie();
|
||||
talkie->begin(nullptr, out);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
struct tm tmstruct ;
|
||||
tmstruct.tm_year = 0;
|
||||
GetLocalTime(&tmstruct, 5000);
|
||||
Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n",
|
||||
tmstruct.tm_year + 1900, tmstruct.tm_mon + 1,
|
||||
tmstruct.tm_mday, tmstruct.tm_hour,
|
||||
tmstruct.tm_min, tmstruct.tm_sec);
|
||||
sayTime(tmstruct.tm_hour, tmstruct.tm_min, talkie);
|
||||
delay(1000);
|
||||
}
|
||||
441
examples/WebRadio/WebRadio.ino
Normal file
441
examples/WebRadio/WebRadio.ino
Normal file
@@ -0,0 +1,441 @@
|
||||
/*
|
||||
WebRadio Example
|
||||
Very simple HTML app to control web streaming
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "AudioFileSourceICYStream.h"
|
||||
#include "AudioFileSourceBuffer.h"
|
||||
#include "AudioGeneratorMP3.h"
|
||||
#include "AudioGeneratorAAC.h"
|
||||
#include "AudioOutputI2S.h"
|
||||
#include <EEPROM.h>
|
||||
|
||||
// Custom web server that doesn't need much RAM
|
||||
#include "web.h"
|
||||
|
||||
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
|
||||
|
||||
// Enter your WiFi setup here:
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
const char* password = STAPSK;
|
||||
|
||||
WiFiServer server(80);
|
||||
|
||||
AudioGenerator *decoder = NULL;
|
||||
AudioFileSourceICYStream *file = NULL;
|
||||
AudioFileSourceBuffer *buff = NULL;
|
||||
AudioOutputI2S *out = NULL;
|
||||
|
||||
int volume = 100;
|
||||
char title[64];
|
||||
char url[96];
|
||||
char status[64];
|
||||
bool newUrl = false;
|
||||
bool isAAC = false;
|
||||
int retryms = 0;
|
||||
|
||||
typedef struct {
|
||||
char url[96];
|
||||
bool isAAC;
|
||||
int16_t volume;
|
||||
int16_t checksum;
|
||||
} Settings;
|
||||
|
||||
// C++11 multiline string constants are neato...
|
||||
static const char HEAD[] PROGMEM = R"KEWL(
|
||||
<head>
|
||||
<title>ESP8266 Web Radio</title>
|
||||
<script type="text/javascript">
|
||||
function updateTitle() {
|
||||
var x = new XMLHttpRequest();
|
||||
x.open("GET", "title");
|
||||
x.onload = function() { document.getElementById("titlespan").innerHTML=x.responseText; setTimeout(updateTitle, 5000); }
|
||||
x.onerror = function() { setTimeout(updateTitle, 5000); }
|
||||
x.send();
|
||||
}
|
||||
setTimeout(updateTitle, 1000);
|
||||
function showValue(n) {
|
||||
document.getElementById("volspan").innerHTML=n;
|
||||
var x = new XMLHttpRequest();
|
||||
x.open("GET", "setvol?vol="+n);
|
||||
x.send();
|
||||
}
|
||||
function updateStatus() {var x = new XMLHttpRequest();
|
||||
x.open("GET", "status");
|
||||
x.onload = function() { document.getElementById("statusspan").innerHTML=x.responseText; setTimeout(updateStatus, 5000); }
|
||||
x.onerror = function() { setTimeout(updateStatus, 5000); }
|
||||
x.send();
|
||||
}
|
||||
setTimeout(updateStatus, 2000);
|
||||
</script>
|
||||
</head>)KEWL";
|
||||
|
||||
static const char BODY[] PROGMEM = R"KEWL(
|
||||
<body>
|
||||
ESP8266 Web Radio!
|
||||
<hr>
|
||||
Currently Playing: <span id="titlespan">%s</span><br>
|
||||
Volume: <input type="range" name="vol" min="1" max="150" steps="10" value="%d" onchange="showValue(this.value)"/> <span id="volspan">%d</span>%%
|
||||
<hr>
|
||||
Status: <span id="statusspan">%s</span>
|
||||
<hr>
|
||||
<form action="changeurl" method="GET">
|
||||
Current URL: %s<br>
|
||||
Change URL: <input type="text" name="url">
|
||||
<select name="type"><option value="mp3">MP3</option><option value="aac">AAC</option></select>
|
||||
<input type="submit" value="Change"></form>
|
||||
<form action="stop" method="POST"><input type="submit" value="Stop"></form>
|
||||
</body>)KEWL";
|
||||
|
||||
void HandleIndex(WiFiClient *client)
|
||||
{
|
||||
char buff[sizeof(BODY) + sizeof(title) + sizeof(status) + sizeof(url) + 3*2];
|
||||
|
||||
Serial.printf_P(PSTR("Sending INDEX...Free mem=%d\n"), ESP.getFreeHeap());
|
||||
WebHeaders(client, NULL);
|
||||
WebPrintf(client, DOCTYPE);
|
||||
client->write_P( PSTR("<html>"), 6 );
|
||||
client->write_P( HEAD, strlen_P(HEAD) );
|
||||
sprintf_P(buff, BODY, title, volume, volume, status, url);
|
||||
client->write(buff, strlen(buff) );
|
||||
client->write_P( PSTR("</html>"), 7 );
|
||||
Serial.printf_P(PSTR("Sent INDEX...Free mem=%d\n"), ESP.getFreeHeap());
|
||||
}
|
||||
|
||||
void HandleStatus(WiFiClient *client)
|
||||
{
|
||||
WebHeaders(client, NULL);
|
||||
client->write(status, strlen(status));
|
||||
}
|
||||
|
||||
void HandleTitle(WiFiClient *client)
|
||||
{
|
||||
WebHeaders(client, NULL);
|
||||
client->write(title, strlen(title));
|
||||
}
|
||||
|
||||
void HandleVolume(WiFiClient *client, char *params)
|
||||
{
|
||||
char *namePtr;
|
||||
char *valPtr;
|
||||
|
||||
while (ParseParam(¶ms, &namePtr, &valPtr)) {
|
||||
ParamInt("vol", volume);
|
||||
}
|
||||
Serial.printf_P(PSTR("Set volume: %d\n"), volume);
|
||||
out->SetGain(((float)volume)/100.0);
|
||||
RedirectToIndex(client);
|
||||
}
|
||||
|
||||
void HandleChangeURL(WiFiClient *client, char *params)
|
||||
{
|
||||
char *namePtr;
|
||||
char *valPtr;
|
||||
char newURL[sizeof(url)];
|
||||
char newType[4];
|
||||
|
||||
newURL[0] = 0;
|
||||
newType[0] = 0;
|
||||
while (ParseParam(¶ms, &namePtr, &valPtr)) {
|
||||
ParamText("url", newURL);
|
||||
ParamText("type", newType);
|
||||
}
|
||||
if (newURL[0] && newType[0]) {
|
||||
newUrl = true;
|
||||
strncpy(url, newURL, sizeof(url)-1);
|
||||
url[sizeof(url)-1] = 0;
|
||||
if (!strcmp_P(newType, PSTR("aac"))) {
|
||||
isAAC = true;
|
||||
} else {
|
||||
isAAC = false;
|
||||
}
|
||||
strcpy_P(status, PSTR("Changing URL..."));
|
||||
Serial.printf_P(PSTR("Changed URL to: %s(%s)\n"), url, newType);
|
||||
RedirectToIndex(client);
|
||||
} else {
|
||||
WebError(client, 404, NULL, false);
|
||||
}
|
||||
}
|
||||
|
||||
void RedirectToIndex(WiFiClient *client)
|
||||
{
|
||||
WebError(client, 301, PSTR("Location: /\r\n"), true);
|
||||
}
|
||||
|
||||
void StopPlaying()
|
||||
{
|
||||
if (decoder) {
|
||||
decoder->stop();
|
||||
delete decoder;
|
||||
decoder = NULL;
|
||||
}
|
||||
if (buff) {
|
||||
buff->close();
|
||||
delete buff;
|
||||
buff = NULL;
|
||||
}
|
||||
if (file) {
|
||||
file->close();
|
||||
delete file;
|
||||
file = NULL;
|
||||
}
|
||||
strcpy_P(status, PSTR("Stopped"));
|
||||
strcpy_P(title, PSTR("Stopped"));
|
||||
}
|
||||
|
||||
void HandleStop(WiFiClient *client)
|
||||
{
|
||||
Serial.printf_P(PSTR("HandleStop()\n"));
|
||||
StopPlaying();
|
||||
RedirectToIndex(client);
|
||||
}
|
||||
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *str)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
(void) isUnicode; // Punt this ball for now
|
||||
(void) ptr;
|
||||
if (strstr_P(type, PSTR("Title"))) {
|
||||
strncpy(title, str, sizeof(title));
|
||||
title[sizeof(title)-1] = 0;
|
||||
} else {
|
||||
// Who knows what to do? Not me!
|
||||
}
|
||||
}
|
||||
void StatusCallback(void *cbData, int code, const char *string)
|
||||
{
|
||||
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||
(void) code;
|
||||
(void) ptr;
|
||||
strncpy_P(status, string, sizeof(status)-1);
|
||||
status[sizeof(status)-1] = 0;
|
||||
}
|
||||
|
||||
#ifdef ESP8266
|
||||
const int preallocateBufferSize = 5*1024;
|
||||
const int preallocateCodecSize = 29192; // MP3 codec max mem needed
|
||||
#else
|
||||
const int preallocateBufferSize = 16*1024;
|
||||
const int preallocateCodecSize = 85332; // AAC+SBR codec max mem needed
|
||||
#endif
|
||||
void *preallocateBuffer = NULL;
|
||||
void *preallocateCodec = NULL;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// First, preallocate all the memory needed for the buffering and codecs, never to be freed
|
||||
preallocateBuffer = malloc(preallocateBufferSize);
|
||||
preallocateCodec = malloc(preallocateCodecSize);
|
||||
if (!preallocateBuffer || !preallocateCodec) {
|
||||
Serial.begin(115200);
|
||||
Serial.printf_P(PSTR("FATAL ERROR: Unable to preallocate %d bytes for app\n"), preallocateBufferSize+preallocateCodecSize);
|
||||
while (1) delay(1000); // Infinite halt
|
||||
}
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
delay(1000);
|
||||
Serial.printf_P(PSTR("Connecting to WiFi\n"));
|
||||
|
||||
WiFi.disconnect();
|
||||
WiFi.softAPdisconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
// Try forever
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.printf_P(PSTR("...Connecting to WiFi\n"));
|
||||
delay(1000);
|
||||
}
|
||||
Serial.printf_P(PSTR("Connected\n"));
|
||||
|
||||
Serial.printf_P(PSTR("Go to http://"));
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.printf_P(PSTR("/ to control the web radio.\n"));
|
||||
|
||||
server.begin();
|
||||
|
||||
strcpy_P(url, PSTR("none"));
|
||||
strcpy_P(status, PSTR("OK"));
|
||||
strcpy_P(title, PSTR("Idle"));
|
||||
|
||||
audioLogger = &Serial;
|
||||
file = NULL;
|
||||
buff = NULL;
|
||||
out = new AudioOutputI2S();
|
||||
decoder = NULL;
|
||||
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
void StartNewURL()
|
||||
{
|
||||
Serial.printf_P(PSTR("Changing URL to: %s, vol=%d\n"), url, volume);
|
||||
|
||||
newUrl = false;
|
||||
// Stop and free existing ones
|
||||
Serial.printf_P(PSTR("Before stop...Free mem=%d\n"), ESP.getFreeHeap());
|
||||
StopPlaying();
|
||||
Serial.printf_P(PSTR("After stop...Free mem=%d\n"), ESP.getFreeHeap());
|
||||
SaveSettings();
|
||||
Serial.printf_P(PSTR("Saved settings\n"));
|
||||
|
||||
file = new AudioFileSourceICYStream(url);
|
||||
Serial.printf_P(PSTR("created icystream\n"));
|
||||
file->RegisterMetadataCB(MDCallback, NULL);
|
||||
buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize);
|
||||
Serial.printf_P(PSTR("created buffer\n"));
|
||||
buff->RegisterStatusCB(StatusCallback, NULL);
|
||||
decoder = isAAC ? (AudioGenerator*) new AudioGeneratorAAC(preallocateCodec, preallocateCodecSize) : (AudioGenerator*) new AudioGeneratorMP3(preallocateCodec, preallocateCodecSize);
|
||||
Serial.printf_P(PSTR("created decoder\n"));
|
||||
decoder->RegisterStatusCB(StatusCallback, NULL);
|
||||
Serial.printf_P("Decoder start...\n");
|
||||
decoder->begin(buff, out);
|
||||
out->SetGain(((float)volume)/100.0);
|
||||
if (!decoder->isRunning()) {
|
||||
Serial.printf_P(PSTR("Can't connect to URL"));
|
||||
StopPlaying();
|
||||
strcpy_P(status, PSTR("Unable to connect to URL"));
|
||||
retryms = millis() + 2000;
|
||||
}
|
||||
Serial.printf_P("Done start new URL\n");
|
||||
}
|
||||
|
||||
void LoadSettings()
|
||||
{
|
||||
// Restore from EEPROM, check the checksum matches
|
||||
Settings s;
|
||||
uint8_t *ptr = reinterpret_cast<uint8_t *>(&s);
|
||||
EEPROM.begin(sizeof(s));
|
||||
for (size_t i=0; i<sizeof(s); i++) {
|
||||
ptr[i] = EEPROM.read(i);
|
||||
}
|
||||
EEPROM.end();
|
||||
int16_t sum = 0x1234;
|
||||
for (size_t i=0; i<sizeof(url); i++) sum += s.url[i];
|
||||
sum += s.isAAC;
|
||||
sum += s.volume;
|
||||
if (s.checksum == sum) {
|
||||
strcpy(url, s.url);
|
||||
isAAC = s.isAAC;
|
||||
volume = s.volume;
|
||||
Serial.printf_P(PSTR("Resuming stream from EEPROM: %s, type=%s, vol=%d\n"), url, isAAC?"AAC":"MP3", volume);
|
||||
newUrl = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SaveSettings()
|
||||
{
|
||||
// Store in "EEPROM" to restart automatically
|
||||
Settings s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
strcpy(s.url, url);
|
||||
s.isAAC = isAAC;
|
||||
s.volume = volume;
|
||||
s.checksum = 0x1234;
|
||||
for (size_t i=0; i<sizeof(url); i++) s.checksum += s.url[i];
|
||||
s.checksum += s.isAAC;
|
||||
s.checksum += s.volume;
|
||||
uint8_t *ptr = reinterpret_cast<uint8_t *>(&s);
|
||||
EEPROM.begin(sizeof(s));
|
||||
for (size_t i=0; i<sizeof(s); i++) {
|
||||
EEPROM.write(i, ptr[i]);
|
||||
}
|
||||
EEPROM.commit();
|
||||
EEPROM.end();
|
||||
}
|
||||
|
||||
void PumpDecoder()
|
||||
{
|
||||
if (decoder && decoder->isRunning()) {
|
||||
strcpy_P(status, PSTR("Playing")); // By default we're OK unless the decoder says otherwise
|
||||
if (!decoder->loop()) {
|
||||
Serial.printf_P(PSTR("Stopping decoder\n"));
|
||||
StopPlaying();
|
||||
retryms = millis() + 2000;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int lastms = 0;
|
||||
if (millis()-lastms > 1000) {
|
||||
lastms = millis();
|
||||
Serial.printf_P(PSTR("Running for %d seconds%c...Free mem=%d\n"), lastms/1000, !decoder?' ':(decoder->isRunning()?'*':' '), ESP.getFreeHeap());
|
||||
}
|
||||
|
||||
if (retryms && millis()-retryms>0) {
|
||||
retryms = 0;
|
||||
newUrl = true;
|
||||
}
|
||||
|
||||
if (newUrl) {
|
||||
StartNewURL();
|
||||
}
|
||||
|
||||
PumpDecoder();
|
||||
|
||||
char *reqUrl;
|
||||
char *params;
|
||||
WiFiClient client = server.available();
|
||||
PumpDecoder();
|
||||
char reqBuff[384];
|
||||
if (client && WebReadRequest(&client, reqBuff, 384, &reqUrl, ¶ms)) {
|
||||
PumpDecoder();
|
||||
if (IsIndexHTML(reqUrl)) {
|
||||
HandleIndex(&client);
|
||||
} else if (!strcmp_P(reqUrl, PSTR("stop"))) {
|
||||
HandleStop(&client);
|
||||
} else if (!strcmp_P(reqUrl, PSTR("status"))) {
|
||||
HandleStatus(&client);
|
||||
} else if (!strcmp_P(reqUrl, PSTR("title"))) {
|
||||
HandleTitle(&client);
|
||||
} else if (!strcmp_P(reqUrl, PSTR("setvol"))) {
|
||||
HandleVolume(&client, params);
|
||||
} else if (!strcmp_P(reqUrl, PSTR("changeurl"))) {
|
||||
HandleChangeURL(&client, params);
|
||||
} else {
|
||||
WebError(&client, 404, NULL, false);
|
||||
}
|
||||
// web clients hate when door is violently shut
|
||||
while (client.available()) {
|
||||
PumpDecoder();
|
||||
client.read();
|
||||
}
|
||||
}
|
||||
PumpDecoder();
|
||||
if (client) {
|
||||
client.flush();
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
314
examples/WebRadio/web.cpp
Normal file
314
examples/WebRadio/web.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
PsychoPlug
|
||||
ESP8266 based remote outlet with standalone timer and MQTT integration
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
#include "web.h"
|
||||
|
||||
void WebPrintError(WiFiClient *client, int code)
|
||||
{
|
||||
switch(code) {
|
||||
case 301: WebPrintf(client, "301 Moved Permanently"); break;
|
||||
case 400: WebPrintf(client, "400 Bad Request"); break;
|
||||
case 401: WebPrintf(client, "401 Unauthorized"); break;
|
||||
case 404: WebPrintf(client, "404 Not Found"); break;
|
||||
case 405: WebPrintf(client, "405 Method Not Allowed"); break;
|
||||
default: WebPrintf(client, "500 Server Error"); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WebError(WiFiClient *client, int code, const char *headers, bool usePMEM)
|
||||
{
|
||||
WebPrintf(client, "HTTP/1.1 %d\r\n", code);
|
||||
WebPrintf(client, "Server: PsychoPlug\r\n");
|
||||
WebPrintf(client, "Content-type: text/html\r\n");
|
||||
WebPrintf(client, "Cache-Control: no-cache, no-store, must-revalidate\r\n");
|
||||
WebPrintf(client, "Pragma: no-cache\r\n");
|
||||
WebPrintf(client, "Expires: 0\r\n");
|
||||
WebPrintf(client, "Connection: close\r\n");
|
||||
if (headers) {
|
||||
if (!usePMEM) {
|
||||
WebPrintf(client, "%s", headers);
|
||||
} else {
|
||||
WebPrintfPSTR(client, headers);
|
||||
}
|
||||
}
|
||||
WebPrintf(client, "\r\n\r\n");
|
||||
WebPrintf(client, DOCTYPE);
|
||||
WebPrintf(client, "<html><head><title>");
|
||||
WebPrintError(client, code);
|
||||
WebPrintf(client, "</title>" ENCODING "</head>\n");
|
||||
WebPrintf(client, "<body><h1>");
|
||||
WebPrintError(client, code);
|
||||
WebPrintf(client, "</h1></body></html>\r\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WebHeaders(WiFiClient *client, PGM_P /*const char **/headers)
|
||||
{
|
||||
WebPrintf(client, "HTTP/1.1 200 OK\r\n");
|
||||
WebPrintf(client, "Server: PsychoPlug\r\n");
|
||||
WebPrintf(client, "Content-type: text/html\r\n");
|
||||
WebPrintf(client, "Cache-Control: no-cache, no-store, must-revalidate\r\n");
|
||||
WebPrintf(client, "Pragma: no-cache\r\n");
|
||||
WebPrintf(client, "Connection: close\r\n");
|
||||
WebPrintf(client, "Expires: 0\r\n");
|
||||
if (headers) {
|
||||
WebPrintfPSTR(client, headers);
|
||||
}
|
||||
WebPrintf(client, "\r\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// In-place decoder, overwrites source with decoded values. Needs 0-termination on input
|
||||
// Try and keep memory needs low, speed not critical
|
||||
static uint8_t b64lut(uint8_t i)
|
||||
{
|
||||
if (i >= 'A' && i <= 'Z') return i - 'A';
|
||||
if (i >= 'a' && i <= 'z') return i - 'a' + 26;
|
||||
if (i >= '0' && i <= '9') return i - '0' + 52;
|
||||
if (i == '-') return 62;
|
||||
if (i == '_') return 63;
|
||||
else return 64;// sentinel
|
||||
}
|
||||
|
||||
void Base64Decode(char *str)
|
||||
{
|
||||
char *dest;
|
||||
dest = str;
|
||||
|
||||
if (strlen(str)%4) return; // Not multiple of 4 == error
|
||||
|
||||
while (*str) {
|
||||
uint8_t a = b64lut(*(str++));
|
||||
uint8_t b = b64lut(*(str++));
|
||||
uint8_t c = b64lut(*(str++));
|
||||
uint8_t d = b64lut(*(str++));
|
||||
*(dest++) = (a << 2) | ((b & 0x30) >> 4);
|
||||
if (c == 64) break;
|
||||
*(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
|
||||
if (d == 64) break;
|
||||
*(dest++) = ((c & 0x03) << 6) | d;
|
||||
}
|
||||
*dest = 0; // Terminate the string
|
||||
}
|
||||
|
||||
|
||||
void URLDecode(char *ptr)
|
||||
{
|
||||
while (*ptr) {
|
||||
if (*ptr == '+') {
|
||||
*ptr = ' ';
|
||||
} else if (*ptr == '%') {
|
||||
if (*(ptr+1) && *(ptr+2)) {
|
||||
byte a = *(ptr + 1);
|
||||
byte b = *(ptr + 2);
|
||||
if (a>='0' && a<='9') a -= '0';
|
||||
else if (a>='a' && a<='f') a = a - 'a' + 10;
|
||||
else if (a>='A' && a<='F') a = a - 'A' + 10;
|
||||
if (b>='0' && b<='9') b -= '0';
|
||||
else if (b>='a' && b<='f') b = b - 'a' + 10;
|
||||
else if (b>='A' && b<='F') b = b - 'A' + 10;
|
||||
*ptr = ((a&0x0f)<<4) | (b&0x0f);
|
||||
// Safe strcpy the rest of the string back
|
||||
char *p1 = ptr + 1;
|
||||
char *p2 = ptr + 3;
|
||||
while (*p2) { *p1 = *p2; p1++; p2++; }
|
||||
*p1 = 0;
|
||||
}
|
||||
// OTW this is a bad encoding, just pass unchanged
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Parse HTTP request
|
||||
bool WebReadRequest(WiFiClient *client, char *reqBuff, int reqBuffLen, char **urlStr, char **paramStr)
|
||||
{
|
||||
static char NUL = 0; // Get around writable strings...
|
||||
|
||||
*urlStr = NULL;
|
||||
*paramStr = NULL;
|
||||
|
||||
unsigned long timeoutMS = millis() + 5000; // Max delay before we timeout
|
||||
while (!client->available() && millis() < timeoutMS) { delay(10); }
|
||||
if (!client->available()) {
|
||||
return false;
|
||||
}
|
||||
int wlen = client->readBytesUntil('\r', reqBuff, reqBuffLen-1);
|
||||
reqBuff[wlen] = 0;
|
||||
|
||||
|
||||
// Delete HTTP version (well, anything after the 2nd space)
|
||||
char *ptr = reqBuff;
|
||||
while (*ptr && *ptr!=' ') ptr++;
|
||||
if (*ptr) ptr++;
|
||||
while (*ptr && *ptr!=' ') ptr++;
|
||||
*ptr = 0;
|
||||
|
||||
URLDecode(reqBuff);
|
||||
|
||||
char *url;
|
||||
char *qp;
|
||||
if (!memcmp_P(reqBuff, PSTR("GET "), 4)) {
|
||||
client->flush(); // Don't need anything here...
|
||||
|
||||
// Break into URL and form data
|
||||
url = reqBuff+4;
|
||||
while (*url && *url=='/') url++; // Strip off leading /s
|
||||
qp = strchr(url, '?');
|
||||
if (qp) {
|
||||
*qp = 0; // End URL
|
||||
qp++;
|
||||
} else {
|
||||
qp = &NUL;
|
||||
}
|
||||
} else if (!memcmp_P(reqBuff, PSTR("POST "), 5)) {
|
||||
uint8_t newline;
|
||||
client->read(&newline, 1); // Get rid of \n
|
||||
|
||||
url = reqBuff+5;
|
||||
while (*url && *url=='/') url++; // Strip off leading /s
|
||||
qp = strchr(url, '?');
|
||||
if (qp) *qp = 0; // End URL @ ?
|
||||
// In a POST the params are in the body
|
||||
int sizeleft = reqBuffLen - strlen(reqBuff) - 1;
|
||||
qp = reqBuff + strlen(reqBuff) + 1;
|
||||
int wlen = client->readBytesUntil('\r', qp, sizeleft-1);
|
||||
qp[wlen] = 0;
|
||||
client->flush();
|
||||
URLDecode(qp);
|
||||
} else {
|
||||
// Not a GET or POST, error
|
||||
WebError(client, 405, PSTR("Allow: GET, POST"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (urlStr) *urlStr = url;
|
||||
if (paramStr) *paramStr = qp;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Scan out and update a pointeinto the param string, returning the name and value or false if done
|
||||
bool ParseParam(char **paramStr, char **name, char **value)
|
||||
{
|
||||
char *data = *paramStr;
|
||||
|
||||
if (*data==0) return false;
|
||||
|
||||
char *namePtr = data;
|
||||
while ((*data != 0) && (*data != '=') && (*data != '&')) data++;
|
||||
if (*data) { *data = 0; data++; }
|
||||
char *valPtr = data;
|
||||
if (*data == '=') data++;
|
||||
while ((*data != 0) && (*data != '=') && (*data != '&')) data++;
|
||||
if (*data) { *data = 0; data++;}
|
||||
|
||||
*paramStr = data;
|
||||
*name = namePtr;
|
||||
*value = valPtr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsIndexHTML(const char *url)
|
||||
{
|
||||
if (!url) return false;
|
||||
if (*url==0 || !strcmp_P(url, PSTR("/")) || !strcmp_P(url, PSTR("/index.html")) || !strcmp_P(url, PSTR("index.html"))) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void WebFormText(WiFiClient *client, /*const char **/ PGM_P label, const char *name, const char *value, bool enabled)
|
||||
{
|
||||
WebPrintfPSTR(client, label);
|
||||
WebPrintf(client, ": <input type=\"text\" name=\"%s\" id=\"%s\" value=\"%s\" %s><br>\n", name, name, value, !enabled?"disabled":"");
|
||||
}
|
||||
void WebFormText(WiFiClient *client, /*const char **/ PGM_P label, const char *name, const int value, bool enabled)
|
||||
{
|
||||
WebPrintfPSTR(client, label);
|
||||
WebPrintf(client, ": <input type=\"text\" name=\"%s\" id=\"%s\" value=\"%d\" %s><br>\n", name, name, value, !enabled?"disabled":"");
|
||||
}
|
||||
void WebFormCheckbox(WiFiClient *client, /*const char **/ PGM_P label, const char *name, bool checked, bool enabled)
|
||||
{
|
||||
WebPrintf(client, "<input type=\"checkbox\" name=\"%s\" id=\"%s\" %s %s> ", name, name, checked?"checked":"", !enabled?"disabled":"");
|
||||
WebPrintfPSTR(client, label);
|
||||
WebPrintf(client, "<br>\n");
|
||||
}
|
||||
void WebFormCheckboxDisabler(WiFiClient *client, PGM_P /*const char **/label, const char *name, bool invert, bool checked, bool enabled, const char *ids[])
|
||||
{
|
||||
WebPrintf(client,"<input type=\"checkbox\" name=\"%s\" id=\"%s\" onclick=\"", name,name);
|
||||
if (invert) WebPrintf(client, "var x = true; if (this.checked) { x = false; }\n")
|
||||
else WebPrintf(client, "var x = false; if (this.checked) { x = true; }\n");
|
||||
for (byte i=0; ids[i][0]; i++ ) {
|
||||
WebPrintf(client, "document.getElementById('%s').disabled = x;\n", ids[i]);
|
||||
}
|
||||
WebPrintf(client, "\" %s %s> ", checked?"checked":"", !enabled?"disabled":"")
|
||||
WebPrintfPSTR(client, label);
|
||||
WebPrintf(client, "<br>\n");
|
||||
}
|
||||
|
||||
// Scan an integer from a string, place it into dest, and then return # of bytes scanned
|
||||
int ParseInt(char *src, int *dest)
|
||||
{
|
||||
byte count = 0;
|
||||
bool neg = false;
|
||||
int res = 0;
|
||||
if (!src) return 0;
|
||||
if (src[0] == '-') {neg = true; src++; count++;}
|
||||
while (*src && (*src>='0') && (*src<='9')) {
|
||||
res = res * 10;
|
||||
res += *src - '0';
|
||||
src++;
|
||||
count++;
|
||||
}
|
||||
if (neg) res *= -1;
|
||||
if (dest) *dest = res;
|
||||
return count;
|
||||
}
|
||||
|
||||
void Read4Int(char *str, byte *p)
|
||||
{
|
||||
int i;
|
||||
str += ParseInt(str, &i); p[0] = i; if (*str) str++;
|
||||
str += ParseInt(str, &i); p[1] = i; if (*str) str++;
|
||||
str += ParseInt(str, &i); p[2] = i; if (*str) str++;
|
||||
str += ParseInt(str, &i); p[3] = i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
64
examples/WebRadio/web.h
Normal file
64
examples/WebRadio/web.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
PsychoPlug
|
||||
ESP8266 based remote outlet with standalone timer and MQTT integration
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _web_h
|
||||
#define _web_h
|
||||
|
||||
// Global way of writing out dynamic HTML to socket
|
||||
// snprintf guarantees a null termination
|
||||
#define WebPrintf(c, fmt, ...) { char webBuff[192]; snprintf_P(webBuff, sizeof(webBuff), PSTR(fmt), ## __VA_ARGS__); (c)->print(webBuff); delay(10);}
|
||||
#define WebPrintfPSTR(c, fmt, ...) { char webBuff[192]; snprintf_P(webBuff, sizeof(webBuff), (fmt), ## __VA_ARGS__); (c)->print(webBuff); delay(10);}
|
||||
|
||||
// Common HTTP header bits
|
||||
#define DOCTYPE "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
|
||||
#define ENCODING "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n"
|
||||
|
||||
|
||||
// Web header creation
|
||||
void WebPrintError(WiFiClient *client, int code); // Sends only the error code string and a description
|
||||
void WebError(WiFiClient *client, int code, const char *headers, bool usePMEM = true); // Sends whole HTTP error headers
|
||||
void WebHeaders(WiFiClient *client, PGM_P /*const char **/headers); // Send success headers
|
||||
|
||||
// Web decoding utilities
|
||||
void Base64Decode(char *str); // In-place B64 decode
|
||||
void URLDecode(char *ptr); // In-place URL decode
|
||||
|
||||
// GET/POST parsing
|
||||
bool WebReadRequest(WiFiClient *client, char *reqBuff, int reqBuffLen, char **urlStr, char **paramStr);
|
||||
bool ParseParam(char **paramStr, char **name, char **value); // Get next name/parameter from a param string
|
||||
bool IsIndexHTML(const char *url); // Is this meant to be index.html (/, index.htm, etc.)
|
||||
|
||||
// HTML FORM generation
|
||||
void WebFormText(WiFiClient *client, /*const char **/ PGM_P label, const char *name, const char *value, bool enabled);
|
||||
void WebFormText(WiFiClient *client, /*const char **/ PGM_P label, const char *name, const int value, bool enabled);
|
||||
void WebFormCheckbox(WiFiClient *client, /*const char **/ PGM_P label, const char *name, bool checked, bool enabled);
|
||||
void WebFormCheckboxDisabler(WiFiClient *client, PGM_P /*const char **/label, const char *name, bool invert, bool checked, bool enabled, const char *ids[]);
|
||||
|
||||
// HTML FORM parsing
|
||||
int ParseInt(char *src, int *dest);
|
||||
void Read4Int(char *str, byte *p);
|
||||
#define ParamText(name, dest) { if (!strcmp(namePtr, (name))) strlcpy((dest), valPtr, sizeof(dest)); }
|
||||
#define ParamCheckbox(name, dest) { if (!strcmp(namePtr, (name))) (dest) = !strcmp("on", valPtr); }
|
||||
#define ParamInt(name, dest) { if (!strcmp(namePtr, (name))) ParseInt(valPtr, &dest); }
|
||||
#define Param4Int(name, dest) { if (!strcmp(namePtr, (name))) Read4Int(valPtr, (dest)); }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user