From 88dba6e8daf4d484d1f1cb69fcced330250013c2 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Wed, 20 Apr 2011 23:22:56 +0200 Subject: [PATCH] [luci] add a sensor configuration page --- .../openwrt/package/flukso/config/flukso.uci | 1 + .../luasrc/controller/mini/sensor.lua | 24 ++++++ .../luasrc/model/cbi/mini/sensor.lua | 79 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/mini/sensor.lua create mode 100644 mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/model/cbi/mini/sensor.lua diff --git a/mote/v2/openwrt/package/flukso/config/flukso.uci b/mote/v2/openwrt/package/flukso/config/flukso.uci index 401a164..9dcff50 100644 --- a/mote/v2/openwrt/package/flukso/config/flukso.uci +++ b/mote/v2/openwrt/package/flukso/config/flukso.uci @@ -6,6 +6,7 @@ config settings main option max_sensors 6 option max_analog_sensors 3 option reset_counters 0 + option phase 1 config settings daemon option logmask info diff --git a/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/mini/sensor.lua b/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/mini/sensor.lua new file mode 100644 index 0000000..ddd1a41 --- /dev/null +++ b/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/controller/mini/sensor.lua @@ -0,0 +1,24 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich +Copyright 2011 Bart Van Der Meerssche + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id: network.lua 3672 2008-10-31 09:35:11Z Cyrus $ +]]-- + +module("luci.controller.mini.sensor", package.seeall) + +function index() + luci.i18n.loadc("admin-core") + local i18n = luci.i18n.translate + + entry({"sensor"}, cbi("mini/sensor", {autoapply=true}), i18n("sensor"), 1) +end diff --git a/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/model/cbi/mini/sensor.lua b/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/model/cbi/mini/sensor.lua new file mode 100644 index 0000000..5e8a08e --- /dev/null +++ b/mote/v2/openwrt/package/luci/modules/admin-mini/luasrc/model/cbi/mini/sensor.lua @@ -0,0 +1,79 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich +Copyright 2011 Bart Van Der Meerssche + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id: network.lua 5949 2010-03-27 14:56:35Z jow $ +]]-- + +local uci = require "luci.model.uci".cursor() + +local FLUKSO = uci:get_all("flukso") +local MAX_SENSORS = tonumber(FLUKSO.main.max_sensors) + + +m = Map("flukso", translate("Sensor"), translate("Fluksometer sensor configuration")) + +-- sync with the sensor board after committing to the uci file +m.on_after_commit = function(self) + luci.util.exec("fsync") +end + + +s = m:section(NamedSection, "main", "settings", "general settings") +phase = s:option(ListValue, "phase", translate("phase")) +phase:value("1") +phase:value("3") + +-- (ab)use phase validation callback to assign port numbers to sensors +function phase:validate(value, section) + if value == "1" then + uci:set_list("flukso", "1", "port", "1") + uci:set_list("flukso", "2", "port", "2") + uci:set_list("flukso", "3", "port", "3") + elseif value == "3" then + uci:set_list("flukso", "1", "port", { "1", "2", "3" }) + uci:delete ("flukso", "2", "port") + uci:delete ("flukso", "3", "port") + end + + uci:commit("flukso") + + return value +end + + +s = {} + +for i = 1, MAX_SENSORS do + s[i] = m:section(NamedSection, tostring(i), "sensor", "sensor #" .. i) + s[i].addremove = false + + s[i]:option(DummyValue, "id", translate("identifier")) + s[i]:option(DummyValue, "class", translate("class")) + + if FLUKSO[tostring(i)].class == "analog" then + s[i]:option(Value, "voltage", translate("voltage")) + current = s[i]:option(ListValue, "current", translate("current")) + current:value("50") + current:value("100") + current:value("250") + current:value("500") + + elseif FLUKSO[tostring(i)].class == "pulse" then + s[i]:option(Value, "constant", translate("constant")) + end + + enable = s[i]:option(Flag, "enable", translate("enable")) + enable.rmempty = false +end + +return m