From 8576246704b208c8e2bb03ca107d375c8fbf4dd9 Mon Sep 17 00:00:00 2001 From: Jeremy Lorelli Date: Thu, 22 Jun 2023 16:20:16 -0700 Subject: [PATCH] FIX: interpret analog input values as int16 Both signed and unsigned representations behave like a signed 16-bit integer. In the case of unsigned, the value is limited to the range 0-32767, the former is limited to -32768-32767. As such, treating the values from the terminal as int16 (and thus sign extending them when assigning to RVAL) is the correct way of doing things. This does not handle the MSB representation properly however. That will require more work down the line if we ever decide to support it. For now, users will need to use the unsigned or signed representations for the data to be correctly read. --- ek9000App/src/devEL3XXX.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ek9000App/src/devEL3XXX.cpp b/ek9000App/src/devEL3XXX.cpp index 1c3d6eb..57ae7e2 100644 --- a/ek9000App/src/devEL3XXX.cpp +++ b/ek9000App/src/devEL3XXX.cpp @@ -73,7 +73,7 @@ struct EL30XXStandardInputPDO_t { uint8_t _r2 : 6; // Last bit in this align is Sync error for EL31XX uint8_t txpdo_state : 1; uint8_t txpdo_toggle : 1; - uint16_t value; + int16_t value; // Must be signed to accommodate bipolar terminals. Unsigned representation still defines range as 0-32767, so this is safe. }; #pragma pack() @@ -432,7 +432,7 @@ struct EL331XInputPDO_t { uint8_t error : 1; uint8_t txpdo_state : 1; uint8_t txpdo_toggle : 1; - uint16_t value; + int16_t value; }; struct EL3314_0010_InputPDO_t { @@ -444,7 +444,7 @@ struct EL3314_0010_InputPDO_t { uint8_t txpdo_state : 1; uint8_t txpdo_toggle : 1; uint8_t padding1 : 7; // Pad it out to byte boundary - uint16_t value; + int16_t value; }; #pragma pack()