Skip to content

Commit

Permalink
Added auto-switch / auto-source to colorlcd
Browse files Browse the repository at this point in the history
Resolves #118
  • Loading branch information
raphaelcoeffic committed Jun 7, 2021
1 parent 65ce8b4 commit 162ffdb
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 36 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ Language: Cpp
BasedOnStyle: Google
BreakBeforeBraces: Linux
BreakConstructorInitializers: AfterColon
AccessModifierOffset: 0
...

15 changes: 15 additions & 0 deletions radio/src/gui/colorlcd/sourcechoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 24 additions & 7 deletions radio/src/gui/colorlcd/switchchoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down
51 changes: 26 additions & 25 deletions radio/src/gui/colorlcd/switchchoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 1 addition & 1 deletion radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions radio/src/opentx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 162ffdb

Please sign in to comment.