-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathframe_app.lua
More file actions
68 lines (57 loc) · 1.74 KB
/
frame_app.lua
File metadata and controls
68 lines (57 loc) · 1.74 KB
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
68
local data = require('data.min')
local battery = require('battery.min')
local code = require('code.min')
local sprite = require('sprite.min')
-- Phone to Frame flags
USER_SPRITE = 0x20
CLEAR_MSG = 0x10
-- register the message parsers so they are automatically called when matching data comes in
data.parsers[USER_SPRITE] = sprite.parse_sprite
data.parsers[CLEAR_MSG] = code.parse_code
-- Main app loop
function app_loop()
-- clear the display
frame.display.text(" ", 1, 1)
frame.display.show()
local last_batt_update = 0
while true do
rc, err = pcall(
function()
-- process any raw data items, if ready
local items_ready = data.process_raw_items()
-- one or more full messages received
if items_ready > 0 then
if (data.app_data[USER_SPRITE] ~= nil) then
-- show the sprite
local spr = data.app_data[USER_SPRITE]
frame.display.bitmap(1, 1, spr.width, 2^spr.bpp, 0, spr.pixel_data)
frame.display.show()
data.app_data[USER_SPRITE] = nil
collectgarbage('collect')
end
if (data.app_data[CLEAR_MSG] ~= nil) then
-- clear the display
frame.display.text(" ", 1, 1)
frame.display.show()
data.app_data[CLEAR_MSG] = nil
end
end
-- periodic battery level updates, 120s for a camera app
last_batt_update = battery.send_batt_if_elapsed(last_batt_update, 120)
-- can't sleep for long, might be lots of incoming bluetooth data to process
frame.sleep(0.001)
end
)
-- Catch the break signal here and clean up the display
if rc == false then
-- send the error back on the stdout stream
print(err)
frame.display.text(" ", 1, 1)
frame.display.show()
frame.sleep(0.04)
break
end
end
end
-- run the main app loop
app_loop()