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);
+18 -5
View File
@@ -51,6 +51,14 @@ uint16_t getRTCBatteryVoltage()
extern uint16_t simuGetAnalog(uint8_t idx);
// Negative = no override, fall back to the vBatWarn-derived default below.
static int32_t s_simuTxVoltageOverride = -1;
void simuSetTxVoltage(int32_t decivolts)
{
s_simuTxVoltageOverride = decivolts;
}
static bool simu_start_conversion()
{
int max_input = adcGetMaxInputs(ADC_INPUT_ALL);
@@ -58,13 +66,18 @@ static bool simu_start_conversion()
setAnalogValue(i, simuGetAnalog(i));
}
// set batteries default voltages
int i = adcGetInputOffset(ADC_INPUT_VBAT);
if (i > 0) {
// +0.5V and prec2
uint16_t vBatWarn = BATTERY_WARN;
if (g_eeGeneral.vBatWarn > 0) vBatWarn = g_eeGeneral.vBatWarn;
uint16_t volts = (vBatWarn + 5) * 10;
uint16_t vBatDeciVolts;
if (s_simuTxVoltageOverride >= 0) {
vBatDeciVolts = (uint16_t)s_simuTxVoltageOverride;
} else {
// set battery default voltage: +0.5V above the warning threshold
uint16_t vBatWarn = BATTERY_WARN;
if (g_eeGeneral.vBatWarn > 0) vBatWarn = g_eeGeneral.vBatWarn;
vBatDeciVolts = vBatWarn + 5;
}
uint16_t volts = vBatDeciVolts * 10; // prec2
setAnalogValue(i, volts * 2);
}
+4
View File
@@ -60,6 +60,10 @@ void WASM_EXPORT(simuSetKey)(uint8_t key, bool state);
void WASM_EXPORT(simuSetTrim)(uint8_t trim, bool state);
void WASM_EXPORT(simuSetSwitch)(uint8_t swtch, int8_t state);
// TX battery voltage override, in decivolts (85 = 8.5V). Pass a negative
// value to clear the override and go back to the vBatWarn-derived default.
void WASM_EXPORT(simuSetTxVoltage)(int32_t decivolts);
// Touch: call simuTouchDown(x,y) on press and repeatedly during drag
// (continuous position updates), then simuTouchUp() on release.
// The firmware detects slides from successive position changes.
+3 -1
View File
@@ -182,7 +182,9 @@ get_target_build_options() {
# Determine parallel job limit based on environment
determine_max_jobs() {
if [[ -n ${CMAKE_BUILD_PARALLEL_LEVEL} ]]; then
if [[ -n ${MAX_JOBS} ]]; then
: # explicit caller override, keep as-is
elif [[ -n ${CMAKE_BUILD_PARALLEL_LEVEL} ]]; then
MAX_JOBS=${CMAKE_BUILD_PARALLEL_LEVEL}
elif [ -n "$GITHUB_ACTIONS" ]; then
# Limit jobs in GitHub Actions to n-1 to avoid resource contention
+1 -3
View File
@@ -47,9 +47,7 @@ if [[ -z ${EDGETX_VERSION_SUFFIX} ]]; then
fi
fi
if [[ -n "$GITHUB_ACTIONS" ]]; then
MAX_JOBS=${MAX_JOBS:-3}
fi
determine_max_jobs
BUILD_DIR="build/wasm"