A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 146 lines 4.2 kB view raw
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]] 46if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end 47 48_LCD = rb.lcd_framebuffer() 49 50local _lcd = {} do 51 52 --internal constants 53 local _NIL = nil -- _NIL placeholder 54 55 -- clamps value to >= min and <= max 56 local function clamp(val, min, max) 57 -- Warning doesn't check if min < max 58 if val < min then 59 return min 60 elseif val < max then 61 return val 62 end 63 return max 64 end 65 66 -- return a copy of lcd screen 67 _lcd.duplicate = function(t, screen_img) 68 screen_img = screen_img or rb.new_image() 69 screen_img:copy(rb.lcd_framebuffer()) 70 return screen_img 71 end 72 73 -- updates screen in specified rectangle 74 _lcd.update_rect = function(t, x, y, w, h) 75 rb.lcd_update_rect(x - 1, y - 1, 76 clamp(x + w, 1, rb.LCD_WIDTH) - 1, 77 clamp(y + h, 1, rb.LCD_HEIGHT) - 1) 78 end 79 80 -- clears lcd, optional.. ([color, x1, y1, x2, y2, clip]) 81 _lcd.clear = function(t, clr, ...) 82 rb.lcd_scroll_stop() --rb really doesn't like bg change while scroll 83 if clr == _NIL and ... == _NIL then 84 rb.lcd_clear_display() 85 else 86 _LCD:clear(clr, ...) 87 end 88 end 89 90 -- loads an image to the screen 91 _lcd.image = function(t, src, x, y) 92 if not src then --make sure an image was passed, otherwise bail 93 rb.splash(rb.HZ, "No Image!") 94 return _NIL 95 end 96 _LCD:copy(src,x,y,1,1) 97 end 98 99 -- Formattable version of splash 100 _lcd.splashf = function(t, timeout, ...) 101 rb.splash(timeout, string.format(...)) 102 end 103 104 -- Gets size of text 105 _lcd.text_extent = function(t, msg, font) 106 font = font or rb.FONT_UI 107 108 return rb.font_getstringsize(msg, font) 109 end 110 111 -- Sets viewport size 112 _lcd.set_viewport = function(t, vp) 113 if not vp then rb.set_viewport() return end 114 if rb.LCD_DEPTH == 2 then -- invert 2-bit screens 115 --vp.drawmode = bit.bxor(vp.drawmode, 4) 116 vp.fg_pattern = 3 - vp.fg_pattern 117 vp.bg_pattern = 3 - vp.bg_pattern 118 end 119 rb.set_viewport(vp) 120 end 121 122 -- allows the use of _lcd() as a identifier for the screen 123 local function index(k, v) 124 return function(x, ...) 125 _LCD[v](_LCD, ...) 126 end 127 end 128 129 -- allows the use of _lcd() as a identifier for the screen 130 local function call() 131 return rb.lcd_framebuffer() 132 end 133 134 --expose functions to the outside through _lcd table 135 _lcd.update = rb.lcd_update 136 _lcd.DEPTH = rb.LCD_DEPTH 137 _lcd.W = rb.LCD_WIDTH 138 _lcd.H = rb.LCD_HEIGHT 139 _lcd.CX = (rb.LCD_WIDTH / 2) 140 _lcd.CY = (rb.LCD_HEIGHT / 2) 141 _lcd = setmetatable(_lcd,{__index = index, __call = call}) 142 143end -- _lcd functions 144 145return _lcd 146