Fixed Indexing on Bell Output Assignments

This commit is contained in:
2025-10-18 18:43:51 +03:00
parent cc0bec97b5
commit 470d7bfacc
5 changed files with 27 additions and 33 deletions

View File

@@ -224,7 +224,14 @@ void BellEngine::playbackLoop() {
// Activate note with MAXIMUM PRECISION // Activate note with MAXIMUM PRECISION
activateNote(note); 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 uint32_t tempoMicros = _player.speed * 1000; // Convert ms to microseconds
preciseDelay(tempoMicros); preciseDelay(tempoMicros);
} }

View File

@@ -44,7 +44,7 @@ void ConfigManager::createDefaultBellConfig() {
// Initialize default durations (90ms for all bells) // Initialize default durations (90ms for all bells)
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
bellConfig.durations[i] = 90; bellConfig.durations[i] = 90;
bellConfig.outputs[i] = i + 1; // 1-indexed mapping by default bellConfig.outputs[i] = i; // 0-indexed mapping
} }
} }

View File

@@ -75,26 +75,20 @@ uint8_t OutputManager::getPhysicalOutput(uint8_t virtualOutput) const {
return virtualOutput; return virtualOutput;
} }
// Get 1-indexed bell output from config // Get 0-indexed bell output from config
uint16_t bellOutput1Indexed = _configManager->getBellOutput(virtualOutput); uint16_t bellOutput = _configManager->getBellOutput(virtualOutput);
// Handle unconfigured bells (255 = disabled) // Handle unconfigured bells (255 = disabled)
if (bellOutput1Indexed == 255) { if (bellOutput == 255) {
LOG_WARNING("⚠️ Bell %d not configured (255)", virtualOutput); LOG_WARNING("⚠️ Bell %d not configured (255)", virtualOutput);
return 255; // Return invalid to prevent firing return 255; // Return invalid to prevent firing
} }
// Handle invalid 0 configuration // Physical output is already 0-indexed from config
if (bellOutput1Indexed == 0) { uint8_t physicalOutput = (uint8_t)bellOutput;
LOG_ERROR("❌ Bell %d configured as 0 (invalid - should be 1-indexed)", virtualOutput);
return 255;
}
// Convert 1-indexed config to 0-indexed physical output LOG_DEBUG("🔗 Bell %d → 0-indexed output %d",
uint8_t physicalOutput = (uint8_t)(bellOutput1Indexed - 1); virtualOutput, physicalOutput);
LOG_DEBUG("🔗 Bell %d → 1-indexed config %d → 0-indexed output %d",
virtualOutput, bellOutput1Indexed, physicalOutput);
return physicalOutput; return physicalOutput;
} }
@@ -140,25 +134,18 @@ void OutputManager::fireClockOutput(uint8_t virtualOutput, uint16_t durationMs)
return; return;
} }
// Convert 1-indexed config value to 0-indexed physical output // Physical output is already 0-indexed from config
if (physicalOutput == 0) { if (!isValidPhysicalOutput(physicalOutput)) {
LOG_ERROR("Clock output configured as 0 (invalid - should be 1-indexed)"); LOG_ERROR("Invalid physical output for clock: %d (max outputs: %d)",
return; physicalOutput, getMaxOutputs());
}
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());
return; return;
} }
// Fire the physical output directly // 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", LOG_DEBUG("🕐 FIRE Clock Virtual %d (C%d) → 0-indexed output %d for %dms",
virtualOutput, virtualOutput + 1, physicalOutput, zeroIndexedOutput, durationMs); virtualOutput, virtualOutput + 1, physicalOutput, durationMs);
} }
// ==================== PCF8574/PCF8575 MULTI-CHIP IMPLEMENTATION ==================== // ==================== PCF8574/PCF8575 MULTI-CHIP IMPLEMENTATION ====================

View File

@@ -10,7 +10,7 @@ Player::Player(CommunicationRouter* comm, FileManager* fm)
, name("melody1") , name("melody1")
, uid("x") , uid("x")
, url("-") , 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) , speed(500)
, segment_duration(15000) , segment_duration(15000)
, pause_duration(0) , pause_duration(0)
@@ -37,7 +37,7 @@ Player::Player()
, name("melody1") , name("melody1")
, uid("x") , uid("x")
, url("-") , 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) , speed(500)
, segment_duration(15000) , segment_duration(15000)
, pause_duration(0) , pause_duration(0)

View File

@@ -62,7 +62,7 @@
* 👨‍💻 AUTHOR: BellSystems bonamin * 👨‍💻 AUTHOR: BellSystems bonamin
*/ */
#define FW_VERSION "0.1" #define FW_VERSION "1.0"
/* /*