/* * Copyright (C) EdgeTX * * Based on code named * opentx - https://github.com/opentx/opentx * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #define LUA_LIB #include #include #include "edgetx.h" #include "lua_api.h" #include "lua_states.h" /*luadoc @function lcd.refresh() Refresh the LCD screen @status current Introduced in 2.2.0 @notice This function only works in stand-alone and telemetry scripts. */ static int luaLcdRefresh(lua_State *L) { if (luaLcdAllowed) lcdRefresh(); return 0; } /*luadoc @function lcd.clear([color]) Clear the LCD screen @param color (optional, only on color screens) @status current Introduced in 2.0.0, `color` parameter introduced in 2.2.0 RC12 @notice This function only works in stand-alone and telemetry scripts. */ static int luaLcdClear(lua_State *L) { if (luaLcdAllowed) { lcdClear(); } return 0; } /*luadoc @function lcd.resetBacklightTimeout() Reset the backlight timeout @status current Introduced in 2.3.6 */ static int luaLcdResetBacklightTimeout(lua_State * L) { if (!luaLcdAllowed) return 0; resetBacklightTimeout(); return 0; } /*luadoc @function lcd.drawPoint(x, y) Draw a single pixel at (x,y) position @param x (positive number) x position @param y (positive number) y position @param flags (optional) lcdflags @notice Taranis has an LCD display width of 212 pixels and height of 64 pixels. Position (0,0) is at top left. Y axis is negative, top line is 0, bottom line is 63. Drawing on an existing black pixel produces white pixel (TODO check this!) @status current Introduced in 2.0.0 */ static int luaLcdDrawPoint(lua_State *L) { if (!luaLcdAllowed) return 0; int x = luaL_checkinteger(L, 1); int y = luaL_checkinteger(L, 2); LcdFlags att = luaL_optunsigned(L, 3, 0); lcdDrawPoint(x, y, att); return 0; } /*luadoc @function lcd.drawLine(x1, y1, x2, y2, pattern, flags) Draw a straight line on LCD @param x1,y1 (positive numbers) starting coordinate @param x2,y2 (positive numbers) end coordinate @param pattern SOLID or DOTTED @param flags lcdflags @notice If the start or the end of the line is outside the LCD dimensions, then the whole line will not be drawn (starting from OpenTX 2.1.5) @status current Introduced in 2.0.0, flags introduced in 2.3.6 */ static int luaLcdDrawLine(lua_State *L) { if (!luaLcdAllowed) return 0; coord_t x1 = luaL_checkunsigned(L, 1); coord_t y1 = luaL_checkunsigned(L, 2); coord_t x2 = luaL_checkunsigned(L, 3); coord_t y2 = luaL_checkunsigned(L, 4); uint8_t pat = luaL_checkunsigned(L, 5); LcdFlags flags = luaL_checkunsigned(L, 6); if (x1 > LCD_W || y1 > LCD_H || x2 > LCD_W || y2 > LCD_H) return 0; if (pat == SOLID) { if (x1 == x2) { lcdDrawSolidVerticalLine(x1, y1 0) lcdDrawSolidFilledRect(x+1, y+1, len, h-2, flags); return 0; } /*luadoc @function lcd.drawScreenTitle(title, page, pages) Draw a title bar @param title (string) text for the title @param page (number) page number @param pages (number) total number of pages. Only used as indicator on the right side of title bar. (i.e. idx=2, cnt=5, display `2/5`) @notice Only available on Taranis @status current Introduced in 2.0.0 */ static int luaLcdDrawScreenTitle(lua_State *L) { if (!luaLcdAllowed) return 0; const char * str = luaL_checkstring(L, 1); int idx = luaL_checkinteger(L, 2); int cnt = luaL_checkinteger(L, 3); if (cnt) drawScreenIndex(idx-1, cnt, 0); #if LCD_DEPTH > 1 lcdDrawFilledRect(0, 0, LCD_W, FH, SOLID, FILL_WHITE|GREY_DEFAULT); #endif title(str); return 0; } /*luadoc @function lcd.drawCombobox(x, y, w, list, idx [, flags]) Draw a combo box @param x,y (positive numbers) top left corner position @param w (number) width of combo box in pixels @param list (table) combo box elements, each element is a string @param idx (integer) index of entry to highlight @param flags (unsigned number) drawing flags, the flags can not be combined: * `BLINK` combo box is expanded * `INVERS` combo box collapsed, text inversed * `0 or not present` combo box collapsed, text normal @notice Only available on Taranis @status current Introduced in 2.0.0 */ static int luaLcdDrawCombobox(lua_State *L) { if (!luaLcdAllowed) return 0; int x = luaL_checkinteger(L, 1); int y = luaL_checkinteger(L, 2); int w = luaL_checkinteger(L, 3); luaL_checktype(L, 4, LUA_TTABLE); int count = luaL_len(L, 4); /* get size of table */ int idx = luaL_checkinteger(L, 5); unsigned int flags = luaL_optunsigned(L, 6, 0); if (idx >= count) { // TODO error } if (flags & BLINK) { lcdDrawFilledRect(x, y, w-9, count*9+2, SOLID, ERASE); lcdDrawRect(x, y, w-9, count*9+2); for (int i=0; i