diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 2c50d613a..5905b802c 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -1259,23 +1259,39 @@ class LimitField: public StructField { template static int exportLimitValue(int value) { - if (value > 10000) - return 1023 + value - 10000; - else if (value < -10000) - return -1024 + value + 10000; - else - return value + shift; + const int GV1 = 4096; + if (value > 10000) { + return -GV1 + value - 10001; + } + if (value < -10000) { + return GV1 + value + 10000; + } + return value + shift; } template static int importLimitValue(int value) { - if (value > 1023) - return 10000 + value - 1023; - else if (value < -1024) - return -10000 + value + 1024; - else - return value - shift; + /* GVARS mapping on radio: + GV1 = -4096 + GV9 = -4088 + -GV1 = 4095 + -GV9 = 4087 + */ + const int GV1 = 4096; + if (value >= GV1) { + return 10001 + value - GV1; + } + if (value >= GV1-9) { + return -10000 + value - GV1; + } + if (value < -GV1) { + return -10000 + value + GV1 + 1; + } + if (value < -GV1+9) { + return 10000 + value + GV1 + 1; + } + return value - shift; } LimitField(LimitData & limit, BoardEnum board, unsigned int version):