feat: Flysky gimbal support for RM Boxer (#3139)

* Adds Flysky digital hall gimbal support for RadioMaster Boxer.

---------

Co-authored-by: rotorman <risto.koiva@web.de>
This commit is contained in:
richardclli
2023-02-26 13:27:37 +01:00
committed by GitHub
co-authored by rotorman
parent 4ea77ee749
commit 9216570d6c
14 changed files with 125 additions and 42 deletions
+29 -12
View File
@@ -27,7 +27,7 @@
void menuCommonCalib(event_t event)
{
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS; i++) { // get low and high vals for sticks and trims
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS; i++) { // get low and high values for sticks, pots and sliders
int16_t vt = anaIn(i);
reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]);
reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]);
@@ -41,12 +41,15 @@ void menuCommonCalib(event_t event)
if (IS_POT_MULTIPOS(i) && count <= XPOTS_MULTIPOS_COUNT) {
// use raw analog value for multipos calibraton, anaIn() already has multipos decoded value
vt = getAnalogValue(i) >> 1;
if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 0 || vt < reusableBuffer.calib.xpotsCalib[idx].lastPosition - XPOT_DELTA || vt > reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) {
if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 0 ||
vt < reusableBuffer.calib.xpotsCalib[idx].lastPosition - XPOT_DELTA ||
vt > reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) {
reusableBuffer.calib.xpotsCalib[idx].lastPosition = vt;
reusableBuffer.calib.xpotsCalib[idx].lastCount = 1;
}
else {
if (reusableBuffer.calib.xpotsCalib[idx].lastCount < 255) reusableBuffer.calib.xpotsCalib[idx].lastCount++;
if (reusableBuffer.calib.xpotsCalib[idx].lastCount < 255)
reusableBuffer.calib.xpotsCalib[idx].lastCount++;
}
if (reusableBuffer.calib.xpotsCalib[idx].lastCount == XPOT_DELAY) {
int16_t position = reusableBuffer.calib.xpotsCalib[idx].lastPosition;
@@ -99,7 +102,16 @@ void menuCommonCalib(event_t event)
reusableBuffer.calib.loVals[i] = 15000;
reusableBuffer.calib.hiVals[i] = -15000;
#if defined(PCBTARANIS)
reusableBuffer.calib.midVals[i] = getAnalogValue(i) >> 1;
#if defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals && (i < FIRST_ANALOG_ADC_FS) )
{
reusableBuffer.calib.midVals[i] = anaIn(i);
}
else
#endif
{
reusableBuffer.calib.midVals[i] = getAnalogValue(i) >> 1;
}
if (i<NUM_XPOTS) {
reusableBuffer.calib.xpotsCalib[i].stepsCount = 0;
reusableBuffer.calib.xpotsCalib[i].lastCount = 0;
@@ -123,9 +135,6 @@ void menuCommonCalib(event_t event)
g_eeGeneral.calib[i].spanPos = v - v/STICK_TOLERANCE;
}
}
break;
case CALIB_STORE:
#if defined(PCBTARANIS)
for (uint8_t i=POT1; i<=POT_LAST; i++) {
int idx = i - POT1;
@@ -145,18 +154,26 @@ void menuCommonCalib(event_t event)
calib->steps[j] = (reusableBuffer.calib.xpotsCalib[idx].steps[j+1] + reusableBuffer.calib.xpotsCalib[idx].steps[j]) >> 5;
}
}
else {
}
}
#endif
break;
case CALIB_STORE:
#if defined(RADIO_BOXER)
// load 6pos calib with factory data if 6 pos was not manually calibrated
for (uint8_t i=POT1; i<=POT_LAST; i++) {
int idx = i - POT1;
if (IS_POT_MULTIPOS(i)) {
int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount;
if (count < XPOTS_MULTIPOS_COUNT)
{
// load 6-pos calib with factory data if 6-pos was not manually calibrated
constexpr int16_t factoryValues[]= {0x5,0xd,0x16,0x1f,0x28};
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[POT3];
calib->count = 5;
for (int j=0; j<calib->count ; j++) {
calib->steps[j] = factoryValues[j];
}
#else
g_eeGeneral.potsConfig &= ~(0x03<<(2*idx));
#endif
}
}
}
+14 -2
View File
@@ -22,12 +22,16 @@
#include "opentx.h"
#include "../../hal/adc_driver.h"
#if defined(FLYSKY_GIMBAL)
#include "flysky_gimbal_driver.h"
#endif
#define HOLDANAVALUEFRAMES 4 /* 4* 50ms = 200 ms update rate */
void menuRadioDiagAnalogs(event_t event)
{
static int8_t entryCount = 0;
static uint16_t lastShownAnalogValue[NUM_STICKS+NUM_POTS+NUM_SLIDERS];
static int16_t lastShownAnalogValue[NUM_STICKS+NUM_POTS+NUM_SLIDERS];
enum ANAVIEWS{
ANAVIEW_FIRST,
@@ -106,7 +110,15 @@ void menuRadioDiagAnalogs(event_t event)
switch (viewpage) {
case (ANAVIEW_RAWLOWFPS):
if (entryCount == 0) {
lastShownAnalogValue[i] = getAnalogValue(i); // Update value
#if defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals && i < FIRST_ANALOG_ADC_FS)
{
lastShownAnalogValue[i] = hall_raw_values[i];
} else
#endif
{
lastShownAnalogValue[i] = getAnalogValue(i); // Update value
}
}
lcdDrawNumber(x+3*FW-1, y, lastShownAnalogValue[i],
LEADING0|LEFT, 4);
+1 -1
View File
@@ -66,7 +66,7 @@ HWPots::HWPots(Window* parent) : FormGroup(parent, rect_t{})
for (int i = 0; i < NUM_POTS; i++) {
// Display EX3 & EX4 (= last two pots) only when FlySky gimbals are present
#if !defined(SIMU) && defined(RADIO_FAMILY_T16)
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
#endif
auto line = newLine(&grid);
+4 -4
View File
@@ -64,7 +64,7 @@ class AnaCalibratedViewWindow: public Window {
void paint(BitmapBuffer * dc) override
{
#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14))
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals)
{
for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) {
@@ -258,7 +258,7 @@ class AnaFilteredDevViewWindow: public Window {
ClearStats = false;
}
#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14))
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals)
{
for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) {
@@ -337,7 +337,7 @@ class AnaUnfilteredRawViewWindow: public Window {
void paint(BitmapBuffer * dc) override
{
#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14))
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals)
{
for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) {
@@ -460,7 +460,7 @@ class AnaMinMaxViewWindow: public Window {
}
dc->drawText(10, 1, STR_ANADIAGS_MOVE, COLOR_THEME_PRIMARY1);
#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14))
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals)
{
for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) {