Skip to content

Instantly share code, notes, and snippets.

@lionello
Last active August 31, 2015 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionello/032768cdf734295bd774 to your computer and use it in GitHub Desktop.
Save lionello/032768cdf734295bd774 to your computer and use it in GitHub Desktop.
ELLA test
wifi.setmode(wifi.STATION)
wifi.sta.config('XinCheJian','imakestuff')
c=net.createConnection(net.TCP, 0)
c:on('connection',function(conn) c:send('GET /api/values/0 HTTP/1.1\r\nHost: thenounproxy.azurewebsites.net\r\nConnection: close\r\n\r\n') file.open('init.lua','w') h='' end )
c:on('receive',function(c,p) if h then h=h..p local i=h:find('\r\n\r\n') if i then file.write(h:sub(i+4)) h=nil end else file.write(p) end end )
c:on('disconnection',function() file.close() dofile('init.lua') end )
c:connect(80,'thenounproxy.azurewebsites.net')
function rgb_set(r, g, b)
uart.write(0,string.format('HTTP/1.1 200 OK\r\nRGB: %u %u %u\r\n\r\n', r, g, b))
end
rgb_set(255,100,0)
http_dump('thenounproxy.azurewebsites.net', '/api/noun/boat?bpp=1')
function echo_off() uart.setup(0,9600,8,0,1,0) end
function echo_on() uart.setup(0,9600,8,0,1,1) end
function ls()
for k,v in pairs(file.list()) do print(k,v) end
end
function cat(fn)
if file.open(fn,'r') then while true do local w = file.readline() if not w then break end uart.write(0,w) end file.close() end
end
function write_file(fn, c)
file.remove(fn)
if file.open(fn,'w') then file.write(c) file.close() end
end
function http_send(c, host, port, resource)
c:send('GET '..resource..' HTTP/1.1\r\nHost: '..host..':'..port..'\r\nConnection: close\r\nAccept: */*\r\n\r\n')
end
function http_connect(c, host, port, resource)
c:on('connection', function(conn) http_send(conn, host, port, resource) end )
c:connect(port, host)
end
function http_dump(host, resource, done)
c=net.createConnection(net.TCP, 0)
c:on('receive', function(conn, payload) uart.write(0, payload) end )
c:on('disconnection', function(conn) conn:close() c=nil if done then done() end end )
http_connect(c, host, 80, resource)
end
function http_get(host, resource, done)
h=''
c=net.createConnection(net.TCP, 0)
c:on('receive', function(conn, payload) h=h..payload end )
c:on('disconnection', function(conn) conn:close() done(h:sub(h:find('\r\n\r\n')+4)) c=nil end )
http_connect(c, host, 80, resource)
end
function http_get_file(host, resource, fn, done)
h=''
c=net.createConnection(net.TCP, 0)
c:on('sent', function(conn) file.open(fn,'w') end )
c:on('receive', function(conn, payload) if h then h=h..payload local i=h:find('\r\n\r\n') if i then file.write(h:sub(i+4)) h=nil end else file.write(payload) end end )
c:on('disconnection', function(conn) conn:close() file.close() c=nil end )
http_connect(c, host, 80, resource)
end
function update_init()
http_get_file('thenounproxy.azurewebsites.net', '/api/values/0', 'init.lua', dofile)
end
function prepare()
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)
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)
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)
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")
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)
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)
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
end
function extra_page(a)
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
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 ---")
end
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
--disp = u8g.ssd1351_128x128_hicolor_hw_spi(8, 4)
--graphics_test(50000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment