5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
27 @function lcd.refresh()
29 Refresh the LCD screen
31 @status current Introduced in 2.2.0
33 @notice This function only works in stand-alone and telemetry scripts.
35 static int luaLcdRefresh(lua_State
*L
)
37 if (luaLcdAllowed
) lcdRefresh();
42 @function lcd.clear([color])
46 @param color (optional, only on color screens)
48 @status current Introduced in 2.0.0, `color` parameter introduced in 2.2.0 RC12
50 @notice This function only works in stand-alone and telemetry scripts.
52 static int luaLcdClear(lua_State
*L
)
56 LcdFlags color
= luaL_optunsigned(L
, 1, TEXT_BGCOLOR
);
66 @function lcd.drawPoint(x, y)
68 Draw a single pixel at (x,y) position
70 @param x (positive number) x position
72 @param y (positive number) y position
74 @notice Taranis has an LCD display width of 212 pixels and height of 64 pixels.
75 Position (0,0) is at top left. Y axis is negative, top line is 0,
76 bottom line is 63. Drawing on an existing black pixel produces white pixel (TODO check this!)
78 @status current Introduced in 2.0.0
80 static int luaLcdDrawPoint(lua_State
*L
)
82 if (!luaLcdAllowed
) return 0;
83 int x
= luaL_checkinteger(L
, 1);
84 int y
= luaL_checkinteger(L
, 2);
90 @function lcd.drawLine(x1, y1, x2, y2, pattern, flags)
92 Draw a straight line on LCD
94 @param x1,y1 (positive numbers) starting coordinate
96 @param x2,y2 (positive numbers) end coordinate
102 @notice If the start or the end of the line is outside the LCD dimensions, then the
103 whole line will not be drawn (starting from OpenTX 2.1.5)
105 @status current Introduced in 2.0.0
107 static int luaLcdDrawLine(lua_State
*L
)
109 if (!luaLcdAllowed
) return 0;
110 coord_t x1
= luaL_checkunsigned(L
, 1);
111 coord_t y1
= luaL_checkunsigned(L
, 2);
112 coord_t x2
= luaL_checkunsigned(L
, 3);
113 coord_t y2
= luaL_checkunsigned(L
, 4);
114 uint8_t pat
= luaL_checkunsigned(L
, 5);
115 LcdFlags flags
= luaL_checkunsigned(L
, 6);
117 if (x1
> LCD_W
|| y1
> LCD_H
|| x2
> LCD_W
|| y2
> LCD_H
)
122 lcdDrawSolidVerticalLine(x1
, y1
<y2
? y1
: y2
, y1
<y2
? (y2
-y1
)+1 : (y1
-y2
)+1, flags
);
126 lcdDrawSolidHorizontalLine(x1
<x2
? x1
: x2
, y1
, x1
<x2
? (x2
-x1
)+1 : (x1
-x2
)+1, flags
);
131 lcdDrawLine(x1
, y1
, x2
, y2
, pat
, flags
);
135 #if !defined(COLORLCD)
137 @function lcd.getLastPos()
139 Returns the rightmost x position from previous output
141 @retval number (integer) x position
143 @notice Only available on Taranis
145 @notice For added clarity, it is recommended to use lcd.getLastRightPos()
147 @status current Introduced in 2.0.0
151 @function lcd.getLastRightPos()
153 Returns the rightest x position from previous drawtext or drawNumber output
155 @retval number (integer) x position
157 @notice Only available on Taranis
159 @notice This is strictly equivalent to former lcd.getLastPos()
161 @status current Introduced in 2.2.0
164 static int luaLcdGetLastPos(lua_State
*L
)
166 lua_pushinteger(L
, lcdLastRightPos
);
171 @function lcd.getLastLeftPos()
173 Returns the leftmost x position from previous drawtext or drawNumber output
175 @retval number (integer) x position
177 @notice Only available on Taranis
179 @status current Introduced in 2.2.0
181 static int luaLcdGetLeftPos(lua_State
*L
)
183 lua_pushinteger(L
, lcdLastLeftPos
);
190 @function lcd.drawText(x, y, text [, flags])
192 Draw a text beginning at (x,y)
194 @param x,y (positive numbers) starting coordinate
196 @param text (string) text to display
198 @param flags (unsigned number) drawing flags. All values can be
199 combined together using the + character. ie BLINK + DBLSIZE.
200 See the [Appendix](../appendix/fonts.md) for available characters in each font set.
201 * `0 or not specified` normal font
202 * `XXLSIZE` jumbo sized font
203 * `DBLSIZE` double size font
204 * `MIDSIZE` mid sized font
205 * `SMLSIZE` small font
206 * `INVERS` inverted display
207 * `BLINK` blinking text
208 * `SHADOWED` Horus only, apply a shadow effect
210 @status current Introduced in 2.0.0, `SHADOWED` introduced in 2.2.1
212 static int luaLcdDrawText(lua_State
*L
)
214 if (!luaLcdAllowed
) return 0;
215 int x
= luaL_checkinteger(L
, 1);
216 int y
= luaL_checkinteger(L
, 2);
217 const char * s
= luaL_checkstring(L
, 3);
218 unsigned int att
= luaL_optunsigned(L
, 4, 0);
219 #if defined(COLORLCD)
220 if ((att
&SHADOWED
) && !(att
&INVERS
)) lcdDrawText(x
+1, y
+1, s
, att
&0xFFFF);
222 lcdDrawText(x
, y
, s
, att
);
227 @function lcd.drawTimer(x, y, value [, flags])
229 Display a value formatted as time at (x,y)
231 @param x,y (positive numbers) starting coordinate
233 @param value (number) time in seconds
235 @param flags (unsigned number) drawing flags:
236 * `0 or not specified` normal representation (minutes and seconds)
237 * `TIMEHOUR` display hours
238 * other general LCD flag also apply
239 * `SHADOWED` Horus only, apply a shadow effect
241 @status current Introduced in 2.0.0, `SHADOWED` introduced in 2.2.1
243 static int luaLcdDrawTimer(lua_State
*L
)
245 if (!luaLcdAllowed
) return 0;
246 int x
= luaL_checkinteger(L
, 1);
247 int y
= luaL_checkinteger(L
, 2);
248 int seconds
= luaL_checkinteger(L
, 3);
249 unsigned int att
= luaL_optunsigned(L
, 4, 0);
250 #if defined(COLORLCD)
251 if (att
&SHADOWED
) drawTimer(x
+1, y
+1, seconds
, (att
&0xFFFF)|LEFT
);
252 drawTimer(x
, y
, seconds
, att
|LEFT
);
254 drawTimer(x
, y
, seconds
, att
|LEFT
, att
);
260 @function lcd.drawNumber(x, y, value [, flags])
262 Display a number at (x,y)
264 @param x,y (positive numbers) starting coordinate
266 @param value (number) value to display
268 @param flags (unsigned number) drawing flags:
269 * `0 or not specified` display with no decimal (like abs())
270 * `PREC1` display with one decimal place (number 386 is displayed as 38.6)
271 * `PREC2` display with tow decimal places (number 386 is displayed as 3.86)
272 * other general LCD flag also apply
273 * `SHADOWED` Horus only, apply a shadow effect
275 @status current Introduced in 2.0.0, `SHADOWED` introduced in 2.2.1
277 static int luaLcdDrawNumber(lua_State
*L
)
279 if (!luaLcdAllowed
) return 0;
280 int x
= luaL_checkinteger(L
, 1);
281 int y
= luaL_checkinteger(L
, 2);
282 int val
= luaL_checkinteger(L
, 3);
283 unsigned int att
= luaL_optunsigned(L
, 4, 0);
284 #if defined(COLORLCD)
285 if ((att
&SHADOWED
) && !(att
&INVERS
)) lcdDrawNumber(x
, y
, val
, att
&0xFFFF);
287 lcdDrawNumber(x
, y
, val
, att
);
292 @function lcd.drawChannel(x, y, source, flags)
294 Display a telemetry value at (x,y)
296 @param x,y (positive numbers) starting coordinate
298 @param source can be a source identifier (number) or a source name (string).
301 @param flags (unsigned number) drawing flags
303 @status current Introduced in 2.0.6, changed in 2.1.0 (only telemetry sources are valid)
305 static int luaLcdDrawChannel(lua_State
*L
)
307 if (!luaLcdAllowed
) return 0;
308 int x
= luaL_checkinteger(L
, 1);
309 int y
= luaL_checkinteger(L
, 2);
311 if (lua_isnumber(L
, 3)) {
312 channel
= luaL_checkinteger(L
, 3);
315 const char * what
= luaL_checkstring(L
, 3);
317 bool found
= luaFindFieldByName(what
, field
);
322 unsigned int att
= luaL_optunsigned(L
, 4, 0);
323 getvalue_t value
= getValue(channel
);
324 drawSensorCustomValue(x
, y
, (channel
-MIXSRC_FIRST_TELEM
)/3, value
, att
);
329 @function lcd.drawSwitch(x, y, switch, flags)
331 Draw a text representation of switch at (x,y)
333 @param x,y (positive numbers) starting coordinate
335 @param switch (number) number of switch to display, negative number
336 displays negated switch
338 @param flags (unsigned number) drawing flags, only SMLSIZE, BLINK and INVERS.
340 @status current Introduced in 2.0.0
342 static int luaLcdDrawSwitch(lua_State
*L
)
344 if (!luaLcdAllowed
) return 0;
345 int x
= luaL_checkinteger(L
, 1);
346 int y
= luaL_checkinteger(L
, 2);
347 int s
= luaL_checkinteger(L
, 3);
348 unsigned int att
= luaL_optunsigned(L
, 4, 0);
349 drawSwitch(x
, y
, s
, att
);
354 @function lcd.drawSource(x, y, source [, flags])
356 Displays the name of the corresponding input as defined by the source at (x,y)
358 @param x,y (positive numbers) starting coordinate
360 @param source (number) source index
362 @param flags (unsigned number) drawing flags
364 @status current Introduced in 2.0.0
366 static int luaLcdDrawSource(lua_State
*L
)
368 if (!luaLcdAllowed
) return 0;
369 int x
= luaL_checkinteger(L
, 1);
370 int y
= luaL_checkinteger(L
, 2);
371 int s
= luaL_checkinteger(L
, 3);
372 unsigned int att
= luaL_optunsigned(L
, 4, 0);
373 drawSource(x
, y
, s
, att
);
377 #if defined(COLORLCD)
379 #define LUA_BITMAPHANDLE "BITMAP*"
382 @function Bitmap.open(name)
384 Loads a bitmap in memory, for later use with lcd.drawBitmap(). Bitmaps should be loaded only
385 once, returned object should be stored and used for drawing. If loading fails for whatever
386 reason the resulting bitmap object will have width and height set to zero.
388 Bitmap loading can fail if:
389 * File is not found or contains invalid image
390 * System is low on memory
391 * Combined memory usage of all Lua script bitmaps exceeds certain value
393 @param name (string) full path to the bitmap on SD card (i.e. “/IMAGES/test.bmp”)
395 @retval bitmap (object) a bitmap object that can be used with other bitmap functions
397 @notice Only available on Horus
399 @status current Introduced in 2.2.0
401 static int luaOpenBitmap(lua_State
* L
)
403 const char * filename
= luaL_checkstring(L
, 1);
405 BitmapBuffer
** b
= (BitmapBuffer
**)lua_newuserdata(L
, sizeof(BitmapBuffer
*));
407 if (luaExtraMemoryUsage
> LUA_MEM_EXTRA_MAX
) {
408 // already allocated more than max allowed, fail
409 TRACE("luaOpenBitmap: Error, using too much memory %u/%u", luaExtraMemoryUsage
, LUA_MEM_EXTRA_MAX
);
413 *b
= BitmapBuffer::load(filename
);
414 if (*b
== NULL
&& G(L
)->gcrunning
) {
415 luaC_fullgc(L
, 1); /* try to free some memory... */
416 *b
= BitmapBuffer::load(filename
); /* try again */
421 uint32_t size
= (*b
)->getDataSize();
422 luaExtraMemoryUsage
+= size
;
423 TRACE("luaOpenBitmap: %p (%u)", *b
, size
);
426 luaL_getmetatable(L
, LUA_BITMAPHANDLE
);
427 lua_setmetatable(L
, -2);
432 static BitmapBuffer
* checkBitmap(lua_State
* L
, int index
)
434 BitmapBuffer
** b
= (BitmapBuffer
**)luaL_checkudata(L
, index
, LUA_BITMAPHANDLE
);
439 @function Bitmap.getSize(name)
441 Return width, height of a bitmap object
443 @param bitmap (pointer) point to a bitmap previously opened with Bitmap.open()
445 @retval multiple returns 2 values:
446 * (number) width in pixels
447 * (number) height in pixels
449 @notice Only available on Horus
451 @status current Introduced in 2.2.0
453 static int luaGetBitmapSize(lua_State
* L
)
455 const BitmapBuffer
* b
= checkBitmap(L
, 1);
457 lua_pushinteger(L
, b
->getWidth());
458 lua_pushinteger(L
, b
->getHeight());
461 lua_pushinteger(L
, 0);
462 lua_pushinteger(L
, 0);
467 static int luaDestroyBitmap(lua_State
* L
)
469 BitmapBuffer
* b
= checkBitmap(L
, 1);
471 uint32_t size
= b
->getDataSize();
472 TRACE("luaDestroyBitmap: %p (%u)", b
, size
);
473 if (luaExtraMemoryUsage
>= size
) {
474 luaExtraMemoryUsage
-= size
;
477 luaExtraMemoryUsage
= 0;
484 const luaL_Reg bitmapFuncs
[] = {
485 { "open", luaOpenBitmap
},
486 { "getSize", luaGetBitmapSize
},
487 { "__gc", luaDestroyBitmap
},
491 void registerBitmapClass(lua_State
* L
)
493 luaL_newmetatable(L
, LUA_BITMAPHANDLE
);
494 luaL_setfuncs(L
, bitmapFuncs
, 0);
495 lua_pushvalue(L
, -1);
496 lua_setfield(L
, -2, "__index");
497 lua_setglobal(L
, "Bitmap");
501 @function lcd.drawBitmap(bitmap, x, y [, scale])
503 Displays a bitmap at (x,y)
505 @param bitmap (pointer) point to a bitmap previously opened with Bitmap.open()
507 @param x,y (positive numbers) starting coordinates
509 @param scale (positive numbers) scale in %, 50 divides size by two, 100 is unchanged, 200 doubles size.
510 Omitting scale draws image in 1:1 scale and is faster than specifying 100 for scale.
512 @notice Only available on Horus
514 @status current Introduced in 2.2.0
516 static int luaLcdDrawBitmap(lua_State
*L
)
518 if (!luaLcdAllowed
) return 0;
519 const BitmapBuffer
* b
= checkBitmap(L
, 1);
522 unsigned int x
= luaL_checkunsigned(L
, 2);
523 unsigned int y
= luaL_checkunsigned(L
, 3);
524 unsigned int scale
= luaL_optunsigned(L
, 4, 0);
526 lcd
->drawBitmap(x
, y
, b
, 0, 0, 0, 0, scale
/100.0f
);
529 lcd
->drawBitmap(x
, y
, b
);
536 @function lcd.drawPixmap(x, y, name)
538 Draw a bitmap at (x,y)
540 @param x,y (positive numbers) starting coordinates
542 @param name (string) full path to the bitmap on SD card (i.e. “/IMAGES/test.bmp”)
544 @notice Only available on Taranis X9 series. Maximum image size if 106 x 64 pixels (width x height).
546 @status current Introduced in 2.0.0
548 static int luaLcdDrawPixmap(lua_State
*L
)
550 if (!luaLcdAllowed
) return 0;
551 int x
= luaL_checkinteger(L
, 1);
552 int y
= luaL_checkinteger(L
, 2);
553 const char * filename
= luaL_checkstring(L
, 3);
555 uint8_t bitmap
[BITMAP_BUFFER_SIZE(LCD_W
/2, LCD_H
)]; // width max is LCD_W/2 pixels for saving stack and avoid a malloc here
556 if (lcdLoadBitmap(bitmap
, filename
, LCD_W
/2, LCD_H
)) {
557 lcdDrawBitmap(x
, y
, bitmap
);
565 @function lcd.drawRectangle(x, y, w, h [, flags [, t]])
567 Draw a rectangle from top left corner (x,y) of specified width and height
569 @param x,y (positive numbers) top left corner position
571 @param w (number) width in pixels
573 @param h (number) height in pixels
575 @param flags (unsigned number) drawing flags
577 @param t (number) thickness in pixels, defaults to 1 (only on Horus)
579 @status current Introduced in 2.0.0, changed in 2.2.0
581 static int luaLcdDrawRectangle(lua_State
*L
)
583 if (!luaLcdAllowed
) return 0;
584 int x
= luaL_checkinteger(L
, 1);
585 int y
= luaL_checkinteger(L
, 2);
586 int w
= luaL_checkinteger(L
, 3);
587 int h
= luaL_checkinteger(L
, 4);
588 unsigned int flags
= luaL_optunsigned(L
, 5, 0);
589 #if defined(PCBHORUS)
590 unsigned int t
= luaL_optunsigned(L
, 6, 1);
591 lcdDrawRect(x
, y
, w
, h
, t
, 0xff, flags
);
593 lcdDrawRect(x
, y
, w
, h
, 0xff, flags
);
599 @function lcd.drawFilledRectangle(x, y, w, h [, flags])
601 Draw a solid rectangle from top left corner (x,y) of specified width and height
603 @param x,y (positive numbers) top left corner position
605 @param w (number) width in pixels
607 @param h (number) height in pixels
609 @param flags (unsigned number) drawing flags
611 @status current Introduced in 2.0.0
613 static int luaLcdDrawFilledRectangle(lua_State
*L
)
615 if (!luaLcdAllowed
) return 0;
616 int x
= luaL_checkinteger(L
, 1);
617 int y
= luaL_checkinteger(L
, 2);
618 int w
= luaL_checkinteger(L
, 3);
619 int h
= luaL_checkinteger(L
, 4);
620 unsigned int flags
= luaL_optunsigned(L
, 5, 0);
621 lcdDrawFilledRect(x
, y
, w
, h
, SOLID
, flags
);
627 @function lcd.drawGauge(x, y, w, h, fill, maxfill [, flags])
629 Draw a simple gauge that is filled based upon fill value
631 @param x,y (positive numbers) top left corner position
633 @param w (number) width in pixels
635 @param h (number) height in pixels
637 @param fill (number) amount of fill to apply
639 @param maxfill (number) total value of fill
641 @param flags (unsigned number) drawing flags
643 @status current Introduced in 2.0.0, changed in 2.2.0
645 static int luaLcdDrawGauge(lua_State
*L
)
647 if (!luaLcdAllowed
) return 0;
648 int x
= luaL_checkinteger(L
, 1);
649 int y
= luaL_checkinteger(L
, 2);
650 int w
= luaL_checkinteger(L
, 3);
651 int h
= luaL_checkinteger(L
, 4);
652 int num
= luaL_checkinteger(L
, 5);
653 int den
= luaL_checkinteger(L
, 6);
654 unsigned int flags
= luaL_optunsigned(L
, 7, 0);
655 #if defined(PCBHORUS)
656 lcdDrawRect(x
, y
, w
, h
, 1, 0xff, flags
);
658 lcdDrawRect(x
, y
, w
, h
, 0xff, flags
);
660 uint8_t len
= limit((uint8_t)1, uint8_t(w
*num
/den
), uint8_t(w
));
661 lcdDrawSolidFilledRect(x
+1, y
+1, len
, h
-2, flags
);
666 #if !defined(COLORLCD)
668 @function lcd.drawScreenTitle(title, page, pages)
672 @param title (string) text for the title
674 @param page (number) page number
676 @param pages (number) total number of pages. Only used as indicator on
677 the right side of title bar. (i.e. idx=2, cnt=5, display `2/5`)
679 @notice Only available on Taranis
681 @status current Introduced in 2.0.0
683 static int luaLcdDrawScreenTitle(lua_State
*L
)
685 if (!luaLcdAllowed
) return 0;
686 const char * str
= luaL_checkstring(L
, 1);
687 int idx
= luaL_checkinteger(L
, 2);
688 int cnt
= luaL_checkinteger(L
, 3);
690 if (cnt
) drawScreenIndex(idx
-1, cnt
, 0);
692 lcdDrawFilledRect(0, 0, LCD_W
, FH
, SOLID
, FILL_WHITE
|GREY_DEFAULT
);
700 #if !defined(COLORLCD)
702 @function lcd.drawCombobox(x, y, w, list, idx [, flags])
706 @param x,y (positive numbers) top left corner position
708 @param w (number) width of combo box in pixels
710 @param list (table) combo box elements, each element is a string
712 @param idx (integer) index of entry to highlight
714 @param flags (unsigned number) drawing flags, the flags can not be combined:
715 * `BLINK` combo box is expanded
716 * `INVERS` combo box collapsed, text inversed
717 * `0 or not present` combo box collapsed, text normal
719 @notice Only available on Taranis
721 @status current Introduced in 2.0.0
723 static int luaLcdDrawCombobox(lua_State
*L
)
725 if (!luaLcdAllowed
) return 0;
726 int x
= luaL_checkinteger(L
, 1);
727 int y
= luaL_checkinteger(L
, 2);
728 int w
= luaL_checkinteger(L
, 3);
729 luaL_checktype(L
, 4, LUA_TTABLE
);
730 int count
= luaL_len(L
, 4); /* get size of table */
731 int idx
= luaL_checkinteger(L
, 5);
732 unsigned int flags
= luaL_optunsigned(L
, 6, 0);
737 lcdDrawFilledRect(x
, y
, w
-9, count
*9+2, SOLID
, ERASE
);
738 lcdDrawRect(x
, y
, w
-9, count
*9+2);
739 for (int i
=0; i
<count
; i
++) {
740 lua_rawgeti(L
, 4, i
+1);
741 const char * item
= luaL_checkstring(L
, -1);
742 lcdDrawText(x
+2, y
+2+9*i
, item
, 0);
744 lcdDrawFilledRect(x
+1, y
+1+9*idx
, w
-11, 9);
745 lcdDrawFilledRect(x
+w
-10, y
, 10, 11, SOLID
, ERASE
);
746 lcdDrawRect(x
+w
-10, y
, 10, 11);
748 else if (flags
& INVERS
) {
749 lcdDrawFilledRect(x
, y
, w
, 11);
750 lcdDrawFilledRect(x
+w
-9, y
+1, 8, 9, SOLID
, ERASE
);
751 lua_rawgeti(L
, 4, idx
+1);
752 const char * item
= luaL_checkstring(L
, -1);
753 lcdDrawText(x
+2, y
+2, item
, INVERS
);
756 lcdDrawFilledRect(x
, y
, w
, 11, SOLID
, ERASE
);
757 lcdDrawRect(x
, y
, w
, 11);
758 lcdDrawFilledRect(x
+w
-10, y
+1, 9, 9, SOLID
);
759 lua_rawgeti(L
, 4, idx
+1);
760 const char * item
= luaL_checkstring(L
, -1);
761 lcdDrawText(x
+2, y
+2, item
, 0);
764 lcdDrawSolidHorizontalLine(x
+w
-8, y
+3, 6);
765 lcdDrawSolidHorizontalLine(x
+w
-8, y
+5, 6);
766 lcdDrawSolidHorizontalLine(x
+w
-8, y
+7, 6);
772 #if defined(COLORLCD)
774 @function lcd.setColor(area, color)
776 Set a color for specific area
778 @param area (unsigned number) specific screen area in the list bellow
782 * `TEXT_INVERTED_COLOR`
783 * `TEXT_INVERTED_BGCOLOR`
786 * `MENU_TITLE_BGCOLOR`
788 * `MENU_TITLE_DISABLE_COLOR`
792 * `TEXT_DISABLE_COLOR`
795 * `CURVE_CURSOR_COLOR`
798 * `TRIM_SHADOW_COLOR`
799 * `MAINVIEW_PANES_COLOR`
800 * `MAINVIEW_GRAPHICS_COLOR`
802 * `HEADER_ICON_BGCOLOR`
803 * `HEADER_CURRENT_BGCOLOR`
806 @param color (number) color in 5/6/5 rgb format. The following prefined colors are available
817 @notice Only available on Horus
819 @status current Introduced in 2.2.0
821 static int luaLcdSetColor(lua_State
*L
)
823 if (!luaLcdAllowed
) return 0;
824 unsigned int index
= luaL_checkunsigned(L
, 1) >> 16;
825 unsigned int color
= luaL_checkunsigned(L
, 2);
826 lcdColorTable
[index
] = color
;
831 @function lcd.RGB(r, g, b)
833 Returns a 5/6/5 rgb color code, that can be used with lcd.setColor
835 @param r (integer) a number between 0x00 and 0xff that expresses te amount of red in the color
837 @param g (integer) a number between 0x00 and 0xff that expresses te amount of green in the color
839 @param b (integer) a number between 0x00 and 0xff that expresses te amount of blue in the color
841 @retval number (integer) rgb color expressed in 5/6/5 format
843 @notice Only available on Horus
845 @status current Introduced in 2.2.0
847 static int luaRGB(lua_State
*L
)
849 if (!luaLcdAllowed
) return 0;
850 int r
= luaL_checkinteger(L
, 1);
851 int g
= luaL_checkinteger(L
, 2);
852 int b
= luaL_checkinteger(L
, 3);
853 lua_pushinteger(L
, RGB(r
, g
, b
));
858 const luaL_Reg lcdLib
[] = {
859 { "refresh", luaLcdRefresh
},
860 { "clear", luaLcdClear
},
861 { "drawPoint", luaLcdDrawPoint
},
862 { "drawLine", luaLcdDrawLine
},
863 { "drawRectangle", luaLcdDrawRectangle
},
864 { "drawFilledRectangle", luaLcdDrawFilledRectangle
},
865 { "drawText", luaLcdDrawText
},
866 { "drawTimer", luaLcdDrawTimer
},
867 { "drawNumber", luaLcdDrawNumber
},
868 { "drawChannel", luaLcdDrawChannel
},
869 { "drawSwitch", luaLcdDrawSwitch
},
870 { "drawSource", luaLcdDrawSource
},
871 { "drawGauge", luaLcdDrawGauge
},
872 #if defined(COLORLCD)
873 { "drawBitmap", luaLcdDrawBitmap
},
874 { "setColor", luaLcdSetColor
},
877 { "getLastPos", luaLcdGetLastPos
},
878 { "getLastRightPos", luaLcdGetLastPos
},
879 { "getLastLeftPos", luaLcdGetLeftPos
},
880 { "drawPixmap", luaLcdDrawPixmap
},
881 { "drawScreenTitle", luaLcdDrawScreenTitle
},
882 { "drawCombobox", luaLcdDrawCombobox
},
884 { NULL
, NULL
} /* sentinel */