-
Notifications
You must be signed in to change notification settings - Fork 1
/
toled.lua
67 lines (53 loc) · 1.32 KB
/
toled.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
tOled = {
locked = false
, text = ""
}
function tOled.new( config )
local o = {}
local disp = {}
o.config = config
setmetatable(o, { __index = tOled })
return o
end
function tOled:init()
if self.config.type == 2 then
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
-- we won't be using the HSPI /CS line, so disable it again
gpio.mode(8, gpio.INPUT, gpio.PULLUP)
self.disp = u8g.ssd1306_128x64_hw_spi( self.config.spi.cs, self.config.spi.dc, self.config.spi.res)
else
i2c.setup( 0, self.config.i2c.sda, self.config.i2c.scl, i2c.SLOW )
self.disp = u8g.ssd1306_128x64_i2c( self.config.i2c.sla )
end
self.disp:setFont( u8g.font_6x10 )
self.disp:setFontRefHeightExtendedText()
self.disp:setDefaultForegroundColor()
self.disp:setFontPosTop()
-- Show boot message
self:_splash()
end
function tOled:_splash()
self:update( "Initialising..." )
end
function tOled:lock()
self.locked = true
end
function tOled:unlock()
self.locked = false
end
function tOled:isLocked()
return self.locked
end
function tOled:update( text )
self.text = text
self:_display()
end
function tOled:_draw()
self.disp:drawStr( 0, 0, self.text )
end
function tOled:_display()
self.disp:firstPage()
repeat
self:_draw()
until self.disp:nextPage() == false
end