diff --git a/README.md b/README.md
index b46f221..4598f18 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,19 @@
## NEWS
Currently I'm working on a new Tonuino that is completely based on 3.3V and makes use of an (optional) [headphone-pcb](https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/PCBs/Headphone%20with%20PCM5102a%20and%20TMD1308). As uC-develboard a Lolin32 is used and it's (optionally) battery-powered. So stay tuned...
+## History
+[...]
+* 11.07.2020: Added support for reversed Neopixel addressing.
+* 09.10.2020: mqttUser / mqttPassword can now be configured via webgui.
+* 16.10.2020: Added English as supported lanuage.
+* 01.11.2020: Added directive `SD_NOT_MANDATORY_ENABLE`: for debugging puposes SD can be bypassed at boot.
+* 17.11.2020: Introduced a distinct volume for headphone for optional headphone-PCB.
+* 20.11.2020: Added directive `MEASURE_BATTERY_VOLTAGE`: monitoring battery's voltage is now supported.
+* 25.11.2020: WiFi can npw be activated/deactivated instantly by pressing two buttons.
+* 28.11.2020: Battery's voltage can now be visualized by Neopixel by short-press of rotary encoder's burtton.
+* 28.11.2020. Added directive `PLAY_LAST_RFID_AFTER_REBOOT`: Tonuino will recall the last RFID played after reboot.
+More to come...
+
## Disclaimer
This is a **fork** of the popular [Tonuino-project](https://github.com/xfjx/TonUINO) which means, that it only shares the basic concept of controlling a music-player by RFID-tags and buttons. **Said this I want to rule out, that the code-basis is completely different and developed by myself**. So there might be features, that are supported by my fork whereas others are missing or implemented differently. For sure both share that it's non-profit, DIY and developed on [Arduino](https://www.arduino.cc/).
@@ -10,7 +23,7 @@ This is a **fork** of the popular [Tonuino-project](https://github.com/xfjx/TonU
## What's different (basically)?
The original project makes use of microcontrollers (uC) like Arduino nano (which is the [Microchip AVR-platform](https://de.wikipedia.org/wiki/Microchip_AVR) behind the scenes). Music-decoding is done in hardware using [DFPlayer mini](https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299) which offers a uSD-card-slot and an integrated amp as well. Control of this unit is done by a serial-interconnect with a uC using the API provided.
-The core of my implementation is based on the popular [ESP32 by Espressif](https://www.espressif.com/en/products/hardware/esp32/overview). Having WiFi-support out-of-the-box makes it possible to provide further features like an integrated FTP-server (to feed the player with music), smarthome-integration via MQTT and webradio. However, my primary focus was to port the project to a modular base. Said this mp3-decoding is done in software with a dedicated uSD-card-slot and music-output is done via I2S-protocol. I did all my tests on [Adafruit's MAX98357A](https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp/pinouts). Hopefully, not only in theory, other DACs that support I2S can be used as well.
+The core of my implementation is based on the popular [ESP32 by Espressif](https://www.espressif.com/en/products/hardware/esp32/overview). Having WiFi-support out-of-the-box makes it possible to provide further features like an integrated FTP-server (to feed the player with music), smarthome-integration via MQTT, webradio and administration via webgui. However, my primary focus was to port the project to a modular base. Said this mp3-decoding is done in software with a dedicated uSD-card-slot and music-output is done via I2S-protocol. I did all my tests on [Adafruit's MAX98357A](https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp/pinouts). Hopefully, not only in theory, other DACs that support I2S can be used as well.
## Basic concept/handling
The basic idea of Tonuino (and my fork, respectively) is to provide a way, to use the Arduino-platform for a music-control-concept that supports locally stored music-files instead of being fully cloud-dependend. This basically means that RFID-tags are used to direct a music-player. Even for kids this concept is simple: place an RFID-object (card, character) on top of a box and the music starts to play. Place another RFID-object on it and anything else is played. Simple as that.
@@ -31,7 +44,7 @@ The heart of my project is an ESP32 on a [Wemos Lolin32 development-board](https
Most of them can be ordered cheaper directly in China. It's just a give an short impression of the hardware; feel free to order where ever you want to. These are not affiliate-links.
## Getting Started
-I recommend Microsoft's [Visual Studio Code](https://code.visualstudio.com/) alongside with [Platformio Plugin](https://platformio.org/install/ide?install=vscode). Since my project on Github contains [platformio.ini](platformio.ini), libraries used should be fetched automatically. Please note: if you use another ESP32-develboard (Lolin32 e.g.) you might have to change "env:" in platformio.ini to the corresponding value. Documentation can be found [here](https://docs.platformio.org/en/latest/projectconf.html). After that it might be necessary to adjust the names of the GPIO-pins in the upper #define-section of my code.
+I recommend Microsoft's [Visual Studio Code](https://code.visualstudio.com/) or [Atom](https://atom.io/) alongside with [Platformio Plugin](https://platformio.org/install/ide?install=vscode). Since my project on Github contains [platformio.ini](platformio.ini), libraries used should be fetched automatically. Please note: if you use another ESP32-develboard (different to Lolin32) you might have to change "env:" in platformio.ini to the corresponding value. Documentation can be found [here](https://docs.platformio.org/en/latest/projectconf.html). After that it might be necessary to adjust the names of the GPIO-pins in the upper #define-section of my code.
In the upper section of main.cpp you can specify the modules that should be compiled into the code.
Please note: if MQTT is enabled it's still possible to deactivate it via webgui.
@@ -73,14 +86,15 @@ A lot of wiring is necessary to get ESP32-Tonuino working. After my first experi
| GND | Neopixel | GND | |
| 12 | Neopixel | DI | Might be necessary to use a logic-converter 3.3 => 5V |
| 17 | (e.g.) BC337 (via R5) | Base | Don't forget R5! |
-| 33 | Voltage-divider / BAT | | Optional: Voltage-divider to monitor battery-voltage |
+| 33 | Voltage-divider / BAT | | Optional: voltage-divider to monitor battery-voltage |
+| 22 | Headphone jack | | Optional: if pulled to ground, headphone-volume is set |
Optionally, GPIO 17 can be used to drive a NPN-transistor (BC337-40) that pulls a p-channel MOSFET (IRF9520) to GND in order to switch on/off 5V-current. Transistor-circuit is described [here](https://dl6gl.de/schalten-mit-transistoren.html): Just have a look at Abb. 4. Values of the resistors I used: R1: 10k, R2: omitted(!), R4: 10k, R5: 4,7k.
-Also tested this successfully for a 3.3V-setup with IRF530NPBF (N-channel MOSFET) and NDP6020P (P-channel MOSFET). Resistor-values: R1: 100k, R2: omitted(!), R4: 100k, R5: 4,7k. A 3.3V-setup is helpful if you want to battery-power your Tonuino and 5V is not available in battery-mode. For example this is the case when using Wemos Lolin32 with only having LiPo connected.
+I also tested this successfully for a 3.3V-setup with IRF530NPBF (N-channel MOSFET) and NDP6020P (P-channel MOSFET). Resistor-values: R1: 100k, R2: omitted(!), R4: 100k, R5: 4,7k. A 3.3V-setup is helpful if you want to battery-power your Tonuino and 5V is not available in battery-mode. For example this is the case when using Wemos Lolin32 with only having LiPo connected.
Advice: When powering a SD-card-reader solely with 3.3V, make sure to use one WITHOUT a voltage regulator. Or at least one with a pin dedicated for 3.3V (bypassing voltage regulator). This is because if 3.3V go through the voltage regulator a small voltage-drop will be introduced, which may lead to SD-malfunction as the resulting voltage is a bit too low. Vice versa if you want to connect your reader solely to 5V, make sure to have one WITH a voltage regulator :-).
-## Wiring (1 SPI-instance) [EXPERIMENTAL!]
+## Wiring (1 SPI-instance) [EXPERIMENTAL, maybe not working!]
Basically the same as using 2 SPI-instances but...
In this case RFID-reader + SD-reader share SPI's SCK, MISO and MOSI. But make sure to use different CS-pins.
@@ -117,23 +131,25 @@ In this case RFID-reader + SD-reader share SPI's SCK, MISO and MOSI. But make su
| 12 | Neopixel | DI | Might be necessary to use a logic-converter 3.3 => 5V |
| 17 | (e.g.) BC337 (via R5) | Base | Don't forget R5! |
| 33 | Voltage-divider / BAT | | Optional: Voltage-divider to monitor battery-voltage |
+| 22 | Headphone jack | | Optional: if pulled to ground, headphone-volume is set |
## Wiring (custom) / different pinout
When using a develboard with for example SD-card-reader already integrated (Lolin D32 Pro), the pinouts described above my not fit; feel free to change them according your needs. Additionaly some boards may use one or some of the GPIOs I used for their internal purposes and that reason for are maybe not exposed via pin-headers. However, having them exposed doesn't mean they can be used without limits. This is because some GPIOs have to be logical LOW or HIGH at start for example and this is probably not the case when connecting stuff to it. Feel free to adjust the GPIOs proposed by me (but be adviced it could take a while to get it running). If you encounter problems please refer the board's manual first.
-Keep in mind the RFID-lib I used is intended for default-SPI-pins only (SCK, MISO, MOSI). [Here](https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/Hardware-Plaforms/ESP32-A1S-Audiokit) I described a solution for a board with many GPIOs used internally and a very limited number of GPIOs exposed. That's why I had to use different SPI-GPIOs for RFID as well. Please note I used a slightly modified [RFID-lib](https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/Hardware-Plaforms/ESP32-A1S-Audiokit/lib/MFRC522) there.
+[Here](https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/Hardware-Plaforms/ESP32-A1S-Audiokit) I described a solution for a board with many GPIOs used internally and a very limited number of GPIOs exposed. That's why I had to use different SPI-GPIOs for RFID as well. Please note I used a slightly modified [RFID-lib](https://github.com/biologist79/Tonuino-ESP32-I2S/tree/master/Hardware-Plaforms/ESP32-A1S-Audiokit/lib/MFRC522) there.
## Prerequisites / tipps
* choose if optional modules (MQTT, FTP, Neopixel) should be compiled/enabled
* for debugging-purposes serialDebug can be set to ERROR, NOTICE, INFO or DEBUG.
-* if MQTT=yes, set the IP of the MQTT-server accordingly and check the MQTT-topics (states and commands)
+* if MQTT=yes, set the IP or hostname of the MQTT-server accordingly and check the MQTT-topics (states and commands)
* if Neopixel enabled: set NUM_LEDS to the LED-number of your Neopixel-ring and define the Neopixel-type using `#define CHIPSET`
* If you're using Arduino-IDE please make sure to change ESP32's partition-layout to `No OTA (2MB APP/2MB Spiffs)` as otherwise the sketch won't fit into the flash-memory.
-* Please keep in mind that working SD is mandatory. Unless `SD_NOT_MANDATORY_ENABLE` is not set, Tonuino will never fully start up if SD is not working. Only use `SD_NOT_MANDATORY_ENABLE` for debugging as for normal operational mode, not having SD working doesn't make sense.
-* If you want to monitor the battery-voltage, make sure to enable `MEASURE_BATTERY_VOLTAGE`. Use a voltage-divider as voltage of a LiPo is way too high for ESP32 (only 3.3V supported!). For my tests I connected VBat with a serial connection of 130k + 390k resistors (VBat--130k--X--390k--GND). X is the measure-point where to connect the GPIO to. Please note: via GUI upper and lower voltage for visualisation of battery-voltage (Neopixel) is available. Additional GUI-configurable values are interval (in minutes) for checking battery voltage and the cut off-voltage below whose a warning is shown via Neopixel.
-* If you're using a headphone-pcb with a [headphone jack](https://www.conrad.de/de/p/cliff-fcr1295-klinken-steckverbinder-3-5-mm-buchse-einbau-horizontal-polzahl-3-stereo-schwarz-1-st-705830.html) that has a pin to indicate if there's a plug, you can use this signal along with the feature `HEADPHONE_ADJUST_ENABLE` to limit the maximum headphone-voltage automatically. As per default you have to invert this signal and connect it to GPIO22.
-* Enabling `SHUTDOWN_IF_SD_BOOT_FAILS` is really recommended if you run your Tonuino in battery-mode without having a restart-button exposed to the outside of the Tonuino's enclosure. Because otherwise there's no way to restart your Tonuino and the error-state will remain until battery is empty (or you open the enclosure, hehe).
+* Please keep in mind that working SD is mandatory. Unless `SD_NOT_MANDATORY_ENABLE` is not set, Tonuino will never fully start up if SD is not working. Only use `SD_NOT_MANDATORY_ENABLE` for debugging as for normal operational mode, not having SD working doesn't make sense. Even if only webradio-mode is intended, SD would be used to backup RFID-tag-learnings (/backup.txt).
+* If you want to monitor battery's voltage, make sure to enable `MEASURE_BATTERY_VOLTAGE`. Use a voltage-divider as voltage of a LiPo is way too high for ESP32 (only 3.3V supported!). For my tests I connected VBat with a serial connection of 130k + 390k resistors (VBat(+)--130k--X--390k--VBat(-)). X is the measure-point where to connect the GPIO to. If using Lolin D32 or Lolin D32 pro, make sure to adjust both values to 100k each and change GPIO to 35 as this is already integrated and wired fixed.
+Please note: via GUI upper and lower voltage cut-offs for visualisation of battery-voltage (Neopixel) is available. Additional GUI-configurable values are interval (in minutes) for checking battery voltage and the cut off-voltage below whose a warning is shown via Neopixel.
+* If you're using a headphone-pcb with a [headphone jack](https://www.conrad.de/de/p/cliff-fcr1295-klinken-steckverbinder-3-5-mm-buchse-einbau-horizontal-polzahl-3-stereo-schwarz-1-st-705830.html) that has a pin to indicate if there's a plug, you can use this signal along with the feature `HEADPHONE_ADJUST_ENABLE` to limit the maximum headphone-voltage automatically. As per default you have to invert this signal (with a P-channel MOSFET) and connect it to GPIO22.
+* Enabling `SHUTDOWN_IF_SD_BOOT_FAILS` is really recommended if you run your Tonuino in battery-mode without having a restart-button exposed to the outside of Tonuino's enclosure. Because otherwise there's no way to restart your Tonuino and the error-state will remain until battery is empty (or you open the enclosure, hehe).
* Enabling `PLAY_LAST_RFID_AFTER_REBOOT` will tell Tonuino to remember the last RFID-tag played after next reboot. So rebooting Tonuino will end up in autoplay.
-* compile and upload the sketch
+* Compile and upload the sketch.
## Starting Tonuino-ESP32 first time
After plugging in it takes a few seconds until neopixel indicates that Tonuino is ready (by four (slow) rotating LEDs; white if Wifi enabled and blue if disabled). If uC was not able to connect to WiFi, an access-point (named Tonuino) is opened and after connecting this WiFi, a [configuration-Interface](http://192.168.4.1) is available via webbrowser. Enter WiFI-credentials + the hostname (Tonuio's name), save them and restart the uC. Then reconnect to your "regular" WiFi. Now you're ready to go: start learning RFID-tags via GUI. To reach the GUI enter the IP stated in the serial console or use the hostname. For example if you're using a Fritzbox as router and entered tonuino as hostname in the previous configuration-step, in your webbrowser tonuino.fritz.box should work. After doing rfid-learnings, place your RFID-tag next to the RFID-reader and the music (or whatever else you choosed) should start to play. While the playlist is generated/processed, fast-rotating LEDs are shown to indicate that Tonuino is busy. The more tracks a playlist/directory contains the longer this step will take.
@@ -142,10 +158,10 @@ Please note: hostname can be used to call webgui or FTP-server. I tested it with
## WiFi
WiFi is mandatory for webgui, FTP and MQTT. However, WiFi can be temporarily or permanently disabled. There are two ways to do that:
* Use a special modification-card that can be configured via webgui
-* Press previous-key (and keep pressed!) + press next-button in parallel shortly. Now release both.
-This toggles the current WiFi-status which means: if it's currently enabled, it will be disabled instantly and vice versa. Please note: This WiFi-status will remain until you change it again. Having Wifi enabled is indicated in idle-mode (no playlist active) with four white slow rotating LEDs whereas disabled WiFi is represented by those ones colored blue.
+* Press previous-key (and keep it pressed) + press next-button in parallel shortly. Now release both.
+This toggles the current WiFi-status which means: if it's currently enabled, it will be disabled instantly and vice versa. Please note: this WiFi-status will remain until you change it again, which means, that Tonuino will remember this state after the next reboot. Having Wifi enabled is indicated in idle-mode (no playlist active) with four *white* slow rotating LEDs whereas disabled WiFi is represented by those ones coloured *blue*.
## After Tonuino-ESP32 is connected to your WiFi
-After getting Tonuino part of your LAN/WiFi, the 'regular' webgui is available at the IP assigned by your router (or the configured hostname). Using this GUI, you can configure:
+After bringing Tonuino part of your LAN/WiFi, the 'regular' webgui is available at the IP assigned by your router (or the configured hostname). Using this GUI, you can configure:
* WiFi
* Binding between RFID-tag, file/directory/URL and playMode
* Binding between RFID-tag and a modification-type
@@ -190,7 +206,7 @@ It's not just simply playing music; different playmodes are supported:
* webradio (always only one "track")
### Modification RFID-tags
-There are special RFID-tags, that don't start music by themself but can modify things. If applied a second time, it's previous action will be reversed. Please note: all sleep-modes do dimming automatically because it's supposed to be used in the evening when going to bed. Well, at least that's my children's indication :-) So first make sure to start the music then use a modification-card in order to apply your desired modification:
+There are special RFID-tags, that don't start music by themself but can modify things. If applied a second time, it's previous action/modification will be reversed. Please note: all sleep-modes do dimming (Neopixel) automatically because it's supposed to be used in the evening when going to bed. Well, at least that's my children's indication :-) So first make sure to start the music then use a modification-card in order to apply your desired modification:
* lock/unlock all buttons
* sleep after 5/30/60/120 minutes
* sleep after end of current track
@@ -205,20 +221,20 @@ There are special RFID-tags, that don't start music by themself but can modify t
### Neopixel-ring (optional)
Indicates different things. Don't forget configuration of number of LEDs via #define NUM_LEDS
* While booting: 1/2 LEDs rotating orange
-* Unable to mount SD: LEDs flashing red (will remain forever unless SD-card is available)
+* Unable to mount SD: LEDs flashing red (will remain forever unless SD-card is available or `SHUTDOWN_IF_SD_BOOT_FAILS` is active)
* IDLE: four LEDs slow rotating (white if WiFi enabled; blue if WiFi disabled)
-* ERROR: all LEDs flashing red (1x)
-* OK: all LEDs flashing green (1x)
-* BUSY: violet; four fast rotating LEDs
+* ERROR: all LEDs flashing red (1x) if an action was not accepted
+* OK: all LEDs flashing green (1x) if an action was accepted
+* BUSY: violet; four fast rotating LEDs when generating a playlist
* track-progress: rainbow; number of LEDs relative to play-progress
* playlist-progress: blue; appears only shortly in playlist-mode with every new track; number of LEDs relative to progress
-* volume: green => red-gradient; number of LEDs relative from actual to max volume
+* volume: green => red-gradient; number of LEDs relative from current to max volume
* switching off: red; circle that grows until long-press-time is reached
* buttons locked: track-progress-LEDs coloured red
* paused: track-progress-LEDs coloured orange
* rewind: if single-track-loop is activated a LED-rewind is performed when restarting the given track
* (Optional) Undervoltage: flashes three times red if battery-voltage is too low. This voltage-level can be configured via GUI.
-* (Optional) Short press of rotary encoder's button provides battery-voltage visualisation via Neopixel. Upper und lower voltage can be adjusted via GUI.
+* (Optional) Short press of rotary encoder's button provides battery-voltage visualisation via Neopixel. Upper und lower voltage cut-offs can be adjusted via GUI.
Please note: some Neopixels use a reversed addressing which leads to the 'problem', that all effects are shown
counter clockwise. If you want to change that behaviour, just enable `NEOPIXEL_REVERSE_ROTATION`.
@@ -232,11 +248,13 @@ Some buttons have different actions if pressed long or short. Minimum duration f
* pause/play (short/long): pause/play
* rotary encoder (turning): vol +/-
* rotary encoder (button long): switch off (only when on)
-* rotary encoder (button short): switch on (only when off)
-* previous (long; keep pressed) + next (short): toggle WiFi enabled/disabled
+* rotary encoder (button short): switch on (when switched off)
+* rotary encoder (button short): show battery-voltage (when switched on and `MEASURE_BATTERY_VOLTAGE` is active)
+* previous (long; keep pressed) + next (short) + release (both): toggle WiFi enabled/disabled
### Music-play
* music starts to play right after valid RFID-tag was applied
+* if `PLAY_LAST_RFID_AFTER_REBOOT` is active, Tonuino will remember the last RFID applied => music-autoplay
* if a folder should be played that contains many mp3s, the playlist generation can take a few seconds. Please note that a file's name including path cannot exceed 255 characters.
* while playlist is generated Neopixel indicates BUSY-mode
* after last track was played, Neopixel indicates IDLE-mode
diff --git a/src/main.cpp b/src/main.cpp
index f442076..e01a2a7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -112,7 +112,7 @@ char *logBuf = (char*) calloc(serialLoglength, sizeof(char)); // Buffer for all
// GPIOs (Rotary encoder)
#define DREHENCODER_CLK 34 // If you want to reverse encoder's direction, just switch GPIOs of CLK with DT
-#define DREHENCODER_DT 35 // If you want to reverse encoder's direction, just switch GPIOs of CLK with DT
+#define DREHENCODER_DT 35 // Info: Lolin D32 / Lolin D32 pro 35 are using 35 for battery-voltage-monitoring!
#define DREHENCODER_BUTTON 32 // Button is used to switch Tonuino on and off
// GPIOs (Control-buttons)
@@ -188,7 +188,7 @@ float voltageIndicatorHigh = 4.2; // Upper range for Neopixel-
#define REPEAT_PLAYLIST 110 // Changes active playmode to endless-loop (for a playlist)
#define REPEAT_TRACK 111 // Changes active playmode to endless-loop (for a single track)
#define DIMM_LEDS_NIGHTMODE 120 // Changes LED-brightness
-#define TOGGLE_WIFI_STATUS 130 // Toggles WiFi-status; effective after next reboot
+#define TOGGLE_WIFI_STATUS 130 // Toggles WiFi-status
// Repeat-Modes
#define NO_REPEAT 0 // No repeat
@@ -263,7 +263,9 @@ uint8_t buttonDebounceInterval = 50; // Interval in ms to sof
uint16_t intervalToLongPress = 700; // Interval in ms to distinguish between short and long press of previous/next-button
// Where to store the backup-file
-static const char backupFile[] PROGMEM = "/backup.txt"; // File is written every time a (new) RFID-assignment via GUI is done
+#ifndef SD_NOT_MANDATORY_ENABLE
+ static const char backupFile[] PROGMEM = "/backup.txt"; // File is written every time a (new) RFID-assignment via GUI is done
+#endif
// Don't change anything here unless you know what you're doing
// HELPER //
@@ -419,7 +421,9 @@ void buttonHandler();
void deepSleepManager(void);
void doButtonActions(void);
void doRfidCardModifications(const uint32_t mod);
-bool dumpNvsToSd(char *_namespace, char *_destFile);
+#ifndef SD_NOT_MANDATORY_ENABLE
+ bool dumpNvsToSd(char *_namespace, char *_destFile);
+#endif
bool endsWith (const char *str, const char *suf);
bool fileValid(const char *_fileItem);
void freeMultiCharArray(char **arr, const uint32_t cnt);
@@ -497,10 +501,12 @@ void IRAM_ATTR onTimer() {
#ifdef PLAY_LAST_RFID_AFTER_REBOOT
+ // Store last RFID-tag to NVS
void storeLastRfidPlayed(char *_rfid) {
prefsSettings.putString("lastRfid", (String) _rfid);
}
+ // Get last RFID-tag applied from NVS
void recoverLastRfidPlayed(void) {
if (recoverLastRfid) {
recoverLastRfid = false;
@@ -2321,6 +2327,14 @@ void trackQueueDispatcher(const char *_itemToPlay, const uint32_t _lastPlayPos,
// Modification-cards can change some settings (e.g. introducing track-looping or sleep after track/playlist).
// This function handles them.
void doRfidCardModifications(const uint32_t mod) {
+ #ifdef PLAY_LAST_RFID_AFTER_REBOOT
+ if (recoverLastRfid) {
+ recoverLastRfid = false;
+ // We don't want to remember modification-cards
+ return;
+ }
+ #endif
+
switch (mod) {
case LOCK_BUTTONS_MOD: // Locks/unlocks all buttons
lockControls = !lockControls;
@@ -2798,7 +2812,7 @@ bool getWifiEnableStatusFromNVS(void) {
}
-// Writes to NVS whether WiFi should be activated (not effective until next reboot!)
+// Writes to NVS whether WiFi should be activated
bool writeWifiStatusToNVS(bool wifiStatus) {
if (!wifiStatus) {
if (prefsSettings.putUInt("enableWifi", 0)) { // disable
@@ -3039,7 +3053,9 @@ bool processJsonRequest(char *_serialJson) {
if (s.compareTo(rfidString)) {
return false;
}
- dumpNvsToSd("rfidTags", (char *) FPSTR(backupFile)); // Store backup-file every time when a new rfid-tag is programmed
+ #ifndef SD_NOT_MANDATORY_ENABLE
+ dumpNvsToSd("rfidTags", (char *) FPSTR(backupFile)); // Store backup-file every time when a new rfid-tag is programmed
+ #endif
} else if (doc.containsKey("rfidAssign")) {
const char *_rfidIdAssinId = object["rfidAssign"]["rfidIdMusic"];
@@ -3055,7 +3071,9 @@ bool processJsonRequest(char *_serialJson) {
if (s.compareTo(rfidString)) {
return false;
}
- dumpNvsToSd("rfidTags", (char *) FPSTR(backupFile)); // Store backup-file every time when a new rfid-tag is programmed
+ #ifndef SD_NOT_MANDATORY_ENABLE
+ dumpNvsToSd("rfidTags", (char *) FPSTR(backupFile)); // Store backup-file every time when a new rfid-tag is programmed
+ #endif
} else if (doc.containsKey("wifiConfig")) {
const char *_ssid = object["wifiConfig"]["ssid"];
@@ -3241,69 +3259,71 @@ void webserverStart(void) {
// Dumps all RFID-entries from NVS into a file on SD-card
-bool dumpNvsToSd(char *_namespace, char *_destFile) {
- esp_partition_iterator_t pi; // Iterator for find
- const esp_partition_t* nvs; // Pointer to partition struct
- esp_err_t result = ESP_OK;
- const char* partname = "nvs";
- uint8_t pagenr = 0; // Page number in NVS
- uint8_t i; // Index in Entry 0..125
- uint8_t bm; // Bitmap for an entry
- uint32_t offset = 0; // Offset in nvs partition
- uint8_t namespace_ID; // Namespace ID found
-
- pi = esp_partition_find ( ESP_PARTITION_TYPE_DATA, // Get partition iterator for
- ESP_PARTITION_SUBTYPE_ANY, // this partition
- partname ) ;
- if (pi) {
- nvs = esp_partition_get(pi); // Get partition struct
- esp_partition_iterator_release(pi); // Release the iterator
- dbgprint ( "Partition %s found, %d bytes",
- partname,
- nvs->size ) ;
- } else {
- Serial.printf("Partition %s not found!", partname) ;
- return NULL;
- }
- namespace_ID = FindNsID (nvs, _namespace) ; // Find ID of our namespace in NVS
+#ifndef SD_NOT_MANDATORY_ENABLE
+ bool dumpNvsToSd(char *_namespace, char *_destFile) {
+ esp_partition_iterator_t pi; // Iterator for find
+ const esp_partition_t* nvs; // Pointer to partition struct
+ esp_err_t result = ESP_OK;
+ const char* partname = "nvs";
+ uint8_t pagenr = 0; // Page number in NVS
+ uint8_t i; // Index in Entry 0..125
+ uint8_t bm; // Bitmap for an entry
+ uint32_t offset = 0; // Offset in nvs partition
+ uint8_t namespace_ID; // Namespace ID found
+
+ pi = esp_partition_find ( ESP_PARTITION_TYPE_DATA, // Get partition iterator for
+ ESP_PARTITION_SUBTYPE_ANY, // this partition
+ partname ) ;
+ if (pi) {
+ nvs = esp_partition_get(pi); // Get partition struct
+ esp_partition_iterator_release(pi); // Release the iterator
+ dbgprint ( "Partition %s found, %d bytes",
+ partname,
+ nvs->size ) ;
+ } else {
+ Serial.printf("Partition %s not found!", partname) ;
+ return NULL;
+ }
+ namespace_ID = FindNsID (nvs, _namespace) ; // Find ID of our namespace in NVS
- File backupFile = SD.open(_destFile, FILE_WRITE);
- if (!backupFile) {
- return false;
- }
- while (offset < nvs->size) {
- result = esp_partition_read (nvs, offset, // Read 1 page in nvs partition
- &buf,
- sizeof(nvs_page));
- if (result != ESP_OK) {
- Serial.println(F("Error reading NVS!"));
+ File backupFile = SD.open(_destFile, FILE_WRITE);
+ if (!backupFile) {
return false;
}
+ while (offset < nvs->size) {
+ result = esp_partition_read (nvs, offset, // Read 1 page in nvs partition
+ &buf,
+ sizeof(nvs_page));
+ if (result != ESP_OK) {
+ Serial.println(F("Error reading NVS!"));
+ return false;
+ }
- i = 0;
+ i = 0;
- while (i < 126) {
- bm = (buf.Bitmap[i/4] >> ((i % 4) * 2 )) & 0x03; // Get bitmap for this entry
- if (bm == 2) {
- if ((namespace_ID == 0xFF) || // Show all if ID = 0xFF
- (buf.Entry[i].Ns == namespace_ID)) { // otherwise just my namespace
- if (isNumber(buf.Entry[i].Key)) {
- String s = prefsRfid.getString((const char *)buf.Entry[i].Key);
- backupFile.printf("%s%s%s%s\n", stringOuterDelimiter, buf.Entry[i].Key, stringOuterDelimiter, s.c_str());
+ while (i < 126) {
+ bm = (buf.Bitmap[i/4] >> ((i % 4) * 2 )) & 0x03; // Get bitmap for this entry
+ if (bm == 2) {
+ if ((namespace_ID == 0xFF) || // Show all if ID = 0xFF
+ (buf.Entry[i].Ns == namespace_ID)) { // otherwise just my namespace
+ if (isNumber(buf.Entry[i].Key)) {
+ String s = prefsRfid.getString((const char *)buf.Entry[i].Key);
+ backupFile.printf("%s%s%s%s\n", stringOuterDelimiter, buf.Entry[i].Key, stringOuterDelimiter, s.c_str());
+ }
}
+ i += buf.Entry[i].Span; // Next entry
+ } else {
+ i++;
}
- i += buf.Entry[i].Span; // Next entry
- } else {
- i++;
}
+ offset += sizeof(nvs_page); // Prepare to read next page in nvs
+ pagenr++;
}
- offset += sizeof(nvs_page); // Prepare to read next page in nvs
- pagenr++;
- }
- backupFile.close();
- return true;
-}
+ backupFile.close();
+ return true;
+ }
+#endif
// Handles uploaded backup-file and writes valid entries into NVS