From a7c119311c2d8a702c4bbd94df753a4b3013f3df Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Fri, 22 Aug 2025 14:23:53 -0400 Subject: [PATCH] misc: fixed matrix shift effect layer bug --- src/fx/matrixfx/MatrixShiftEffectBase.h | 69 ++++++++------------ src/ledcontrol/loader/TableConfigSetting.cpp | 2 +- src/ledcontrol/setup/Configurator.cpp | 25 +++---- src/test.cpp | 48 ++++++++------ 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/fx/matrixfx/MatrixShiftEffectBase.h b/src/fx/matrixfx/MatrixShiftEffectBase.h index 9ca705e..ff205bd 100644 --- a/src/fx/matrixfx/MatrixShiftEffectBase.h +++ b/src/fx/matrixfx/MatrixShiftEffectBase.h @@ -103,41 +103,40 @@ template void MatrixShiftEffectBase= 0 && stepIndex < (int)m_step2Element.size()) - { - toElementNr = m_step2Element[stepIndex]; + toElementNr = m_step2Element[(m_currentStep - kv.first)]; - if ((int)fromElementNr == (int)toElementNr) - { - value[(int)fromElementNr] += (fromElementNr - toElementNr) * (float)lastValue; - } - else - { - if (fromElementNr != (float)(int)fromElementNr) - { - value[(int)fromElementNr] += (fromElementNr - (float)(int)fromElementNr) * (float)lastValue; - } - - int toNr = (int)(toElementNr + 0.999f); - for (int i = (int)fromElementNr - 1; i >= toNr; i--) - { - if (i >= 0 && i < (int)value.size()) - value[i] = (float)lastValue; - } - if (toElementNr != (float)(int)toElementNr) - { - value[(int)toElementNr] += ((float)(int)toElementNr + 1.0f - toElementNr) * (float)lastValue; - } - } - fromElementNr = toElementNr; - lastValue = kv.second; + if ((int)fromElementNr == (int)toElementNr) + value[(int)fromElementNr] += (fromElementNr - toElementNr) * (float)lastValue; + else + { + if (fromElementNr != (float)(int)fromElementNr) + value[(int)fromElementNr] += (fromElementNr - (float)(int)fromElementNr) * (float)lastValue; + + toNr = (int)(toElementNr + 0.999f); + for (int i = (int)fromElementNr - 1; i >= toNr; i--) + value[i] = (float)lastValue; + if (toElementNr != (float)(int)toElementNr) + value[(int)toElementNr] += ((float)(int)toElementNr + 1.0f - toElementNr) * (float)lastValue; } + fromElementNr = toElementNr; + lastValue = kv.second; + } + toElementNr = 0; + if (fromElementNr != toElementNr) + { + if (fromElementNr != (float)(int)fromElementNr && (int)fromElementNr < numberOfElements - 1) + value[(int)fromElementNr] += (fromElementNr - (float)(int)fromElementNr) * (float)lastValue; + + toNr = MathExtensions::Limit((int)(toElementNr + 0.999f), 0, 2147483647); + for (int i = (int)fromElementNr - 1; i >= toNr; i--) + value[i] = (float)lastValue; + if (toElementNr != (float)(int)toElementNr) + value[(int)toElementNr] += ((float)(int)toElementNr + 1.0f - toElementNr) * (float)lastValue; } - // Data output - matches C# lines 157-213 switch (m_shiftDirection) { case MatrixShiftDirectionEnum::Right: @@ -145,9 +144,7 @@ template void MatrixShiftEffectBase 0 && this->GetFadeMode() == FadeModeEnum::OnOff) - { v = 255; - } MatrixElementType d = GetEffectValue(v); for (int y = this->m_areaTop; y <= this->m_areaBottom; y++) @@ -162,9 +159,7 @@ template void MatrixShiftEffectBase 0 && this->GetFadeMode() == FadeModeEnum::OnOff) - { v = 255; - } MatrixElementType d = GetEffectValue(v); for (int x = this->m_areaLeft; x <= this->m_areaRight; x++) @@ -179,9 +174,7 @@ template void MatrixShiftEffectBase 0 && this->GetFadeMode() == FadeModeEnum::OnOff) - { v = 255; - } MatrixElementType d = GetEffectValue(v); for (int x = this->m_areaLeft; x <= this->m_areaRight; x++) @@ -197,9 +190,7 @@ template void MatrixShiftEffectBase 0 && this->GetFadeMode() == FadeModeEnum::OnOff) - { v = 255; - } MatrixElementType d = GetEffectValue(v); for (int y = this->m_areaTop; y <= this->m_areaBottom; y++) @@ -221,9 +212,7 @@ template void MatrixShiftEffectBasem_table->GetPinball()->GetAlarms()->UnregisterIntervalAlarm(this); @@ -242,9 +231,7 @@ template void MatrixShiftEffectBaseGetNumber()), std::to_string(settingNumber)); flickerEffect->SetName(effectName); flickerEffect->SetToyName(toy->GetName()); - if (tcs->HasLayer()) - flickerEffect->SetLayerNr(tcs->GetLayer()); + int layer = tcs->HasLayer() ? tcs->GetLayer() : settingNumber; + flickerEffect->SetLayerNr(layer); ColorConfig* colorConfig = tcs->GetColorConfig(); flickerEffect->SetActiveColor(RGBAColor(colorConfig->GetRed(), colorConfig->GetGreen(), colorConfig->GetBlue(), colorConfig->GetAlpha())); @@ -364,8 +364,8 @@ void Configurator::SetupTable( "Ledwiz {0:00} Column {1:00} Setting {2:00} RGBAMatrixPlasmaEffect", std::to_string(ledWizNr), std::to_string(tcc->GetNumber()), std::to_string(settingNumber)); plasmaEffect->SetName(effectName); plasmaEffect->SetToyName(toy->GetName()); - if (tcs->HasLayer()) - plasmaEffect->SetLayerNr(tcs->GetLayer()); + int layer = tcs->HasLayer() ? tcs->GetLayer() : settingNumber; + plasmaEffect->SetLayerNr(layer); ColorConfig* colorConfig = tcs->GetColorConfig(); RGBAColor activeColor1; @@ -416,8 +416,8 @@ void Configurator::SetupTable( std::to_string(tcc->GetNumber()), std::to_string(settingNumber)); shiftEffect->SetName(effectName); shiftEffect->SetToyName(toy->GetName()); - if (tcs->HasLayer()) - shiftEffect->SetLayerNr(tcs->GetLayer()); + int layer = tcs->HasLayer() ? tcs->GetLayer() : settingNumber; + shiftEffect->SetLayerNr(layer); shiftEffect->SetShiftDirection(tcs->GetAreaDirection()); shiftEffect->SetShiftAcceleration(tcs->GetAreaAcceleration()); shiftEffect->SetActiveColor(activeColor); @@ -443,8 +443,8 @@ void Configurator::SetupTable( std::to_string(tcc->GetNumber()), std::to_string(settingNumber)); matrixEffect->SetName(effectName); matrixEffect->SetToyName(toy->GetName()); - if (tcs->HasLayer()) - matrixEffect->SetLayerNr(tcs->GetLayer()); + int layer = tcs->HasLayer() ? tcs->GetLayer() : settingNumber; + matrixEffect->SetLayerNr(layer); matrixEffect->SetActiveColor(activeColor); matrixEffect->SetInactiveColor(inactiveColor); @@ -495,7 +495,8 @@ void Configurator::SetupTable( std::to_string(tcc->GetNumber()), std::to_string(settingNumber)); shiftEffect->SetName(effectName); shiftEffect->SetToyName(toy->GetName()); - shiftEffect->SetLayerNr(tcs->GetLayer()); + int layer = tcs->HasLayer() ? tcs->GetLayer() : settingNumber; + shiftEffect->SetLayerNr(layer); shiftEffect->SetShiftDirection(tcs->GetAreaDirection()); shiftEffect->SetShiftAcceleration(tcs->GetAreaAcceleration()); @@ -511,7 +512,8 @@ void Configurator::SetupTable( std::to_string(tcc->GetNumber()), std::to_string(settingNumber)); flickerEffect->SetName(effectName); flickerEffect->SetToyName(toy->GetName()); - flickerEffect->SetLayerNr(tcs->GetLayer()); + int layer = tcs->HasLayer() ? tcs->GetLayer() : settingNumber; + flickerEffect->SetLayerNr(layer); flickerEffect->SetDensity(MathExtensions::Limit(tcs->GetAreaFlickerDensity(), 1, 99)); AnalogAlpha activeValue(MathExtensions::Limit(tcs->GetIntensity(), 0, 255), 255); @@ -547,7 +549,8 @@ void Configurator::SetupTable( std::to_string(tcc->GetNumber()), std::to_string(settingNumber)); matrixEffect->SetName(effectName); matrixEffect->SetToyName(toy->GetName()); - matrixEffect->SetLayerNr(tcs->GetLayer()); + int layer = tcs->HasLayer() ? tcs->GetLayer() : settingNumber; + matrixEffect->SetLayerNr(layer); effect = static_cast(matrixEffect); } diff --git a/src/test.cpp b/src/test.cpp index de79474..2e27381 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -80,6 +80,8 @@ void RunIJTests(DOF::DOF* pDof) Log("========================================"); pDof->Init("", "ij_l7"); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + Log("=== DOF Protocol Test Scenarios ==="); Log("1. L88 lamp test - 5 seconds on"); @@ -112,10 +114,10 @@ void RunTNATests(DOF::DOF* pDof) Log("========================================"); pDof->Init("", "tna"); - Log("=== TNA Matrix Effects Test Scenarios ==="); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + Log("=== TNA Matrix Effects Test Scenarios ==="); + Log("1. Run E105 for 5 seconds ON"); pDof->DataReceive('E', 105, 1); @@ -188,28 +190,36 @@ void RunGWTests(DOF::DOF* pDof) Log("========================================"); pDof->Init("", "gw"); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + Log("=== DOF Protocol Test Scenarios ==="); - Log("1. S12 solenoid test - trigger for 3 seconds"); + Log("1. W65 switch test - trigger for 3 seconds"); + pDof->DataReceive('W', 65, 1); + std::this_thread::sleep_for(std::chrono::milliseconds(3000)); + pDof->DataReceive('W', 65, 0); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + Log("2. S12 solenoid test - trigger for 3 seconds"); pDof->DataReceive('S', 12, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('S', 12, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("2. S16 solenoid test - trigger for 3 seconds"); + Log("3. S16 solenoid test - trigger for 3 seconds"); pDof->DataReceive('S', 16, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('S', 16, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("3. S24 solenoid test - trigger for 3 seconds"); + Log("4. S24 solenoid test - trigger for 3 seconds"); pDof->DataReceive('S', 24, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('S', 24, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // S46 & S48 also require W78 to be on - Log("4. S46 solenoid test (with W78 on) - trigger for 3 seconds"); + Log("5. S46 solenoid test (with W78 on) - trigger for 3 seconds"); pDof->DataReceive('W', 78, 1); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); pDof->DataReceive('S', 46, 1); @@ -217,7 +227,7 @@ void RunGWTests(DOF::DOF* pDof) pDof->DataReceive('S', 46, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("5. S48 solenoid test (with W78 on) - trigger for 3 seconds"); + Log("6. S48 solenoid test (with W78 on) - trigger for 3 seconds"); pDof->DataReceive('S', 48, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('S', 48, 0); @@ -225,73 +235,73 @@ void RunGWTests(DOF::DOF* pDof) pDof->DataReceive('W', 78, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("6. W17 switch test - press for 3 seconds"); + Log("7. W17 switch test - press for 3 seconds"); pDof->DataReceive('W', 17, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 17, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("7. W27 switch test - press for 3 seconds"); + Log("8. W27 switch test - press for 3 seconds"); pDof->DataReceive('W', 27, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 27, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("8. W28 switch test - press for 3 seconds"); + Log("9. W28 switch test - press for 3 seconds"); pDof->DataReceive('W', 28, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 28, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("9. W36 switch test - press for 3 seconds"); + Log("10. W36 switch test - press for 3 seconds"); pDof->DataReceive('W', 36, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 36, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("10. W41 switch test - press for 3 seconds"); + Log("11. W41 switch test - press for 3 seconds"); pDof->DataReceive('W', 41, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 41, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("11. W44 switch test - press for 3 seconds"); + Log("12. W44 switch test - press for 3 seconds"); pDof->DataReceive('W', 44, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 44, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("12. W45 switch test - press for 3 seconds"); + Log("13. W45 switch test - press for 3 seconds"); pDof->DataReceive('W', 45, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 45, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("13. W46 switch test - press for 3 seconds"); + Log("14. W46 switch test - press for 3 seconds"); pDof->DataReceive('W', 46, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 46, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("14. W51 switch test - press for 3 seconds"); + Log("15. W51 switch test - press for 3 seconds"); pDof->DataReceive('W', 51, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 51, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("15. W65 switch test - press for 3 seconds"); + Log("16. W65 switch test - press for 3 seconds"); pDof->DataReceive('W', 65, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 65, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("16. W78 switch test - press for 3 seconds"); + Log("17. W78 switch test - press for 3 seconds"); pDof->DataReceive('W', 78, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 78, 0); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - Log("17. W81 switch test - press for 3 seconds"); + Log("18. W81 switch test - press for 3 seconds"); pDof->DataReceive('W', 81, 1); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); pDof->DataReceive('W', 81, 0);