Commit 6092219f authored by UncleRedz's avatar UncleRedz
Browse files

Some cleanup based on review comments

Cleaned up the draw loop and changed some comments.
parent 73583fc3
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- u8glib example which shows how to implement the draw loop without causing -- u8glib example which shows how to implement the draw loop without causing
-- timeout issues with the WiFi stack. This is done by drawing one page at -- timeout issues with the WiFi stack. This is done by drawing one page at
-- a time, allowing the ESP SDK to do its house keeping between the page
-- draws. -- draws.
-- --
-- This example assumes you have an SSD1306 display connected to pins 4 and 5 -- This example assumes you have an SSD1306 display connected to pins 4 and 5
...@@ -9,10 +9,9 @@ ...@@ -9,10 +9,9 @@
-- Please edit the init_display function to match your setup. -- Please edit the init_display function to match your setup.
-- --
-- Example: -- Example:
-- dofile("u8g_displayloop.lua") -- dofile("u8g_drawloop.lua")
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
local updateDrawFunc
local disp local disp
local font local font
...@@ -32,17 +31,16 @@ local function setLargeFont() ...@@ -32,17 +31,16 @@ local function setLargeFont()
disp:setFontPosTop() disp:setFontPosTop()
end end
-- Draws one page and schedules the next page, if there is one -- Start the draw loop with the draw implementation in the provided function callback
local function drawPages() function updateDisplay(func)
updateDrawFunc() -- Draws one page and schedules the next page, if there is one
local function drawPages()
func()
if (disp:nextPage() == true) then if (disp:nextPage() == true) then
node.task.post(drawPages) node.task.post(drawPages)
end end
end end
-- Restart the draw loop and start drawing pages
-- Start the draw loop with the draw implementation in the provided function callback
function updateDisplay(func)
updateDrawFunc = func
disp:firstPage() disp:firstPage()
node.task.post(drawPages) node.task.post(drawPages)
end end
...@@ -58,18 +56,18 @@ function drawWorld() ...@@ -58,18 +56,18 @@ function drawWorld()
end end
local drawDemo = { drawHello, drawWorld } local drawDemo = { drawHello, drawWorld }
local drawIndex = 1
function demoLoop() function demoLoop()
-- Start the draw loop with one of the demo functions -- Start the draw loop with one of the demo functions
updateDisplay(drawDemo[drawIndex]) local f = table.remove(drawDemo,1)
drawIndex = drawIndex + 1 updateDisplay(f)
if drawDemo[drawIndex] == nil then table.insert(drawDemo,f)
drawIndex = 1
end
end end
-- Initialise the display and start the demo loop -- Initialise the display
init_display() init_display()
-- Draw demo page immediately and then schedule an update every 5 seconds.
-- To test your own drawXYZ function, disable the next two lines and call updateDisplay(drawXYZ) instead.
demoLoop() demoLoop()
tmr.alarm(4, 5000, 1, demoLoop) tmr.alarm(4, 5000, 1, demoLoop)
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