AP_Periph: Fix bad conversion of APD ESC telemetry

le16toh() returns an unsigned type, which keeps the number as positive
when cast to float. It needs to be explictly converted to a signed
number first.

Tested with real hardware.
This commit is contained in:
Michael du Breuil 2023-09-26 17:04:23 -07:00 committed by Tom Pittenger
parent daf427f6d6
commit 4381c17cb2

View File

@ -48,7 +48,7 @@ bool ESC_APD_Telem::update() {
// valid packet, copy the data we need and reset length
decoded.voltage = le16toh(received.packet.voltage) * 1e-2f;
decoded.temperature = convert_temperature(le16toh(received.packet.temperature));
decoded.current = le16toh(received.packet.bus_current) * (1 / 12.5f);
decoded.current = ((int16_t)le16toh(received.packet.bus_current)) * (1 / 12.5f);
decoded.rpm = le32toh(received.packet.erpm) / pole_count;
decoded.power_rating_pct = le16toh(received.packet.motor_duty) * 1e-2f;
ret = true;