-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.lua
More file actions
44 lines (34 loc) · 1.18 KB
/
test.lua
File metadata and controls
44 lines (34 loc) · 1.18 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
print"require"
local udev = require 'udev'
local socket = require 'socket'
print"start"
local ud = udev() print("ud", ud, ud and ud._native)
local enum = udev.enumerate(ud)
assert(enum:match_subsystem("power_supply"))
enum:match_property("power_supply_name", "AC")
print"scan subsystems"
assert(enum:scan_subsystems()) for k,v in pairs(enum:getlist()) do print(k,v) end
print"scan devices"
assert(enum:scan_devices()) for k,v in pairs(enum:getlist()) do print(k,v) end
enum:close()
local mon = udev.monitor(ud, "udev") print("monitor", mon, mon and mon._native, mon:getfd())
print("add subsystem devtype", mon:filter_subsystem_devtype())
print("start monitor", mon:start())
while true do
if #socket.select({mon}, nil, nil) > 0 then
local device = mon:receive()
print("["..tostring(device:getseqnum()).."] "..device:getaction().." device", device:getsyspath())
print("properties:")
for k,v in pairs(device:getproperties()) do
print("", k, v)
end
print("sysattrs:")
for k,v in pairs(device:getsysattrs()) do
print("", k, v)
end
device:close()
end
end
mon:close()
ud:close()
print"done."