Customisable Data script for multiline LCD displays

No replies
AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012

Hi All,

Firstly - A special thanks to Brett for extending the LCD Buffer in 307.2 Avio for some example code and Mark Baldwin for modifying the AVR code and bug finding :)

I have commented the code to the best of my knowledge, Configurable options are detailed below

My current setup is a 20x4 LCD but in theory any multiline HD44780 character LCD could be used with the relevant AVR mods

lcdcols = set to LCD length i.e 20 columns

refresh = time in seconds to check for updates (higher refresh may become annoying with lcd flickers)

fill = currently set to space, you can use any character but spaces work best imo unless you want dots and dashes

Line1-3 = if changing the pre data text be sure to set at both ends (if LCD is less than 20 Columns you may need to shorten these to avoid overrun)

Prefix1-3 = set as a data source prefix, i.e "Phase 1" for a feed where no identifier is provided

Unit1-3 = set as a data source suffix, i.e oC for temp, Watts for power etc (note the leading space for neatness not always required)

additional feeds can be added if required i.e "("xap-header", "source", "dbzoo.livebox.jeenode:livingroom.temp")"

be sure to set the correct channel where required - "dbzoo.livebox.Controller:1wire.1"

Line4 is currently set to a 4 digit clock - if you wish to use Line4 for a data feed, simply remove "Line4 = "        "..os.date("%H:%M")" from the update timer and add relevant code for the data feed

Version 2 will work towards scrolling text and a status line for RF / Relay data

**************************************************************************************************************************

module(...,package.seeall)
require("xap")

info = {version="1.0", description="20x4LCDInfo"}

lcdcols = 20 -- Specify for LCD Row length
refresh = 10 -- Refresh period in seconds for collecting values and sending to LCD
fill = " " -- Char used to fill blank LCD colums

Line1 = "Waiting for Data - 1"..string.rep(fill, lcdcols - string.len("Waiting for Data - 1")) -- Sets Line Var to contain basic text until overwritten with Catch routines
Line2 = "Waiting for Data - 2"..string.rep(fill, lcdcols - string.len("Waiting for Data - 2"))
Line3 = "Waiting for Data - 3"..string.rep(fill, lcdcols - string.len("Waiting for Data - 3"))

Prefix1 = ""
Prefix2 = ""
Prefix3 = "Phase 1 "

Unit1 = " oC" -- Customisable Units (note the space prefix)
Unit2 = " oC"
Unit3 = " Watts"
 
function init() -- Sets up 3 filters
  Filter1 = xap.Filter()
  Filter1:add("xap-header", "source", "dbzoo.livebox.Controller:1wire.1")
  Filter1:callback(catch1wire1) -- A temperature change in the filter will trigger the Catch1wire1 routine
 
  Filter2 = xap.Filter()
  Filter2:add("xap-header", "source", "dbzoo.livebox.Controller:1wire.2")
  Filter2:callback(catch1wire2)
 
  Filter3 = xap.Filter()
  Filter3:add("xap-header", "source", "dbzoo.livebox.CurrentCost:ch.*")
  Filter3:callback(catchCurrentCost)
  
  send2lcd("Waiting for Data") -- Test LCD at applet start
  xap.Timer(update, refresh):start() -- Starts update routine timer with a 10 second interval
end

function catch1wire1()
  Value1 = Prefix1..xap.getValue("input.state","displaytext") -- Sets Value1 as 1Wire data
  Line1 = Value1..Unit1..string.rep(fill, (lcdcols - string.len(Value1) - string.len(Unit1))) -- Sets Line1 Var with 1Wire data (Value1) and appends Unit1, fills remaining Lcd colums with spaces
end

function catch1wire2()
  Value2 = Prefix2..xap.getValue("input.state","displaytext")
  Line2 = Value2..Unit2..string.rep(fill, (lcdcols - string.len(Value2) - string.len(Unit2)))
end

function catchCurrentCost()
  Value3 = Prefix3..xap.getValue("input.state","text")
  Line3 = Value3..Unit3..string.rep(fill, (lcdcols - string.len(Value3) - string.len(unit3)))
end

function update(self) -- Timer routine
  Line4 = "        "..os.date("%H:%M") -- Sets Line 4 as basic clock
  lcdstring = Line1..Line2..Line3..Line4 -- Conbines all LCD Lines1-4 into one string ready to send to the LCD every 10 seconds
  send2lcd(lcdstring) -- Sends to LCD
end

function send2lcd(lcdstr) -- LCD Routine
  xap.sendShort(string.format([[xap-header
   {
    target=dbzoo.livebox.Controller:lcd
    class=xAPBSC.cmd
   }
  output.state.1
   {
    id=*
    state=on
    text=%s
   }]], lcdstr))
end

AttachmentSize
20x4lcdApplet.lua2.67 KB
Hardware Info