X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/3d8af53f1b0fde15ccb2ec381f4f907648f1d35a..fad63ef17f825df2d1a58cc64be8bb19fb8e561f:/bin/weather-lcd?ds=inline diff --git a/bin/weather-lcd b/bin/weather-lcd index 9ee87ba..9abd84f 100755 --- a/bin/weather-lcd +++ b/bin/weather-lcd @@ -47,22 +47,29 @@ function process_file() end function get_display_config() + width = tonumber(uci.get(config_name,"display","width")) height = tonumber(uci.get(config_name,"display","height")) charwidth = tonumber(uci.get(config_name,"display","charwidth")) charheight = tonumber(uci.get(config_name,"display","charheight")) - cols = tonumber(uci.get(config_name,"display","columns")) title = uci.get(config_name,"display","title") - col_width = math.floor(width/cols) pages = {} pagetitles = {} pagedurations = {} + pagecolumns = {} + pagecolwidth = {} local page, def, line, col, pos cur.foreach(config_name,"display", function(s) page = {} + local columns = s["columns"] + if not columns or columns == "" then + columns = 1 + else + columns = tonumber(columns) + end local pagetitle = s["title"] if not pagetitle then pagetitle = title @@ -91,7 +98,7 @@ function get_display_config() page[#page+1] = def end col = col + 1 - if col > cols then + if col > columns then col = 1 line = line + 1 end @@ -99,6 +106,8 @@ function get_display_config() pages[#pages+1] = page pagetitles[#pages] = pagetitle pagedurations[#pages] = pageduration + pagecolumns[#pages] = columns + pagecolwidth[#pages] = math.floor(width/columns) end) end @@ -144,15 +153,16 @@ function setup_pages(conn) pageid = def["sensor"].."."..def["param"] pagetitle = trim(def["label"])..", "..def["unit"] write_command(conn,"screen_add "..pageid) - write_command(conn,"screen_set "..pageid.." -cursor off") - write_command(conn,"screen_set "..pageid.." -name "..pagetitle.." -duration "..graph_duration) + write_command(conn,"screen_set "..pageid.." -cursor off -name "..pagetitle.." -duration "..graph_duration) write_command(conn,"widget_add "..pageid.." "..pageid..".title title") + if height>2 then + write_command(conn,"widget_add "..pageid.." "..pageid..".max string") + write_command(conn,"widget_add "..pageid.." "..pageid..".min string") + for k = 3,height-1 do + write_command(conn,"widget_add "..pageid.." "..pageid..".place"..trim(tostring(k)).." string") + end + end write_command(conn,"widget_set "..pageid.." "..pageid..".title \"".. pagetitle.."\"") - write_command(conn,"widget_add "..pageid.." "..pageid..".max string") - write_command(conn,"widget_add "..pageid.." "..pageid..".min string") - for k=1,width-def["pos"] do - write_command(conn,"widget_add "..pageid.." "..pageid..".bar"..trim(tostring(k)).." vbar") - end end end end @@ -160,6 +170,7 @@ end function process_vals(vals) for i,page in pairs(pages) do + col_width = pagecolwidth[i] local pageid = "page"..trim(tostring(i)) for j,def in pairs(page) do val = vals[def["sensor"]][def["param"]] @@ -187,9 +198,10 @@ function process_graphs() local vals = {} local maxval = -99999999 local minval = 99999999 - for k=width-def["pos"],1,-1 do + local len + for k=width,1,-1 do if row then - val = row["val"] + val = row["val"] * def["scale"] row = cur:fetch ({}, "a") else val = nil @@ -199,19 +211,33 @@ function process_graphs() if val and (val < minval) then minval = val; end end minval = math.floor(minval) - minvalstr = trim(tostring(minval)) maxval = math.ceil(maxval) - maxvalstr = trim(tostring(maxval)) - write_command(conn,"widget_set "..pageid.." "..pageid..".max "..trim(tostring(width-string.len(maxvalstr)+1)).." 2 "..maxvalstr) - write_command(conn,"widget_set "..pageid.." "..pageid..".min "..trim(tostring(width-string.len(minvalstr)+1)).." "..height.." "..minvalstr) - for k = 1,width-def["pos"] do - val = vals[k] + if height>2 then + local minvalstr = trim(tostring(minval)) + local maxvalstr = trim(tostring(maxval)) + len = math.max(string.len(minvalstr),string.len(maxvalstr)) + write_command(conn,"widget_set "..pageid.." "..pageid..".max "..trim(tostring(width-string.len(maxvalstr)+1)).." 2 "..maxvalstr) + write_command(conn,"widget_set "..pageid.." "..pageid..".min "..trim(tostring(width-string.len(minvalstr)+1)).." "..height.." "..minvalstr) + for k = 3,height-1 do + write_command(conn,"widget_set "..pageid.." "..pageid..".place"..trim(tostring(k)).." "..trim(tostring(width-len+1)).." "..k.." \" "..string.rep("-",len-1).."\"") + end + else + len = 0 + end + local m = width + for k=1,width do + write_command(conn,"widget_del "..pageid.." "..pageid..".bar"..trim(tostring(k))) + end + for k = width-len,1,-1 do + val = vals[m] if val then h = math.floor(0.5+(val-minval)/(maxval-minval)*(height-1)*charheight) else h = 0 end + write_command(conn,"widget_add "..pageid.." "..pageid..".bar"..trim(tostring(k)).." vbar") write_command(conn,"widget_set "..pageid.." "..pageid..".bar"..trim(tostring(k)).." "..k.." "..height.." "..h) + m = m - 1 end end end @@ -225,14 +251,19 @@ setup_pages(conn) while true do - vals = process_file() - process_vals(vals) + pcall( function () - if log_con then - process_graphs() - end + vals = process_file() + process_vals(vals) + + if log_con then + process_graphs() + end - os.execute("inotifywait -e MODIFY \""..weather_file.."\"") - socket.sleep(3) + os.execute("inotifywait -e MODIFY \""..weather_file.."\"") + + end) + + socket.sleep(3) end