Skip to content

Commit

Permalink
Event params implemented for widgets.
Browse files Browse the repository at this point in the history
  • Loading branch information
qba667 committed Oct 9, 2019
1 parent 23ba709 commit 624101c
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 78 deletions.
4 changes: 2 additions & 2 deletions radio/src/gui/480x272/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ Zone Layout::getZone(unsigned int index) const
return zone;
}

void Layout::refresh()
void Layout::refresh(event_ext_t event)
{
WidgetsContainer::refresh();
WidgetsContainer::refresh(event);
}

uint16_t Layout::topBarHeight() const
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/480x272/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
}

void create() override;
void refresh() override;
void refresh(event_ext_t event = event_ext_t()) override;
Zone getZone(unsigned int index) const override;

unsigned int getZonesCount() const override
Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/480x272/layouts/layout2x4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class Layout2x4: public Layout
return zone;
}

void refresh() override;
void refresh(event_ext_t event = event_ext_t()) override;
};

void Layout2x4::refresh()
void Layout2x4::refresh(event_ext_t event)
{
Zone fullScreen = Layout::getZone(0);
fullScreen.w /=2;
Expand All @@ -84,7 +84,7 @@ void Layout2x4::refresh()
lcdSetColor(getZoneOptionValue(Panel2BGC)->unsignedValue);
lcdDrawSolidFilledRect(fullScreen.x, fullScreen.y, fullScreen.w, fullScreen.h, CUSTOM_COLOR);
}
Layout::refresh();
Layout::refresh(event);
}

BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", LBM_LAYOUT_2x4, OPTIONS_LAYOUT_2x4);
2 changes: 1 addition & 1 deletion radio/src/gui/480x272/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Widget
return &persistentData->options[index];
}

virtual void refresh() = 0;
virtual void refresh(event_ext_t event = event_ext_t()) = 0;

virtual void background()
{
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/480x272/widgets/gauge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GaugeWidget: public Widget
{
}

virtual void refresh();
virtual void refresh(event_ext_t event = event_ext_t());

static const ZoneOption options[];
};
Expand All @@ -43,7 +43,7 @@ const ZoneOption GaugeWidget::options[] = {
{ NULL, ZoneOption::Bool }
};

void GaugeWidget::refresh()
void GaugeWidget::refresh(event_ext_t event)
{
mixsrc_t index = persistentData->options[0].unsignedValue;
int32_t min = persistentData->options[1].signedValue;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/480x272/widgets/modelbmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ModelBitmapWidget: public Widget
}
}

virtual void refresh()
virtual void refresh(event_ext_t event = event_ext_t())
{
uint32_t new_hash = MathUtil::hash(g_model.header.bitmap, sizeof(g_model.header.bitmap));
new_hash ^= MathUtil::hash(g_model.header.name, sizeof(g_model.header.name));
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/480x272/widgets/outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OutputsWidget: public Widget
{
}

virtual void refresh();
virtual void refresh(event_ext_t event = event_ext_t());

uint8_t drawChannels(const uint16_t & x, const uint16_t & y, const uint16_t & w, const uint16_t & h, const uint8_t & firstChan, const bool & bg_shown, const uint16_t & bg_color)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ const ZoneOption OutputsWidget::options[] = {
};


void OutputsWidget::refresh()
void OutputsWidget::refresh(event_ext_t event)
{
if (zone.w > 300 && zone.h > 20)
twoColumns();
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/480x272/widgets/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TextWidget: public Widget
{
}

virtual void refresh();
virtual void refresh(event_ext_t event = event_ext_t());

static const ZoneOption options[];
};
Expand All @@ -43,7 +43,7 @@ const ZoneOption TextWidget::options[] = {
{ NULL, ZoneOption::Bool }
};

void TextWidget::refresh()
void TextWidget::refresh(event_ext_t event)
{
lcdSetColor(persistentData->options[1].unsignedValue);
LcdFlags fontsize = FONTSIZE(persistentData->options[2].unsignedValue << 8);
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/480x272/widgets/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TimerWidget: public Widget
{
}

virtual void refresh();
virtual void refresh(event_ext_t event = event_ext_t());

static const ZoneOption options[];
};
Expand All @@ -40,7 +40,7 @@ const ZoneOption TimerWidget::options[] = {
{ NULL, ZoneOption::Bool }
};

void TimerWidget::refresh()
void TimerWidget::refresh(event_ext_t event)
{
uint32_t index = persistentData->options[0].unsignedValue;
uint16_t textcolor = persistentData->options[1].unsignedValue;
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/480x272/widgets/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ValueWidget: public Widget
{
}

virtual void refresh();
virtual void refresh(event_ext_t event = event_ext_t());

static const ZoneOption options[];
};
Expand All @@ -40,7 +40,7 @@ const ZoneOption ValueWidget::options[] = {
{ NULL, ZoneOption::Bool }
};

void ValueWidget::refresh()
void ValueWidget::refresh(event_ext_t event)
{
const int NUMBERS_PADDING = 4;

Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/480x272/widgets_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ class WidgetsContainer: public WidgetsContainerInterface

virtual Zone getZone(unsigned int index) const = 0;

virtual void refresh()
virtual void refresh(event_ext_t event = event_ext_t())
{
if (widgets) {
for (int i=0; i<N; i++) {
if (widgets[i]) {
widgets[i]->refresh();
widgets[i]->refresh(event);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion radio/src/gui/common/windows/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ void MainWindow::checkEvents(bool luaActive) {
touchState.lastX = touchState.X;
touchState.lastY = touchState.Y;
}
if (event && !handled) putEvent(EVT_TOUCH(event), touchState.X, touchState.Y);

if (event && !handled) {
int32_t args[2] = {touchState.X, touchState.Y};
putEvent(EVT_TOUCH(event), args, 2);
}
}


Expand Down
41 changes: 12 additions & 29 deletions radio/src/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,36 @@
#define KSTATE_PAUSE 98
#define KSTATE_KILLED 99

event_lua_t empty_event = { };
event_t s_evt;
uint s_evtWParam;
uint s_evtLParam;
event_ext_t empty_event = { };
event_ext_t s_evt;

struct t_inactivity inactivity = {0};
Key keys[NUM_KEYS];

#if defined(CPUARM)
event_t getEvent(bool trim, event_lua_t& event)
event_t getEvent(bool trim, event_ext_t& event)
{
event.evt = 0;
event.wParam = 0;
event.lParam = 0;
event.clear();
#if !defined(BOOT) && IS_TOUCH_ENABLED()
//if (!trim && !KeyEventEmulator::keyEventsSuspended())
//TouchManager::instance()->processQueue(&KeyEventEmulator::mapToKeyEvent);
#endif
event_ext_t localEvent = s_evt;

event_t evt = s_evt;
int8_t k = EVT_KEY_MASK(s_evt) - TRM_BASE;
int8_t k = EVT_KEY_MASK(localEvent.evt) - TRM_BASE;
bool trim_evt = (k>=0 && k<TRM_LAST-TRM_BASE+1);

if (evt)
{
evt = s_evt;
}
if (trim == trim_evt) {
s_evt = 0;
event.evt = evt;
event.wParam = s_evtWParam;
event.lParam = s_evtLParam;
s_evtWParam = 0;
s_evtLParam = 0;
return evt;
s_evt.clear();
event.set(&localEvent);
return localEvent.evt;
}
else {
return 0;
}
}
event_t getEvent(bool trim) {
event_lua_t eventStruct;
event_ext_t eventStruct;
return getEvent(trim, eventStruct);
}
#else
Expand All @@ -89,14 +77,9 @@ event_t getEvent()
return evt;
}
#endif
void putEvent(event_t evt, uint32_t wParam, uint32_t lParam) {
s_evt = evt;
s_evtWParam = wParam;
s_evtLParam = lParam;

}
void putEvent(event_t evt) {
putEvent(evt, 0, 0);
void putEvent(event_t evt, event_param_t * params, int count) {
s_evt.set(evt, params, count);
}

void Key::input(bool val)
Expand Down
9 changes: 4 additions & 5 deletions radio/src/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,17 @@ class Key
};

extern Key keys[NUM_KEYS];
extern event_t s_evt;
extern event_lua_t empty_event;
extern event_ext_t s_evt;
extern event_ext_t empty_event;

void putEvent(event_t evt);
void putEvent(event_t evt, uint32_t wParam, uint32_t lParam);
void putEvent(event_t evt, event_param_t* params = nullptr, int count = 0);
void pauseEvents(event_t event);
void killEvents(event_t event);

#if defined(CPUARM)
bool clearKeyEvents();
event_t getEvent(bool trim=false);
event_t getEvent(bool trim, event_lua_t& event);
event_t getEvent(bool trim, event_ext_t& event);
#else
void clearKeyEvents();
event_t getEvent();
Expand Down
22 changes: 13 additions & 9 deletions radio/src/lua/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,21 +814,23 @@ void luaExec(const char * filename)
}
}

void luaDoOneRunStandalone(event_lua_t evt)
void luaDoOneRunStandalone(event_ext_t evt)
{
static uint8_t luaDisplayStatistics = false;

if (standaloneScript.state == SCRIPT_OK && standaloneScript.run) {
luaSetInstructionsLimit(lsScripts, MANUAL_SCRIPTS_MAX_INSTRUCTIONS);
lua_rawgeti(lsScripts, LUA_REGISTRYINDEX, standaloneScript.run);
lua_pushunsigned(lsScripts, evt.evt);
lua_pushunsigned(lsScripts, evt.wParam);
lua_pushunsigned(lsScripts, evt.lParam);
for(int i=0; i<evt.paramsCount(); i++) {
//tbd check type and push it with correct type
lua_pushunsigned(lsScripts, evt.params[i]);
}
//always work on copy to avoid flickering
BitmapBuffer * previous = lcd;
lcdNextLayer();
DMACopy(previous->getData(), lcd->getData(), DISPLAY_BUFFER_SIZE);
if (lua_pcall(lsScripts, 3, 1, 0) == 0) {
if (lua_pcall(lsScripts, evt.paramsCount() + 1, 1, 0) == 0) {
if (!lua_isnumber(lsScripts, -1)) {
if (instructionsPercent > 100) {
TRACE("Script killed");
Expand Down Expand Up @@ -902,7 +904,7 @@ void luaDoOneRunStandalone(event_lua_t evt)
}
}

bool luaDoOneRunPermanentScript(event_lua_t evt, int i, uint32_t scriptType)
bool luaDoOneRunPermanentScript(event_ext_t evt, int i, uint32_t scriptType)
{
ScriptInternalData & sid = scriptInternalData[i];
if (sid.state != SCRIPT_OK) return false;
Expand Down Expand Up @@ -953,9 +955,11 @@ bool luaDoOneRunPermanentScript(event_lua_t evt, int i, uint32_t scriptType)
if ((scriptType & RUN_TELEM_FG_SCRIPT) && (menuHandlers[0]==menuViewTelemetryFrsky && sid.reference==SCRIPT_TELEMETRY_FIRST+s_frsky_view)) {
lua_rawgeti(lsScripts, LUA_REGISTRYINDEX, sid.run);
lua_pushunsigned(lsScripts, evt.evt);
lua_pushunsigned(lsScripts, evt.wParam);
lua_pushunsigned(lsScripts, evt.lParam);
inputsCount = 3;
inputsCount = 1 + evt.paramsCount();
for(int i=0; i<evt.paramsCount(); i++) {
//tbd check type and push it with correct type
lua_pushunsigned(lsScripts, evt.params[i]);
}
}
else if ((scriptType & RUN_TELEM_BG_SCRIPT) && (sid.background)) {
lua_rawgeti(lsScripts, LUA_REGISTRYINDEX, sid.background);
Expand Down Expand Up @@ -1006,7 +1010,7 @@ bool luaDoOneRunPermanentScript(event_lua_t evt, int i, uint32_t scriptType)
return true;
}

bool luaTask(event_lua_t evt, uint8_t scriptType, bool allowLcdUsage)
bool luaTask(event_ext_t evt, uint8_t scriptType, bool allowLcdUsage)
{
if (luaState == INTERPRETER_PANIC) return false;
luaLcdAllowed = allowLcdUsage;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/lua/lua_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extern ScriptInternalData standaloneScript;
extern ScriptInternalData scriptInternalData[MAX_SCRIPTS];
extern ScriptInputsOutputs scriptInputsOutputs[MAX_SCRIPTS];
void luaClose(lua_State ** L);
bool luaTask(event_lua_t evt, uint8_t scriptType, bool allowLcdUsage);
bool luaTask(event_ext_t evt, uint8_t scriptType, bool allowLcdUsage);
void checkLuaMemoryUsage();
void luaExec(const char * filename);
void luaDoGc(lua_State * L, bool full);
Expand Down
11 changes: 8 additions & 3 deletions radio/src/lua/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class LuaWidget: public Widget

virtual void update();

virtual void refresh();
virtual void refresh(event_ext_t event);

virtual void background();

Expand Down Expand Up @@ -373,7 +373,7 @@ const char * LuaWidget::getErrorMessage() const
return errorMessage;
}

void LuaWidget::refresh()
void LuaWidget::refresh(event_ext_t event)
{
if (lsWidgets == 0) return;

Expand All @@ -387,7 +387,12 @@ void LuaWidget::refresh()
LuaWidgetFactory * factory = (LuaWidgetFactory *)this->factory;
lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, factory->refreshFunction);
lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, widgetData);
if (lua_pcall(lsWidgets, 1, 0, 0) != 0) {
lua_pushinteger(lsWidgets, event.evt);
for(int i=0; i<event.paramsCount(); i++) {
//tbd check type and push it with correct type
lua_pushunsigned(lsWidgets, event.params[i]);
}
if (lua_pcall(lsWidgets, event.paramsCount() + 1, 0, 0) != 0) {
setErrorMessage("refresh()");
}
}
Expand Down
Loading

0 comments on commit 624101c

Please sign in to comment.