fix(cpn): TX battery voltage input collided with left-horizontal stick slot (#7805)

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Peter Feerick
2026-09-19 10:09:15 +10:00
committed by GitHub
co-authored by Claude Sonnet 5
parent 44da67ed7a
commit feb1bee9a5
8 changed files with 53 additions and 13 deletions
+2
View File
@@ -57,6 +57,8 @@ class Node : public QGraphicsObject
void setCenteringX(bool val) { centerX = val; }
void setCenteringY(bool val) { centerY = val; }
bool getCenteringX() const { return centerX; }
bool getCenteringY() const { return centerY; }
void setFixedX(bool val) { fixedX = val; }
void setFixedY(bool val) { fixedY = val; }
bool getFixedX() { return fixedX; }
@@ -331,6 +331,8 @@ bool WasmSimulatorInterface::resolveExports()
m_fnSetKey = wasm_runtime_lookup_function(m_moduleInst, "simuSetKey");
m_fnSetTrim = wasm_runtime_lookup_function(m_moduleInst, "simuSetTrim");
m_fnSetSwitch = wasm_runtime_lookup_function(m_moduleInst, "simuSetSwitch");
m_fnSetTxVoltage =
wasm_runtime_lookup_function(m_moduleInst, "simuSetTxVoltage");
m_fnLcdChanged =
wasm_runtime_lookup_function(m_moduleInst, "simuLcdChanged");
m_fnLcdCopy = wasm_runtime_lookup_function(m_moduleInst, "simuLcdCopy");
@@ -441,10 +443,10 @@ void WasmSimulatorInterface::init()
}
m_stopRequested = false;
memset(m_analogValues, 0, sizeof(m_analogValues));
// Call simuInit
QMutexLocker lckr(&m_mutex);
memset(m_analogValues, 0, sizeof(m_analogValues));
wasm_runtime_call_wasm(m_execEnv, m_fnInit, 0, nullptr);
// Query LCD dimensions
@@ -612,12 +614,14 @@ void WasmSimulatorInterface::setVolumeGain(const int value)
void WasmSimulatorInterface::setAnalogValue(uint8_t index, int16_t value)
{
QMutexLocker lckr(&m_mutex);
if (index < MAX_ANALOGS)
m_analogValues[index] = value;
}
int16_t WasmSimulatorInterface::getAnalogValue(uint8_t index)
{
QMutexLocker lckr(&m_mutex);
if (index < MAX_ANALOGS)
return m_analogValues[index];
return 0;
@@ -641,6 +645,15 @@ void WasmSimulatorInterface::setSwitch(uint8_t swtch, int8_t state)
wasm_runtime_call_wasm(m_execEnv, m_fnSetSwitch, 2, argv);
}
void WasmSimulatorInterface::setTxVoltage(int32_t decivolts)
{
if (!m_fnSetTxVoltage || !m_execEnv)
return;
QMutexLocker lckr(&m_mutex);
uint32_t argv[1] = {(uint32_t)decivolts};
wasm_runtime_call_wasm(m_execEnv, m_fnSetTxVoltage, 1, argv);
}
void WasmSimulatorInterface::setTrim(unsigned int idx, int value)
{
if (!m_fnSetTrimValue || !m_execEnv)
@@ -679,7 +692,9 @@ void WasmSimulatorInterface::setInputValue(int type, uint8_t index,
setAnalogValue(index, value);
break;
case INPUT_SRC_TXVIN:
setAnalogValue(index, value);
// Routed via a dedicated WASM export, not setAnalogValue(): index here
// is always 0, which would collide with STICK_AXIS_LH.
setTxVoltage(value);
emit txBatteryVoltageChanged((unsigned int)value);
break;
case INPUT_SRC_SWITCH:
@@ -56,6 +56,7 @@ class WasmSimulatorInterface : public SimulatorInterface
void setSwitch(uint8_t swtch, int8_t state) override;
void setTrim(unsigned int idx, int value) override;
void setTrimSwitch(uint8_t trim, bool state) override;
void setTxVoltage(int32_t decivolts);
void setTrainerInput(unsigned int inputNumber, int16_t value) override;
void setInputValue(int type, uint8_t index, int16_t value) override;
void rotaryEncoderEvent(int steps) override;
@@ -157,6 +158,7 @@ class WasmSimulatorInterface : public SimulatorInterface
wasm_function_inst_t m_fnSetKey = nullptr;
wasm_function_inst_t m_fnSetTrim = nullptr;
wasm_function_inst_t m_fnSetSwitch = nullptr;
wasm_function_inst_t m_fnSetTxVoltage = nullptr;
wasm_function_inst_t m_fnLcdChanged = nullptr;
wasm_function_inst_t m_fnLcdCopy = nullptr;
wasm_function_inst_t m_fnLcdGetWidth = nullptr;
@@ -419,8 +419,12 @@ void VirtualJoystickWidget::setSize(const QSize & size, const QSize &)
qreal h = qr.height() - ballSize;
qreal cx = qr.width() / 2;
qreal cy = qr.height() / 2;
qreal nodeX = node->getX();
qreal nodeY = node->getY();
// Self-centering axes always resolve to 0 after a resize instead of
// reapplying a captured value, which can be garbage from a transient
// scene rect during construction/layout and would otherwise get
// permanently re-latched on every subsequent resize.
qreal nodeX = (node->getCenteringX() && !node->isPressed()) ? 0.0 : node->getX();
qreal nodeY = (node->getCenteringY() && !node->isPressed()) ? 0.0 : node->getY();
scene->setSceneRect(-cx,-cy,w,h);