Skip to content

Commit

Permalink
Removed horus constants for switches & ADC inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Dec 23, 2022
1 parent d25faee commit 1d9c7ee
Show file tree
Hide file tree
Showing 49 changed files with 298 additions and 1,028 deletions.
124 changes: 5 additions & 119 deletions radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,121 +394,7 @@ enum SwitchSources {
SWSRC_NONE = 0,

SWSRC_FIRST_SWITCH SKIP,

#if defined(STORAGE_SWITCH_A)
SWSRC_SA0 = SWSRC_FIRST_SWITCH,
SWSRC_SA1,
SWSRC_SA2,
#endif

#if defined(STORAGE_SWITCH_B)
SWSRC_SB0,
SWSRC_SB1,
SWSRC_SB2,
#endif

#if defined(STORAGE_SWITCH_C)
SWSRC_SC0,
SWSRC_SC1,
SWSRC_SC2,
#endif

#if defined(STORAGE_SWITCH_D)
SWSRC_SD0,
SWSRC_SD1,
SWSRC_SD2,
#endif

#if defined(FUNCTION_SWITCHES) && defined(RADIO_TPRO)
SWSRC_FIRST_FUNCTION_SWITCH SKIP,
SWSRC_SE0 = SWSRC_FIRST_FUNCTION_SWITCH,
SWSRC_SE1,
SWSRC_SE2,
#elif defined(STORAGE_SWITCH_E)
SWSRC_SE0,
SWSRC_SE1,
SWSRC_SE2,
#endif

#if defined(STORAGE_SWITCH_F)
SWSRC_SF0,
SWSRC_SF1,
SWSRC_SF2,
#endif

#if defined(STORAGE_SWITCH_G)
SWSRC_SG0,
SWSRC_SG1,
SWSRC_SG2,
#endif

#if defined(STORAGE_SWITCH_H)
SWSRC_SH0,
SWSRC_SH1,
SWSRC_SH2,
#endif

#if defined(STORAGE_SWITCH_I)
SWSRC_SI0,
SWSRC_SI1,
SWSRC_SI2,
#endif

#if defined(STORAGE_SWITCH_J)
SWSRC_SJ0,
SWSRC_SJ1,
SWSRC_SJ2,
#endif

#if defined(STORAGE_SWITCH_K)
SWSRC_SK0,
SWSRC_SK1,
SWSRC_SK2,
#endif

#if defined(STORAGE_SWITCH_L)
SWSRC_SL0,
SWSRC_SL1,
SWSRC_SL2,
#endif

#if defined(STORAGE_SWITCH_M)
SWSRC_SM0,
SWSRC_SM1,
SWSRC_SM2,
#endif

#if defined(STORAGE_SWITCH_N)
SWSRC_SN0,
SWSRC_SN1,
SWSRC_SN2,
#endif

#if defined(STORAGE_SWITCH_O)
SWSRC_SO0,
SWSRC_SO1,
SWSRC_SO2,
#endif

#if defined(STORAGE_SWITCH_P)
SWSRC_SP0,
SWSRC_SP1,
SWSRC_SP2,
#endif

#if defined(STORAGE_SWITCH_Q)
SWSRC_SQ0,
SWSRC_SQ1,
SWSRC_SQ2,
#endif

#if defined(STORAGE_SWITCH_R)
SWSRC_SR0,
SWSRC_SR1,
SWSRC_SR2,
#endif

SWSRC_LAST_SWITCH SKIP = SWSRC_FIRST_SWITCH + STORAGE_NUM_SWITCHES_POSITIONS - 1,
SWSRC_LAST_SWITCH SKIP = SWSRC_FIRST_SWITCH + (MAX_SWITCHES * 3) - 1,

SWSRC_FIRST_MULTIPOS_SWITCH SKIP,
SWSRC_LAST_MULTIPOS_SWITCH SKIP = SWSRC_FIRST_MULTIPOS_SWITCH + (MAX_POTS * XPOTS_MULTIPOS_COUNT) - 1,
Expand Down Expand Up @@ -650,6 +536,9 @@ enum MixSources {
#if defined(PCBHORUS)
MIXSRC_MOUSE1, LUA_EXPORT("jsx", "Joystick X")
MIXSRC_MOUSE2, LUA_EXPORT("jsy", "Joystick Y")
MIXSRC_LAST_ANALOG SKIP = MIXSRC_MOUSE2,
#else
MIXSRC_LAST_ANALOG SKIP = MIXSRC_LAST_POT,
#endif

#if defined(IMU)
Expand Down Expand Up @@ -690,7 +579,7 @@ enum MixSources {
//#endif

MIXSRC_FIRST_SWITCH SKIP,
MIXSRC_LAST_SWITCH SKIP = MIXSRC_FIRST_SWITCH + STORAGE_NUM_SWITCHES - 1,
MIXSRC_LAST_SWITCH SKIP = MIXSRC_FIRST_SWITCH + MAX_SWITCHES - 1,
// #if defined(HARDWARE_SWITCH_A)
// MIXSRC_SA = MIXSRC_FIRST_SWITCH, LUA_EXPORT("sa", "Switch A")
// MIXSRC_SB, LUA_EXPORT("sb", "Switch B")
Expand Down Expand Up @@ -764,9 +653,6 @@ enum MixSources {
MIXSRC_LAST_TELEM SKIP = MIXSRC_FIRST_TELEM + 3 * MAX_TELEMETRY_SENSORS - 1,
};

#if defined(__cplusplus)
static_assert(MIXSRC_FIRST_LOGICAL_SWITCH == MIXSRC_FIRST_SWITCH + STORAGE_NUM_SWITCHES, "Wrong switches definition in MIXSRC list");
#endif

// #define MIXSRC_FIRST (MIXSRC_NONE + 1)
#define MIXSRC_LAST MIXSRC_LAST_CH
Expand Down
7 changes: 4 additions & 3 deletions radio/src/gui/colorlcd/hw_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ HWPots::HWPots(Window* parent) : FormGroup(parent, rect_t{})
// TODO: check initialised ADC inputs instead!

// Display EX3 & EX4 (= last two pots) only when FlySky gimbals are present
#if !defined(SIMU) && defined(RADIO_FAMILY_T16)
if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
#endif
// TODO!
// #if !defined(SIMU) && defined(RADIO_FAMILY_T16)
// if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
// #endif
auto line = newLine(&grid);
new StaticText(line, rect_t{}, analogGetCanonicalPotName(i), 0,
COLOR_THEME_PRIMARY1);
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/layouts/sliders.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MainViewSlider : public Window
void checkEvents() override
{
Window::checkEvents();
int16_t newValue = calibratedAnalogs[idx];
int16_t newValue = calibratedAnalogs[MAX_STICKS + idx];
if (value != newValue) {
value = newValue;
invalidate();
Expand Down
56 changes: 30 additions & 26 deletions radio/src/gui/colorlcd/preflight_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ struct SwitchWarnMatrix : public ButtonMatrix {
void onPress(uint8_t btn_id);
bool isActive(uint8_t btn_id);
private:
uint8_t sw_idx[NUM_SWITCHES];
uint8_t sw_idx[MAX_SWITCHES];
};

struct PotWarnMatrix : public ButtonMatrix {
PotWarnMatrix(Window* parent, const rect_t& rect);
void onPress(uint8_t btn_id);
bool isActive(uint8_t btn_id);
private:
uint8_t pot_idx[NUM_POTS + NUM_SLIDERS];
uint8_t pot_idx[MAX_POTS];
};

struct CenterBeepsMatrix : public ButtonMatrix {
CenterBeepsMatrix(Window* parent, const rect_t& rect);
void onPress(uint8_t btn_id);
bool isActive(uint8_t btn_id);
private:
uint8_t ana_idx[NUM_STICKS + NUM_POTS + NUM_SLIDERS];
uint8_t ana_idx[MAX_ANALOG_INPUTS];
};

PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)
Expand Down Expand Up @@ -140,17 +140,16 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)
new SwitchWarnMatrix(form, rect_t{});

// Pots and sliders warning
#if NUM_POTS + NUM_SLIDERS
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_POTWARNINGSTATE, 0, COLOR_THEME_PRIMARY1);
auto pots_wm = new Choice(line, rect_t{}, {"OFF", "ON", "AUTO"}, 0, 2,
GET_SET_DEFAULT(g_model.potsWarnMode));
#if (NUM_POTS)
// Pot warnings
auto pwm = new PotWarnMatrix(form, rect_t{});
make_conditional(pwm, pots_wm);
#endif
#endif
if (adcGetMaxPots() > 0) {
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_POTWARNINGSTATE, 0, COLOR_THEME_PRIMARY1);
auto pots_wm = new Choice(line, rect_t{}, {"OFF", "ON", "AUTO"}, 0, 2,
GET_SET_DEFAULT(g_model.potsWarnMode));

// Pot warnings
auto pwm = new PotWarnMatrix(form, rect_t{});
make_conditional(pwm, pots_wm);
}

// Center beeps
line = form->newLine(&grid);
Expand All @@ -170,7 +169,7 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) :
{
// Setup button layout & texts
uint8_t btn_cnt = 0;
for (uint8_t i = 0; i < NUM_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if (SWITCH_EXISTS(i)) {
sw_idx[btn_cnt] = i;
btn_cnt++;
Expand All @@ -180,7 +179,7 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) :
initBtnMap(4, btn_cnt);

uint8_t btn_id = 0;
for (uint8_t i = 0; i < NUM_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if (SWITCH_EXISTS(i)) {
std::string txt = switchWarninglabel(i);
setText(btn_id, txt.c_str());
Expand Down Expand Up @@ -208,7 +207,7 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) :

void SwitchWarnMatrix::onPress(uint8_t btn_id)
{
if (btn_id >= NUM_SWITCHES) return;
if (btn_id >= MAX_SWITCHES) return;
auto sw = sw_idx[btn_id];

swarnstate_t newstate = bfGet(g_model.switchWarningState, 3 * sw, 3);
Expand All @@ -228,7 +227,7 @@ void SwitchWarnMatrix::onPress(uint8_t btn_id)

bool SwitchWarnMatrix::isActive(uint8_t btn_id)
{
if (btn_id >= NUM_SWITCHES) return false;
if (btn_id >= MAX_SWITCHES) return false;
return bfGet(g_model.switchWarningState, 3 * sw_idx[btn_id], 3) != 0;
}

Expand Down Expand Up @@ -274,7 +273,7 @@ PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) :

void PotWarnMatrix::onPress(uint8_t btn_id)
{
if (btn_id >= NUM_POTS + NUM_SLIDERS) return;
if (btn_id >= MAX_POTS) return;
auto pot = pot_idx[btn_id];

g_model.potsWarnEnabled ^= (1 << pot);
Expand All @@ -287,7 +286,7 @@ void PotWarnMatrix::onPress(uint8_t btn_id)

bool PotWarnMatrix::isActive(uint8_t btn_id)
{
if (btn_id >= NUM_POTS + NUM_SLIDERS) return false;
if (btn_id >= MAX_POTS) return false;
return (g_model.potsWarnEnabled & (1 << pot_idx[btn_id])) != 0;
}

Expand All @@ -296,9 +295,12 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) :
{
// Setup button layout & texts
uint8_t btn_cnt = 0;
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++) {
auto max_analogs = MAX_STICKS + adcGetMaxPots();
for (uint8_t i = 0; i < max_analogs; i++) {
// multipos cannot be centered
if (i < NUM_STICKS || (IS_POT_SLIDER_AVAILABLE(i) && !IS_POT_MULTIPOS(i))) {
if (i < adcGetMaxSticks() ||
(i >= MAX_STICKS && IS_POT_SLIDER_AVAILABLE(i) &&
!IS_POT_MULTIPOS(i))) {
ana_idx[btn_cnt] = i;
btn_cnt++;
}
Expand All @@ -307,8 +309,10 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) :
initBtnMap(4, btn_cnt);

uint8_t btn_id = 0;
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++) {
if (i < NUM_STICKS || (IS_POT_SLIDER_AVAILABLE(i) && !IS_POT_MULTIPOS(i))) {
for (uint8_t i = 0; i < max_analogs; i++) {
if (i < adcGetMaxSticks() ||
(i >= MAX_STICKS && IS_POT_SLIDER_AVAILABLE(i) &&
!IS_POT_MULTIPOS(i))) {
setText(btn_id, STR_RETA123[i]);
btn_id++;
}
Expand All @@ -334,15 +338,15 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) :

void CenterBeepsMatrix::onPress(uint8_t btn_id)
{
if (btn_id >= NUM_STICKS + NUM_POTS + NUM_SLIDERS) return;
if (btn_id >= MAX_STICKS + adcGetMaxPots()) return;
uint8_t i = ana_idx[btn_id];
BFBIT_FLIP(g_model.beepANACenter, bfBit<BeepANACenter>(i));
SET_DIRTY();
}

bool CenterBeepsMatrix::isActive(uint8_t btn_id)
{
if (btn_id >= NUM_STICKS + NUM_POTS + NUM_SLIDERS) return false;
if (btn_id >= MAX_STICKS + adcGetMaxPots()) return false;
uint8_t i = ana_idx[btn_id];
return bfSingleBitGet<BeepANACenter>(g_model.beepANACenter, i) != 0;
}
13 changes: 7 additions & 6 deletions radio/src/gui/colorlcd/radio_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ void RadioCalibrationPage::buildBody(FormWindow * window)
// The two sticks

//TODO: dynamic placing
new StickCalibrationWindow(window,
{window->width() / 3, window->height() / 2, 0, 0},
STICK1, STICK2);
new StickCalibrationWindow(
window, {window->width() / 3, window->height() / 2, 0, 0}, 0, 1);

new StickCalibrationWindow(window,
{(2 * window->width()) / 3, window->height() / 2, 0, 0},
STICK4, STICK3);
if (adcGetMaxSticks() > 2) {
new StickCalibrationWindow(
window, {(2 * window->width()) / 3, window->height() / 2, 0, 0}, 3,
2);
}

std::unique_ptr<ViewMainDecoration> deco(new ViewMainDecoration(window));
deco->setTrimsVisible(false);
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/colorlcd/radio_diaganas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ class AnaFilteredDevViewWindow: public Window {
(int16_t)calibratedAnalogs[CONVERT_MODE(i)] * 25 / 256,
RIGHT | COLOR_THEME_PRIMARY1);
stats[i].write(getAnalogValue(i));
extern uint32_t s_anaFilt[NUM_ANALOGS];

dc->drawNumber(
x + VALUE_X_OFFSET, y, s_anaFilt[i] / JITTER_ALPHA,
x + VALUE_X_OFFSET, y, anaIn_diag(i),
RIGHT | COLOR_THEME_PRIMARY1); // use integrated filter
dc->drawNumber(
dc->drawText(x + DEV_X_OFFSET, y, " +/- ", COLOR_THEME_PRIMARY1),
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/radio_diagkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RadioKeyDiagsWindow : public Window
}
#endif
// SWITCHES
for (uint8_t i = 0; i < NUM_SWITCHES; i++) {
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if (SWITCH_EXISTS(i)) {
coord_t y = 1 + FH * i;
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH + i);
Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/colorlcd/switch_warn_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void SwitchWarnDialog::checkEvents()

std::string warn_txt;
swarnstate_t states = g_model.switchWarningState;
for (int i = 0; i < NUM_SWITCHES; ++i) {
for (int i = 0; i < MAX_SWITCHES; ++i) {
if (SWITCH_WARNING_ALLOWED(i)) {
swarnstate_t mask = ((swarnstate_t)0x07 << (i*3));
if (states & mask) {
Expand All @@ -88,8 +88,8 @@ void SwitchWarnDialog::checkEvents()

if (g_model.potsWarnMode) {
if (!warn_txt.empty()) { warn_txt += '\n'; }
for (int i = 0; i < NUM_POTS + NUM_SLIDERS; i++) {
if (!IS_POT_SLIDER_AVAILABLE(POT1 + i)) { continue; }
for (int i = 0; i < MAX_POTS; i++) {
if (!IS_POT_SLIDER_AVAILABLE(i)) { continue; }
if ( (g_model.potsWarnEnabled & (1 << i))) {
if (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) {
warn_txt += getPotName(i);
Expand Down
Loading

0 comments on commit 1d9c7ee

Please sign in to comment.