1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-13 11:29:49 +03:00

Added auto-switch / auto-source to colorlcd

Resolves #118
This commit is contained in:
Raphael Coeffic 2021-06-06 11:45:56 +02:00 committed by Raphael Coeffic
parent 65ce8b4602
commit 162ffdb148
6 changed files with 67 additions and 36 deletions

View file

@ -3,6 +3,5 @@ Language: Cpp
BasedOnStyle: Google
BreakBeforeBraces: Linux
BreakConstructorInitializers: AfterColon
AccessModifierOffset: 0
...

View file

@ -93,6 +93,21 @@ void SourceChoice::fillMenu(Menu * menu, const std::function<bool(int16_t)> & fi
if (current >= 0) {
menu->select(current);
}
#if defined(AUTOSOURCE)
menu->setWaitHandler([=]() {
int8_t val = getMovedSource(0);
if (val) {
if (filter && filter(val)) {
return;
}
if (setValue) {
setValue(val);
}
this->fillMenu(menu);
}
});
#endif
}
void SourceChoice::openMenu()

View file

@ -65,13 +65,9 @@ void SwitchChoice::fillMenu(Menu * menu, std::function<bool(int16_t)> filter)
menu->removeLines();
for (int i = vmin; i <= vmax; ++i) {
if (filter && !filter(i))
continue;
if (isValueAvailable && !isValueAvailable(i))
continue;
menu->addLine(getSwitchPositionName(i), [=]() {
setValue(i);
});
if (filter && !filter(i)) continue;
if (isValueAvailable && !isValueAvailable(i)) continue;
menu->addLine(getSwitchPositionName(i), [=]() { setValue(i); });
if (value == i) {
current = count;
}
@ -93,6 +89,27 @@ void SwitchChoice::openMenu()
editMode = false;
setFocus(SET_FOCUS_DEFAULT);
});
#if defined(AUTOSWITCH)
menu->setWaitHandler([=]() {
swsrc_t val = 0;
swsrc_t swtch = getMovedSwitch();
if (swtch) {
div_t info = switchInfo(swtch);
if (IS_CONFIG_TOGGLE(info.quot)) {
if (info.rem != 0) {
val = (val == swtch ? swtch - 2 : swtch);
}
} else {
val = swtch;
}
if (val && (!isValueAvailable || isValueAvailable(val))) {
if (setValue) setValue(val);
this->fillMenu(menu);
}
}
});
#endif
}
#if defined(HARDWARE_KEYS)

View file

@ -26,11 +26,15 @@
class Menu;
bool isSwitchAvailableInMixes(int swtch);
class SwitchChoice : public FormField {
template <class T> friend class MenuToolbar;
class SwitchChoice : public FormField
{
template <class T>
friend class MenuToolbar;
public:
SwitchChoice(Window * parent, const rect_t & rect, int vmin, int vmax, std::function<int16_t()> getValue, std::function<void(int16_t)> setValue):
SwitchChoice(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue) :
FormField(parent, rect),
vmin(vmin),
vmax(vmax),
@ -40,10 +44,7 @@ class SwitchChoice : public FormField {
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "SwitchChoice";
}
std::string getName() const override { return "SwitchChoice"; }
#endif
void paint(BitmapBuffer* dc) override;

View file

@ -383,7 +383,7 @@ bool isInputRecursive(int index)
#if defined(AUTOSOURCE)
constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / XPOTS_MULTIPOS_COUNT;
int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS)
int8_t getMovedSource(uint8_t min)
{
int8_t result = 0;
static tmr10ms_t s_move_last_time = 0;

View file

@ -549,8 +549,7 @@ void logicalSwitchesCopyState(uint8_t src, uint8_t dst);
extern swarnstate_t switches_states;
swsrc_t getMovedSwitch();
#define GET_MOVED_SOURCE_PARAMS uint8_t min
int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS);
int8_t getMovedSource(uint8_t min);
#define GET_MOVED_SOURCE(min, max) getMovedSource(min)
#if defined(FLIGHT_MODES)