Added HTTP-API support, Standalone AP Support and Built-in Melodies
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "../Communication/CommunicationRouter/CommunicationRouter.hpp"
|
||||
#include "../BellEngine/BellEngine.hpp"
|
||||
#include "../Telemetry/Telemetry.hpp"
|
||||
#include "../BuiltInMelodies/BuiltInMelodies.hpp"
|
||||
|
||||
// Note: Removed global melody_steps dependency for cleaner architecture
|
||||
|
||||
@@ -245,19 +246,42 @@ void Player::setMelodyAttributes(JsonVariant doc) {
|
||||
}
|
||||
|
||||
void Player::loadMelodyInRAM() {
|
||||
String filePath = "/melodies/" + String(uid.c_str());
|
||||
String uidStr = String(uid.c_str());
|
||||
|
||||
// 🎵 PRIORITY 1: Check if this is a built-in melody
|
||||
if (BuiltInMelodies::isBuiltInMelody(uidStr)) {
|
||||
LOG_INFO("Loading built-in melody: %s", uidStr.c_str());
|
||||
|
||||
if (BuiltInMelodies::loadBuiltInMelody(uidStr, _melodySteps)) {
|
||||
LOG_INFO("✅ Built-in melody loaded successfully: %d steps", _melodySteps.size());
|
||||
|
||||
// Set default speed from built-in melody info
|
||||
const BuiltInMelodies::MelodyInfo* melodyInfo = BuiltInMelodies::findMelodyByUID(uidStr);
|
||||
if (melodyInfo && speed == 0) {
|
||||
speed = melodyInfo->defaultSpeed;
|
||||
LOG_DEBUG("Using default speed: %d ms/beat", speed);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
LOG_ERROR("Failed to load built-in melody: %s", uidStr.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 🎵 PRIORITY 2: Load from SD card
|
||||
String filePath = "/melodies/" + uidStr;
|
||||
|
||||
File bin_file = SD.open(filePath.c_str(), FILE_READ);
|
||||
if (!bin_file) {
|
||||
LOG_ERROR("Failed to open file: %s", filePath.c_str());
|
||||
LOG_ERROR("Check Servers for the File...");
|
||||
|
||||
|
||||
// Try to download the file using FileManager
|
||||
if (_fileManager) {
|
||||
StaticJsonDocument<128> doc;
|
||||
doc["download_url"] = url;
|
||||
doc["melodys_uid"] = uid;
|
||||
|
||||
|
||||
if (!_fileManager->addMelody(doc)) {
|
||||
LOG_ERROR("Failed to Download File. Check Internet Connection");
|
||||
return;
|
||||
@@ -286,7 +310,7 @@ void Player::loadMelodyInRAM() {
|
||||
_melodySteps[i] = (high << 8) | low;
|
||||
}
|
||||
|
||||
LOG_INFO("Melody loaded successfully: %d steps", _melodySteps.size());
|
||||
LOG_INFO("Melody loaded successfully from SD: %d steps", _melodySteps.size());
|
||||
bin_file.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user