refact: ADC, switches and keys

Add "hardware_defs" target to dump hardware defines from hal.h per target

Fixed hal.h definitions for switches & ADC inputs

Tools to generate hardware definitions from current hal.h

generator: add support for EXTx and analog switches

WiP

Add generated header to hardware_defs target

Add support for ADC input direction and index per GPIO port

Incredible: it compiles

Removed StdPeriph ADC driver

Works on QX7

Works on TX16S (VBat missing)

Switch driver using generated switches for stm32 targets

Switch driver with generated switches for simu

Use switch names from switch driver

Fixed single conversion handling

Fixed horus VBat reading

Added switch name

Fix warnings about bitfield offsets and GCC 4.4

This is caused by bitfields that cross type boundaries. In this particular case, it happens as the bitfield is not defined the same in `rtc_backup.cpp`.

Switches has already been moved to generic driver

Jitter measurement for each sample, not just for oversampled values

Moved periph clock init to the ADC driver

ADC & GPIOs.

Add switchInit() to init pins

Fix NV14 CMake

Fix taranis target

Fix NV14 (again)

Model audio files: use new interface for switch index

Fix X9-lite

Fix simu headers

Fix getSwitchName()

Add support for ADC switches

Fix switch warning YAML

Test only switches which are defined

Conversions tests for QX7 only on QX7

Fix X12S

Fix function switch names

Enable ADC periph clock before initialising channels

NV14: offset inputs for the sticks & fix switches

WiP: get rid of VSRCRAW and some more

Simu shall use normal ADC driver

fix x7

fix nv14

Fix 9x nav

fix 212x64

fix xlite

fix x9e

fix simu lib

fix unit tests

fix x7 tests

PWM stick values should be written directly into adcValues

... just like FlySky sticks.

fix x12s

fix nv14

Add some support for SPI ADC (only unit tests)

Remove `jq` usage

fix generate_yaml.py for newer libclang

fix pot config

fix stick names

Some YAML generator improvements

Max 16 Pots on COLORLCD

Fix some source names

Use 10 bits for switches to prevent overflow

Removed horus constants for switches & ADC inputs

Fix unit tests

Fix curve edit

Fix libsimulator

Fix function switches (tpro)

Refine ADC & analog API

Moved hardware definitions scripts and templates into own dir

cleanup API refine

Fix unit tests

Mixer: apply calibration only on required inputs

Place ADC switches after all other ADC inputs

Fix X12S

Remove useless TR_POTS_VSRCRAW, TR_SW_VSRCRAW, and TR_VSRCRAW

Cleanup redundant generated YAML parsers

Fixes Boxer rebase

Add boxer to generate-hw-defs.sh

Obsolete LUA exports

Add boxer ADC_DIRECTION

Split generate_hw_defs.py into multiple files

Some cleanup (+ LUA switches)

Fix AXIS definitions

Fixed translation strings declarations

Some rebase fixes

Remove some useless StdPeriph drivers

fix: set pin mode to reset state on usart deinit

fix: use canonical names for calibration data

fix: ADC driver does not care about unconfigured inputs

fix X12S ADC

Add support for ADC conversion chaining

Better X12S ADC implem

Moved X12S ADC driver to HAL/LL

Improve ADC driver separation

Fixed taranis & nv14

Moved PWM gimbals to HAL/LL

Removed useless TR_EXTRA_VSRCRAW

Fixed include guards

Small fixes

Renamed control inputs

Moved internal and external module pulse driver def to boards

Move more things to the generic_stm32 board

Remove STR_VMIXTRIMS

Added analog labels

Generate main control names

Misuse labels / short labels for main controls

Backward compatibility: sliders and legacy names

New keys driver

Let's get rid of StdPeriph headers in simu

Add jinja2 to CI workflows

Use `grep` instead of `sed`

chore: add python jinja2 oto msys setup script

Removed more static definitions and use dynamic ones instead

Fixes X9E

Fix x7 nav too

212 switch display

Fix default sliders

Removed NUM_STICKS

212 switch display working nicely

Surface radio 'stick' replacements

fix: switch, trim & rotary pin init

Remove old key drivers

Removed VKEYS

Removed ETX_FOURCC

Fixed SURFACE_NAME

Removed TR_VSWITCHES & TR_TRIMS_SWITCHES

Fix xpot switches

Store calibrated analogs in physical order

Use getSourceString in drawSource

Implement missing YAML read/write

Fix isSourceAvailableInInputs()

Fix isSourceAvailable()

Some surface fixes

Fix CLI debug

Ported colour UI of analog diagnostics to new ADC API

Small fixes

Better input mapping

Minor tpro fixes

Fix trims available

Remove TX mode choice on surface radio

Rename surface controls

Channel order alignement

Fix throttle warning

Fix checkTrims()

Fix pot config casting issue

Fix IS_SWITCH_FS()

Fixed input mapping

Fix fswitch auto-switch

Fixed storing / reading function switches in YAML

Fix enableVBatBridge() / disableVBatBridge()

Fix interesting mode conversion

Fix sources issues

Fix special funnction list

Proper function switch handling

128 GUI improvements

Fix compilation

Boxer cosmetics

128 hardware screen cosmetic

Fix TX12 switches

More switches fixes

Simplify CPU type handling

Fix flash size

Fixed page-up / page-down in libopenui
This commit is contained in:
Raphael Coeffic
2023-06-25 14:32:39 +02:00
committed by Malte Langermann
parent b6dd3a0ef8
commit 2b100e0eb5
323 changed files with 12812 additions and 22301 deletions
+10 -11
View File
@@ -20,6 +20,7 @@
*/
#include "opentx.h"
#include "hal/rotary_encoder.h"
#include "LvglWrapper.h"
#include "themes/etx_lv_theme.h"
@@ -120,16 +121,17 @@ static void keyboardDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
data->key = 0;
if (isEvent()) { // event waiting
event_t evt = getEvent(false); // get keyEvent for hard keys other than trim switches
if (isEvent()) { // event waiting
event_t evt = getEvent();
if(evt == EVT_KEY_FIRST(KEY_PGUP) || // generate acoustic/haptic feedback if radio settings allow
evt == EVT_KEY_FIRST(KEY_PGDN) ||
if(evt == EVT_KEY_FIRST(KEY_PAGEUP) ||
evt == EVT_KEY_FIRST(KEY_PAGEDN) ||
evt == EVT_KEY_FIRST(KEY_ENTER) ||
evt == EVT_KEY_FIRST(KEY_MODEL) ||
evt == EVT_KEY_FIRST(KEY_EXIT) ||
evt == EVT_KEY_FIRST(KEY_TELEM) ||
evt == EVT_KEY_FIRST(KEY_RADIO)) {
evt == EVT_KEY_FIRST(KEY_TELE) ||
evt == EVT_KEY_FIRST(KEY_SYS)) {
// generate acoustic/haptic feedback if radio settings allow
audioKeyPress();
}
@@ -244,7 +246,7 @@ static void rotaryDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
static int8_t prevDir = 0;
static uint32_t lastDt = 0;
rotenc_t newPos = ROTARY_ENCODER_NAVIGATION_VALUE;
rotenc_t newPos = rotaryEncoderGetRawValue();
rotenc_t diff = (newPos - prevPos) / ROTARY_ENCODER_GRANULARITY;
prevPos += diff * ROTARY_ENCODER_GRANULARITY;
@@ -270,9 +272,6 @@ static void rotaryDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
_rotary_enc_accel = 0;
}
// For Lua getRotEncSpeed() function
rotencSpeed = max(_rotary_enc_accel, (int8_t)1);
prevDir = dir;
lastDt = rotencDt;
}
@@ -299,7 +298,7 @@ uint32_t makeLvColor32(uint32_t colorFlags)
std::string makeRecolor(std::string value, uint32_t colorFlags)
{
char s[32];
snprintf(s, 32, "#%06x %s#", makeLvColor32(colorFlags), value.c_str());
snprintf(s, 32, "#%06" PRIx32 " %s#", makeLvColor32(colorFlags), value.c_str());
return std::string(s);
}
+2 -1
View File
@@ -346,7 +346,8 @@ void CurveEdit::checkEvents()
if (!lockSource) {
int16_t val = getMovedSource(MIXSRC_FIRST_INPUT);
if (val > 0) {
if (val > NUM_STICKS + NUM_POTS + NUM_SLIDERS)
// TODO: this code seems odd
if (val > MAX_STICKS + MAX_POTS)
CurveEdit::currentSource = val + 1 - MIXSRC_FIRST_INPUT;
else {
CurveEdit::currentSource = expoAddress(val - 1)->srcRaw;
+1 -1
View File
@@ -239,7 +239,7 @@ FailSafePage::FailSafePage(uint8_t moduleIdx) :
// Channel name
auto line = form->newLine(&grid);
const char* ch_label = getSourceString(MIXSRC_CH1 + ch);
const char* ch_label = getSourceString(MIXSRC_FIRST_CH + ch);
new StaticText(line, rect_t{}, ch_label, 0, COLOR_THEME_PRIMARY1);
// Channel value
+2 -5
View File
@@ -24,6 +24,8 @@
#include "theme_manager.h"
#include "libopenui.h"
#include "watchdog_driver.h"
coord_t drawStringWithIndex(BitmapBuffer * dc, coord_t x, coord_t y, const char * str, int idx, LcdFlags flags, const char * prefix, const char * suffix)
{
char s[64];
@@ -237,11 +239,6 @@ void drawCurveRef(BitmapBuffer * dc, coord_t x, coord_t y, const CurveRef & curv
}
}
void drawStickName(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t idx, LcdFlags att)
{
dc->drawText(x, y, STR_VSRCRAW[idx]+1, att);
}
void drawModelName(BitmapBuffer * dc, coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att)
{
uint8_t len = sizeof(g_model.header.name);
+1 -1
View File
@@ -81,7 +81,7 @@ void drawHexNumber(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t val, LcdFla
void drawTextLines(BitmapBuffer * dc, coord_t left, coord_t top, coord_t width, coord_t height, const char * str, LcdFlags flags);
inline void drawChn(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t idx, LcdFlags flags)
{
drawSource(dc, x, y, MIXSRC_CH1 + idx - 1, flags);
drawSource(dc, x, y, MIXSRC_FIRST_CH + idx - 1, flags);
}
// Screen templates
@@ -25,6 +25,8 @@
#include "opentx.h"
#include "libopenui.h"
#include "watchdog_driver.h"
static Window* _get_parent()
{
Window* p = Layer::back();
+34 -67
View File
@@ -22,6 +22,11 @@
#include "hw_inputs.h"
#include "opentx.h"
#include "hal/adc_driver.h"
#include "hal/switch_driver.h"
#include "analogs.h"
#include "switches.h"
#define SET_DIRTY() storageDirty(EE_GENERAL)
struct HWInputEdit : public RadioTextEdit {
@@ -42,10 +47,13 @@ HWSticks::HWSticks(Window* parent) : FormGroup(parent, rect_t{})
FlexGridLayout grid(col_two_dsc, row_dsc, 2);
setFlexLayout();
for (int i = 0; i < NUM_STICKS; i++) {
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
for (int i = 0; i < max_sticks; i++) {
auto line = newLine(&grid);
new StaticText(line, rect_t{}, STR_VSRCRAW[i + 1], 0, COLOR_THEME_PRIMARY1);
new HWInputEdit(line, g_eeGeneral.anaNames[i], LEN_ANA_NAME);
new StaticText(line, rect_t{}, analogGetCanonicalName(ADC_INPUT_MAIN, i),
0, COLOR_THEME_PRIMARY1);
new HWInputEdit(line, (char*)analogGetCustomLabel(ADC_INPUT_MAIN, i),
LEN_ANA_NAME);
}
#if defined(STICK_DEAD_ZONE)
@@ -64,13 +72,17 @@ HWPots::HWPots(Window* parent) : FormGroup(parent, rect_t{})
FlexGridLayout grid(col_two_dsc, row_dsc, 2);
setFlexLayout();
for (int i = 0; i < NUM_POTS; i++) {
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
for (int i = 0; i < max_pots; i++) {
// TODO: check initialised ADC inputs instead!
// Display EX3 & EX4 (= last two pots) only when FlySky gimbals are present
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
#endif
// TODO: use input disabled mask instead
// #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{}, STR_VSRCRAW[i + NUM_STICKS + 1], 0,
new StaticText(line, rect_t{}, analogGetCanonicalName(ADC_INPUT_POT, i), 0,
COLOR_THEME_PRIMARY1);
auto box = new FormGroup(line, rect_t{});
@@ -79,56 +91,21 @@ HWPots::HWPots(Window* parent) : FormGroup(parent, rect_t{})
auto box_obj = box->getLvObj();
lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0);
new HWInputEdit(box, g_eeGeneral.anaNames[i + NUM_STICKS], LEN_ANA_NAME);
new HWInputEdit(box, (char*)analogGetCustomLabel(ADC_INPUT_POT, i), LEN_ANA_NAME);
new Choice(
box, rect_t{}, STR_POTTYPES, POT_NONE, POT_WITHOUT_DETENT,
box, rect_t{}, STR_POTTYPES, POT_NONE, POT_SLIDER_WITH_DETENT,
[=]() -> int {
return bfGet<uint32_t>(g_eeGeneral.potsConfig, 2 * i, 2);
return bfGet<potconfig_t>(g_eeGeneral.potsConfig, POT_CFG_BITS * i,
POT_CFG_BITS);
},
[=](int newValue) {
g_eeGeneral.potsConfig =
bfSet<uint32_t>(g_eeGeneral.potsConfig, newValue, 2 * i, 2);
g_eeGeneral.potsConfig = bfSet<potconfig_t>(
g_eeGeneral.potsConfig, newValue, POT_CFG_BITS * i, POT_CFG_BITS);
SET_DIRTY();
});
}
}
HWSliders::HWSliders(Window* parent) : FormGroup(parent, rect_t{})
{
FlexGridLayout grid(col_two_dsc, row_dsc, 2);
setFlexLayout();
#if (NUM_SLIDERS > 0)
for (int i = 0; i < NUM_SLIDERS; i++) {
const int idx = i + NUM_STICKS + NUM_POTS;
auto line = newLine(&grid);
new StaticText(line, rect_t{}, STR_VSRCRAW[idx + 1], 0,
COLOR_THEME_PRIMARY1);
auto box = new FormGroup(line, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4));
auto box_obj = box->getLvObj();
lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0);
new HWInputEdit(box, g_eeGeneral.anaNames[idx], LEN_ANA_NAME);
new Choice(
box, rect_t{}, STR_SLIDERTYPES, SLIDER_NONE, SLIDER_WITH_DETENT,
[=]() -> int {
uint8_t mask = (0x01 << i);
return (g_eeGeneral.slidersConfig & mask) >> i;
},
[=](int newValue) {
uint8_t mask = (0x01 << i);
g_eeGeneral.slidersConfig &= ~mask;
g_eeGeneral.slidersConfig |= (newValue << i);
SET_DIRTY();
});
}
#endif
}
class SwitchDynamicLabel : public StaticText
{
public:
@@ -141,7 +118,7 @@ class SwitchDynamicLabel : public StaticText
std::string label()
{
std::string str(STR_VSRCRAW[index + MIXSRC_FIRST_SWITCH - MIXSRC_Rud + 1]);
std::string str(switchGetName(index));
return str + getSwitchPositionSymbol(lastpos);
}
@@ -170,22 +147,12 @@ class SwitchDynamicLabel : public StaticText
uint8_t lastpos = 0xff;
};
#if defined(PCBHORUS)
#define SWITCH_TYPE_MAX(sw) \
((MIXSRC_SF - MIXSRC_FIRST_SWITCH == sw || \
MIXSRC_SH - MIXSRC_FIRST_SWITCH == sw) \
? SWITCH_2POS \
: SWITCH_3POS)
#else
#define SWITCH_TYPE_MAX(sw) (SWITCH_3POS)
#endif
HWSwitches::HWSwitches(Window* parent) : FormGroup(parent, rect_t{})
{
FlexGridLayout grid(col_two_dsc, row_dsc, 2);
setFlexLayout();
for (int i = 0; i < NUM_SWITCHES; i++) {
for (int i = 0; i < switchGetMaxSwitches(); i++) {
auto line = newLine(&grid);
new SwitchDynamicLabel(line, i);
@@ -195,14 +162,15 @@ HWSwitches::HWSwitches(Window* parent) : FormGroup(parent, rect_t{})
auto box_obj = box->getLvObj();
lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0);
new HWInputEdit(box, g_eeGeneral.switchNames[i], LEN_SWITCH_NAME);
new HWInputEdit(box, (char*)switchGetCustomName(i), LEN_SWITCH_NAME);
new Choice(
box, rect_t{}, STR_SWTYPES, SWITCH_NONE, SWITCH_TYPE_MAX(i),
box, rect_t{}, STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i),
[=]() -> int { return SWITCH_CONFIG(i); },
[=](int newValue) {
swconfig_t mask = (swconfig_t)0x03 << (2 * i);
g_eeGeneral.switchConfig = (g_eeGeneral.switchConfig & ~mask) |
((swconfig_t(newValue) & 0x03) << (2 * i));
swconfig_t mask = (swconfig_t)SWITCH_CONFIG_MASK(i);
g_eeGeneral.switchConfig =
(g_eeGeneral.switchConfig & ~mask) |
((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * i));
SET_DIRTY();
});
}
@@ -221,5 +189,4 @@ HWInputDialog<T>::HWInputDialog(const char* title) :
template struct HWInputDialog<HWSticks>;
template struct HWInputDialog<HWPots>;
template struct HWInputDialog<HWSliders>;
template struct HWInputDialog<HWSwitches>;
-3
View File
@@ -33,9 +33,6 @@ struct HWPots : public FormGroup {
HWPots(Window* parent);
};
struct HWSliders : public FormGroup {
HWSliders(Window* parent);
};
struct HWSwitches : public FormGroup {
HWSwitches(Window* parent);
+9 -4
View File
@@ -59,11 +59,16 @@ InputEditAdvanced::InputEditAdvanced(uint8_t input_n, uint8_t index) :
// Trim
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_TRIM, 0, COLOR_THEME_PRIMARY1);
auto c = new Choice(line, rect_t{}, STR_VMIXTRIMS, -TRIM_OFF,
-TRIM_LAST, GET_VALUE(-input->trimSource),
SET_VALUE(input->trimSource, -newValue));
auto c = new Choice(line, rect_t{}, -TRIM_OFF, -TRIM_LAST,
GET_VALUE(-input->trimSource),
SET_VALUE(input->trimSource, -newValue));
uint16_t srcRaw = input->srcRaw;
c->setAvailableHandler([=](int value) {
return value != TRIM_ON || input->srcRaw <= MIXSRC_Ail;
return value != TRIM_ON || srcRaw <= MIXSRC_LAST_STICK;
});
c->setTextHandler([=](int value) -> std::string {
return getTrimSourceLabel(srcRaw, -value);
});
// Flight modes
+2 -2
View File
@@ -55,9 +55,9 @@ InputMixGroup::InputMixGroup(Window* parent, mixsrc_t idx) :
lv_obj_t* chText = nullptr;
if (idx >= MIXSRC_FIRST_CH && idx <= MIXSRC_LAST_CH
&& g_model.limitData[idx - MIXSRC_CH1].name[0] != '\0') {
&& g_model.limitData[idx - MIXSRC_FIRST_CH].name[0] != '\0') {
chText = lv_label_create(lvobj);
lv_label_set_text_fmt(chText, TR_CH "%zu", (size_t)(idx - MIXSRC_CH1 + 1));
lv_label_set_text_fmt(chText, TR_CH "%zu", (size_t)(idx - MIXSRC_FIRST_CH + 1));
lv_obj_set_style_text_font(chText, getFont(FONT(XS)), 0);
#if LCD_H > LCD_W
lv_obj_set_style_pad_bottom(chText, -2, 0);
+1 -19
View File
@@ -32,24 +32,6 @@ class SensorValue : public StaticText
{
}
// void paint(BitmapBuffer *dc) override
// {
// if (isTelemetryValue()) {
// uint8_t sensorIndex = (input->srcRaw - MIXSRC_FIRST_TELEM) / 3;
// #if defined(SIMU)
// if (true) {
// #else
// TelemetryItem &telemetryItem = telemetryItems[sensorIndex];
// if (telemetryItem.isAvailable()) {
// #endif
// LcdFlags flags = LEFT | COLOR_THEME_PRIMARY1;
// drawSensorCustomValue(dc, 3, 2, sensorIndex, lastSensorVal, flags);
// } else {
// dc->drawText(3, 2, "---", COLOR_THEME_PRIMARY1);
// }
// }
// }
bool isTelemetryValue()
{
return input->srcRaw >= MIXSRC_FIRST_TELEM &&
@@ -143,7 +125,7 @@ InputSource::InputSource(Window* parent, ExpoData* input) :
void InputSource::update()
{
if (input->srcRaw > MIXSRC_Ail && input->trimSource == TRIM_ON) {
if (input->srcRaw > MIXSRC_LAST_STICK && input->trimSource == TRIM_ON) {
input->trimSource = TRIM_OFF;
}
+23 -7
View File
@@ -21,6 +21,9 @@
#include "sliders.h"
#include "opentx.h"
#include "switches.h"
#include "hal/adc_driver.h"
enum slider_type {
SLIDER_HORIZ,
@@ -43,6 +46,23 @@ static void slider_self_size(lv_event_t* e)
}
}
MainViewSlider::MainViewSlider(Window* parent, const rect_t& rect,
uint8_t idx) :
Window(parent, rect), idx(idx)
{
}
void MainViewSlider::checkEvents()
{
Window::checkEvents();
auto pot_idx = adcGetInputOffset(ADC_INPUT_POT) + idx;
int16_t newValue = calibratedAnalogs[pot_idx];
if (value != newValue) {
value = newValue;
invalidate();
}
}
MainViewHorizontalSlider::MainViewHorizontalSlider(Window* parent,
uint8_t idx) :
MainViewSlider(parent, rect_t{}, idx)
@@ -86,7 +106,6 @@ MainView6POS::MainView6POS(Window* parent, uint8_t idx) :
void MainView6POS::paint(BitmapBuffer * dc)
{
#if NUM_XPOTS > 0 // prevent compiler warning
coord_t x = MULTIPOS_W_SPACING/4;
for (uint8_t value = 0; value < XPOTS_MULTIPOS_COUNT; value++) {
dc->drawNumber(x+TRIM_SQUARE_SIZE/4, 0, value+1, FONT(XS) | COLOR_THEME_SECONDARY1);
@@ -94,23 +113,20 @@ void MainView6POS::paint(BitmapBuffer * dc)
}
// The square
value = (potsPos[idx] & 0x0f);
x = MULTIPOS_W_SPACING/4+MULTIPOS_W_SPACING*value;
value = getXPotPosition(idx);
x = MULTIPOS_W_SPACING / 4 + MULTIPOS_W_SPACING * value;
drawTrimSquare(dc, x, 0, COLOR_THEME_FOCUS);
dc->drawNumber(x+MULTIPOS_W_SPACING/4, -2, value+1, FONT(BOLD) | COLOR_THEME_PRIMARY2);
#endif
}
void MainView6POS::checkEvents()
{
Window::checkEvents();
#if NUM_XPOTS > 0 // prevent compiler warning
int16_t newValue = (potsPos[idx] & 0x0f);
int16_t newValue = getXPotPosition(idx);
if (value != newValue) {
value = newValue;
invalidate();
}
#endif
}
MainViewVerticalSlider::MainViewVerticalSlider(Window* parent, uint8_t idx) :
+10 -23
View File
@@ -38,34 +38,21 @@ constexpr coord_t VERTICAL_SLIDERS_HEIGHT = SLIDER_TICKS_COUNT * 4 + TRIM_SQUARE
class MainViewSlider : public Window
{
public:
MainViewSlider(Window * parent, const rect_t & rect, uint8_t idx):
Window(parent, rect),
idx(idx)
{
}
public:
MainViewSlider(Window* parent, const rect_t& rect, uint8_t idx);
void checkEvents() override;
void checkEvents() override
{
Window::checkEvents();
int16_t newValue = calibratedAnalogs[idx];
if (value != newValue) {
value = newValue;
invalidate();
}
}
protected:
uint8_t idx;
int16_t value = 0;
protected:
uint8_t idx;
int16_t value = 0;
};
class MainViewHorizontalSlider : public MainViewSlider
{
public:
using MainViewSlider::MainViewSlider;
MainViewHorizontalSlider(Window* parent, uint8_t idx);
void paint(BitmapBuffer * dc) override;
public:
using MainViewSlider::MainViewSlider;
MainViewHorizontalSlider(Window* parent, uint8_t idx);
void paint(BitmapBuffer* dc) override;
};
class MainView6POS : public MainViewSlider
+2 -1
View File
@@ -21,6 +21,7 @@
#include "trims.h"
#include "sliders.h"
#include "input_mapping.h"
#include "opentx.h"
@@ -67,7 +68,7 @@ void MainViewTrim::setRange()
void MainViewTrim::checkEvents()
{
Window::checkEvents();
int8_t stickIndex = CONVERT_MODE(idx);
int8_t stickIndex = inputMappingConvertMode(idx);
int newValue = getTrimValue(mixerCurrentFlightMode, stickIndex);
setRange();
+1 -1
View File
@@ -72,7 +72,7 @@ MixEditWindow::MixEditWindow(int8_t channel, uint8_t index) :
void MixEditWindow::buildHeader(Window *window)
{
std::string title2(getSourceString(MIXSRC_CH1 + channel));
std::string title2(getSourceString(MIXSRC_FIRST_CH + channel));
header.setTitle(STR_MIXES);
header.setTitle2(title2);
+1 -1
View File
@@ -32,7 +32,7 @@ MixEditAdvanced::MixEditAdvanced(int8_t channel, uint8_t index) :
{
std::string title(STR_MIXES);
title += "\n";
title += getSourceString(MIXSRC_CH1 + channel);
title += getSourceString(MIXSRC_FIRST_CH + channel);
header.setTitle(title);
auto form = new FormWindow(&body, rect_t{});
+12 -11
View File
@@ -23,6 +23,7 @@
#include "opentx.h"
#include "libopenui.h"
#include "lvgl_widgets/input_mix_line.h"
#include "hal/key_driver.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
@@ -107,7 +108,7 @@ class FlightModeEdit : public Page
FlexGridLayout trim_grid(trims_col_dsc, line_row_dsc);
for (int t = 0; t < NUM_TRIMS; t++) {
for (int t = 0; t < MAX_TRIMS; t++) {
lastTrim[t] = p_fm->trim[t].value;
if ((t % TRIMS_PER_LINE) == 0) {
@@ -160,7 +161,7 @@ class FlightModeEdit : public Page
void checkEvents() override
{
for (int i = 0; i < NUM_TRIMS; i += 1) {
for (int i = 0; i < keysGetMaxTrims(); i += 1) {
const auto& fm = g_model.flightModeData[index];
if (lastTrim[i] != fm.trim[i].value) {
lastTrim[i] = fm.trim[i].value;
@@ -171,9 +172,9 @@ class FlightModeEdit : public Page
protected:
uint8_t index;
Choice* tr_mode[NUM_TRIMS] = {nullptr};
NumberEdit* tr_value[NUM_TRIMS] = {nullptr};
int lastTrim[NUM_TRIMS];
Choice* tr_mode[MAX_TRIMS] = {nullptr};
NumberEdit* tr_value[MAX_TRIMS] = {nullptr};
int lastTrim[MAX_TRIMS];
void showControls(int trim, uint8_t mode)
{
@@ -413,7 +414,7 @@ class FlightModeBtn : public Button
lv_obj_t* trims_cont = fmStyle.newTrimCont(container);
lv_obj_set_user_data(trims_cont, this);
for (int i = 0; i < NUM_TRIMS; i += 1) {
for (int i = 0; i < keysGetMaxTrims(); i += 1) {
fmTrimMode[i] = fmStyle.newTrimMode(trims_cont, i);
fmTrimValue[i] = fmStyle.newTrimValue(trims_cont, i);
}
@@ -446,7 +447,7 @@ class FlightModeBtn : public Button
if (!refreshing && init) {
refreshing = true;
const auto& fm = g_model.flightModeData[index];
for (int t = 0; t < NUM_TRIMS; t += 1) {
for (int t = 0; t < keysGetMaxTrims(); t += 1) {
if (lastTrim[t] != fm.trim[t].value) {
lastTrim[t] = fm.trim[t].value;
@@ -485,7 +486,7 @@ class FlightModeBtn : public Button
lv_label_set_text(fmSwitch, "");
}
for (int i = 0; i < NUM_TRIMS; i += 1) {
for (int i = 0; i < keysGetMaxTrims(); i += 1) {
uint8_t mode = fm.trim[i].mode;
bool checked = (mode != TRIM_MODE_NONE);
bool showValue = (index == 0) || ((mode & 1) || (mode >> 1 == index));
@@ -510,11 +511,11 @@ class FlightModeBtn : public Button
lv_obj_t* fmID = nullptr;
lv_obj_t* fmName = nullptr;
lv_obj_t* fmSwitch = nullptr;
lv_obj_t* fmTrimMode[NUM_TRIMS] = {nullptr};
lv_obj_t* fmTrimValue[NUM_TRIMS] = {nullptr};
lv_obj_t* fmTrimMode[MAX_TRIMS] = {nullptr};
lv_obj_t* fmTrimValue[MAX_TRIMS] = {nullptr};
lv_obj_t* fmFadeIn = nullptr;
lv_obj_t* fmFadeOut = nullptr;
int lastTrim[NUM_TRIMS];
int lastTrim[MAX_TRIMS];
};
ModelFlightModesPage::ModelFlightModesPage():
+8 -1
View File
@@ -28,8 +28,11 @@
#include "input_edit.h"
#include "input_mix_group.h"
#include "input_mix_button.h"
#include "input_mapping.h"
#include "tasks/mixer_task.h"
#include "hal/adc_driver.h"
#include <algorithm>
#define SET_DIRTY() storageDirty(EE_MODEL)
@@ -90,7 +93,11 @@ void insertExpo(uint8_t idx, uint8_t input)
ExpoData * expo = expoAddress(idx);
memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
memclear(expo, sizeof(ExpoData));
expo->srcRaw = (input >= 4 ? MIXSRC_Rud + input : MIXSRC_Rud + channelOrder(input + 1) - 1);
if (input >= adcGetMaxInputs(ADC_INPUT_MAIN)) {
expo->srcRaw = MIXSRC_FIRST_STICK + input;
} else {
expo->srcRaw = MIXSRC_FIRST_STICK + inputMappingChannelOrder(input);
}
expo->curve.type = CURVE_REF_EXPO;
expo->mode = 3; // pos+neg
expo->chn = input;
@@ -72,7 +72,8 @@ class LogicalSwitchEditPage : public Page
void buildHeader(Window* window)
{
header.setTitle(STR_MENULOGICALSWITCHES);
headerSwitchName = header.setTitle2(getSwitchPositionName(SWSRC_SW1 + index));
headerSwitchName = header.setTitle2(
getSwitchPositionName(SWSRC_FIRST_LOGICAL_SWITCH + index));
lv_obj_set_style_text_color(headerSwitchName->getLvObj(),
makeLvColor(COLOR_THEME_ACTIVE),
@@ -413,7 +414,7 @@ class LogicalSwitchButton : public Button
LogicalSwitchData* ls = lswAddress(lsIndex);
uint8_t lsFamily = lswFamily(ls->func);
lv_label_set_text(lsName, getSwitchPositionName(SWSRC_SW1 + lsIndex));
lv_label_set_text(lsName, getSwitchPositionName(SWSRC_FIRST_LOGICAL_SWITCH + lsIndex));
lv_label_set_text(lsFunc, STR_VCSWFUNC[ls->func]);
// CSW params - V1
@@ -528,7 +529,7 @@ void ModelLogicalSwitchesPage::newLS(FormWindow* window, bool pasteLS)
for (uint8_t i = 0; i < MAX_LOGICAL_SWITCHES; i++) {
LogicalSwitchData* ls = lswAddress(i);
if (ls->func == LS_FUNC_NONE) {
std::string ch_name(getSwitchPositionName(SWSRC_SW1 + i));
std::string ch_name(getSwitchPositionName(SWSRC_FIRST_LOGICAL_SWITCH + i));
menu->addLineBuffered(ch_name.c_str(), [=]() {
if (pasteLS) {
*ls = clipboard.data.csw;
+15 -10
View File
@@ -30,8 +30,10 @@
#include "input_mix_group.h"
#include "input_mix_button.h"
#include "mixer_edit.h"
#include "input_mapping.h"
#include "tasks/mixer_task.h"
#include "hal/adc_driver.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
#define PASTE_BEFORE -2
@@ -75,8 +77,11 @@ void insertMix(uint8_t idx, uint8_t channel)
mix->destCh = channel;
mix->srcRaw = channel + 1;
if (!isSourceAvailable(mix->srcRaw)) {
mix->srcRaw = (channel > 3 ? MIXSRC_Rud - 1 + channel
: MIXSRC_Rud - 1 + channelOrder(channel));
if (channel >= adcGetMaxInputs(ADC_INPUT_MAIN)) {
mix->srcRaw = MIXSRC_FIRST_STICK + channel;
} else {
mix->srcRaw = MIXSRC_FIRST_STICK + inputMappingChannelOrder(channel);
}
while (!isSourceAvailable(mix->srcRaw)) {
mix->srcRaw += 1;
}
@@ -320,13 +325,13 @@ InputMixGroup* ModelMixesPage::getGroupByIndex(uint8_t index)
if (is_memclear(mix, sizeof(MixData))) return nullptr;
int ch = mix->destCh;
return getGroupBySrc(MIXSRC_CH1 + ch);
return getGroupBySrc(MIXSRC_FIRST_CH + ch);
}
InputMixGroup* ModelMixesPage::createGroup(FormWindow* form, mixsrc_t src)
{
auto group = new InputMixGroup(form, src);
if (showMonitors) group->enableMixerMonitor(src - MIXSRC_CH1);
if (showMonitors) group->enableMixerMonitor(src - MIXSRC_FIRST_CH);
return group;
}
@@ -338,7 +343,7 @@ InputMixButton* ModelMixesPage::createLineButton(InputMixGroup *group, uint8_t i
lines.emplace_back(button);
group->addLine(button);
uint8_t ch = group->getMixSrc() - MIXSRC_CH1;
uint8_t ch = group->getMixSrc() - MIXSRC_FIRST_CH;
button->setPressHandler([=]() -> uint8_t {
Menu *menu = new Menu(form);
menu->addLine(STR_EDIT, [=]() {
@@ -394,7 +399,7 @@ void ModelMixesPage::addLineButton(uint8_t index)
if (is_memclear(mix, sizeof(MixData))) return;
int channel = mix->destCh;
addLineButton(MIXSRC_CH1 + channel, index);
addLineButton(MIXSRC_FIRST_CH + channel, index);
}
void ModelMixesPage::newMix()
@@ -416,7 +421,7 @@ void ModelMixesPage::newMix()
skip_mix = (ch == 0 && is_memclear(line, sizeof(MixData)));
}
} else {
std::string ch_name(getSourceString(MIXSRC_CH1 + ch));
std::string ch_name(getSourceString(MIXSRC_FIRST_CH + ch));
menu->addLineBuffered(ch_name.c_str(), [=]() { insertMix(ch, index); });
}
}
@@ -447,7 +452,7 @@ void ModelMixesPage::insertMix(uint8_t channel, uint8_t index)
_copyMode = 0;
::insertMix(index, channel);
addLineButton(MIXSRC_CH1 + channel, index);
addLineButton(MIXSRC_FIRST_CH + channel, index);
editMix(channel, index);
}
@@ -531,7 +536,7 @@ void ModelMixesPage::build(FormWindow * window)
if (line->destCh == ch && !skip_mix) {
// one group for the complete mixer channel
auto group = createGroup(form, MIXSRC_CH1 + ch);
auto group = createGroup(form, MIXSRC_FIRST_CH + ch);
groups.emplace_back(group);
while (index < MAX_MIXERS && (line->destCh == ch) && !skip_mix) {
// one button per input line
@@ -573,7 +578,7 @@ void ModelMixesPage::enableMonitors(bool enabled)
auto h = lv_obj_get_height(form_obj);
for(auto* group : groups) {
if (enabled) {
group->enableMixerMonitor(group->getMixSrc() - MIXSRC_CH1);
group->enableMixerMonitor(group->getMixSrc() - MIXSRC_FIRST_CH);
} else {
group->disableMixerMonitor();
}
+2 -2
View File
@@ -191,10 +191,10 @@ class OutputLineButton : public ListLineButton
lv_obj_set_style_pad_top(source, -7, 0);
lv_obj_set_style_pad_bottom(source, -7, 0);
#endif
lv_label_set_text_fmt(source, "%s\n" TR_CH "%u", getSourceString(MIXSRC_CH1 + index), index + 1);
lv_label_set_text_fmt(source, "%s\n" TR_CH "%u", getSourceString(MIXSRC_FIRST_CH + index), index + 1);
} else {
lv_obj_set_style_text_font(source, getFont(FONT(STD)), 0);
lv_label_set_text(source, getSourceString(MIXSRC_CH1 + index));
lv_label_set_text(source, getSourceString(MIXSRC_FIRST_CH + index));
}
if (output->revert) {
lv_obj_clear_flag(revert, LV_OBJ_FLAG_HIDDEN);
+5 -5
View File
@@ -667,18 +667,18 @@ ModelLabelsWindow::ModelLabelsWindow() : Page(ICON_MODEL)
void ModelLabelsWindow::onEvent(event_t event)
{
#if defined(KEYS_GPIO_REG_PGUP)
if (event == EVT_KEY_BREAK(KEY_PGUP) ||
event == EVT_KEY_BREAK(KEY_PGDN)) {
if (event == EVT_KEY_BREAK(KEY_PAGEUP) ||
event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#else
if (event == EVT_KEY_LONG(KEY_PGDN) ||
event == EVT_KEY_BREAK(KEY_PGDN)) {
if (event == EVT_KEY_LONG(KEY_PAGEDN) ||
event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#endif
std::set<uint32_t> curSel = lblselector->getSelection();
std::set<uint32_t> sellist;
int select = 0;
int rowcount = lblselector->getRowCount();
if (event == EVT_KEY_BREAK(KEY_PGDN)) {
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
if(curSel.size())
select = (*curSel.rbegin() + 1) % rowcount;
} else {
+2 -2
View File
@@ -280,7 +280,7 @@ class USBChannelEditWindow : public Page
void buildHeader(Window *window)
{
header.setTitle(STR_USBJOYSTICK_LABEL);
header.setTitle2(getSourceString(MIXSRC_CH1 + channel));
header.setTitle2(getSourceString(MIXSRC_FIRST_CH + channel));
statusBar = new USBChannelEditStatusBar(
window,
@@ -418,7 +418,7 @@ class USBChannelLineButton : public Button
lv_obj_set_grid_cell(m_btns, LV_GRID_ALIGN_START, USBCH_BTN_MODE_COL+1, 1,
LV_GRID_ALIGN_CENTER, USBCH_BTN_MODE_ROW, 1);
lv_label_set_text(m_chn, getSourceString(MIXSRC_CH1 + index));
lv_label_set_text(m_chn, getSourceString(MIXSRC_FIRST_CH + index));
lv_label_set_text(m_mode, "");
lv_label_set_text(m_param, "");
lv_label_set_text(m_btn_mode, "");
+1 -1
View File
@@ -62,7 +62,7 @@ class OutputEditStatusBar : public Window
OutputEditWindow::OutputEditWindow(uint8_t channel) :
Page(ICON_MODEL_OUTPUTS), channel(channel)
{
std::string title2(getSourceString(MIXSRC_CH1 + channel));
std::string title2(getSourceString(MIXSRC_FIRST_CH + channel));
header.setTitle(STR_MENULIMITS);
header.setTitle2(title2);
+2
View File
@@ -23,6 +23,8 @@
#include "libopenui.h"
#include "pwr.h"
#include "watchdog_driver.h"
static void _run_popup_dialog(const char* title, const char* msg,
const char* info = nullptr)
{
+54 -55
View File
@@ -23,6 +23,10 @@
#include "button_matrix.h"
#include "opentx.h"
#include "hal/adc_driver.h"
#include "hal/switch_driver.h"
#include "strhelpers.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
@@ -79,7 +83,7 @@ struct SwitchWarnMatrix : public ButtonMatrix {
bool isActive(uint8_t btn_id);
void setTextWithColor(uint8_t btn_id);
private:
uint8_t sw_idx[NUM_SWITCHES];
uint8_t sw_idx[MAX_SWITCHES];
};
struct PotWarnMatrix : public ButtonMatrix {
@@ -88,7 +92,7 @@ struct PotWarnMatrix : public ButtonMatrix {
bool isActive(uint8_t btn_id);
void setTextWithColor(uint8_t btn_id);
private:
uint8_t pot_idx[NUM_POTS + NUM_SLIDERS];
uint8_t pot_idx[MAX_POTS];
};
struct CenterBeepsMatrix : public ButtonMatrix {
@@ -97,7 +101,8 @@ struct CenterBeepsMatrix : public ButtonMatrix {
bool isActive(uint8_t btn_id);
void setTextWithColor(uint8_t btn_id);
private:
uint8_t ana_idx[NUM_STICKS + NUM_POTS + NUM_SLIDERS];
uint8_t max_analogs;
uint8_t ana_idx[MAX_ANALOG_INPUTS];
};
PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)
@@ -145,19 +150,18 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)
new SwitchWarnMatrix(line, 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{}, STR_PREFLIGHT_POTSLIDER_CHECK, 0, 2,
GET_SET_DEFAULT(g_model.potsWarnMode));
#if (NUM_POTS)
// Pot warnings
line = form->newLine(&grid);
line->padTop(0);
auto pwm = new PotWarnMatrix(line, rect_t{});
make_conditional(pwm, pots_wm);
#endif
#endif
if (adcGetMaxInputs(ADC_INPUT_POT) > 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,
GET_SET_DEFAULT(g_model.potsWarnMode));
// Pot warnings
line = form->newLine(&grid);
line->padTop(0);
auto pwm = new PotWarnMatrix(line, rect_t{});
make_conditional(pwm, pots_wm);
}
// Center beeps
line = form->newLine(&grid);
@@ -170,8 +174,7 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)
static std::string switchWarninglabel(swsrc_t index)
{
auto warn_pos = g_model.switchWarningState >> (3 * index) & 0x07;
return TEXT_AT_INDEX(STR_VSRCRAW,
(index + MIXSRC_FIRST_SWITCH - MIXSRC_Rud + 1)) +
return std::string(switchGetName(index)) +
std::string(getSwitchWarnSymbol(warn_pos));
}
@@ -187,7 +190,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++;
@@ -198,7 +201,7 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) :
update();
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)) {
lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_RECOLOR);
setTextWithColor(i);
@@ -225,12 +228,13 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) :
void SwitchWarnMatrix::setTextWithColor(uint8_t btn_id)
{
setText(btn_id, makeRecolor(switchWarninglabel(sw_idx[btn_id]), isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1).c_str());
auto color = isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1;
setText(btn_id, makeRecolor(switchWarninglabel(sw_idx[btn_id]), color).c_str());
}
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);
@@ -249,7 +253,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;
}
@@ -258,16 +262,9 @@ PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) :
{
// Setup button layout & texts
uint8_t btn_cnt = 0;
for (uint8_t i = POT_FIRST; i <= POT_LAST; i++) {
if ((IS_POT(i) || IS_POT_MULTIPOS(i)) && IS_POT_AVAILABLE(i)) {
pot_idx[btn_cnt] = i - POT_FIRST;
btn_cnt++;
}
}
for (int8_t i = SLIDER_FIRST; i <= SLIDER_LAST; i++) {
if (IS_SLIDER(i)) {
pot_idx[btn_cnt] = i - POT_FIRST;
for (uint8_t i = 0; i <= MAX_POTS; i++) {
if (IS_POT_AVAILABLE(i)) {
pot_idx[btn_cnt] = i;
btn_cnt++;
}
}
@@ -276,15 +273,8 @@ PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) :
update();
uint8_t btn_id = 0;
for (uint16_t i = POT_FIRST; i <= POT_LAST; i++) {
if ((IS_POT(i) || IS_POT_MULTIPOS(i)) && IS_POT_AVAILABLE(i)) {
lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_RECOLOR);
setTextWithColor(btn_id);
btn_id++;
}
}
for (int8_t i = SLIDER_FIRST; i <= SLIDER_LAST; i++) {
if (IS_SLIDER(i)) {
for (uint16_t i = 0; i <= MAX_POTS; i++) {
if (IS_POT_AVAILABLE(i)) {
lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_RECOLOR);
setTextWithColor(btn_id);
btn_id++;
@@ -310,12 +300,14 @@ PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) :
void PotWarnMatrix::setTextWithColor(uint8_t btn_id)
{
setText(btn_id, makeRecolor(STR_VSRCRAW[pot_idx[btn_id] + POT_FIRST + 1], isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1).c_str());
auto idx = pot_idx[btn_id];
auto color = isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1;
setText(btn_id, makeRecolor(getPotLabel(idx), color).c_str());
}
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);
@@ -329,7 +321,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;
}
@@ -338,9 +330,15 @@ 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_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
max_analogs = max_sticks + max_pots;
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 < max_sticks || (IS_POT_SLIDER_AVAILABLE(i - max_sticks) &&
!IS_POT_MULTIPOS(i - max_sticks))) {
ana_idx[btn_cnt] = i;
btn_cnt++;
}
@@ -350,8 +348,9 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) :
update();
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 < max_sticks || (IS_POT_SLIDER_AVAILABLE(i - max_sticks) &&
!IS_POT_MULTIPOS(i - max_sticks))) {
lv_btnmatrix_set_btn_ctrl(lvobj, btn_id, LV_BTNMATRIX_CTRL_RECOLOR);
setTextWithColor(btn_id);
btn_id++;
@@ -377,15 +376,15 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) :
void CenterBeepsMatrix::setTextWithColor(uint8_t btn_id)
{
if (btn_id < NUM_STICKS)
setText(btn_id, makeRecolor(STR_RETA123[ana_idx[btn_id]], isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1).c_str());
else
setText(btn_id, makeRecolor(STR_VSRCRAW[ana_idx[btn_id] + 1], isActive(btn_id) ? COLOR_THEME_PRIMARY1 : COLOR_THEME_SECONDARY1).c_str());
setText(btn_id, makeRecolor(getAnalogShortLabel(ana_idx[btn_id]),
isActive(btn_id) ? COLOR_THEME_PRIMARY1
: COLOR_THEME_SECONDARY1)
.c_str());
}
void CenterBeepsMatrix::onPress(uint8_t btn_id)
{
if (btn_id >= NUM_STICKS + NUM_POTS + NUM_SLIDERS) return;
if (btn_id >= max_analogs) return;
uint8_t i = ana_idx[btn_id];
BFBIT_FLIP(g_model.beepANACenter, bfBit<BeepANACenter>(i));
setTextWithColor(btn_id);
@@ -394,7 +393,7 @@ void CenterBeepsMatrix::onPress(uint8_t btn_id)
bool CenterBeepsMatrix::isActive(uint8_t btn_id)
{
if (btn_id >= NUM_STICKS + NUM_POTS + NUM_SLIDERS) return false;
if (btn_id >= max_analogs) return false;
uint8_t i = ana_idx[btn_id];
return bfSingleBitGet<BeepANACenter>(g_model.beepANACenter, i) != 0;
}
+16 -100
View File
@@ -45,8 +45,8 @@ class StickCalibrationWindow: public Window {
void paint(BitmapBuffer * dc) override
{
dc->drawBitmap(0, 0, calibStickBackground);
int16_t x = calibratedAnalogs[CONVERT_MODE(stickX)];
int16_t y = calibratedAnalogs[CONVERT_MODE(stickY)];
int16_t x = calibratedAnalogs[stickX];
int16_t y = calibratedAnalogs[stickY];
dc->drawBitmap(width() / 2 - 9 + (bitmapSize / 2 * x) / RESX,
height() / 2 - 9 - (bitmapSize / 2 * y) / RESX,
calibStick);
@@ -78,13 +78,15 @@ 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);
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
if (max_sticks > 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);
@@ -104,100 +106,15 @@ void RadioCalibrationPage::checkEvents()
{
Page::checkEvents();
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS + NUM_MOUSE_ANALOGS; i++) { // get low and high vals for sticks and trims
int16_t vt = i < TX_VOLTAGE ? anaIn(i) : anaIn(i + 1);
reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]);
reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]);
if (i >= POT1 && i <= POT_LAST) {
if (IS_POT_WITHOUT_DETENT(i)) {
reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2;
}
#if NUM_XPOTS > 0
uint8_t idx = i - POT1;
int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount;
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) {
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 == XPOT_DELAY) {
int16_t position = reusableBuffer.calib.xpotsCalib[idx].lastPosition;
bool found = false;
for (int j = 0; j < count; j++) {
int16_t step = reusableBuffer.calib.xpotsCalib[idx].steps[j];
if (position >= step - XPOT_DELTA && position <= step + XPOT_DELTA) {
found = true;
break;
}
}
if (!found) {
if (count < XPOTS_MULTIPOS_COUNT) {
reusableBuffer.calib.xpotsCalib[idx].steps[count] = position;
}
reusableBuffer.calib.xpotsCalib[idx].stepsCount += 1;
}
}
}
#endif
}
}
// Get min / max values
adcCalibMinMax();
if (menuCalibrationState == CALIB_SET_MIDPOINT) {
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS + NUM_MOUSE_ANALOGS; i++) {
reusableBuffer.calib.loVals[i] = 15000;
reusableBuffer.calib.hiVals[i] = -15000;
reusableBuffer.calib.midVals[i] = i < TX_VOLTAGE ? anaIn(i) : anaIn(i + 1);
#if NUM_XPOTS > 0
if (i < NUM_XPOTS) {
reusableBuffer.calib.xpotsCalib[i].stepsCount = 0;
reusableBuffer.calib.xpotsCalib[i].lastCount = 0;
}
#endif
}
adcCalibSetMidPoint();
}
else if (menuCalibrationState == CALIB_MOVE_STICKS) {
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS + NUM_MOUSE_ANALOGS; i++) {
if (abs(reusableBuffer.calib.loVals[i] - reusableBuffer.calib.hiVals[i]) > 50) {
g_eeGeneral.calib[i].mid = reusableBuffer.calib.midVals[i];
int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i];
g_eeGeneral.calib[i].spanNeg = v - v / STICK_TOLERANCE;
v = reusableBuffer.calib.hiVals[i] - reusableBuffer.calib.midVals[i];
g_eeGeneral.calib[i].spanPos = v - v / STICK_TOLERANCE;
}
}
#if NUM_XPOTS > 0
for (int i = POT1; i <= POT_LAST; i++) {
int idx = i - POT1;
int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount;
if (IS_POT_MULTIPOS(i)) {
if (count > 1 && count <= XPOTS_MULTIPOS_COUNT) {
for (int j = 0; j < count; j++) {
for (int k = j + 1; k < count; k++) {
if (reusableBuffer.calib.xpotsCalib[idx].steps[k] < reusableBuffer.calib.xpotsCalib[idx].steps[j]) {
SWAP(reusableBuffer.calib.xpotsCalib[idx].steps[j], reusableBuffer.calib.xpotsCalib[idx].steps[k]);
}
}
}
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i];
calib->count = count - 1;
for (int j = 0; j < calib->count; j++) {
calib->steps[j] = (reusableBuffer.calib.xpotsCalib[idx].steps[j + 1] + reusableBuffer.calib.xpotsCalib[idx].steps[j]) >> 5;
}
}
else {
// g_eeGeneral.potsConfig &= ~(0x03<<(2*idx));
}
}
}
#endif
adcCalibSetMinMax();
adcCalibSetXPot();
}
}
@@ -235,8 +152,7 @@ void RadioCalibrationPage::nextStep()
case CALIB_STORE:
text->setText(STR_CALIB_DONE);
g_eeGeneral.chkSum = evalChkSum();
storageDirty(EE_GENERAL);
adcCalibStore();
menuCalibrationState = CALIB_FINISHED;
// initial calibration completed
+25 -55
View File
@@ -22,16 +22,12 @@
#include "opentx.h"
#include "radio_diaganas.h"
#include "libopenui.h"
#include "../../hal/adc_driver.h"
#include "hal/adc_driver.h"
// #if defined(IMU_LSM6DS33)
// #include "imu_lsm6ds33.h"
// #endif
#if defined(FLYSKY_GIMBAL)
#include "flysky_gimbal_driver.h"
#endif
#define STATSDEPTH 8 // ideally a value of power of 2
#if LCD_W > LCD_H
@@ -74,7 +70,10 @@ class AnaViewWindow: public FormWindow {
{
char s[10];
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++) {
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
for (uint8_t i = 0; i < max_inputs; i++) {
#if LCD_W > LCD_H
if ((i & 1) == 0)
line = newLine(grid);
@@ -88,7 +87,7 @@ class AnaViewWindow: public FormWindow {
new StaticText(line, rect_t{}, s, COLOR_THEME_PRIMARY1);
auto lbl = new DynamicText(line, rect_t{}, [=]() {
return std::to_string((int16_t)calibratedAnalogs[CONVERT_MODE(i)] * 25 / 256);
return std::to_string((int16_t)calibratedAnalogs[i] * 25 / 256);
}, COLOR_THEME_PRIMARY1);
lv_obj_set_style_text_align(lbl->getLvObj(), LV_TEXT_ALIGN_RIGHT, 0);
@@ -209,14 +208,7 @@ class AnaCalibratedViewWindow: public AnaViewWindow {
protected:
int16_t column3(int i) override
{
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals && (i < FLYSKY_HALL_CHANNEL_COUNT))
return hall_raw_values[i];
else
return anaIn(i);
#else
return anaIn(i);
#endif
}
};
@@ -301,24 +293,11 @@ class AnaFilteredDevViewWindow: public AnaViewWindow {
}
};
Stats stats[NUM_STICKS+NUM_POTS+NUM_SLIDERS];
Stats stats[MAX_CALIB_ANALOG_INPUTS];
int16_t column3(int i) override
{
extern uint32_t s_anaFilt[NUM_ANALOGS];
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals && (i < FLYSKY_HALL_CHANNEL_COUNT))
return hall_raw_values[i];
else
return s_anaFilt[i]/JITTER_ALPHA;
#else
#if !defined(SIMU)
return s_anaFilt[i]/JITTER_ALPHA;
#else
return anaIn(i);
#endif
#endif
return anaIn_diag(i);
}
const char* column4prefix() override { return "+/- "; }
@@ -333,21 +312,20 @@ class AnaFilteredDevViewWindow: public AnaViewWindow {
AnaFilteredDevViewWindow(Window * parent):
AnaViewWindow(parent)
{
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++)
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
for (uint8_t i = 0; i < max_inputs; i++)
stats[i].clear();
}
void checkEvents() override
{
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++) {
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals && (i < FLYSKY_HALL_CHANNEL_COUNT))
stats[i].write(hall_raw_values[i]);
else
stats[i].write(getAnalogValue(i));
#else
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
for (uint8_t i = 0; i < max_inputs; i++) {
stats[i].write(getAnalogValue(i));
#endif
}
AnaViewWindow::checkEvents();
}
@@ -363,14 +341,7 @@ class AnaUnfilteredRawViewWindow: public AnaViewWindow {
protected:
int16_t column3(int i) override
{
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals && (i < FLYSKY_HALL_CHANNEL_COUNT))
return hall_raw_values[i];
else
return getAnalogValue(i);
#else
return getAnalogValue(i);
#endif
}
};
@@ -419,7 +390,7 @@ class AnaMinMaxViewWindow: public AnaViewWindow {
}
};
MinMax minmax[NUM_STICKS+NUM_POTS+NUM_SLIDERS];
MinMax minmax[MAX_CALIB_ANALOG_INPUTS];
int16_t column3(int i) override
{
@@ -444,7 +415,10 @@ class AnaMinMaxViewWindow: public AnaViewWindow {
AnaMinMaxViewWindow(Window * parent):
AnaViewWindow(parent)
{
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++)
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
for (uint8_t i = 0; i < max_inputs; i++)
minmax[i].clear();
}
@@ -459,15 +433,11 @@ class AnaMinMaxViewWindow: public AnaViewWindow {
void checkEvents() override
{
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS; i++) {
#if !defined(SIMU) && defined(FLYSKY_GIMBAL)
if (globalData.flyskygimbals && (i < FLYSKY_HALL_CHANNEL_COUNT))
minmax[i].write(hall_raw_values[i]);
else
minmax[i].write(getAnalogValue(i));
#else
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
for (uint8_t i = 0; i < max_inputs; i++) {
minmax[i].write(getAnalogValue(i));
#endif
}
AnaViewWindow::checkEvents();
}
+31 -19
View File
@@ -23,11 +23,21 @@
#include "radio_diagkeys.h"
#include "libopenui.h"
#if defined(KEYS_GPIO_PIN_PGUP)
constexpr uint8_t KEY_START = 0;
#else
constexpr uint8_t KEY_START = 1;
#endif
#include "hal/rotary_encoder.h"
static EnumKeys get_ith_key(uint8_t i)
{
auto supported_keys = keysGetSupported();
for (uint8_t k = 0; k < MAX_KEYS; k++) {
if (supported_keys & (1 << k)) {
if (i-- == 0) return (EnumKeys)k;
}
}
// should not get here,
// we assume: i < keysGetMaxKeys()
return (EnumKeys)0;
}
class RadioKeyDiagsWindow : public Window
{
@@ -45,7 +55,7 @@ class RadioKeyDiagsWindow : public Window
void displayKeyState(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t key)
{
uint8_t t = keys[key].state();
uint8_t t = keysGetState(key);
// TODO use drawChar when done
char status[2];
status[0] = t + '0';
@@ -73,29 +83,31 @@ class RadioKeyDiagsWindow : public Window
#if !defined(PCBNV14)
// KEYS
for (uint8_t i = KEY_START; i <= 6; i++) {
coord_t y = 1 + FH * (i - KEY_START);
dc->drawTextAtIndex(KEY_COLUMN, y, STR_VKEYS, i, COLOR_THEME_PRIMARY1);
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, i);
}
#if defined(ROTARY_ENCODER_NAVIGATION)
coord_t y = FH * (8 - KEY_START);
y += FH;
dc->drawText(KEY_COLUMN, y, STR_ROTARY_ENCODER, COLOR_THEME_PRIMARY1);
dc->drawNumber(70, y, rotencValue, COLOR_THEME_PRIMARY1);
dc->drawNumber(70, y, rotaryEncoderGetValue(), COLOR_THEME_PRIMARY1);
#endif
#else // defined(PCBNV14)
// KEYS
{
coord_t y = 1;
dc->drawTextAtIndex(KEY_COLUMN, y, STR_VKEYS, KEY_ENTER, COLOR_THEME_PRIMARY1);
dc->drawText(KEY_COLUMN, y, keysGetLabel(KEY_ENTER), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, KEY_ENTER);
y += FH;
dc->drawTextAtIndex(KEY_COLUMN, y, STR_VKEYS, KEY_EXIT, COLOR_THEME_PRIMARY1);
dc->drawText(KEY_COLUMN, y, keysGetLabel(KEY_EXIT), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, KEY_EXIT);
}
#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);
@@ -105,18 +117,18 @@ class RadioKeyDiagsWindow : public Window
}
// TRIMS
for (uint8_t i = 0; i < NUM_TRIMS_KEYS; i++) {
#if NUM_TRIMS_KEYS == 12
const uint8_t trimMap[NUM_TRIMS_KEYS] = {6, 7, 4, 5, 2, 3, 0, 1, 8, 9, 10, 11};
for (uint8_t i = 0; i < MAX_TRIMS * 2; i++) {
#if MAX_TRIMS * 2 == 12
const uint8_t trimMap[MAX_TRIMS * 2] = {6, 7, 4, 5, 2, 3, 0, 1, 8, 9, 10, 11};
#else
const uint8_t trimMap[NUM_TRIMS_KEYS] = {6, 7, 4, 5, 2, 3, 0, 1};
const uint8_t trimMap[MAX_TRIMS * 2] = {6, 7, 4, 5, 2, 3, 0, 1};
#endif
coord_t y = 1 + FH + FH * (i / 2);
if (i & 1) {
dc->drawText(TRIM_COLUMN, y, "T", COLOR_THEME_PRIMARY1);
dc->drawNumber(TRIM_COLUMN + 10, y, i / 2 + 1, COLOR_THEME_PRIMARY1);
}
displayKeyState(dc, i & 1 ? TRIM_PLUS_COLUMN : TRIM_MINUS_COLUMN, y, TRM_BASE + trimMap[i]);
// displayKeyState(dc, i & 1 ? TRIM_PLUS_COLUMN : TRIM_MINUS_COLUMN, y, TRM_BASE + trimMap[i]);
}
};
+6 -7
View File
@@ -48,6 +48,11 @@ RadioHardwarePage::RadioHardwarePage():
{
}
void RadioHardwarePage::checkEvents()
{
enableVBatBridge();
}
void RadioHardwarePage::build(FormWindow * window)
{
window->setFlexLayout(LV_FLEX_FLOW_COLUMN, 0);
@@ -163,16 +168,10 @@ void RadioHardwarePage::build(FormWindow * window)
auto btn = makeHWInputButton<HWSticks>(box, STR_STICKS);
lv_obj_set_style_min_width(btn->getLvObj(), LV_DPI_DEF, 0);
// Pots
// Pots & Sliders
btn = makeHWInputButton<HWPots>(box, STR_POTS);
lv_obj_set_style_min_width(btn->getLvObj(), LV_DPI_DEF, 0);
// Sliders
#if (NUM_SLIDERS > 0)
btn = makeHWInputButton<HWSliders>(box, STR_SLIDERS);
lv_obj_set_style_min_width(btn->getLvObj(), LV_DPI_DEF, 0);
#endif
// Switches
btn = makeHWInputButton<HWSwitches>(box, STR_SWITCHES);
lv_obj_set_style_min_width(btn->getLvObj(), LV_DPI_DEF, 0);
+7 -4
View File
@@ -24,11 +24,14 @@
#include "tabsgroup.h"
class RadioHardwarePage: public PageTab {
public:
RadioHardwarePage();
class RadioHardwarePage : public PageTab
{
void checkEvents() override;
void build(FormWindow * window) override;
public:
RadioHardwarePage();
void build(FormWindow* window) override;
};
#endif //_RADIO_HARDWARE_H_
+14 -8
View File
@@ -24,8 +24,10 @@
#include "radio_setup.h"
#include "opentx.h"
#include "libopenui.h"
#include "input_mapping.h"
#include "tasks/mixer_task.h"
#include "hal/adc_driver.h"
#define SET_DIRTY() storageDirty(EE_GENERAL)
@@ -781,12 +783,16 @@ void RadioSetupPage::build(FormWindow * window)
line = window->newLine(&grid);
new StaticText(line, rect_t{}, STR_DEF_CHAN_ORD, 0,
COLOR_THEME_PRIMARY1); // RAET->AETR
choice = new Choice(line, rect_t{}, 0, 4 * 3 * 2 - 1,
uint8_t mains = adcGetMaxInputs(ADC_INPUT_MAIN);
auto max_order = inputMappingGetMaxChannelOrder() - 1;
choice = new Choice(line, rect_t{}, 0, max_order,
GET_SET_DEFAULT(g_eeGeneral.templateSetup));
choice->setTextHandler([](uint8_t value) {
choice->setTextHandler([=](uint8_t value) {
std::string s;
for (uint8_t i = 0; i < 4; i++) {
s += STR_RETA123[channelOrder(value, i + 1) - 1];
for (uint8_t i = 0; i < mains; i++) {
s += getAnalogShortLabel(inputMappingChannelOrder(value, i));
}
return s;
});
@@ -803,11 +809,11 @@ void RadioSetupPage::build(FormWindow * window)
mixerTaskStart();
});
choice->setTextHandler([](uint8_t value) {
auto stick0 = inputMappingConvertMode(value, 0);
auto stick1 = inputMappingConvertMode(value, 1);
return std::to_string(1 + value) + ": " + STR_LEFT_STICK + " = " +
std::string(&getSourceString(MIXSRC_Rud + modn12x3[4 * value])[1]) +
"+" +
std::string(
&getSourceString(MIXSRC_Rud + modn12x3[4 * value + 1])[1]);
std::string(getMainControlLabel(stick0)) + "+" +
std::string(getMainControlLabel(stick1));
});
// Model quick select
+9 -5
View File
@@ -22,6 +22,10 @@
#include "radio_trainer.h"
#include "opentx.h"
#include "libopenui.h"
#include "input_mapping.h"
#include "hal/adc_driver.h"
#include "strhelpers.h"
#define SET_DIRTY() storageDirty(EE_GENERAL)
@@ -59,13 +63,13 @@ void RadioTrainerPage::build(FormWindow * form)
form->padRight(8);
#endif
for (uint8_t i = 0; i < NUM_STICKS; i++) {
uint8_t chan = channelOrder(i + 1);
TrainerMix* td = &g_eeGeneral.trainer.mix[chan - 1];
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
for (uint8_t i = 0; i < max_sticks; i++) {
uint8_t chan = inputMappingChannelOrder(i);
TrainerMix* td = &g_eeGeneral.trainer.mix[chan];
auto line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_VSRCRAW[chan], 0, COLOR_THEME_PRIMARY1);
new StaticText(line, rect_t{}, getMainControlLabel(chan), 0, COLOR_THEME_PRIMARY1);
new Choice(line, rect_t{}, STR_TRNMODE, 0, 2, GET_SET_DEFAULT(td->mode));
new Choice(line, rect_t{}, STR_TRNCHN, 0, 3, GET_SET_DEFAULT(td->srcChn));
+1
View File
@@ -28,6 +28,7 @@
#include "strhelpers.h"
#include "draw_functions.h"
#include "opentx.h"
#include "switches.h"
class SourceChoiceMenuToolbar : public MenuToolbar
{
+18 -14
View File
@@ -25,6 +25,9 @@
#include "view_main.h"
#include "lvgl_widgets/input_mix_line.h"
#include "hal/adc_driver.h"
#include "strhelpers.h"
#define SET_DIRTY() storageDirty(functions == g_model.customFn ? EE_MODEL : EE_GENERAL)
static const lv_coord_t col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(3),
@@ -125,17 +128,16 @@ class SpecialFunctionEditPage : public Page
case FUNC_TRAINER: {
new StaticText(line, rect_t{}, STR_VALUE, 0, COLOR_THEME_PRIMARY1);
auto choice =
new Choice(line, rect_t{}, 0,
NUM_STICKS + 1, GET_SET_DEFAULT(CFN_CH_INDEX(cfn)));
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
auto choice = new Choice(line, rect_t{}, 0, max_sticks + 1,
GET_SET_DEFAULT(CFN_CH_INDEX(cfn)));
choice->setTextHandler([=](int32_t value) {
if (value == 0)
return std::string(STR_STICKS);
else if (value == NUM_STICKS + 1)
else if (value == MAX_STICKS + 1)
return std::string(STR_CHANS);
else
return TEXT_AT_INDEX(STR_VSRCRAW, value);
;
return std::string(getMainControlLabel(value));
});
break;
}
@@ -398,9 +400,11 @@ class SpecialFunctionEditPage : public Page
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_FUNC, 0, COLOR_THEME_PRIMARY1);
auto functionChoice =
new Choice(line, rect_t{}, STR_VFSWFUNC,
0, FUNC_MAX - 1,
new Choice(line, rect_t{}, 0, FUNC_MAX - 1,
GET_DEFAULT(CFN_FUNC(cfn)));
functionChoice->setTextHandler([=](int val) {
return funcGetLabel(val);
});
functionChoice->setSetValueHandler([=](int32_t newValue) {
CFN_FUNC(cfn) = newValue;
CFN_RESET(cfn);
@@ -560,22 +564,22 @@ class SpecialFunctionButton : public Button
lv_label_set_text(sfName, s);
lv_label_set_text(sfSwitch, getSwitchPositionName(CFN_SWITCH(cfn)));
strcpy(s, STR_VFSWFUNC[func]);
strcpy(s, funcGetLabel(func));
strcat(s, " - ");
switch (func) {
case FUNC_OVERRIDE_CHANNEL:
sprintf(s+strlen(s), "%s = %s", getSourceString(MIXSRC_CH1 + CFN_CH_INDEX(cfn)), formatNumberAsString(CFN_PARAM(cfn)).c_str());
sprintf(s+strlen(s), "%s = %s", getSourceString(MIXSRC_FIRST_CH + CFN_CH_INDEX(cfn)), formatNumberAsString(CFN_PARAM(cfn)).c_str());
break;
case FUNC_TRAINER: {
int16_t value = CFN_CH_INDEX(cfn);
if (value == 0)
strcat(s, STR_STICKS);
else if (value == NUM_STICKS + 1)
else if (value == MAX_STICKS + 1)
strcat(s, STR_CHANS);
else
strcat(s, STR_VSRCRAW[value]);
strcat(s, getMainControlLabel(value - 1));
break;
}
@@ -646,7 +650,7 @@ class SpecialFunctionButton : public Button
break;
default:
strcpy(s, STR_VFSWFUNC[func]);
strcpy(s, funcGetLabel(func));
break;
}
@@ -72,7 +72,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) {
@@ -86,11 +86,11 @@ 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 += STR_VSRCRAW[POT1 + i + 1];
warn_txt += getPotLabel(i);
}
}
}
+1
View File
@@ -27,6 +27,7 @@
#include "menutoolbar.h"
#include "opentx.h"
#include "strhelpers.h"
#include "switches.h"
class SwitchChoiceMenuToolbar : public MenuToolbar
{
+4 -4
View File
@@ -278,18 +278,18 @@ void TabsGroup::onEvent(event_t event)
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
#if defined(KEYS_GPIO_REG_PGUP)
if (event == EVT_KEY_FIRST(KEY_PGDN)) {
if (event == EVT_KEY_FIRST(KEY_PAGEDN)) {
#else
if (event == EVT_KEY_BREAK(KEY_PGDN)) {
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#endif
killEvents(event);
uint8_t current = header.carousel.getCurrentIndex() + 1;
setCurrentTab(current >= tabs.size() ? 0 : current);
}
#if defined(KEYS_GPIO_REG_PGUP)
else if (event == EVT_KEY_FIRST(KEY_PGUP)) {
else if (event == EVT_KEY_FIRST(KEY_PAGEUP)) {
#else
else if (event == EVT_KEY_LONG(KEY_PGDN)) {
else if (event == EVT_KEY_LONG(KEY_PAGEDN)) {
#endif
killEvents(event);
uint8_t current = header.carousel.getCurrentIndex();
@@ -230,7 +230,7 @@ class LogicalSwitchDisplayButton : public TextButton
void checkEvents() override
{
bool newvalue = getSwitch(SWSRC_SW1 + index);
bool newvalue = getSwitch(SWSRC_FIRST_LOGICAL_SWITCH + index);
if (value != newvalue) {
if (newvalue) {
lv_obj_add_state(lvobj, LV_STATE_CHECKED);
+8 -8
View File
@@ -260,29 +260,29 @@ void ViewMain::onEvent(event_t event)
new ModelLabelsWindow();
break;
case EVT_KEY_BREAK(KEY_RADIO):
case EVT_KEY_BREAK(KEY_SYS):
if (viewMainMenu) viewMainMenu->onCancel();
new RadioMenu();
break;
case EVT_KEY_LONG(KEY_RADIO):
case EVT_KEY_LONG(KEY_SYS):
{
killEvents(KEY_RADIO);
killEvents(KEY_SYS);
// Radio setup
auto m = new RadioMenu();
m->setCurrentTab(2);
}
break;
case EVT_KEY_FIRST(KEY_TELEM):
case EVT_KEY_FIRST(KEY_TELE):
if (viewMainMenu) viewMainMenu->onCancel();
new ScreenMenu();
break;
#if defined(KEYS_GPIO_REG_PGUP)
case EVT_KEY_FIRST(KEY_PGDN):
case EVT_KEY_FIRST(KEY_PAGEDN):
#else
case EVT_KEY_BREAK(KEY_PGDN):
case EVT_KEY_BREAK(KEY_PAGEDN):
#endif
if (!widget_select) {
if (viewMainMenu) viewMainMenu->onCancel();
@@ -293,9 +293,9 @@ void ViewMain::onEvent(event_t event)
//TODO: these need to go away!
// -> board code should map the keys as required
#if defined(KEYS_GPIO_REG_PGUP)
case EVT_KEY_FIRST(KEY_PGUP):
case EVT_KEY_FIRST(KEY_PAGEUP):
#else
case EVT_KEY_LONG(KEY_PGDN):
case EVT_KEY_LONG(KEY_PAGEDN):
#endif
killEvents(event);
if (!widget_select) {
+40 -46
View File
@@ -30,6 +30,7 @@
#include "layouts/trims.h"
#include "board.h"
#include "hal/adc_driver.h"
static Window* create_layout_box(Window* parent, lv_align_t align,
lv_flex_flow_t flow)
@@ -130,64 +131,57 @@ rect_t ViewMainDecoration::getMainZone() const
void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br)
{
Window* sl = new MainViewHorizontalSlider(bl, CALIBRATED_POT1);
// TODO: make dynamic
//uint8_t pot_idx = 0;
Window* sl = new MainViewHorizontalSlider(bl, 0);
sl->updateSize();
sliders[SLIDERS_POT1] = sl;
sliders[0] = sl;
#if !defined(HARDWARE_POT3)
bc = br;
#endif
if (IS_POT_MULTIPOS(POT2)) {
if (!IS_POT_AVAILABLE(2)) {
bc = br;
}
if (IS_POT_MULTIPOS(1)) {
sl = new MainView6POS(bc, 1);
sl->updateSize();
sliders[SLIDERS_POT2] = sl;
sliders[1] = sl;
}
else if (IS_POT(POT2)) {
sl = new MainViewHorizontalSlider(bc, CALIBRATED_POT2);
else if (IS_POT_AVAILABLE(1)) {
sl = new MainViewHorizontalSlider(bc, 1);
sl->updateSize();
sliders[SLIDERS_POT2] = sl;
sliders[1] = sl;
}
#if defined(HARDWARE_POT3)
sl = new MainViewHorizontalSlider(br, CALIBRATED_POT3);
sl->updateSize();
sliders[SLIDERS_POT3] = sl;
#endif
#if NUM_SLIDERS > 0
// 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
auto leftPots = create_layout_box(ml, LV_ALIGN_LEFT_MID, LV_FLEX_FLOW_COLUMN);
leftPots->setHeight(VERTICAL_SLIDERS_HEIGHT);
auto rightPots = create_layout_box(mr, LV_ALIGN_RIGHT_MID, LV_FLEX_FLOW_COLUMN);
rightPots->setHeight(VERTICAL_SLIDERS_HEIGHT);
auto vertSlLeft1 = new MainViewVerticalSlider(leftPots, CALIBRATED_SLIDER_REAR_LEFT);
sliders[SLIDERS_REAR_LEFT] = vertSlLeft1;
auto vertSlRight1 = new MainViewVerticalSlider(rightPots, CALIBRATED_SLIDER_REAR_RIGHT);
sliders[SLIDERS_REAR_RIGHT] = vertSlRight1;
#if defined(HARDWARE_EXT1) || defined(PCBX12S)
if (IS_POT_SLIDER_AVAILABLE(EXT1)) {
sl = new MainViewVerticalSlider(leftPots, CALIBRATED_POT_EXT1);
if (IS_POT_AVAILABLE(2)) {
sl = new MainViewHorizontalSlider(br, 2);
sl->updateSize();
sliders[SLIDERS_EXT1] = sl;
sliders[2] = sl;
}
#endif
#if defined(HARDWARE_EXT2) || defined(PCBX12S)
if (IS_POT_SLIDER_AVAILABLE(EXT2)) {
sl = new MainViewVerticalSlider(rightPots, CALIBRATED_POT_EXT2);
sl->updateSize();
sliders[SLIDERS_EXT2] = sl;
// TODO: check how many pots are configured instead
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
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
auto leftPots = create_layout_box(ml, LV_ALIGN_LEFT_MID, LV_FLEX_FLOW_COLUMN);
leftPots->setHeight(VERTICAL_SLIDERS_HEIGHT);
auto rightPots = create_layout_box(mr, LV_ALIGN_RIGHT_MID, LV_FLEX_FLOW_COLUMN);
rightPots->setHeight(VERTICAL_SLIDERS_HEIGHT);
for (int i = 3; i <= 6; i++) {
if (IS_POT_AVAILABLE(i)) {
sl = new MainViewVerticalSlider(i & 1 ? leftPots : rightPots, i);
sliders[i] = sl;
}
}
// update size AFTER all pots/sliders are created
for (int i = 3; i <= 6; i++) {
if (sliders[i] != nullptr)
sliders[i]->updateSize();
}
}
#endif
vertSlLeft1->updateSize();
vertSlRight1->updateSize();
#endif // NUM_SLIDERS > 0
}
void ViewMainDecoration::createTrims(Window* ml, Window* mr, Window* bl, Window* br)
+2 -2
View File
@@ -156,12 +156,12 @@ void ViewTextWindow::onEvent(event_t event)
#if defined(HARDWARE_KEYS)
if (int(bufSize) < fileLength) {
TRACE("BEFORE offset=%d", offset);
if (event == EVT_KEY_BREAK(KEY_PGDN)) {
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
offset += bufSize;
TRACE("event=DOWN");
}
if (event == EVT_KEY_BREAK(KEY_PGUP)) {
if (event == EVT_KEY_BREAK(KEY_PAGEUP)) {
TRACE("event=UP");
offset -= bufSize;
}
+1 -1
View File
@@ -204,7 +204,7 @@ class ValueWidget: public Widget
};
const ZoneOption ValueWidget::options[] = {
{ STR_SOURCE, ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_Rud) },
{ STR_SOURCE, ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_FIRST_STICK) },
{ STR_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY2) },
{ STR_SHADOW, ZoneOption::Bool, OPTION_VALUE_BOOL(false) },
{ STR_ALIGN_LABEL, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT) },
+1 -1
View File
@@ -137,7 +137,7 @@ void SetupWidgetsPage::deleteLater(bool detach, bool trash)
void SetupWidgetsPage::onEvent(event_t event)
{
if (event == EVT_KEY_FIRST(KEY_PGUP) || event == EVT_KEY_FIRST(KEY_PGDN)) {
if (event == EVT_KEY_FIRST(KEY_PAGEUP) || event == EVT_KEY_FIRST(KEY_PAGEDN)) {
killEvents(event);
} else {
FormWindow::onEvent(event);