Skip to content

Commit 84330d5

Browse files
committed
[fsync] add LED_MODE command
1 parent 049c22c commit 84330d5

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

openwrt/package/flukso/config/flukso.uci

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ config settings main
1515
option reset_counters 0
1616
option phase 1
1717
option dsmr 4.0
18+
option led_mode 256
1819

1920
config settings daemon
2021
option logmask info

openwrt/package/flukso/luasrc/fsync.lua

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
fsync.lua - synchronize /etc/config/flukso settings with the sensor board
66
7-
Copyright (C) 2014 Bart Van Der Meerssche <bart@flukso.net>
7+
Copyright (C) 2015 Bart Van Der Meerssche <bart@flukso.net>
88
99
This program is free software: you can redistribute it and/or modify
1010
it under the terms of the GNU General Public License as published by
@@ -47,6 +47,7 @@ local MAX_PROV_SENSORS = tonumber(flukso.main.max_provisioned_sensors)
4747
local MAX_ANALOG_SENSORS = tonumber(flukso.main.max_analog_sensors)
4848
local ANALOG_ENABLE = (MAX_ANALOG_SENSORS == 3) and 1 or 0
4949
local RESET_COUNTERS = (flukso.main.reset_counters == "1")
50+
local LED_MODE = tonumber(flukso.main.led_mode or 256)
5051
local WAN_ENABLED = (flukso.daemon.enable_wan_branch == "1")
5152
local LAN_ENABLED = (flukso.daemon.enable_lan_branch == "1")
5253

@@ -69,6 +70,7 @@ local GET_HW_VERSION = "gh"
6970
local GET_HW_VERSION_R = "^gh%s+(%d+)%s+(%d+)$"
7071
local SET_ENABLE = "se %d %d"
7172
local SET_HW_LINES = "sk %d %d %d" -- ANALOG_EN, UART_RX_INV, UART_TX_INV
73+
local SET_LED_MODE = "si %d" -- [0..255] with 255 being default heartbeat
7274
local SET_PHY_TO_LOG = "sp" -- with [1..MAX_SENSORS] arguments
7375
local SET_METERCONST = "sm %d %d"
7476
local SET_FRACTION = "sf %d %d"
@@ -198,7 +200,7 @@ end
198200
-- @return none
199201
local function disable_all_sensors(ub)
200202
for i = 1, MAX_SENSORS do
201-
local cmd = string.format(SET_ENABLE, toc(i), 0)
203+
local cmd = SET_ENABLE:format(toc(i), 0)
202204
send(ub, cmd)
203205
end
204206
end
@@ -207,7 +209,15 @@ end
207209
-- @param ub ub object
208210
-- @return none
209211
local function set_hardware_lines(ub)
210-
local cmd = string.format(SET_HW_LINES, ANALOG_ENABLE, UART_RX_INVERT, UART_TX_INVERT)
212+
local cmd = SET_HW_LINES:format(ANALOG_ENABLE, UART_RX_INVERT, UART_TX_INVERT)
213+
send(ub, cmd)
214+
end
215+
216+
--- Set the mode of the heatbeat LED.
217+
-- @param ub ub object
218+
-- @return none
219+
local function set_led_mode(ub)
220+
local cmd = SET_LED_MODE:format(toc(LED_MODE))
211221
send(ub, cmd)
212222
end
213223

@@ -257,27 +267,27 @@ local function set_meterconst(ub)
257267
local cmd = { }
258268

259269
if flukso[tostring(i)] == nil then
260-
cmd[1] = string.format(SET_METERCONST, toc(i), 0)
270+
cmd[1] = SET_METERCONST:format(toc(i), 0)
261271

262272
elseif flukso[tostring(i)]["class"] == "analog" then
263273
local voltage = tonumber(flukso[tostring(i)].voltage or "0")
264274
local current = tonumber(flukso[tostring(i)].current or "0")
265275

266-
cmd[1] = string.format(SET_METERCONST, toc(i), math.floor(METERCONST_FACTOR * voltage * current))
276+
cmd[1] = SET_METERCONST:format(toc(i), math.floor(METERCONST_FACTOR * voltage * current))
267277

268278
elseif flukso[tostring(i)]["class"] == "pulse" then
269279
local real = tonumber(flukso[tostring(i)].constant or "0")
270280
local meterconst = math.floor(real)
271281
local fraction = math.floor((real % 1) * 1000)
272282

273-
cmd[1] = string.format(SET_METERCONST, toc(i), meterconst)
274-
cmd[2] = string.format(SET_FRACTION, toc(i), fraction)
283+
cmd[1] = SET_METERCONST:format(toc(i), meterconst)
284+
cmd[2] = SET_FRACTION:format(toc(i), fraction)
275285
else
276-
cmd[1] = string.format(SET_METERCONST, toc(i), 0)
286+
cmd[1] = SET_METERCONST:format(toc(i), 0)
277287
end
278288

279289
if not cmd[2] then
280-
cmd[2] = string.format(SET_FRACTION, toc(i), 0)
290+
cmd[2] = SET_FRACTION:format(toc(i), 0)
281291
end
282292

283293
send(ub, cmd[1])
@@ -290,7 +300,7 @@ end
290300
-- @return none
291301
local function reset_counters(ub)
292302
for i = 1, MAX_SENSORS do
293-
local cmd = string.format(SET_COUNTER, toc(i), 0)
303+
local cmd = SET_COUNTER:format(toc(i), 0)
294304
send(ub, cmd)
295305
end
296306

@@ -304,7 +314,7 @@ end
304314
local function enable_sensors(ub)
305315
for i = 1, MAX_SENSORS do
306316
if flukso[tostring(i)] ~= nil and flukso[tostring(i)].enable == "1" then
307-
cmd = string.format(SET_ENABLE, toc(i), 1)
317+
cmd = SET_ENABLE:format(toc(i), 1)
308318
send(ub, cmd)
309319
end
310320
end
@@ -506,6 +516,7 @@ if MODEL ~= "FLM02W" then
506516

507517
if MODEL == "FLM02B" or MODEL == "FLM02C" then
508518
set_hardware_lines(ub)
519+
set_led_mode(ub)
509520
end
510521

511522
set_phy_to_log(ub)

0 commit comments

Comments
 (0)