diff options
Diffstat (limited to 'apps/plugins/lua/include_lua/lcd.lua')
-rw-r--r-- | apps/plugins/lua/include_lua/lcd.lua | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/apps/plugins/lua/include_lua/lcd.lua b/apps/plugins/lua/include_lua/lcd.lua deleted file mode 100644 index 62fa988ec1..0000000000 --- a/apps/plugins/lua/include_lua/lcd.lua +++ /dev/null | |||
@@ -1,153 +0,0 @@ | |||
1 | --[[ Lua LCD Wrapper functions | ||
2 | /*************************************************************************** | ||
3 | * __________ __ ___. | ||
4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | * \/ \/ \/ \/ \/ | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Copyright (C) 2017 William Wilgus | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | ]] | ||
23 | |||
24 | --[[ Exposed Functions | ||
25 | |||
26 | _lcd.clear | ||
27 | _lcd.duplicate | ||
28 | _lcd.image | ||
29 | _lcd.set_viewport | ||
30 | _lcd.splashf | ||
31 | _lcd.text_extent | ||
32 | _lcd.update | ||
33 | _lcd.update_rect | ||
34 | |||
35 | -- Exposed Constants | ||
36 | _lcd.CX | ||
37 | _lcd.CY | ||
38 | _lcd.DEPTH | ||
39 | _lcd.W | ||
40 | _lcd.H | ||
41 | |||
42 | _lcd | ||
43 | _LCD | ||
44 | |||
45 | ]] | ||
46 | if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end | ||
47 | |||
48 | _LCD = rb.lcd_framebuffer() | ||
49 | |||
50 | local _lcd = {} do | ||
51 | |||
52 | --internal constants | ||
53 | local _NIL = nil -- _NIL placeholder | ||
54 | local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT | ||
55 | |||
56 | -- clamps value to >= min and <= max | ||
57 | local function clamp(val, min, max) | ||
58 | -- Warning doesn't check if min < max | ||
59 | if val < min then | ||
60 | return min | ||
61 | elseif val < max then | ||
62 | return val | ||
63 | end | ||
64 | return max | ||
65 | end | ||
66 | |||
67 | -- return a copy of lcd screen | ||
68 | local function duplicate(t, screen_img) | ||
69 | screen_img = screen_img or rb.new_image() | ||
70 | screen_img:copy(rb.lcd_framebuffer()) | ||
71 | return screen_img | ||
72 | end | ||
73 | |||
74 | -- updates screen in specified rectangle | ||
75 | local function update_rect(t, x, y, w, h) | ||
76 | rb.lcd_update_rect(x - 1, y - 1, | ||
77 | clamp(x + w, 1, LCD_W) - 1, | ||
78 | clamp(y + h, 1, LCD_H) - 1) | ||
79 | end | ||
80 | |||
81 | -- clears lcd, optional.. ([color, x1, y1, x2, y2, clip]) | ||
82 | local function clear(t, clr, ...) | ||
83 | if clr == _NIL and ... == _NIL then | ||
84 | rb.lcd_clear_display() | ||
85 | else | ||
86 | rb.lcd_scroll_stop() --rb really doesn't like bg change while scroll | ||
87 | _LCD:clear(clr, ...) | ||
88 | end | ||
89 | end | ||
90 | |||
91 | -- loads an image to the screen | ||
92 | local function image(t, src, x, y) | ||
93 | if not src then --make sure an image was passed, otherwise bail | ||
94 | rb.splash(rb.HZ, "No Image!") | ||
95 | return _NIL | ||
96 | end | ||
97 | _LCD:copy(src,x,y,1,1) | ||
98 | end | ||
99 | |||
100 | -- Formattable version of splash | ||
101 | local function splashf(t, timeout, ...) | ||
102 | rb.splash(timeout, string.format(...)) | ||
103 | end | ||
104 | |||
105 | -- Gets size of text | ||
106 | local function text_extent(t, msg, font) | ||
107 | font = font or rb.FONT_UI | ||
108 | |||
109 | return rb.font_getstringsize(msg, font) | ||
110 | end | ||
111 | |||
112 | -- Sets viewport size | ||
113 | local function set_viewport(t, vp) | ||
114 | if not vp then rb.set_viewport() return end | ||
115 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens | ||
116 | --vp.drawmode = bit.bxor(vp.drawmode, 4) | ||
117 | vp.fg_pattern = 3 - vp.fg_pattern | ||
118 | vp.bg_pattern = 3 - vp.bg_pattern | ||
119 | end | ||
120 | rb.set_viewport(vp) | ||
121 | end | ||
122 | |||
123 | -- allows the use of _lcd() as a identifier for the screen | ||
124 | local function index(k, v) | ||
125 | return function(x, ...) | ||
126 | _LCD[v](_LCD, ...) | ||
127 | end | ||
128 | end | ||
129 | |||
130 | -- allows the use of _lcd() as a identifier for the screen | ||
131 | local function call() | ||
132 | return rb.lcd_framebuffer() | ||
133 | end | ||
134 | |||
135 | --expose functions to the outside through _lcd table | ||
136 | _lcd.text_extent = text_extent | ||
137 | _lcd.set_viewport = set_viewport | ||
138 | _lcd.duplicate = duplicate | ||
139 | _lcd.update = rb.lcd_update | ||
140 | _lcd.update_rect = update_rect | ||
141 | _lcd.clear = clear | ||
142 | _lcd.splashf = splashf | ||
143 | _lcd.image = image | ||
144 | _lcd.DEPTH = rb.LCD_DEPTH | ||
145 | _lcd.W = rb.LCD_WIDTH | ||
146 | _lcd.H = rb.LCD_HEIGHT | ||
147 | _lcd.CX = (rb.LCD_WIDTH / 2) | ||
148 | _lcd.CY = (rb.LCD_HEIGHT / 2) | ||
149 | _lcd = setmetatable(_lcd,{__index = index, __call = call}) | ||
150 | |||
151 | end -- _lcd functions | ||
152 | |||
153 | return _lcd | ||