summaryrefslogtreecommitdiff
path: root/files/common/openwrt/sensors.module_lua
diff options
context:
space:
mode:
Diffstat (limited to 'files/common/openwrt/sensors.module_lua')
-rw-r--r--files/common/openwrt/sensors.module_lua75
1 files changed, 59 insertions, 16 deletions
diff --git a/files/common/openwrt/sensors.module_lua b/files/common/openwrt/sensors.module_lua
index 499886b0..dbae81ea 100644
--- a/files/common/openwrt/sensors.module_lua
+++ b/files/common/openwrt/sensors.module_lua
@@ -84,18 +84,18 @@ end
function _M.i2c_add_devices_recursive(bus, devices)
- local num_devices = 0
+ local num_sensors = 0
local device
for _, device in base.ipairs(devices) do
local ret, err = _M.i2c_add_device(bus, device.address, device.type)
if not ret then return nil, err end
- num_devices = num_devices + 1
local setup_function = _internal_.setup[device.type]
if setup_function ~= nil then
time.nanosleep({tv_sec = 0, tv_nsec = 100000000})
local ret, err = setup_function(bus, device.address)
- if not ret then return nil, err end
+ if ret == nil then return nil, err end
+ num_sensors = num_sensors + ret
end
if device.channels then
@@ -106,13 +106,13 @@ function _M.i2c_add_devices_recursive(bus, devices)
for _, channel in base.ipairs(device.channels) do
if not mux_channels[channel.number] then return nil, string.format("i2c-mux %s has no channel %d", _M.i2c_device_name(bus, device.address), channel.number) end
local tmp, err = _M.i2c_add_devices_recursive(mux_channels[channel.number], channel.devices)
- if not tmp then return nil, err end
- num_devices = num_devices + tmp
+ if ret == nil then return nil, err end
+ num_sensors = num_sensors + tmp
end
end
end
- return num_devices
+ return num_sensors
end
function _M.i2c_read_sensors_recursive(bus, devices)
@@ -160,6 +160,24 @@ function _M.w1_device_family_and_serial(address)
end
+function _M.w1_setup_devices(devices)
+ local num_sensors = 0
+ local device
+ for _, device in base.ipairs(devices) do
+ local family, _ = _M.w1_device_family_and_serial(device.address)
+ if family ~= nil then
+ local setup_function = _internal_.setup["w1-" .. family]
+ if setup_function ~= nil then
+ local tmp, err = setup_function(device.address)
+ if tmp == nil then return nil, err end
+ num_sensors = num_sensors + tmp
+ end
+ end
+ end
+
+ return num_sensors
+end
+
function _M.w1_read_sensors(devices)
local readings = {}
local device
@@ -209,7 +227,7 @@ function _M.gpio_setup_pins(pins)
local pin
for _, pin in base.ipairs(pins) do
local ret, err = _M.gpio_export_pin(pin.number)
- if not ret then return nil, err end
+ if ret == nil then return nil, err end
num_pins = num_pins + 1
end
@@ -253,7 +271,10 @@ function _M.iio_setup_bmp280(bus, address)
local ret, err = _internal_.write_to_file(iio_device .. '/in_pressure_oversampling_ratio', '1')
if not ret then return nil, err end
- return _internal_.write_to_file(iio_device .. '/in_temp_oversampling_ratio', '1')
+ local ret, err = _internal_.write_to_file(iio_device .. '/in_temp_oversampling_ratio', '1')
+ if not ret then return nil, err end
+
+ return 2
end
_internal_.setup['bmp280'] = _M.iio_setup_bmp280
@@ -286,7 +307,10 @@ function _M.iio_setup_bme280(bus, address)
if not ret then return nil, err end
local ret, err = _internal_.write_to_file(iio_device .. '/in_pressure_oversampling_ratio', '1')
if not ret then return nil, err end
- return _internal_.write_to_file(iio_device .. '/in_temp_oversampling_ratio', '1')
+ local ret, err = _internal_.write_to_file(iio_device .. '/in_temp_oversampling_ratio', '1')
+ if not ret then return nil, err end
+
+ return 3
end
_internal_.setup['bme280'] = _M.iio_setup_bme280
@@ -316,6 +340,11 @@ end
_internal_.read['bme280'] = _M.iio_read_bme280
+function _M.iio_setup_am2315(bus, address)
+ return 2
+end
+_internal_.setup['am2315'] = _M.iio_setup_am2315
+
function _M.iio_read_am2315(bus, address)
local iio_device, err = _M.iio_device_path_from_i2c_device(bus, address)
if not iio_device then return end
@@ -354,6 +383,15 @@ function _M.hwmon_device_path_from_w1_device(address)
end
+function _M.hwmon_setup_w1_therm(address)
+ return 1
+end
+_internal_.setup['w1-10'] = _M.hwmon_setup_w1_therm
+_internal_.setup['w1-22'] = _M.hwmon_setup_w1_therm
+_internal_.setup['w1-28'] = _M.hwmon_setup_w1_therm
+_internal_.setup['w1-3B'] = _M.hwmon_setup_w1_therm
+_internal_.setup['w1-42'] = _M.hwmon_setup_w1_therm
+
function _M.hwmon_read_w1_therm(address)
local hwmon_device, err = _M.hwmon_device_path_from_w1_device(address)
if not hwmon_device then return end
@@ -385,22 +423,27 @@ function _M.read_config(path)
end
function _M.setup(config)
- local num_devices = 0
+ local num_sensors = 0
if config.i2c then
local i2c_bus
for _, i2c_bus in base.ipairs(config.i2c) do
local tmp, err = _M.i2c_add_devices_recursive(i2c_bus.number, i2c_bus.devices)
- if not tmp then return nil, err end
- num_devices = num_devices + tmp
+ if tmp == nil then return nil, err end
+ num_sensors = num_sensors + tmp
end
end
- -- for now the only supported 1-wire master device is i2c based and will be initialized above
- -- also sensors on 1-wire busses are discvored automatically and for now no supported sensor needs any setup
+ if config.w1 then
+ local tmp, err = _M.w1_setup_devices(config.w1)
+ if tmp == nil then return nil, err end
+ num_sensors = num_sensors + tmp
+ end
if config.gpio then
local tmp, err = _M.gpio_setup_pins(config.gpio)
- if not tmp then return nil, err end
- num_devices = num_devices + tmp
+ if tmp == nil then return nil, err end
+ num_sensors = num_sensors + tmp
end
+
+ return num_sensors
end
function _M.read(config)