-
Notifications
You must be signed in to change notification settings - Fork 0
/
saul.lua
70 lines (55 loc) · 1.33 KB
/
saul.lua
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
69
70
-- Emulate SAUL devices.
-- This tries to expose the same api as the "saul" lua module in RIOT.
local code2devtype = {
"ACT_ANY",
"ACT_DIMMER",
"ACT_LED_RGB",
"ACT_MOTOR",
"ACT_SERVO",
"ACT_SWITCH",
"CLASS_ANY",
"CLASS_UNDEF",
"SENSE_ACCEL",
"SENSE_ANALOG",
"SENSE_ANY",
"SENSE_BTN",
"SENSE_CO2",
"SENSE_COLOR",
"SENSE_COUNT",
"SENSE_DISTANCE",
"SENSE_GYRO",
"SENSE_HUM",
"SENSE_LIGHT",
"SENSE_MAG",
"SENSE_OBJTEMP",
"SENSE_OCCUP",
"SENSE_PRESS",
"SENSE_TEMP",
"SENSE_TVOC",
"SENSE_UV",
}
local devtype2code = {}
for k, v in ipairs(code2devtype) do
devtype2code[v] = k
end
-- The C module in RIOT has a cache to keep the devices while the user
-- code holds a reference. Here we just keep all devices alive all the time.
local Device = {}
function Device:get_name()
return self.name;
end
function Device:get_type()
return self.type;
end
Device.__index = Device
local devices = {}
local saul = {__index=devices, types=code2devtype, _devices = devices}
function saul.find_type(t)
error("Not implemented")
end
-- Add a device with fields {name, type, read_fn, write_fn}
function saul.add_device(dev)
saul._devices[dev.name] = setmetatable(dev, Device)
end
setmetatable(saul, saul)
package.preload.saul = function() return saul end