Redid layout with JLC library symbols

This commit is contained in:
zyphlar
2026-07-04 03:28:12 -07:00
parent 600cf052a8
commit 03ff592b3c
18 changed files with 156292 additions and 2404 deletions
+26 -18
View File
@@ -81,8 +81,8 @@ using namespace Adafruit_LittleFS_Namespace;
// SPI MOSI/MISO/SCK use default SPI pins
// Buttons (directly to GPIO, active LOW with internal pull-up)
#define PIN_BTN1 3
#define PIN_BTN2 4
#define PIN_BTN1 0
#define PIN_BTN2 1
#define PIN_BTN3 5
#define PIN_BTN4 3
/*
@@ -874,6 +874,15 @@ void waitButtonRelease(uint8_t btn) {
// ============================================================
void enterDeepSleep() {
// Don't sleep if any button is currently LOW — would wake instantly.
// Also catches floating pins that the internal pull-up isn't winning against.
for (uint8_t i = 0; i < NUM_BUTTONS; i++) {
if (analogRead(BTN_PINS[i]) < 128) {
g_lastActivity = millis(); // postpone
return;
}
}
Serial.println("Entering deep sleep...");
audioStop();
motorStop();
@@ -885,14 +894,11 @@ void enterDeepSleep() {
// Stop BLE advertising to save power
Bluefruit.Advertising.stop();
// Configure buttons as wake sources
// On nRF52840, any GPIO can wake from System OFF
// We use System ON sleep (RTOS idle) for quick wake
// For deepest sleep, use sd_power_system_off()
// Use pin sense for wake
// Configure buttons as wake sources.
// nrf_gpio_cfg_sense_input takes nRF GPIO numbers, not Arduino pin numbers —
// use g_ADigitalPinMap[] to convert.
for (uint8_t i = 0; i < NUM_BUTTONS; i++) {
nrf_gpio_cfg_sense_input(BTN_PINS[i],
nrf_gpio_cfg_sense_input(g_ADigitalPinMap[BTN_PINS[i]],
NRF_GPIO_PIN_PULLUP,
NRF_GPIO_PIN_SENSE_LOW);
}
@@ -1205,6 +1211,7 @@ static void serUploadTick() {
void loop() {
// ---- Audio sample output (8kHz, loop-driven) ----
if (g_playing) {
g_lastActivity = millis(); // stay awake while audio is playing
uint32_t now = micros();
if ((int32_t)(now - g_nextSampleUs) >= 0) {
g_nextSampleUs += 125; // 1/8000s = 125µs
@@ -1259,6 +1266,8 @@ void loop() {
switch (btn) {
case 1: // Play / Pause
case 2:
case 3:
if (g_playing) {
audioStop();
} else if (g_numTracks > 0) {
@@ -1266,40 +1275,40 @@ void loop() {
}
break;
case 2: // Next track
case 4: // Next track
if (g_numTracks > 0) {
g_currentTrack = (g_currentTrack + 1) % g_numTracks;
if (g_playing) { audioStop(); audioStart(g_currentTrack); }
}
break;
case 3: // Previous track
case 5: // Previous track
if (g_numTracks > 0) {
g_currentTrack = (g_currentTrack == 0) ? g_numTracks - 1 : g_currentTrack - 1;
if (g_playing) { audioStop(); audioStart(g_currentTrack); }
}
break;
case 4: // Motor toggle
case 6: // Motor toggle
if (g_motorOn) motorStop(); else motorStart(g_motorSpeed);
break;
case 5: // Motor faster
case 7: // Motor faster
if (g_motorSpeed < 240) g_motorSpeed += 20;
if (g_motorOn) analogWrite(PIN_MOTOR_PWM, g_motorSpeed);
break;
case 6: // Motor slower
case 8: // Motor slower
if (g_motorSpeed > 60) g_motorSpeed -= 20;
if (g_motorOn) analogWrite(PIN_MOTOR_PWM, g_motorSpeed);
break;
case 7: // Play all (music + motor)
case 9: // Play all (music + motor)
motorStart(g_motorSpeed);
if (!g_playing && g_numTracks > 0) audioStart(0);
break;
case 8: // Stop all
case 10: // Stop all
audioStop();
motorStop();
break;
@@ -1308,12 +1317,11 @@ void loop() {
waitButtonRelease(btn);
}
// ---- Auto shutoff ----
// ---- Auto shutoff / idle sleep ----
if (millis() - g_lastActivity > AUTO_OFF_MS) {
enterDeepSleep();
}
// ---- Idle sleep (if nothing happening, no USB) ----
if (!g_playing && !g_motorOn && !g_usbConnected && !g_bleUploading) {
if (millis() - g_lastActivity > IDLE_SLEEP_MS) {
enterDeepSleep();