tuned amp, added transistor for button
This commit is contained in:
@@ -52,7 +52,15 @@
|
||||
// ============================================================
|
||||
// When defined, a wake from deep sleep (button press) plays a random track
|
||||
// immediately instead of waiting for user input.
|
||||
//#define WAKE_PLAY_RANDOM
|
||||
#define WAKE_PLAY_RANDOM
|
||||
|
||||
// ============================================================
|
||||
// Button playback mode:
|
||||
// Undefined — short press toggles play/stop (press again to stop).
|
||||
// Defined — every press always starts a track; never stops mid-play.
|
||||
// If WAKE_PLAY_RANDOM is also defined, picks a random track;
|
||||
// otherwise advances to the next track (wrapping around).
|
||||
#define BTN_ALWAYS_START
|
||||
|
||||
// ============================================================
|
||||
// POC MODE: stream audio from internal LittleFS instead of SPI flash.
|
||||
@@ -89,10 +97,10 @@ using namespace Adafruit_LittleFS_Namespace;
|
||||
|
||||
// Buttons (directly to GPIO, active LOW with internal pull-up)
|
||||
#define PIN_BTN1 1
|
||||
/*
|
||||
#define PIN_BTN2 1
|
||||
#define PIN_BTN3 1
|
||||
#define PIN_BTN4 1
|
||||
/*
|
||||
#define PIN_BTN5 4
|
||||
#define PIN_BTN6 5
|
||||
#define PIN_BTN7 3
|
||||
@@ -104,10 +112,10 @@ using namespace Adafruit_LittleFS_Namespace;
|
||||
// LED_G is 12/13
|
||||
|
||||
const uint8_t BTN_PINS[] = {
|
||||
PIN_BTN1, PIN_BTN2, PIN_BTN3, PIN_BTN4,
|
||||
PIN_BTN1 /*, PIN_BTN2, PIN_BTN3, PIN_BTN4,*/
|
||||
/*PIN_BTN5, PIN_BTN6, PIN_BTN7, PIN_BTN8*/
|
||||
};
|
||||
#define NUM_BUTTONS 4
|
||||
#define NUM_BUTTONS 1
|
||||
|
||||
// ============================================================
|
||||
// FLASH CONSTANTS
|
||||
@@ -253,8 +261,9 @@ unsigned long g_lastActivity = 0;
|
||||
volatile bool g_usbConnected = false;
|
||||
|
||||
// Wake-from-sleep detection. Read before SoftDevice starts (setupBLE), stored here.
|
||||
static bool g_wakeFromSleep = false;
|
||||
static uint8_t g_wakeTrack = 0;
|
||||
static bool g_wakeFromSleep = false;
|
||||
static uint8_t g_wakeTrack = 0;
|
||||
static uint32_t g_debugResetreas = 0; // printed 10 s after boot for post-sleep diagnosis
|
||||
|
||||
#ifdef POC_INTERNAL_FLASH
|
||||
static void pocFilename(uint8_t n, char *buf) { // buf must be >=16 bytes
|
||||
@@ -1456,13 +1465,17 @@ void setup() {
|
||||
// Read RESETREAS and collect a random byte BEFORE starting the SoftDevice.
|
||||
// Once Bluefruit.begin() enables S140, the SoftDevice owns NRF_RNG and
|
||||
// NRF_POWER — direct register access after that point causes a hard fault.
|
||||
g_wakeFromSleep = (NRF_POWER->RESETREAS & POWER_RESETREAS_OFF_Msk) != 0;
|
||||
uint32_t resetreas = NRF_POWER->RESETREAS;
|
||||
NRF_POWER->RESETREAS = 0xFFFFFFFFUL; // write-1-to-clear
|
||||
if (g_wakeFromSleep) Serial.println("Woke from deep sleep.");
|
||||
g_wakeFromSleep = (resetreas & POWER_RESETREAS_OFF_Msk) != 0;
|
||||
g_debugResetreas = resetreas; // printed 10 s after boot once serial reconnects
|
||||
// Seed Arduino random() from hardware RNG now, before Bluefruit.begin().
|
||||
// After the SoftDevice starts it owns NRF_RNG — hwRandom() must not be
|
||||
// called again after that point. Use random() everywhere in loop().
|
||||
randomSeed(hwRandom());
|
||||
#ifdef WAKE_PLAY_RANDOM
|
||||
if (g_wakeFromSleep && g_numTracks > 0) {
|
||||
// hwRandom() is safe here — SoftDevice not yet started.
|
||||
g_wakeTrack = hwRandom() % g_numTracks;
|
||||
g_wakeTrack = (uint8_t)random(g_numTracks);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1752,6 +1765,16 @@ static void serUploadTick() {
|
||||
void loop() {
|
||||
if (g_playing || g_bleUploading) g_lastActivity = millis();
|
||||
|
||||
// Print RESETREAS once, 10 s after boot, so serial has time to reconnect
|
||||
// after a wake-from-sleep reset.
|
||||
static bool resetreasLogged = false;
|
||||
if (!resetreasLogged && millis() > 10000) {
|
||||
resetreasLogged = true;
|
||||
Serial.print("RESETREAS: 0x"); Serial.println(g_debugResetreas, HEX);
|
||||
Serial.print("g_wakeFromSleep: "); Serial.println(g_wakeFromSleep);
|
||||
Serial.print("g_numTracks: "); Serial.println(g_numTracks);
|
||||
}
|
||||
|
||||
// ---- Serial upload ----
|
||||
serUploadTick();
|
||||
|
||||
@@ -1799,14 +1822,27 @@ void loop() {
|
||||
if (g_trackDoneMs != 0 && millis() >= g_trackDoneMs) {
|
||||
g_trackDoneMs = 0; audioStop();
|
||||
}
|
||||
} else {
|
||||
delay(1); // yield to RTOS idle task so the watchdog gets fed
|
||||
}
|
||||
}
|
||||
if (longPress) {
|
||||
startBLEAdvertising();
|
||||
waitButtonRelease(1);
|
||||
} else {
|
||||
#ifdef BTN_ALWAYS_START
|
||||
if (g_numTracks > 0) {
|
||||
if (g_playing) audioStop();
|
||||
#ifdef WAKE_PLAY_RANDOM
|
||||
audioStart((uint8_t)random(g_numTracks));
|
||||
#else
|
||||
audioStart((g_currentTrack + 1) % g_numTracks);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
if (g_playing) { audioStop(); }
|
||||
else if (g_numTracks > 0) { audioStart(g_currentTrack); }
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1814,11 +1850,22 @@ void loop() {
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
#ifdef BTN_ALWAYS_START
|
||||
if (g_numTracks > 0) {
|
||||
if (g_playing) audioStop();
|
||||
#ifdef WAKE_PLAY_RANDOM
|
||||
audioStart((uint8_t)random(g_numTracks));
|
||||
#else
|
||||
audioStart((g_currentTrack + 1) % g_numTracks);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
if (g_playing) {
|
||||
audioStop();
|
||||
} else if (g_numTracks > 0) {
|
||||
audioStart(g_currentTrack);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
/*
|
||||
case 4: // Next track
|
||||
|
||||
Reference in New Issue
Block a user