Fixed Indexing on Bell Output Assignments
This commit is contained in:
@@ -224,7 +224,14 @@ void BellEngine::playbackLoop() {
|
||||
// Activate note with MAXIMUM PRECISION
|
||||
activateNote(note);
|
||||
|
||||
// Precise timing delay
|
||||
// Precise timing delay - validate speed to prevent division by zero
|
||||
if (_player.speed == 0) {
|
||||
LOG_ERROR("❌ Invalid speed=0 detected, stopping playback");
|
||||
_player.hardStop = true;
|
||||
_engineRunning.store(false);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t tempoMicros = _player.speed * 1000; // Convert ms to microseconds
|
||||
preciseDelay(tempoMicros);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ void ConfigManager::createDefaultBellConfig() {
|
||||
// Initialize default durations (90ms for all bells)
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
bellConfig.durations[i] = 90;
|
||||
bellConfig.outputs[i] = i + 1; // 1-indexed mapping by default
|
||||
bellConfig.outputs[i] = i; // 0-indexed mapping
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,26 +75,20 @@ uint8_t OutputManager::getPhysicalOutput(uint8_t virtualOutput) const {
|
||||
return virtualOutput;
|
||||
}
|
||||
|
||||
// Get 1-indexed bell output from config
|
||||
uint16_t bellOutput1Indexed = _configManager->getBellOutput(virtualOutput);
|
||||
// Get 0-indexed bell output from config
|
||||
uint16_t bellOutput = _configManager->getBellOutput(virtualOutput);
|
||||
|
||||
// Handle unconfigured bells (255 = disabled)
|
||||
if (bellOutput1Indexed == 255) {
|
||||
if (bellOutput == 255) {
|
||||
LOG_WARNING("⚠️ Bell %d not configured (255)", virtualOutput);
|
||||
return 255; // Return invalid to prevent firing
|
||||
}
|
||||
|
||||
// Handle invalid 0 configuration
|
||||
if (bellOutput1Indexed == 0) {
|
||||
LOG_ERROR("❌ Bell %d configured as 0 (invalid - should be 1-indexed)", virtualOutput);
|
||||
return 255;
|
||||
}
|
||||
// Physical output is already 0-indexed from config
|
||||
uint8_t physicalOutput = (uint8_t)bellOutput;
|
||||
|
||||
// Convert 1-indexed config to 0-indexed physical output
|
||||
uint8_t physicalOutput = (uint8_t)(bellOutput1Indexed - 1);
|
||||
|
||||
LOG_DEBUG("🔗 Bell %d → 1-indexed config %d → 0-indexed output %d",
|
||||
virtualOutput, bellOutput1Indexed, physicalOutput);
|
||||
LOG_DEBUG("🔗 Bell %d → 0-indexed output %d",
|
||||
virtualOutput, physicalOutput);
|
||||
|
||||
return physicalOutput;
|
||||
}
|
||||
@@ -140,25 +134,18 @@ void OutputManager::fireClockOutput(uint8_t virtualOutput, uint16_t durationMs)
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert 1-indexed config value to 0-indexed physical output
|
||||
if (physicalOutput == 0) {
|
||||
LOG_ERROR("❌ Clock output configured as 0 (invalid - should be 1-indexed)");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t zeroIndexedOutput = physicalOutput - 1; // Convert 1-indexed to 0-indexed
|
||||
|
||||
if (!isValidPhysicalOutput(zeroIndexedOutput)) {
|
||||
LOG_ERROR("❌ Invalid physical output for clock: %d (1-indexed config: %d, max outputs: %d)",
|
||||
zeroIndexedOutput, physicalOutput, getMaxOutputs());
|
||||
// Physical output is already 0-indexed from config
|
||||
if (!isValidPhysicalOutput(physicalOutput)) {
|
||||
LOG_ERROR("❌ Invalid physical output for clock: %d (max outputs: %d)",
|
||||
physicalOutput, getMaxOutputs());
|
||||
return;
|
||||
}
|
||||
|
||||
// Fire the physical output directly
|
||||
fireOutputForDuration(zeroIndexedOutput, durationMs);
|
||||
fireOutputForDuration(physicalOutput, durationMs);
|
||||
|
||||
LOG_DEBUG("🕐 FIRE Clock Virtual %d (C%d) → 1-indexed config %d → 0-indexed output %d for %dms",
|
||||
virtualOutput, virtualOutput + 1, physicalOutput, zeroIndexedOutput, durationMs);
|
||||
LOG_DEBUG("🕐 FIRE Clock Virtual %d (C%d) → 0-indexed output %d for %dms",
|
||||
virtualOutput, virtualOutput + 1, physicalOutput, durationMs);
|
||||
}
|
||||
|
||||
// ==================== PCF8574/PCF8575 MULTI-CHIP IMPLEMENTATION ====================
|
||||
|
||||
@@ -10,7 +10,7 @@ Player::Player(CommunicationRouter* comm, FileManager* fm)
|
||||
, name("melody1")
|
||||
, uid("x")
|
||||
, url("-")
|
||||
, noteAssignments{1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0}
|
||||
, noteAssignments{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
|
||||
, speed(500)
|
||||
, segment_duration(15000)
|
||||
, pause_duration(0)
|
||||
@@ -37,7 +37,7 @@ Player::Player()
|
||||
, name("melody1")
|
||||
, uid("x")
|
||||
, url("-")
|
||||
, noteAssignments{1,2,3,4,5,6,0,0,0,0,0,0,0,0,0,0}
|
||||
, noteAssignments{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
|
||||
, speed(500)
|
||||
, segment_duration(15000)
|
||||
, pause_duration(0)
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
* 👨💻 AUTHOR: BellSystems bonamin
|
||||
*/
|
||||
|
||||
#define FW_VERSION "0.1"
|
||||
#define FW_VERSION "1.0"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user