Commit 38efa482 authored by Robert Foss's avatar Robert Foss
Browse files

Merge remote-tracking branch 'upstream/dev' into dev

parents d2fc8782 340edbbe
......@@ -30,7 +30,7 @@ function init_spi_display()
local dc = 4 -- GPIO2
local res = 0 -- GPIO16
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
end
......@@ -61,35 +61,46 @@ function draw(draw_state)
end
function bitmap_test(delay)
-- read XBM picture
file.open("u8glib_logo.xbm", "r")
xbm_data = file.read()
file.close()
function bitmap_test()
dir = 0
next_rotation = 0
-- read Bitmap picture
file.open("u8g_rook.bm", "r")
bm_data = file.read()
file.close()
disp:firstPage()
repeat
draw(draw_state)
until disp:nextPage() == false
print("--- Starting Bitmap Test ---")
dir = 0
next_rotation = 0
if (draw_state <= 7 + 1*8) then
draw_state = draw_state + 1
else
print("--- Restarting Bitmap Test ---")
draw_state = 1
end
local draw_state
for draw_state = 1, 7 + 1*8, 1 do
disp:firstPage()
repeat
draw(draw_state)
until disp:nextPage() == false
print("Heap: " .. node.heap())
-- retrigger timer to give room for system housekeeping
tmr.start(0)
tmr.delay(delay)
tmr.wdclr()
end
print("--- Bitmap Test done ---")
end
--init_i2c_display()
init_spi_display()
bitmap_test(50000)
draw_state = 1
init_i2c_display()
--init_spi_display()
-- read XBM picture
file.open("u8glib_logo.xbm", "r")
xbm_data = file.read()
file.close()
-- read Bitmap picture
file.open("u8g_rook.bm", "r")
bm_data = file.read()
file.close()
-- set up timer 0 with short interval, will be retriggered in graphics_test()
tmr.register(0, 100, tmr.ALARM_SEMI, function() bitmap_test() end)
print("--- Starting Bitmap Test ---")
tmr.start(0)
......@@ -11,148 +11,155 @@
-- setup I2c and connect display
function init_i2c_display()
-- SDA and SCL can be assigned freely to available GPIOs
local sda = 5 -- GPIO14
local scl = 6 -- GPIO12
local sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
-- SDA and SCL can be assigned freely to available GPIOs
local sda = 5 -- GPIO14
local scl = 6 -- GPIO12
local sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
end
-- setup SPI and connect display
function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- CS, D/C, and RES can be assigned freely to available GPIOs
local cs = 8 -- GPIO15, pull-down 10k to GND
local dc = 4 -- GPIO2
local res = 0 -- GPIO16
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- CS, D/C, and RES can be assigned freely to available GPIOs
local cs = 8 -- GPIO15, pull-down 10k to GND
local dc = 4 -- GPIO2
local res = 0 -- GPIO16
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
end
-- graphic test components
function prepare()
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
end
function box_frame(a)
disp:drawStr(0, 0, "drawBox")
disp:drawBox(5, 10, 20, 10)
disp:drawBox(10+a, 15, 30, 7)
disp:drawStr(0, 30, "drawFrame")
disp:drawFrame(5, 10+30, 20, 10)
disp:drawFrame(10+a, 15+30, 30, 7)
disp:drawStr(0, 0, "drawBox")
disp:drawBox(5, 10, 20, 10)
disp:drawBox(10+a, 15, 30, 7)
disp:drawStr(0, 30, "drawFrame")
disp:drawFrame(5, 10+30, 20, 10)
disp:drawFrame(10+a, 15+30, 30, 7)
end
function disc_circle(a)
disp:drawStr(0, 0, "drawDisc")
disp:drawDisc(10, 18, 9)
disp:drawDisc(24+a, 16, 7)
disp:drawStr(0, 30, "drawCircle")
disp:drawCircle(10, 18+30, 9)
disp:drawCircle(24+a, 16+30, 7)
disp:drawStr(0, 0, "drawDisc")
disp:drawDisc(10, 18, 9)
disp:drawDisc(24+a, 16, 7)
disp:drawStr(0, 30, "drawCircle")
disp:drawCircle(10, 18+30, 9)
disp:drawCircle(24+a, 16+30, 7)
end
function r_frame(a)
disp:drawStr(0, 0, "drawRFrame/Box")
disp:drawRFrame(5, 10, 40, 30, a+1)
disp:drawRBox(50, 10, 25, 40, a+1)
disp:drawStr(0, 0, "drawRFrame/Box")
disp:drawRFrame(5, 10, 40, 30, a+1)
disp:drawRBox(50, 10, 25, 40, a+1)
end
function stringtest(a)
disp:drawStr(30+a, 31, " 0")
disp:drawStr90(30, 31+a, " 90")
disp:drawStr180(30-a, 31, " 180")
disp:drawStr270(30, 31-a, " 270")
disp:drawStr(30+a, 31, " 0")
disp:drawStr90(30, 31+a, " 90")
disp:drawStr180(30-a, 31, " 180")
disp:drawStr270(30, 31-a, " 270")
end
function line(a)
disp:drawStr(0, 0, "drawLine")
disp:drawLine(7+a, 10, 40, 55)
disp:drawLine(7+a*2, 10, 60, 55)
disp:drawLine(7+a*3, 10, 80, 55)
disp:drawLine(7+a*4, 10, 100, 55)
disp:drawStr(0, 0, "drawLine")
disp:drawLine(7+a, 10, 40, 55)
disp:drawLine(7+a*2, 10, 60, 55)
disp:drawLine(7+a*3, 10, 80, 55)
disp:drawLine(7+a*4, 10, 100, 55)
end
function triangle(a)
local offset = a
disp:drawStr(0, 0, "drawTriangle")
disp:drawTriangle(14,7, 45,30, 10,40)
disp:drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset)
disp:drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53)
disp:drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset)
local offset = a
disp:drawStr(0, 0, "drawTriangle")
disp:drawTriangle(14,7, 45,30, 10,40)
disp:drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset)
disp:drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53)
disp:drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset)
end
function ascii_1()
local x, y, s
disp:drawStr(0, 0, "ASCII page 1")
for y = 0, 5, 1 do
for x = 0, 15, 1 do
s = y*16 + x + 32
disp:drawStr(x*7, y*10+10, string.char(s))
end
end
local x, y, s
disp:drawStr(0, 0, "ASCII page 1")
for y = 0, 5, 1 do
for x = 0, 15, 1 do
s = y*16 + x + 32
disp:drawStr(x*7, y*10+10, string.char(s))
end
end
end
function extra_page(a)
disp:drawStr(0, 12, "setScale2x2")
disp:setScale2x2()
disp:drawStr(0, 6+a, "setScale2x2")
disp:undoScale()
disp:drawStr(0, 12, "setScale2x2")
disp:setScale2x2()
disp:drawStr(0, 6+a, "setScale2x2")
disp:undoScale()
end
-- the draw() routine
function draw(draw_state)
local component = bit.rshift(draw_state, 3)
prepare()
if (component == 0) then
box_frame(bit.band(draw_state, 7))
elseif (component == 1) then
disc_circle(bit.band(draw_state, 7))
elseif (component == 2) then
r_frame(bit.band(draw_state, 7))
elseif (component == 3) then
stringtest(bit.band(draw_state, 7))
elseif (component == 4) then
line(bit.band(draw_state, 7))
elseif (component == 5) then
triangle(bit.band(draw_state, 7))
elseif (component == 6) then
ascii_1()
elseif (component == 7) then
extra_page(bit.band(draw_state, 7))
end
local component = bit.rshift(draw_state, 3)
prepare()
if (component == 0) then
box_frame(bit.band(draw_state, 7))
elseif (component == 1) then
disc_circle(bit.band(draw_state, 7))
elseif (component == 2) then
r_frame(bit.band(draw_state, 7))
elseif (component == 3) then
stringtest(bit.band(draw_state, 7))
elseif (component == 4) then
line(bit.band(draw_state, 7))
elseif (component == 5) then
triangle(bit.band(draw_state, 7))
elseif (component == 6) then
ascii_1()
elseif (component == 7) then
extra_page(bit.band(draw_state, 7))
end
end
function graphics_test(delay)
print("--- Starting Graphics Test ---")
-- cycle through all components
local draw_state
for draw_state = 0, 7 + 8*8, 1 do
disp:firstPage()
repeat
draw(draw_state)
until disp:nextPage() == false
--print(node.heap())
tmr.delay(delay)
-- re-trigger Watchdog!
tmr.wdclr()
end
print("--- Graphics Test done ---")
function graphics_test()
disp:firstPage()
repeat
draw(draw_state)
until disp:nextPage() == false
if (draw_state <= 7 + 8*8) then
draw_state = draw_state + 1
else
print("--- Restarting Graphics Test ---")
draw_state = 0
end
print("Heap: " .. node.heap())
-- retrigger timer to give room for system housekeeping
tmr.start(0)
end
--init_i2c_display()
init_spi_display()
graphics_test(50000)
draw_state = 0
init_i2c_display()
--init_spi_display()
-- set up timer 0 with short interval, will be retriggered in graphics_test()
tmr.register(0, 100, tmr.ALARM_SEMI, function() graphics_test() end)
print("--- Starting Graphics Test ---")
tmr.start(0)
......@@ -30,7 +30,7 @@ function init_spi_display()
local dc = 4 -- GPIO2
local res = 0 -- GPIO16
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
end
......
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component box...")
local x, y, w, h
local m
disp:setColor(0, 0, 40, 80)
disp:setColor(1, 60, 0, 40)
disp:setColor(2, 128, 0, 140)
disp:setColor(3, 0, 128, 140)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintPos(2,18)
disp:setPrintDir(0)
disp:print("Box")
m = millis() + T
while millis() < m do
disp:setColor(bit.band(lcg_rnd(), 127)+127, bit.band(lcg_rnd(), 127)+64, bit.band(lcg_rnd(), 31))
w = bit.band(lcg_rnd(), 31)
h = bit.band(lcg_rnd(), 31)
w = w + 10
h = h + 10
x = bit.rshift(lcg_rnd() * (disp:getWidth()-w), 8)
y = bit.rshift(lcg_rnd() * (disp:getHeight()-h-20), 8)
disp:drawBox(x, y+20, w, h)
end
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component clip...")
disp:setColor(0, 0x00, 0xd1, 0x5e) -- dark green
disp:setColor(1, 0xff, 0xf7, 0x61) -- yellow
disp:setColor(2, 0xd1, 0xc7, 0x00) -- dark yellow
disp:setColor(3, 0x61, 0xff, 0xa8) -- green
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintPos(2,18)
disp:setPrintDir(0)
disp:print("ClipRange")
disp:setColor(0xd1, 0x00, 0x073)
disp:setFont(ucg.font_helvB18_hr)
disp:setPrintPos(25,45)
disp:setPrintDir(0)
disp:print("Ucg")
disp:setPrintDir(1)
disp:print("Ucg")
disp:setPrintDir(2)
disp:print("Ucg")
disp:setPrintDir(3)
disp:print("Ucg")
disp:setMaxClipRange()
disp:setColor(0xff, 0xff, 0xff)
disp:drawFrame(20-1,30-1,15+2,20+2)
disp:setClipRange(20, 30, 15, 20)
disp:setColor(0xff, 0x61, 0x0b8)
disp:setPrintPos(25,45)
disp:setPrintDir(0)
disp:print("Ucg")
disp:setPrintDir(1)
disp:print("Ucg")
disp:setPrintDir(2)
disp:print("Ucg")
disp:setPrintDir(3)
disp:print("Ucg")
disp:setMaxClipRange()
disp:setColor(0xff, 0xff, 0xff)
disp:drawFrame(60-1,35-1,25+2,18+2)
disp:setClipRange(60, 35, 25, 18)
disp:setColor(0xff, 0x61, 0x0b8)
disp:setPrintPos(25,45)
disp:setPrintDir(0)
disp:print("Ucg")
disp:setPrintDir(1)
disp:print("Ucg")
disp:setPrintDir(2)
disp:print("Ucg")
disp:setPrintDir(3)
disp:print("Ucg")
disp:setMaxClipRange()
disp:setColor(0xff, 0xff, 0xff)
disp:drawFrame(7-1,58-1,90+2,4+2)
disp:setClipRange(7, 58, 90, 4)
disp:setColor(0xff, 0x61, 0x0b8)
disp:setPrintPos(25,45)
disp:setPrintDir(0)
disp:print("Ucg")
disp:setPrintDir(1)
disp:print("Ucg")
disp:setPrintDir(2)
disp:print("Ucg")
disp:setPrintDir(3)
disp:print("Ucg")
disp:setFont(ucg.font_ncenR14_hr)
disp:setMaxClipRange()
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component color_test...")
local mx
local c, x
mx = disp:getWidth() / 2
--my = disp:getHeight() / 2
disp:setColor(0, 0, 0, 0)
disp:drawBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintPos(2,18)
disp:setPrintDir(0)
disp:print("Color Test")
disp:setColor(0, 127, 127, 127)
disp:drawBox(0, 20, 16*4+4, 5*8+4)
c = 0
x = 2
while c < 255 do
disp:setColor(0, c, c, c)
disp:drawBox(x, 22, 4, 8)
disp:setColor(0, c, 0, 0)
disp:drawBox(x, 22+8, 4, 8)
disp:setColor(0, 0, c, 0)
disp:drawBox(x, 22+2*8, 4, 8)
disp:setColor(0, 0, 0, c)
disp:drawBox(x, 22+3*8, 4, 8)
disp:setColor(0, c, 255-c, 0)
disp:drawBox(x, 22+4*8, 4, 8)
c = c + 17
x = x + 4
end
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component cross...")
local mx, my
disp:setColor(0, 250, 0, 0)
disp:setColor(1, 255, 255, 30)
disp:setColor(2, 220, 235, 10)
disp:setColor(3, 205, 0, 30)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
mx = disp:getWidth() / 2
my = disp:getHeight() / 2
disp:setColor(0, 255, 255, 255)
disp:setPrintPos(2,18)
disp:print("Cross")
disp:setColor(0, 0, 0x66, 0xcc)
disp:setPrintPos(mx+15, my-5)
disp:print("dir0")
disp:setPrintPos(mx+5, my+26)
disp:print("dir1")
disp:setPrintPos(mx-40, my+20)
disp:print("dir2")
disp:setPrintPos(mx+5,my-25)
disp:print("dir3")
disp:setColor(0, 0, 0x66, 0xff)
disp:setColor(1, 0, 0x66, 0xcc)
disp:setColor(2, 0, 0, 0x99)
disp:draw90Line(mx+2, my-1, 20, 0, 0)
disp:draw90Line(mx+2, my, 20, 0, 1)
disp:draw90Line(mx+2, my+1, 20, 0, 2)
disp:draw90Line(mx+1, my+2, 20, 1, 0)
disp:draw90Line(mx, my+2, 20, 1, 1)
disp:draw90Line(mx-1, my+2, 20, 1, 2)
disp:draw90Line(mx-2, my+1, 20, 2, 0)
disp:draw90Line(mx-2, my, 20, 2, 1)
disp:draw90Line(mx-2, my-1, 20, 2, 2)
disp:draw90Line(mx-1, my-2, 20, 3, 0)
disp:draw90Line(mx, my-2, 20, 3, 1)
disp:draw90Line(mx+1, my-2, 20, 3, 2)
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component fonts...")
local d = 5
disp:setColor(0, 0, 40, 80)
disp:setColor(1, 150, 0, 200)
disp:setColor(2, 60, 0, 40)
disp:setColor(3, 0, 160, 160)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintDir(0)
disp:setPrintPos(2,18)
disp:print("Fonts")
disp:setFontMode(ucg.FONT_MODE_TRANSPARENT)
disp:setColor(255, 200, 170)
disp:setFont(ucg.font_helvB08_hr)
disp:setPrintPos(2,30+d)
disp:print("ABC abc 123")
disp:setFont(ucg.font_helvB10_hr)
disp:setPrintPos(2,45+d)
disp:print("ABC abc 123")
disp:setFont(ucg.font_helvB12_hr)
--disp:setPrintPos(2,62+d)
--disp:print("ABC abc 123")
disp:drawString(2,62+d, 0, "ABC abc 123") -- test drawString
disp:setFontMode(ucg.FONT_MODE_SOLID)
disp:setColor(255, 200, 170)
disp:setColor(1, 0, 100, 120) -- background color in solid mode
disp:setFont(ucg.font_helvB08_hr)
disp:setPrintPos(2,75+30+d)
disp:print("ABC abc 123")
disp:setFont(ucg.font_helvB10_hr)
disp:setPrintPos(2,75+45+d)
disp:print("ABC abc 123")
disp:setFont(ucg.font_helvB12_hr)
disp:setPrintPos(2,75+62+d)
disp:print("ABC abc 123")
disp:setFontMode(ucg.FONT_MODE_TRANSPARENT)
disp:setFont(ucg.font_ncenR14_hr)
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component gradient...")
disp:setColor(0, 0, 255, 0)
disp:setColor(1, 255, 0, 0)
disp:setColor(2, 255, 0, 255)
disp:setColor(3, 0, 255, 255)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintPos(2,18)
disp:setPrintDir(0)
disp:print("GradientBox")
disp:setColor(0, 0, 255, 0)
disp:drawBox(2, 25, 8, 8)
disp:setColor(0, 255, 0, 0)
disp:drawBox(2+10, 25, 8, 8)
disp:setColor(0, 255, 0, 255)
disp:drawBox(2, 25+10, 8, 8)
disp:setColor(0, 0, 255, 255)
disp:drawBox(2+10, 25+10, 8, 8)
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component graphics_test...")
--ucg.setMaxClipRange()
disp:setColor(0, 0, 40, 80)
disp:setColor(1, 80, 0, 40)
disp:setColor(2, 255, 0, 255)
disp:setColor(3, 0, 255, 255)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 168, 0)
disp:setPrintDir(0)
disp:setPrintPos(2, 18)
disp:print("Ucglib")
disp:setPrintPos(2, 18+20)
disp:print("GraphicsTest")
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component pixel_and_lines...")
local mx
local x, xx
mx = disp:getWidth() / 2
--my = disp:getHeight() / 2
disp:setColor(0, 0, 0, 150)
disp:setColor(1, 0, 60, 40)
disp:setColor(2, 60, 0, 40)
disp:setColor(3, 120, 120, 200)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintPos(2, 18)
disp:setPrintDir(0)
disp:print("Pix&Line")
disp:drawPixel(0, 0)
disp:drawPixel(1, 0)
--disp:drawPixel(disp:getWidth()-1, 0)
--disp:drawPixel(0, disp:getHeight()-1)
disp:drawPixel(disp:getWidth()-1, disp:getHeight()-1)
disp:drawPixel(disp:getWidth()-1-1, disp:getHeight()-1)
x = 0
while x < mx do
xx = ((x)*255)/mx
disp:setColor(255, 255-xx/2, 255-xx)
disp:drawPixel(x, 24)
disp:drawVLine(x+7, 26, 13)
x = x + 1
end
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component text...")
local x, y, w, h, i
local m
disp:setColor(0, 80, 40, 0)
disp:setColor(1, 60, 0, 40)
disp:setColor(2, 20, 0, 20)
disp:setColor(3, 60, 0, 0)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintPos(2,18)
disp:setPrintDir(0)
disp:print("Text")
m = millis() + T
i = 0
while millis() < m do
disp:setColor(bit.band(lcg_rnd(), 31), bit.band(lcg_rnd(), 127) + 127, bit.band(lcg_rnd(), 127) + 64)
w = 40
h = 22
x = bit.rshift(lcg_rnd() * (disp:getWidth() - w), 8)
y = bit.rshift(lcg_rnd() * (disp:getHeight() - h), 8)
disp:setPrintPos(x, y+h)
disp:setPrintDir(bit.band(bit.rshift(i, 2), 3))
i = i + 1
disp:print("Ucglib")
end
disp:setPrintDir(0)
print("...done")
end
return M
local M, module = {}, ...
_G[module] = M
function M.run()
-- make this a volatile module:
package.loaded[module] = nil
print("Running component triangle...")
local m
disp:setColor(0, 0, 80, 20)
disp:setColor(1, 60, 80, 20)
disp:setColor(2, 60, 120, 0)
disp:setColor(3, 0, 140, 30)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255)
disp:setPrintPos(2, 18)
disp:print("Triangle")
m = millis() + T
while millis() < m do
disp:setColor(bit.band(lcg_rnd(), 127)+127, bit.band(lcg_rnd(), 31), bit.band(lcg_rnd(), 127)+64)
disp:drawTriangle(
bit.rshift(lcg_rnd() * (disp:getWidth()), 8),
bit.rshift(lcg_rnd() * (disp:getHeight()-20), 8) + 20,
bit.rshift(lcg_rnd() * (disp:getWidth()), 8),
bit.rshift(lcg_rnd() * (disp:getHeight()-20), 8) + 20,
bit.rshift(lcg_rnd() * (disp:getWidth()), 8),
bit.rshift(lcg_rnd() * (disp:getHeight()-20), 8) + 20
)
tmr.wdclr()
end
print("...done")
end
return M
-- setup SPI and connect display
function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- CS, D/C, and RES can be assigned freely to available GPIOs
local cs = 8 -- GPIO15, pull-down 10k to GND
local dc = 4 -- GPIO2
local res = 0 -- GPIO16
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
-- initialize the matching driver for your display
-- see app/include/ucg_config.h
--disp = ucg.ili9341_18x240x320_hw_spi(cs, dc, res)
disp = ucg.st7735_18x128x160_hw_spi(cs, dc, res)
end
-- switch statement http://lua-users.org/wiki/SwitchStatement
function switch(c)
local swtbl = {
casevar = c,
caseof = function (self, code)
local f
if (self.casevar) then
f = code[self.casevar] or code.default
else
f = code.missing or code.default
end
if f then
if type(f)=="function" then
return f(self.casevar,self)
else
error("case "..tostring(self.casevar).." not a function")
end
end
end
}
return swtbl
end
z = 127 -- start value
function lcg_rnd()
z = bit.band(65 * z + 17, 255)
return z
end
function millis()
local usec = tmr.now()
return usec/1000
end
function set_clip_range()
local x, y, w, h
w = bit.band(lcg_rnd(), 31)
h = bit.band(lcg_rnd(), 31)
w = w + 25
h = h + 25
x = bit.rshift(lcg_rnd() * (disp:getWidth() - w), 8)
y = bit.rshift(lcg_rnd() * (disp:getHeight() - h), 8)
disp:setClipRange(x, y, w, h)
end
function loop()
if (loop_idx == 0) then
switch(bit.band(r, 3)) : caseof {
[0] = function() disp:undoRotate() end,
[1] = function() disp:setRotate90() end,
[2] = function() disp:setRotate180() end,
default = function() disp:setRotate270() end
}
if ( r > 3 ) then
disp:clearScreen()
set_clip_range()
end
r = bit.band(r + 1, 255)
end
switch(loop_idx) : caseof {
[0] = function() end,
[1] = function() require("GT_graphics_test").run() end,
[2] = function() require("GT_cross").run() end,
[3] = function() require("GT_pixel_and_lines").run() end,
[4] = function() require("GT_color_test").run() end,
[5] = function() require("GT_triangle").run() end,
[6] = function() require("GT_fonts").run() end,
[7] = function() require("GT_text").run() end,
[8] = function() if r <= 3 then require("GT_clip").run() end end,
[9] = function() require("GT_box").run() end,
[10] = function() require("GT_gradient").run() end,
[11] = function() disp:setMaxClipRange() end,
default = function() loop_idx = -1 end
}
loop_idx = loop_idx + 1
print("Heap: " .. node.heap())
end
T = 1000
r = 0
loop_idx = 0
init_spi_display()
disp:begin(ucg.FONT_MODE_TRANSPARENT)
disp:setFont(ucg.font_ncenR14_hr)
disp:clearScreen()
tmr.register(0, 3000, tmr.ALARM_AUTO, function() loop() end)
tmr.start(0)
-- setup SPI and connect display
function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- CS, D/C, and RES can be assigned freely to available GPIOs
local cs = 8 -- GPIO15, pull-down 10k to GND
local dc = 4 -- GPIO2
local res = 0 -- GPIO16
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
disp = ucg.ili9341_18x240x320_hw_spi(cs, dc, res)
end
init_spi_display()
disp:begin(ucg.FONT_MODE_TRANSPARENT)
disp:clearScreen()
disp:setFont(ucg.font_ncenR12_tr);
disp:setColor(255, 255, 255);
disp:setColor(1, 255, 0,0);
disp:setPrintPos(0, 25)
disp:print("Hello World!")
-- setup SPI and connect display
function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- CS, D/C, and RES can be assigned freely to available GPIOs
local cs = 8 -- GPIO15, pull-down 10k to GND
local dc = 4 -- GPIO2
local res = 0 -- GPIO16
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
disp = ucg.st7735_18x128x160_hw_spi(cs, dc, res)
end
function upper_pin(x, y)
local w = 7
local h = 6
disp:setColor(0, 212, 212, 212)
disp:setColor(1, 200, 200, 200)
disp:setColor(2, 200, 200, 200)
disp:setColor(3, 188, 188, 188)
disp:drawGradientBox(x, y, w, h)
--disp:drawVLine(x+w, y+1, len)
disp:setColor(0, 220, 220, 220)
disp:setColor(1, 232, 232, 232)
disp:drawGradientLine(x+w, y, h, 1)
end
function lower_pin(x, y)
local w = 7
local h = 5
disp:setColor(0, 212, 212, 212)
disp:setColor(1, 200, 200, 200)
disp:setColor(2, 200, 200, 200)
disp:setColor(3, 188, 188, 188)
disp:drawGradientBox(x, y, w, h)
--disp:drawVLine(x+w, y+1, len)
disp:setColor(0, 220, 220, 220)
disp:setColor(1, 232, 232, 232)
disp:drawGradientLine(x+w, y, h, 1)
disp:setColor(0, 220, 220, 220)
disp:setColor(1, 232, 232, 232)
disp:drawGradientLine(x, y+h, w, 0)
disp:setColor(0, 240, 240, 240)
disp:drawPixel(x+w, y+h)
end
function ic_body(x, y)
local w = 4*14+4
local h = 31
disp:setColor(0, 60, 60, 60)
disp:setColor(1, 40, 40, 40)
disp:setColor(2, 48, 48, 48)
disp:setColor(3, 30, 30, 30)
disp:drawGradientBox(x, y, w, h)
disp:setColor(0, 255, 168, 0)
--disp:setColor(0, 225, 168, 30)
disp:drawDisc(x+w-1, y+h/2-1, 7, bit.bor(ucg.DRAW_UPPER_LEFT, ucg.DRAW_LOWER_LEFT))
disp:setColor(0, 60, 30, 0)
--disp:drawDisc(x+w-1, y+h/2+1, 7, bit.bor(ucg.DRAW_UPPER_LEFT, ucg.DRAW_LOWER_LEFT))
disp:setColor(0, 50, 50, 50)
disp:setColor(0, 25, 25, 25)
disp:drawDisc(x+w-1, y+h/2+1, 7, bit.bor(ucg.DRAW_UPPER_LEFT, ucg.DRAW_LOWER_LEFT))
end
function draw_ucg_logo()
local a, b
--ucg_Init(ucg, ucg_sdl_dev_cb, ucg_ext_none, (ucg_com_fnptr)0)
disp:setFont(ucg.font_ncenB24_tr)
--disp:setRotate270()
--disp:setClipRange(10,5,40,20)
a = 2
b = 3
disp:setColor(0, 135*a/b,206*a/b,250*a/b)
disp:setColor(1, 176*a/b,226*a/b,255*a/b)
disp:setColor(2, 25*a/b,25*a/b,112*a/b)
disp:setColor(3, 85*a/b,26*a/b,139*a/b)
disp:drawGradientBox(0, 0, disp:getWidth()/4, disp:getHeight())
disp:setColor(1, 135*a/b,206*a/b,250*a/b)
disp:setColor(0, 176*a/b,226*a/b,255*a/b)
disp:setColor(3, 25*a/b,25*a/b,112*a/b)
disp:setColor(2, 85*a/b,26*a/b,139*a/b)
disp:drawGradientBox(disp:getWidth()/4, 0, disp:getWidth()/4, disp:getHeight())
disp:setColor(0, 135*a/b,206*a/b,250*a/b)
disp:setColor(1, 176*a/b,226*a/b,255*a/b)
disp:setColor(2, 25*a/b,25*a/b,112*a/b)
disp:setColor(3, 85*a/b,26*a/b,139*a/b)
disp:drawGradientBox(disp:getWidth()*2/4, 0, disp:getWidth()/4, disp:getHeight())
disp:setColor(1, 135*a/b,206*a/b,250*a/b)
disp:setColor(0, 176*a/b,226*a/b,255*a/b)
disp:setColor(3, 25*a/b,25*a/b,112*a/b)
disp:setColor(2, 85*a/b,26*a/b,139*a/b)
disp:drawGradientBox(disp:getWidth()*3/4, 0, disp:getWidth()/4, disp:getHeight())
upper_pin(7+0*14, 4)
upper_pin(7+1*14, 4)
upper_pin(7+2*14, 4)
upper_pin(7+3*14, 4)
ic_body(2, 10)
lower_pin(7+0*14, 41)
lower_pin(7+1*14, 41)
lower_pin(7+2*14, 41)
lower_pin(7+3*14, 41)
disp:setColor(0, 135*a/b, 206*a/b, 250*a/b)
disp:drawString(63+1, 33+1, 0, "glib")
disp:setColor(0, 255, 168, 0)
disp:drawGlyph(26, 38, 0, 'U')
disp:drawString(63, 33, 0, "glib")
disp:setColor(0, 135*a/b, 206*a/b, 250*a/b)
disp:setColor(1, 135*a/b, 206*a/b, 250*a/b)
disp:setColor(2, 135*a/b, 206*a/b, 250*a/b)
disp:setColor(3, 135*a/b, 206*a/b, 250*a/b)
disp:drawGradientBox(84+1, 42+1-6, 42, 4)
disp:setColor(0, 255, 180, 40)
disp:setColor(1, 235, 148, 0)
--disp:drawGradientLine(79, 42, 20, 0)
disp:setColor(2, 245, 158, 0)
disp:setColor(3, 220, 138, 0)
disp:drawGradientBox(84, 42-6, 42, 4)
disp:setColor(0, 255, 168, 0)
--disp:setFont(ucg.font_5x8_tr)
disp:setFont(ucg.font_7x13B_tr)
--disp:setFont(ucg.font_courB08_tr)
--disp:setFont(ucg.font_timR08_tr)
disp:drawString(2, 54+5, 0, "http://github.com")
disp:drawString(2, 61+10, 0, "/olikraus/ucglib")
--disp:drawString(1, 61, 0, "code.google.com/p/ucglib/")
end
init_spi_display()
disp:begin(ucg.FONT_MODE_TRANSPARENT)
disp:clearScreen()
disp:setRotate180()
draw_ucg_logo()
#ifndef _OVERRIDE_C_TYPES_H_
#define _OVERRIDE_C_TYPES_H_
#include "../../sdk/esp_iot_sdk_v1.4.0/include/c_types.h"
typedef sint64_t int64_t;
#endif
ESPRSSIF MIT License
Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, it is free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
乐鑫 MIT 许可证
版权 (c) 2015 <乐鑫信息科技(上海)有限公司>
该许可证授权仅限于乐鑫信息科技 ESP8266 产品的应用开发。在此情况下,该许可证免费授权任何获得该软件及其相关文档(统称为“软件”)的人无限制地经营该软件,包括无限制的使用、复制、修改、合并、出版发行、散布、再授权、及贩售软件及软件副本的权利。被授权人在享受这些权利的同时,需服从下面的条件:
在软件和软件的所有副本中都必须包含以上的版权声明和授权声明。
该软件按本来的样子提供,没有任何明确或暗含的担保,包括但不仅限于关于试销性、适合某一特定用途和非侵权的保证。作者和版权持有人在任何情况下均不就由软件或软件使用引起的以合同形式、民事侵权或其它方式提出的任何索赔、损害或其它责任负责。
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment