feat: More flexible ADC inputs (#3870)

Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
Raphael Coeffic
2023-11-02 11:07:53 +10:00
committed by GitHub
co-authored by 3djc Peter Feerick philmoz
parent f5593c44e8
commit b48e07026d
78 changed files with 1291 additions and 773 deletions
+6 -6
View File
@@ -344,7 +344,7 @@ inline uint8_t TIMER_ROW(uint8_t timer, uint8_t value)
return HIDDEN_ROW;
}
#define POT_WARN_ROWS PREFLIGHT_ROW(((g_model.potsWarnMode) ? adcGetMaxInputs(ADC_INPUT_POT) : (uint8_t)0))
#define POT_WARN_ROWS PREFLIGHT_ROW(((g_model.potsWarnMode) ? adcGetMaxInputs(ADC_INPUT_FLEX) : (uint8_t)0))
#define TIMER_ROWS(x) \
1, TIMER_ROW(x,0), \
@@ -592,7 +592,7 @@ void menuModelSetup(event_t event)
PREFLIGHT_ROW(0), // Custom position for throttle warning value
WARN_ROWS
uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_POT + 1) - 1)), // Center beeps
uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_FLEX + 1) - 1)), // Center beeps
0, // ADC Jitter filter
@@ -899,7 +899,7 @@ void menuModelSetup(event_t event)
if (attr)
CHECK_INCDEC_MODELVAR_ZERO_CHECK(
event, g_model.thrTraceSrc,
adcGetMaxInputs(ADC_INPUT_POT) + MAX_OUTPUT_CHANNELS,
adcGetMaxInputs(ADC_INPUT_FLEX) + MAX_OUTPUT_CHANNELS,
isThrottleSourceAvailable);
uint8_t idx = throttleSource2Source(g_model.thrTraceSrc);
@@ -1078,7 +1078,7 @@ void menuModelSetup(event_t event)
}
if (g_model.potsWarnMode) {
coord_t x = MODEL_SETUP_2ND_COLUMN+28;
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
for (int i = 0; i < max_pots; ++i) {
if (!IS_POT_SLIDER_AVAILABLE(i)) {
@@ -1092,7 +1092,7 @@ void menuModelSetup(event_t event)
flags |= INVERS;
}
if (max_pots > 3) {
lcdDrawText(x, y, getAnalogShortLabel(adcGetInputOffset(ADC_INPUT_POT) + i), flags);
lcdDrawText(x, y, getAnalogShortLabel(adcGetInputOffset(ADC_INPUT_FLEX) + i), flags);
x = lcdNextPos + 1;
}
else {
@@ -1106,7 +1106,7 @@ void menuModelSetup(event_t event)
case ITEM_MODEL_SETUP_BEEP_CENTER: {
lcdDrawTextAlignedLeft(y, STR_BEEPCTR);
uint8_t input_max = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_POT);
uint8_t input_max = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < input_max; i++) {
coord_t x = MODEL_SETUP_2ND_COLUMN + i*FW;
LcdFlags flags = 0;
+5 -5
View File
@@ -81,8 +81,8 @@ void drawExternalAntennaAndRSSI()
void drawPotsBars()
{
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
uint8_t offset = adcGetInputOffset(ADC_INPUT_FLEX);
uint8_t configured_pots = 0;
for (uint8_t i = 0; i < max_pots; i++) {
@@ -567,14 +567,14 @@ void menuMainView(event_t event)
uint8_t configured_switches = 0;
for (uint8_t i = 0; i < switches; i++) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
configured_switches ++;
}
}
if (configured_switches < 9) {
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (switch_display.row >= 3) {
drawSmallSwitch(switch_display.col == 0 ? 28 : 16 * FW + 1,
@@ -594,7 +594,7 @@ void menuMainView(event_t event)
}
else {
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
coord_t x = (switch_display.col == 0 ? 8 : 96) + switch_display.row * 5;
drawSmallSwitch(x, 5 * FH + 1, 4, i);
+5 -5
View File
@@ -538,7 +538,7 @@ void menuModelSetup(event_t event)
SW_WARN_ROWS, // ITEM_MODEL_SETUP_SWITCHES_WARNING1
POT_WARN_ROWS, // ITEM_MODEL_SETUP_POTS_WARNING
uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_POT + 1) - 1)), // ITEM_MODEL_SETUP_BEEP_CENTER
uint8_t(NAVIGATION_LINE_BY_LINE | (adcGetInputOffset(ADC_INPUT_FLEX + 1) - 1)), // ITEM_MODEL_SETUP_BEEP_CENTER
0, // ITEM_MODEL_SETUP_USE_JITTER_FILTER
@@ -977,7 +977,7 @@ void menuModelSetup(event_t event)
}
if (g_model.potsWarnMode) {
coord_t x = MODEL_SETUP_2ND_COLUMN+28;
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
for (int i = 0; i < max_pots; ++i) {
if (!IS_POT_SLIDER_AVAILABLE(i)) {
@@ -1011,8 +1011,8 @@ void menuModelSetup(event_t event)
case ITEM_MODEL_SETUP_BEEP_CENTER: {
lcdDrawTextAlignedLeft(y, STR_BEEPCTR);
uint8_t pot_offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_POT);
uint8_t pot_offset = adcGetInputOffset(ADC_INPUT_FLEX);
uint8_t max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN) + adcGetMaxInputs(ADC_INPUT_FLEX);
coord_t x = MODEL_SETUP_2ND_COLUMN;
for (uint8_t i = 0; i < max_inputs; i++) {
if ( i >= pot_offset && IS_POT_MULTIPOS(i - pot_offset) ) {
@@ -1024,7 +1024,7 @@ void menuModelSetup(event_t event)
flags = BLINK | INVERS;
else if (ANALOG_CENTER_BEEP(i) || (attr && CURSOR_ON_LINE()))
flags = INVERS;
if (adcGetMaxInputs(ADC_INPUT_POT) > 4 || i < pot_offset) {
if (adcGetMaxInputs(ADC_INPUT_FLEX) > 4 || i < pot_offset) {
lcdDrawText(x, y, getAnalogShortLabel(i), flags);
}
else {
+2 -2
View File
@@ -31,8 +31,8 @@
void drawPotsBars()
{
// Optimization by Mike Blandford
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
uint8_t offset = adcGetInputOffset(ADC_INPUT_FLEX);
for (uint8_t x = LCD_W / 2 - max_pots / 2 * BAR_SPACING + BAR_SPACING / 2,
i = 0;
+4 -4
View File
@@ -183,8 +183,8 @@ static const coord_t _pot_slots[] = {
void drawSliders()
{
uint8_t slot_idx = 0;
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_POT);
uint8_t offset = adcGetInputOffset(ADC_INPUT_POT);
uint8_t max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
uint8_t offset = adcGetInputOffset(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_pots; i++) {
@@ -534,7 +534,7 @@ void menuMainView(event_t event)
uint8_t switches = switchGetMaxSwitches();
if (getSwitchCount() > 16) { // beware, there is a desired col/row swap in this special mode
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (g_model.view == VIEW_INPUTS) {
coord_t x = 50 + (switch_display.row % 5) * 4 +
@@ -552,7 +552,7 @@ void menuMainView(event_t event)
else {
coord_t shiftright = switchGetMaxRow(1) < 4 ? 20 : 0;
for (int i = 0; i < switches; ++i) {
if (SWITCH_EXISTS(i)) {
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (g_model.view == VIEW_INPUTS) {
coord_t x = (switch_display.col == 0 ? 50 : 125) +
+80 -24
View File
@@ -39,8 +39,16 @@ struct HWInputEdit : public RadioTextEdit {
static const lv_coord_t col_two_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2),
LV_GRID_TEMPLATE_LAST};
static const lv_coord_t col_three_dsc[] = {
LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST};
static const lv_coord_t col_three_dsc[] = {LV_GRID_FR(8), LV_GRID_FR(12), LV_GRID_FR(20),
LV_GRID_TEMPLATE_LAST};
#if LCD_W > LCD_H
static const lv_coord_t pots_col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(2), LV_GRID_FR(5),
LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST};
#else
static const lv_coord_t pots_col_dsc[] = {LV_GRID_FR(22), LV_GRID_FR(48), LV_GRID_FR(16),
LV_GRID_TEMPLATE_LAST};
#endif
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
@@ -71,7 +79,7 @@ HWSticks::HWSticks(Window* parent) : FormWindow(parent, rect_t{})
HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{})
{
FlexGridLayout grid(col_three_dsc, row_dsc, 2);
FlexGridLayout grid(pots_col_dsc, row_dsc, 2);
setFlexLayout();
potsChanged = false;
@@ -83,7 +91,7 @@ HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{})
}
});
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
for (int i = 0; i < max_pots; i++) {
// TODO: check initialised ADC inputs instead!
@@ -93,29 +101,32 @@ HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{})
// if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
// #endif
auto line = newLine(&grid);
new StaticText(line, rect_t{}, adcGetInputLabel(ADC_INPUT_POT, i), 0,
new StaticText(line, rect_t{}, adcGetInputLabel(ADC_INPUT_FLEX, i), 0,
COLOR_THEME_PRIMARY1);
auto box = new FormWindow(line, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4));
#if LCD_H > LCD_W
line = newLine(&grid);
#endif
auto box_obj = box->getLvObj();
lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0);
new HWInputEdit(box, (char*)analogGetCustomLabel(ADC_INPUT_POT, i),
new HWInputEdit(line, (char*)analogGetCustomLabel(ADC_INPUT_FLEX, i),
LEN_ANA_NAME);
new Choice(
box, rect_t{}, STR_POTTYPES, POT_NONE, POT_SLIDER_WITH_DETENT,
[=]() -> int {
return bfGet<potconfig_t>(g_eeGeneral.potsConfig, POT_CFG_BITS * i,
POT_CFG_BITS);
},
auto pot = new Choice(
line, rect_t{}, STR_POTTYPES, FLEX_NONE, FLEX_SWITCH,
[=]() -> int { return getPotType(i); },
[=](int newValue) {
g_eeGeneral.potsConfig = bfSet<potconfig_t>(
g_eeGeneral.potsConfig, newValue, POT_CFG_BITS * i, POT_CFG_BITS);
setPotType(i, newValue);
switchFixFlexConfig();
potsChanged = true;
SET_DIRTY();
});
pot->setAvailableHandler([=](int val) { return isPotTypeAvailable(val); });
new ToggleSwitch(
line, rect_t{}, [=]() -> uint8_t { return (uint8_t)getPotInversion(i); },
[=](int8_t newValue) {
setPotInversion(i, newValue);
SET_DIRTY();
});
}
}
@@ -130,7 +141,7 @@ class SwitchDynamicLabel : public StaticText
std::string label()
{
std::string str(switchGetName(index));
std::string str(switchGetCanonicalName(index));
return str + getSwitchPositionSymbol(lastpos);
}
@@ -159,18 +170,53 @@ class SwitchDynamicLabel : public StaticText
uint8_t lastpos = 0xff;
};
static void flex_channel_changed(lv_event_t* e)
{
auto target = lv_event_get_target(e);
auto channel = (Choice*)lv_obj_get_user_data(target);
auto sw_cfg = (Choice*)lv_event_get_user_data(e);
lv_obj_t* sw_cfg_obj = sw_cfg->getLvObj();
if (channel->getIntValue() < 0) {
lv_obj_add_flag(sw_cfg_obj, LV_OBJ_FLAG_HIDDEN);
sw_cfg->setValue(0);
} else {
lv_obj_clear_flag(sw_cfg_obj, LV_OBJ_FLAG_HIDDEN);
}
}
HWSwitches::HWSwitches(Window* parent) : FormWindow(parent, rect_t{})
{
FlexGridLayout grid(col_three_dsc, row_dsc, 2);
setFlexLayout();
for (int i = 0; i < switchGetMaxSwitches(); i++) {
auto max_switches = switchGetMaxSwitches();
for (int i = 0; i < max_switches; i++) {
auto line = newLine(&grid);
new SwitchDynamicLabel(line, i);
new HWInputEdit(line, (char*)switchGetCustomName(i), LEN_SWITCH_NAME);
new Choice(
line, rect_t{}, STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i),
auto box = new FormWindow(line, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4));
box->setWidth(lv_pct(45));
Choice* channel = nullptr;
if (switchIsFlex(i)) {
channel = new Choice(
box, rect_t{}, -1, adcGetMaxInputs(ADC_INPUT_FLEX) - 1,
[=]() -> int { return switchGetFlexConfig(i); },
[=](int newValue) { switchConfigFlex(i, newValue); });
channel->setAvailableHandler(
[=](int val) { return val < 0 || switchIsFlexInputAvailable(i, val); });
channel->setTextHandler([=](int val) -> std::string {
if (val < 0) return STR_NONE;
return adcGetInputLabel(ADC_INPUT_FLEX, val);
});
}
auto sw_cfg = new Choice(
box, rect_t{}, STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i),
[=]() -> int { return SWITCH_CONFIG(i); },
[=](int newValue) {
swconfig_t mask = (swconfig_t)SWITCH_CONFIG_MASK(i);
@@ -179,6 +225,12 @@ HWSwitches::HWSwitches(Window* parent) : FormWindow(parent, rect_t{})
((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * i));
SET_DIRTY();
});
if (channel) {
lv_obj_t* obj = channel->getLvObj();
lv_obj_add_event_cb(obj, flex_channel_changed, LV_EVENT_VALUE_CHANGED, sw_cfg);
lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
}
}
}
@@ -189,7 +241,11 @@ HWInputDialog<T>::HWInputDialog(const char* title) :
setCloseWhenClickOutside(true);
if (title) content->setTitle(title);
new T(&content->form);
#if LCD_W > LCD_H
content->setWidth(LCD_W * 0.8);
#else
content->setWidth(LCD_W * 0.95);
#endif
content->updateSize();
}
+1 -1
View File
@@ -38,7 +38,7 @@ MainViewSlider::MainViewSlider(Window* parent, const rect_t& rect,
void MainViewSlider::checkEvents()
{
Window::checkEvents();
auto pot_idx = adcGetInputOffset(ADC_INPUT_POT) + idx;
auto pot_idx = adcGetInputOffset(ADC_INPUT_FLEX) + idx;
int16_t newValue = calibratedAnalogs[pot_idx];
if (value != newValue) {
value = newValue;
+4 -4
View File
@@ -163,7 +163,7 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)
new SwitchWarnMatrix(line, rect_t{});
// Pots and sliders warning
if (adcGetMaxInputs(ADC_INPUT_POT) > 0) {
if (adcGetMaxInputs(ADC_INPUT_FLEX) > 0) {
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_POTWARNINGSTATE, 0, COLOR_THEME_PRIMARY1);
auto pots_wm = new Choice(line, rect_t{}, STR_PREFLIGHT_POTSLIDER_CHECK, 0, 2,
@@ -218,7 +218,7 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) :
uint8_t btn_id = 0;
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if (SWITCH_EXISTS(i)) {
setTextAndState(i);
setTextAndState(btn_id);
btn_id++;
}
}
@@ -332,7 +332,7 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) :
uint8_t btn_cnt = 0;
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
max_analogs = max_sticks + max_pots;
for (uint8_t i = 0; i < max_analogs; i++) {
@@ -373,7 +373,7 @@ void CenterBeepsMatrix::setTextAndState(uint8_t btn_id)
if (ana_idx[btn_id] < max_sticks)
setText(btn_id, getAnalogShortLabel(ana_idx[btn_id]));
else
setText(btn_id, getAnalogLabel(ADC_INPUT_POT, ana_idx[btn_id] - max_sticks));
setText(btn_id, getAnalogLabel(ADC_INPUT_FLEX, ana_idx[btn_id] - max_sticks));
setChecked(btn_id);
}
+9 -6
View File
@@ -70,11 +70,14 @@ class AnaViewWindow: public FormWindow {
{
char s[10];
auto pot_offset = adcGetInputOffset(ADC_INPUT_FLEX);
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++) {
if (i > adcGetMaxInputs(ADC_INPUT_MAIN) && !IS_POT_AVAILABLE(i - adcGetMaxInputs(ADC_INPUT_MAIN))) continue;
if (i >= pot_offset && (POT_CONFIG(i - pot_offset) == FLEX_NONE))
continue;
#if LCD_W > LCD_H
if ((i & 1) == 0)
line = newLine(grid);
@@ -316,7 +319,7 @@ class AnaFilteredDevViewWindow: public AnaViewWindow {
AnaViewWindow(parent)
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++)
stats[i].clear();
@@ -325,7 +328,7 @@ class AnaFilteredDevViewWindow: public AnaViewWindow {
void checkEvents() override
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++) {
stats[i].write(getAnalogValue(i));
@@ -419,7 +422,7 @@ class AnaMinMaxViewWindow: public AnaViewWindow {
AnaViewWindow(parent)
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++)
minmax[i].clear();
@@ -437,7 +440,7 @@ class AnaMinMaxViewWindow: public AnaViewWindow {
void checkEvents() override
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++) {
minmax[i].write(getAnalogValue(i));
+4 -17
View File
@@ -27,7 +27,6 @@
static const uint8_t _trimMap[MAX_TRIMS * 2] = {6, 7, 4, 5, 2, 3, 0, 1, 8, 9, 10, 11};
#if !defined(PCBNV14)
static EnumKeys get_ith_key(uint8_t i)
{
auto supported_keys = keysGetSupported();
@@ -41,7 +40,6 @@ static EnumKeys get_ith_key(uint8_t i)
// we assume: i < keysGetMaxKeys()
return (EnumKeys)0;
}
#endif
class RadioKeyDiagsWindow : public Window
{
@@ -96,38 +94,27 @@ class RadioKeyDiagsWindow : public Window
dc->drawText(TRIM_MINUS_COLUMN, 1, "-", COLOR_THEME_PRIMARY1);
dc->drawText(TRIM_PLUS_COLUMN, 1, "+", COLOR_THEME_PRIMARY1);
#if !defined(PCBNV14)
// KEYS
coord_t y = 1;
for (uint8_t i = 0; i < keysGetMaxKeys(); i++) {
auto k = get_ith_key(i);
y += FH;
dc->drawText(KEY_COLUMN, y, keysGetLabel(k), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, k);
y += FH;
}
#if defined(ROTARY_ENCODER_NAVIGATION)
#if defined(ROTARY_ENCODER_NAVIGATION) && !defined(USE_HATS_AS_KEYS)
y += FH;
dc->drawText(KEY_COLUMN, y, STR_ROTARY_ENCODER, COLOR_THEME_PRIMARY1);
dc->drawNumber(70, y, rotaryEncoderGetValue(), COLOR_THEME_PRIMARY1);
#endif
#else // defined(PCBNV14)
// KEYS
{
coord_t y = 1;
dc->drawText(KEY_COLUMN, y, keysGetLabel(KEY_ENTER), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, KEY_ENTER);
y += FH;
dc->drawText(KEY_COLUMN, y, keysGetLabel(KEY_EXIT), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, KEY_EXIT);
}
#endif
// SWITCHES
y = 1;
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
if (SWITCH_EXISTS(i)) {
coord_t y = 1 + FH * i;
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH + i);
getvalue_t sw = ((val < 0) ? 3 * i + 1 : ((val == 0) ? 3 * i + 2 : 3 * i + 3));
drawSwitch(dc, SWITCHES_COLUMN, y, sw, COLOR_THEME_PRIMARY1);
y +=FH;
}
}
@@ -145,7 +145,7 @@ void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Windo
sliders[2] = new MainViewHorizontalSlider(br, 2);
// TODO: check how many pots are configured instead
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
if (max_pots > 3) {
// create containers for the sliders, so that they are at the borders of the display
// on top of each other, when there are two sliders to display per side
+68 -28
View File
@@ -143,16 +143,16 @@ static void _init_menu_tab_array(uint8_t* tab, size_t len)
tab[i] = idx < max_sticks ? 0 : HIDDEN_ROW;
}
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
for (int i = ITEM_RADIO_HARDWARE_POT; i <= ITEM_RADIO_HARDWARE_POT_END; i++) {
uint8_t idx = i - ITEM_RADIO_HARDWARE_POT;
tab[i] = idx < max_pots ? 1 : HIDDEN_ROW;
tab[i] = idx < max_pots ? 2 : HIDDEN_ROW;
}
auto max_switches = switchGetMaxSwitches();
for (int i = ITEM_RADIO_HARDWARE_SWITCH; i <= ITEM_RADIO_HARDWARE_SWITCH_END; i++) {
uint8_t idx = i - ITEM_RADIO_HARDWARE_SWITCH;
tab[i] = idx < max_switches ? 1 : HIDDEN_ROW;
tab[i] = (idx < max_switches && idx < max_switches + MAX_FLEX_SWITCHES) ? 2 : idx < max_switches ? 1 : HIDDEN_ROW;
}
tab[ITEM_RADIO_HARDWARE_BATTERY_CALIB] = 0;
@@ -479,33 +479,38 @@ void menuRadioHardware(event_t event)
} else if (k <= ITEM_RADIO_HARDWARE_POT_END) {
// Pots & sliders
int idx = k - ITEM_RADIO_HARDWARE_POT;
uint8_t shift = (POT_CFG_BITS * idx);
potconfig_t mask = POT_CONFIG_MASK(idx);
// draw hw name
LcdFlags flags = menuHorizontalPosition < 0 ? attr : 0;
lcdDrawText(INDENT_WIDTH, y, STR_CHAR_POT, flags);
lcdDrawText(lcdNextPos, y, adcGetInputLabel(ADC_INPUT_POT, idx), flags);
lcdDrawText(lcdNextPos, y, adcGetInputLabel(ADC_INPUT_FLEX, idx), flags);
// draw custom name
if (analogHasCustomLabel(ADC_INPUT_POT, idx) ||
if (analogHasCustomLabel(ADC_INPUT_FLEX, idx) ||
(attr && s_editMode > 0 && menuHorizontalPosition == 0)) {
editName(HW_SETTINGS_COLUMN1, y,
(char*)analogGetCustomLabel(ADC_INPUT_POT, idx), LEN_ANA_NAME, event,
(char*)analogGetCustomLabel(ADC_INPUT_FLEX, idx), LEN_ANA_NAME, event,
attr && menuHorizontalPosition == 0, 0, old_editMode);
} else {
lcdDrawMMM(HW_SETTINGS_COLUMN1, y, menuHorizontalPosition==0 ? attr : 0);
}
// pot config
uint8_t potType = (g_eeGeneral.potsConfig & mask) >> shift;
uint8_t potType = getPotType(idx);
potType = editChoice(HW_SETTINGS_COLUMN2, y, "", STR_POTTYPES, potType,
POT_NONE, POT_SLIDER_WITH_DETENT,
FLEX_NONE, FLEX_SWITCH,
menuHorizontalPosition == 1 ? attr : 0, event);
g_eeGeneral.potsConfig &= ~mask;
g_eeGeneral.potsConfig |= (potType << shift);
if (checkIncDec_Ret) switchFixFlexConfig();
setPotType(idx, potType);
} else if (k <= ITEM_RADIO_HARDWARE_SWITCH_END) {
// ADC inversion
flags = menuHorizontalPosition == 2 ? attr : 0;
bool potinversion = getPotInversion(idx);
lcdDrawChar(LCD_W - 8, y, potinversion ? 127 : 126, flags);
if (flags & (~RIGHT)) potinversion = checkIncDec(event, potinversion, 0, 1, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL);
setPotInversion(idx, potinversion);
}
else if (k <= ITEM_RADIO_HARDWARE_SWITCH_END) {
// Switches
int index = k - ITEM_RADIO_HARDWARE_SWITCH;
int config = SWITCH_CONFIG(index);
@@ -514,24 +519,59 @@ void menuRadioHardware(event_t event)
lcdDrawText(INDENT_WIDTH, y, STR_CHAR_SWITCH, flags);
lcdDrawText(lcdNextPos, y, switchGetName(index), flags);
flags = menuHorizontalPosition == 0 ? attr : 0;
if (switchHasCustomName(index) ||
(attr && s_editMode > 0 && menuHorizontalPosition == 0)) {
editName(HW_SETTINGS_COLUMN1, y, (char*)switchGetCustomName(index),
LEN_SWITCH_NAME, event, flags, 0, old_editMode);
} else {
lcdDrawMMM(HW_SETTINGS_COLUMN1, y, flags);
if (switchIsFlex(index)) {
// flexSwitch source
flags = menuHorizontalPosition == 0 ? attr : 0;
auto source = switchGetFlexConfig(index);
lcdDrawText(HW_SETTINGS_COLUMN1, y, (source < 0) ? STR_NONE : adcGetInputLabel(ADC_INPUT_FLEX, source), flags);
if (flags & (~RIGHT)) source = checkIncDec(event, source, -1, adcGetMaxInputs(ADC_INPUT_FLEX) - 1, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL, isFlexSwitchSourceValid);
switchConfigFlex(index, source);
//Name
flags = menuHorizontalPosition == 1 ? attr : 0;
if (switchHasCustomName(index) ||
(attr && s_editMode > 0 && menuHorizontalPosition == 1)) {
editName(HW_SETTINGS_COLUMN2, y,
(char*)switchGetCustomName(index), LEN_SWITCH_NAME,
event, flags, 0, old_editMode);
} else {
lcdDrawMMM(HW_SETTINGS_COLUMN2, y, flags);
}
// Switch type
flags = menuHorizontalPosition == 2 ? attr : 0;
config = editChoice(HW_SETTINGS_COLUMN2 + 25, y, "", STR_SWTYPES, config,
SWITCH_NONE, switchGetMaxType(index), flags, event);
if (attr && checkIncDec_Ret) {
swconfig_t mask = SWITCH_CONFIG_MASK(index);
g_eeGeneral.switchConfig =
(g_eeGeneral.switchConfig & ~mask) |
((swconfig_t(config) & SW_CFG_MASK) << (SW_CFG_BITS * index));
}
}
else {
flags = menuHorizontalPosition == 0 ? attr : 0;
if (switchHasCustomName(index) ||
(attr && s_editMode > 0 && menuHorizontalPosition == 0)) {
editName(HW_SETTINGS_COLUMN1, y,
(char*)switchGetCustomName(index), LEN_SWITCH_NAME,
event, flags, 0, old_editMode);
} else {
lcdDrawMMM(HW_SETTINGS_COLUMN1, y, flags);
}
flags = menuHorizontalPosition == 1 ? attr : 0;
config = editChoice(HW_SETTINGS_COLUMN2, y, "", STR_SWTYPES, config,
SWITCH_NONE, switchGetMaxType(index), flags, event);
flags = menuHorizontalPosition == 1 ? attr : 0;
config =
editChoice(HW_SETTINGS_COLUMN2, y, "", STR_SWTYPES, config,
SWITCH_NONE, switchGetMaxType(index), flags, event);
if (attr && checkIncDec_Ret) {
swconfig_t mask = SWITCH_CONFIG_MASK(index);
g_eeGeneral.switchConfig =
(g_eeGeneral.switchConfig & ~mask) |
((swconfig_t(config) & SW_CFG_MASK) << (SW_CFG_BITS * index));
if (attr && checkIncDec_Ret) {
swconfig_t mask = SWITCH_CONFIG_MASK(index);
g_eeGeneral.switchConfig =
(g_eeGeneral.switchConfig & ~mask) |
((swconfig_t(config) & SW_CFG_MASK) << (SW_CFG_BITS * index));
}
}
} else if (k <= ITEM_RADIO_HARDWARE_SERIAL_PORT_END) {
auto port_nr = k - ITEM_RADIO_HARDWARE_SERIAL_PORT;
+55 -13
View File
@@ -198,11 +198,6 @@ bool isSourceAvailable(int source)
return IS_POT_SLIDER_AVAILABLE(source - MIXSRC_FIRST_POT);
}
#if MAX_AXIS > 0
if (source >= MIXSRC_FIRST_AXIS && source <= MIXSRC_LAST_AXIS)
return source - MIXSRC_FIRST_AXIS < adcGetMaxInputs(ADC_INPUT_AXIS);
#endif
#if defined(PCBHORUS) && !defined(SPACEMOUSE)
if (source >= MIXSRC_FIRST_SPACEMOUSE && source <= MIXSRC_LAST_SPACEMOUSE)
return false;
@@ -298,13 +293,6 @@ bool isSourceAvailableInInputs(int source)
if (source >= MIXSRC_FIRST_POT && source <= MIXSRC_LAST_POT)
return IS_POT_SLIDER_AVAILABLE(source - MIXSRC_FIRST_POT);
#if MAX_AXIS > 0
if (source >= MIXSRC_FIRST_AXIS && source <= MIXSRC_LAST_AXIS) {
auto idx = source - MIXSRC_FIRST_AXIS;
return idx < adcGetMaxInputs(ADC_INPUT_AXIS);
}
#endif
#if defined(IMU)
if (source == MIXSRC_TILT_X || source == MIXSRC_TILT_Y)
return true;
@@ -391,7 +379,7 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
if (swtch >= SWSRC_FIRST_MULTIPOS_SWITCH && swtch <= SWSRC_LAST_MULTIPOS_SWITCH) {
int index = (swtch - SWSRC_FIRST_MULTIPOS_SWITCH) / XPOTS_MULTIPOS_COUNT;
return (index < adcGetMaxInputs(ADC_INPUT_POT)) ? IS_POT_MULTIPOS(index) : false;
return (index < adcGetMaxInputs(ADC_INPUT_FLEX)) ? IS_POT_MULTIPOS(index) : false;
}
if (swtch >= SWSRC_FIRST_TRIM && swtch <= SWSRC_LAST_TRIM) {
@@ -1209,3 +1197,57 @@ uint8_t expandableSection(coord_t y, const char* title, uint8_t value, uint8_t a
return value;
}
#endif
bool isPotTypeAvailable(uint8_t type)
{
if (type == FLEX_SWITCH) {
if (MAX_FLEX_SWITCHES == 0)
return false;
auto availableFlexSwitch = MAX_FLEX_SWITCHES;
for (uint8_t i = 0; i < adcGetMaxInputs(ADC_INPUT_FLEX); i++) {
if (POT_CONFIG(i) == FLEX_SWITCH) availableFlexSwitch--;
if (availableFlexSwitch == 0) return false;
}
}
return true;
}
bool isFlexSwitchSourceValid(int source)
{
if (MAX_FLEX_SWITCHES == 0) return false;
// Allow NONE
if (source < 0) return true;
// already assigned ?
for (int i=0; i < MAX_FLEX_SWITCHES;i++) {
if (source == switchGetFlexConfig_raw(i))
return false;
}
if (POT_CONFIG(source) != FLEX_SWITCH) return false;
return true;
}
bool getPotInversion(int index)
{
return bfGet<potconfig_t>(g_eeGeneral.potsConfig, (POT_CFG_BITS * index) + POT_CFG_TYPE_BITS, POT_CFG_INV_BITS);
}
void setPotInversion(int index, bool value)
{
g_eeGeneral.potsConfig = bfSet<potconfig_t>(g_eeGeneral.potsConfig, value, (POT_CFG_BITS * index) + POT_CFG_TYPE_BITS, POT_CFG_INV_BITS);
}
uint8_t getPotType(int index)
{
return bfGet<potconfig_t>(g_eeGeneral.potsConfig, POT_CFG_BITS * index, POT_CFG_TYPE_BITS);
}
void setPotType(int index, int value)
{
g_eeGeneral.potsConfig = bfSet<potconfig_t>(g_eeGeneral.potsConfig, value, (POT_CFG_BITS * index), POT_CFG_TYPE_BITS);
}
+6
View File
@@ -99,6 +99,12 @@ bool isInternalModuleSupported(int moduleType);
bool isRfProtocolAvailable(int protocol);
bool isTrainerModeAvailable(int mode);
bool isAssignableFunctionAvailable(int function, CustomFunctionData * functions);
bool isPotTypeAvailable(uint8_t type);
bool isFlexSwitchSourceValid(int source);
bool getPotInversion(int index);
void setPotInversion(int index, bool value);
uint8_t getPotType(int index);
void setPotType(int index, int value);
bool isSensorUnit(int sensor, uint8_t unit);
bool isCellsSensor(int sensor);