Skip to content

Commit

Permalink
update examples to task posting (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsaurus authored and marcelstoer committed Apr 18, 2016
1 parent 4710f73 commit 25b4285
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
35 changes: 22 additions & 13 deletions lua_examples/u8glib/u8g_bitmaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- Hardware SPI /CS = GPIO15 (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)
-- we won't be using the HSPI /CS line, so disable it again
gpio.mode(8, gpio.INPUT, gpio.PULLUP)

disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
end

Expand Down Expand Up @@ -61,14 +65,22 @@ function draw(draw_state)
end


function bitmap_test()
dir = 0
next_rotation = 0

disp:firstPage()
repeat
function draw_loop()
-- Draws one page and schedules the next page, if there is one
local function draw_pages()
draw(draw_state)
until disp:nextPage() == false
if disp:nextPage() then
node.task.post(draw_pages)
else
node.task.post(bitmap_test)
end
end
-- Restart the draw loop and start drawing pages
disp:firstPage()
node.task.post(draw_pages)
end

function bitmap_test()

if (draw_state <= 7 + 1*8) then
draw_state = draw_state + 1
Expand All @@ -78,8 +90,8 @@ function bitmap_test()
end

print("Heap: " .. node.heap())
-- retrigger timer to give room for system housekeeping
tmr.start(0)
-- retrigger draw_loop
node.task.post(draw_loop)

end

Expand All @@ -99,8 +111,5 @@ 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)
node.task.post(draw_loop)
34 changes: 23 additions & 11 deletions lua_examples/u8glib/u8g_graphics_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- Hardware SPI /CS = GPIO15 (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)
-- we won't be using the HSPI /CS line, so disable it again
gpio.mode(8, gpio.INPUT, gpio.PULLUP)

disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
end

Expand Down Expand Up @@ -134,12 +138,22 @@ function draw(draw_state)
end
end

function graphics_test()

disp:firstPage()
repeat
function draw_loop()
-- Draws one page and schedules the next page, if there is one
local function draw_pages()
draw(draw_state)
until disp:nextPage() == false
if disp:nextPage() then
node.task.post(draw_pages)
else
node.task.post(graphics_test)
end
end
-- Restart the draw loop and start drawing pages
disp:firstPage()
node.task.post(draw_pages)
end

function graphics_test()

if (draw_state <= 7 + 8*8) then
draw_state = draw_state + 1
Expand All @@ -149,17 +163,15 @@ function graphics_test()
end

print("Heap: " .. node.heap())
-- retrigger timer to give room for system housekeeping
tmr.start(0)
-- retrigger draw_loop
node.task.post(draw_loop)

end

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)
node.task.post(draw_loop)
4 changes: 4 additions & 0 deletions lua_examples/u8glib/u8g_rotation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- Hardware SPI /CS = GPIO15 (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)
-- we won't be using the HSPI /CS line, so disable it again
gpio.mode(8, gpio.INPUT, gpio.PULLUP)

disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
end

Expand Down

0 comments on commit 25b4285

Please sign in to comment.