mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-13 11:29:49 +03:00
parent
65ce8b4602
commit
162ffdb148
6 changed files with 67 additions and 36 deletions
|
@ -3,6 +3,5 @@ Language: Cpp
|
|||
BasedOnStyle: Google
|
||||
BreakBeforeBraces: Linux
|
||||
BreakConstructorInitializers: AfterColon
|
||||
AccessModifierOffset: 0
|
||||
...
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -26,49 +26,50 @@
|
|||
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):
|
||||
public:
|
||||
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),
|
||||
getValue(std::move(getValue)),
|
||||
setValue(std::move(setValue))
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
{
|
||||
return "SwitchChoice";
|
||||
}
|
||||
std::string getName() const override { return "SwitchChoice"; }
|
||||
#endif
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
void paint(BitmapBuffer* dc) override;
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
void onEvent(event_t event) override;
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchEnd(coord_t x, coord_t y) override ;
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
#endif
|
||||
|
||||
void setAvailableHandler(std::function<bool(int)> handler)
|
||||
{
|
||||
isValueAvailable = std::move(handler);
|
||||
}
|
||||
void setAvailableHandler(std::function<bool(int)> handler)
|
||||
{
|
||||
isValueAvailable = std::move(handler);
|
||||
}
|
||||
|
||||
protected:
|
||||
int16_t vmin;
|
||||
int16_t vmax;
|
||||
std::function<int16_t()> getValue;
|
||||
std::function<void(int16_t)> setValue;
|
||||
std::function<bool(int)> isValueAvailable = isSwitchAvailableInMixes;
|
||||
void fillMenu(Menu * menu, std::function<bool(int16_t)> condition=nullptr);
|
||||
void openMenu();
|
||||
protected:
|
||||
int16_t vmin;
|
||||
int16_t vmax;
|
||||
std::function<int16_t()> getValue;
|
||||
std::function<void(int16_t)> setValue;
|
||||
std::function<bool(int)> isValueAvailable = isSwitchAvailableInMixes;
|
||||
void fillMenu(Menu* menu, std::function<bool(int16_t)> condition = nullptr);
|
||||
void openMenu();
|
||||
};
|
||||
|
||||
#endif // _SWITCHCHOICE_H_
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue