initial commit with all the stuff
This commit is contained in:
114
3B/archive/root_10.bak/run_line.lua
Normal file
114
3B/archive/root_10.bak/run_line.lua
Normal file
@@ -0,0 +1,114 @@
|
||||
-- LUA default run file
|
||||
|
||||
-- LUA default run file
|
||||
|
||||
require "env"
|
||||
MQTT = require("mqtt")
|
||||
Scheduler = require('scheduler')
|
||||
|
||||
LOGING = 1
|
||||
|
||||
local function errLog(msg)
|
||||
io.stderr:write(msg)
|
||||
end
|
||||
|
||||
function logPrint(msg,aux)
|
||||
if ( LOGING ) then
|
||||
if aux then
|
||||
print(msg.." , "..aux)
|
||||
else
|
||||
print(msg);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function dbgPrint(msg,aux)
|
||||
if ( DEBUG ) then
|
||||
if aux then
|
||||
print(msg.." , "..aux)
|
||||
else
|
||||
print(msg);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
MQTT.onConnect (
|
||||
function()
|
||||
errLog("MQTT:\t Connect\n");
|
||||
MQTT.subscribe("+/#")
|
||||
end
|
||||
)
|
||||
|
||||
MQTT.onMessage (
|
||||
function(mid, topic, payload)
|
||||
logPrint("MQTT:\t Message <"..topic..">", payload)
|
||||
--posY,posX,strData,attrData = string.match(payload,"(%d+)|(%d+)|([^|])|([^|])")
|
||||
posY,posX,rawData = string.match(payload,"(%d+)|(%d+)|(.+)")
|
||||
strData=string.sub(rawData,1,string.len(rawData)/2)
|
||||
attrData=string.sub(rawData,string.len(rawData)/2+1)
|
||||
print(posY.."|"..posX.."|"..strData.."|"..attrData.."\n")
|
||||
if posY and posX and strData then
|
||||
line[posY+1]:setText(strData);
|
||||
line[posY+1]:draw()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
function setup()
|
||||
|
||||
if app.mqttBroker then
|
||||
MQTT.begin(app.mqttBroker[1])
|
||||
end
|
||||
MQTT.loop()
|
||||
|
||||
instance = HMI.App.instance;
|
||||
layout = HMI.Layout(instance,200,48);
|
||||
|
||||
mono = HMI.Font("/root/font/mono.ttf",34)
|
||||
|
||||
line = {}
|
||||
for i=1, 6, 1 do
|
||||
line[i] = HMI.Label(layout,0,8+4*(i-1),200,4,"1234567890123456789012345678901234567890");
|
||||
line[i]:setTextColor(HMI.Color.green);
|
||||
line[i]:setBackground(HMI.Color.black);
|
||||
line[i]:setFont(mono)
|
||||
end
|
||||
|
||||
number = {}
|
||||
for i=1, 10, 1 do
|
||||
number[i] = HMI.Cell(layout,1+20*(i-1),0,20,7,i-1);
|
||||
number[i]:setTextColor(HMI.Color.black);
|
||||
number[i]:setBackground(HMI.Color.grey);
|
||||
number[i]:setFont(mono)
|
||||
end
|
||||
|
||||
control = {}
|
||||
for j=0, 1, 1 do
|
||||
for i=1, 10, 1 do
|
||||
control[i+j] = HMI.Cell(layout,1+20*(i-1),34+j*7,20,7,i-1);
|
||||
control[i+j]:setTextColor(HMI.Color.black);
|
||||
control[i+j]:setBackground(HMI.Color.grey);
|
||||
control[i+j]:setFont(mono)
|
||||
end
|
||||
end
|
||||
|
||||
updateTimer = Scheduler.Timer(500)
|
||||
cnt = 0;
|
||||
end
|
||||
|
||||
function loop()
|
||||
--[[
|
||||
if updateTimer.elapsed() then
|
||||
line[1]:setText(string.format("%5.2f",cnt))
|
||||
line[1]:draw()
|
||||
cnt = cnt + 1
|
||||
updateTimer.restart()
|
||||
end
|
||||
--]]
|
||||
MQTT.loop()
|
||||
end
|
||||
|
||||
io.stderr:write("Run LUA\n");
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user