feat: Deadzone option for NV14 sticks (#1777)

Imported from open-flysky/Flysky-OpenTX-Test-Branch

* companion: Don't nuke `stickDeadZone` setting

* Implement data storage properly

* Add missing check for NV14 storage struct sizes

* Formatting

* Use one less byte in the packed data struct
Thanks @raphaelcoeffic :)

* Move setting of stickDeadZone default

* Use a Choice combo rather than NumberEdit

* Good riddance magic number

* Also set default stick zone if setting is missing

* Teach tests about `STICK_DEAD_ZONE`

* Tweak choice width

* Cpn NV14 add stick dead zone to hardware and section labels

* Cpn NV14 align default pot names to radio

Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
Peter Feerick
2022-04-06 10:30:20 +10:00
committed by GitHub
co-authored by elecpower
parent 9d27a6923c
commit d9b51f8ecf
46 changed files with 173 additions and 11 deletions
+3
View File
@@ -141,6 +141,9 @@ static inline void check_struct()
CHKSIZE(RadioData, 901);
CHKSIZE(ModelData, 11023);
#endif
#elif defined(PCBNV14)
CHKSIZE(RadioData, 849);
CHKSIZE(ModelData, 10839);
#endif
#undef CHKSIZE
+7 -1
View File
@@ -823,7 +823,7 @@ PACK(struct TrainerData {
#if defined(BUZZER)
#define BUZZER_FIELD int8_t buzzerMode:2 // -2=quiet, -1=only alarms, 0=no keys, 1=all (only used on AVR radios without audio hardware)
#else
#define BUZZER_FIELD int8_t spare4:2 SKIP
#define BUZZER_FIELD int8_t spare1:2 SKIP
#endif
PACK(struct RadioData {
@@ -913,6 +913,12 @@ PACK(struct RadioData {
GYRO_FIELDS
NOBACKUP(int8_t uartSampleMode:2); // See UartSampleModes
#if defined(STICK_DEAD_ZONE)
NOBACKUP(uint8_t stickDeadZone:3);
NOBACKUP(uint8_t spare2:3 SKIP);
#else
NOBACKUP(uint8_t spare2:6 SKIP);
#endif
});
#undef SWITCHES_WARNING_DATA
+14
View File
@@ -346,6 +346,20 @@ void RadioHardwarePage::build(FormWindow * window)
grid.nextLine();
}
#if defined(STICK_DEAD_ZONE)
new StaticText(window, grid.getLabelSlot(true), STR_DEAD_ZONE);
auto choice =
new Choice(window, grid.getFieldSlot(2,0), 0, 7,
GET_DEFAULT(g_eeGeneral.stickDeadZone), [=](uint8_t newValue) {
g_eeGeneral.stickDeadZone = newValue;
SET_DIRTY();
});
choice->setTextHandler([](uint8_t value) {
return std::to_string(value ? 2 << (value - 1) : 0);
});
grid.nextLine();
#endif
// Pots
new Subtitle(window, grid.getLineSlot(), STR_POTS, 0, COLOR_THEME_PRIMARY1);
grid.nextLine();
+33
View File
@@ -442,6 +442,23 @@ void evalInputs(uint8_t mode)
{
BeepANACenter anaCenter = 0;
#if defined(STICK_DEAD_ZONE)
static int16_t P_OFFSET = 0;
static int16_t N_OFFSET = 0;
static float aParam = 0.0f;
static float bParam = 0.0f;
static int16_t lastDeadZone = -1;
if (lastDeadZone != g_eeGeneral.stickDeadZone) {
P_OFFSET =
(g_eeGeneral.stickDeadZone ? 2 << (g_eeGeneral.stickDeadZone - 1) : 0);
N_OFFSET = (-1) * P_OFFSET;
aParam = 1024.0 / (1024.0 - (float)P_OFFSET);
bParam = 1024.0 * (aParam - 1.0f);
lastDeadZone = g_eeGeneral.stickDeadZone;
}
#endif
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++) {
// normalization [0..2048] -> [-1024..1024]
uint8_t ch = (i < NUM_STICKS ? CONVERT_MODE(i) : i);
@@ -461,6 +478,22 @@ void evalInputs(uint8_t mode)
if (v < -RESX) v = -RESX;
if (v > RESX) v = RESX;
#if defined(STICK_DEAD_ZONE)
// dead zone invented by FlySky in my opinion it should goes into ADC
// float calculations are not efficient
if (g_eeGeneral.stickDeadZone && ch != THR_STICK) {
if (v > P_OFFSET) {
// y=ax+b
v = (int)((aParam * (float)v) - bParam);
} else if ((v <= P_OFFSET) && (v >= N_OFFSET)) {
v = 0;
} else if (v < N_OFFSET) {
// y=ax+b
v = (int)((aParam * (float)v) + bParam);
}
}
#endif
if (g_model.throttleReversed && ch==THR_STICK) {
v = -v;
}
+6 -1
View File
@@ -298,7 +298,12 @@ void generalDefault()
g_eeGeneral.slidersConfig = DEFAULT_SLIDERS_CONFIG;
#endif
// vBatWarn is voltage in 100mV, vBatMin is in 100mV but with -9V offset, vBatMax has a -12V offset
#if defined(STICK_DEAD_ZONE)
g_eeGeneral.stickDeadZone = DEFAULT_STICK_DEADZONE;
#endif
// vBatWarn is voltage in 100mV, vBatMin is in 100mV but with -9V offset,
// vBatMax has a -12V offset
g_eeGeneral.vBatWarn = BATTERY_WARN;
if (BATTERY_MIN != 90)
g_eeGeneral.vBatMin = BATTERY_MIN - 90;
+5
View File
@@ -98,6 +98,11 @@ void postRadioSettingsLoad()
g_eeGeneral.internalModule = DEFAULT_INTERNAL_MODULE;
}
#endif
#if defined(STICK_DEAD_ZONE)
if (!g_eeGeneral.stickDeadZone) {
g_eeGeneral.stickDeadZone = DEFAULT_STICK_DEADZONE;
}
#endif
}
#if defined(EXTERNAL_ANTENNA) && defined(INTERNAL_MODULE_PXX1)
@@ -438,6 +438,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRUCT("themeData", 480, struct_OpenTxTheme__PersistentData, NULL),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_UNSIGNED( "stickDeadZone", 3 ),
YAML_PADDING( 2 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -407,6 +407,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -407,6 +407,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -407,6 +407,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -413,6 +413,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_PADDING( 144 ),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -407,6 +407,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -459,6 +459,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRUCT("themeData", 480, struct_OpenTxTheme__PersistentData, NULL),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -457,6 +457,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRUCT("themeData", 480, struct_OpenTxTheme__PersistentData, NULL),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -407,6 +407,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -414,6 +414,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -453,6 +453,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -392,6 +392,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_PADDING( 120 ),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -402,6 +402,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -399,6 +399,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -403,6 +403,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_SIGNED( "gyroMax", 8 ),
YAML_SIGNED( "gyroOffset", 8 ),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -407,6 +407,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_STRING("bluetoothName", 10),
YAML_STRING("ownerRegistrationID", 8),
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_PADDING( 5 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
+5
View File
@@ -1,5 +1,6 @@
option(DISK_CACHE "Enable SD card disk cache" ON)
option(UNEXPECTED_SHUTDOWN "Enable the Unexpected Shutdown screen" ON)
option(STICKS_DEAD_ZONE "Enable sticks dead zone" YES)
option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger/DIY-Multiprotocol-TX-Module)" ON)
option(AFHDS2 "Support for AFHDS2" ON)
option(GHOST "Ghost TX Module" ON)
@@ -90,6 +91,10 @@ if(NOT UNEXPECTED_SHUTDOWN)
add_definitions(-DNO_UNEXPECTED_SHUTDOWN)
endif()
if(STICKS_DEAD_ZONE)
add_definitions(-DSTICK_DEAD_ZONE)
endif()
set(AFHDS2 ON)
# disable for now as it crashes on radio
+2
View File
@@ -299,6 +299,8 @@ enum Analogs {
#define SLIDER_FIRST 0
#define SLIDER_LAST -1
#define DEFAULT_STICK_DEADZONE 2
#define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITHOUT_DETENT << 2) // 2 pots without detent
enum CalibratedAnalogs {
+12
View File
@@ -337,7 +337,11 @@ TEST_F(TrimsTest, CopySticksToOffset)
anaInValues[ELE_STICK] = -100;
evalMixes(1);
copySticksToOffset(1);
#if defined(STICK_DEAD_ZONE)
EXPECT_EQ(g_model.limitData[1].offset, -93);
#else
EXPECT_EQ(g_model.limitData[1].offset, -97);
#endif
}
TEST_F(TrimsTest, MoveTrimsToOffsets)
@@ -444,7 +448,11 @@ TEST_F(TrimsTest, InstantTrim)
{
anaInValues[AIL_STICK] = 50;
instantTrim();
#if defined(STICK_DEAD_ZONE)
EXPECT_EQ(23, getTrimValue(0, AIL_STICK));
#else
EXPECT_EQ(25, getTrimValue(0, AIL_STICK));
#endif
}
TEST_F(TrimsTest, InstantTrimNegativeCurve)
@@ -459,7 +467,11 @@ TEST_F(TrimsTest, InstantTrimNegativeCurve)
g_model.points[4] = 0;
anaInValues[AIL_STICK] = 512;
instantTrim();
#if defined(STICK_DEAD_ZONE)
EXPECT_EQ(127, getTrimValue(0, AIL_STICK));
#else
EXPECT_EQ(128, getTrimValue(0, AIL_STICK));
#endif
}
TEST(Curves, LinearIntpol)
+1
View File
@@ -765,6 +765,7 @@ const char STR_MENU_DISPLAY[] = TR_MENU_DISPLAY;
const char STR_MENU_OTHER[] = TR_MENU_OTHER;
const char STR_MENU_INVERT[] = TR_MENU_INVERT;
const char STR_JITTER_FILTER[] = TR_JITTER_FILTER;
const char STR_DEAD_ZONE[] = TR_DEAD_ZONE;
const char STR_RTC_CHECK[] = TR_RTC_CHECK;
const char STR_EXIT[] = TR_EXIT;
const char STR_MODULE_RANGE[] = TR_MODULE_RANGE;
+1
View File
@@ -1110,6 +1110,7 @@ extern const char STR_MENU_DISPLAY[];
extern const char STR_MENU_OTHER[];
extern const char STR_MENU_INVERT[];
extern const char STR_JITTER_FILTER[];
extern const char STR_DEAD_ZONE[];
extern const char STR_RTC_CHECK[];
extern const char STR_SPORT_UPDATE_POWER_MODE[];
extern const char STR_SPORT_UPDATE_POWER_MODES[];
+1
View File
@@ -1154,6 +1154,7 @@
#define TR_MENU_OTHER "其它"
#define TR_MENU_INVERT "反向"
#define TR_JITTER_FILTER "类比输入滤波"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "检查时间驱动电池电压")
#define TR_AUTH_FAILURE "验证失败"
#define TR_RACING_MODE "竞速模式"
+1
View File
@@ -1201,6 +1201,7 @@
#define TR_MENU_OTHER "Ostatní"
#define TR_MENU_INVERT "Invertovat"
#define TR_JITTER_FILTER "ADC Filtr"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1207,6 +1207,7 @@
#define TR_MENU_OTHER "Weitere"
#define TR_MENU_INVERT "Invertieren<!>"
#define TR_JITTER_FILTER "ADC Filter"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1205,6 +1205,7 @@
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define TR_JITTER_FILTER "ADC filter"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1207,6 +1207,7 @@
#define TR_MENU_OTHER "Otros"
#define TR_MENU_INVERT "Invertir"
#define TR_JITTER_FILTER "Filtro ADC"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltaje")
#define TR_AUTH_FAILURE "Fallo " LCDW_128_480_LINEBREAK "autentificación"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1213,6 +1213,7 @@
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define TR_JITTER_FILTER "ADC Filter"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1230,6 +1230,7 @@
#define TR_MENU_OTHER "Autres"
#define TR_MENU_INVERT "Inverser"
#define TR_JITTER_FILTER "Filtre ADC"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Vérif. RTC", "Vérif. pile RTC")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1226,6 +1226,7 @@
#define TR_MENU_OTHER "Altro"
#define TR_MENU_INVERT "Inverti"
#define TR_JITTER_FILTER "Filtro ADC"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Controllo RTC", "Controllo volt. RTC")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1217,6 +1217,7 @@
#define TR_MENU_OTHER "Verdere"
#define TR_MENU_INVERT "Inverteer"
#define TR_JITTER_FILTER "ADC Filter"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1222,6 +1222,7 @@
#define TR_MENU_OTHER "Inny "
#define TR_MENU_INVERT "Odwróć"
#define TR_JITTER_FILTER "ADC Filter"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1229,6 +1229,7 @@
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define TR_JITTER_FILTER "ADC Filter"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1230,6 +1230,7 @@
#define TR_MENU_OTHER "Annat"
#define TR_MENU_INVERT "Invertera"
#define TR_JITTER_FILTER "ADC Filter"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "Check RTC voltage")
#define TR_AUTH_FAILURE "Auth-failure"
#define TR_RACING_MODE "Racing mode"
+1
View File
@@ -1154,6 +1154,7 @@
#define TR_MENU_OTHER "其它"
#define TR_MENU_INVERT "反向"
#define TR_JITTER_FILTER "類比輸入濾波"
#define TR_DEAD_ZONE "Dead zone"
#define TR_RTC_CHECK TR("Check RTC", "檢查時間驅動電池電壓")
#define TR_AUTH_FAILURE "驗證失敗"
#define TR_RACING_MODE "Racing mode"