From d6d305ec7049e371be46cc5162e9e4dce515bc2e Mon Sep 17 00:00:00 2001 From: Ollo Date: Mon, 1 Nov 2021 19:02:12 +0100 Subject: [PATCH] Temperature is calcualted, only once --- main.lua | 13 ++++--------- mqtt.lua | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/main.lua b/main.lua index b7ab043..398c17f 100644 --- a/main.lua +++ b/main.lua @@ -38,20 +38,15 @@ function displayTime() collectgarbage() mydofile("wordclock") if (wc ~= nil) then - words = wc.timestat(time.hour, time.minute) - if ((dim ~= nil) and (dim == "on")) then + words = wc.timestat(time.hour, time.minute) + if ((dim ~= nil) and (dim == "on")) then words.briPer=briPer if (words.briPer ~= nil and words.briPer < 3) then words.briPer=3 end - else + else words.briPer=nil - end - end - local tw=nil - local tcol=nil - if (mqttDispTemp ~= nil) then - tw, tcol = wc.temp(dw, rgbBuffer, invertRows) + end end wc = nil collectgarbage() diff --git a/mqtt.lua b/mqtt.lua index a8a9c3b..665c579 100644 --- a/mqtt.lua +++ b/mqtt.lua @@ -3,7 +3,8 @@ local m=nil local mqttConnected = false -- Temp: local t=nil -dispTemp=nil +local tw=nil +local tcol=nil function handleSingleCommand(client, topic, data) if (data == "ON") then @@ -118,9 +119,20 @@ function registerMqtt() handleSingleCommand(client, topic, data) elseif (topic == (mqttPrefix .. "/cmd/temp")) then if ( data == "" ) then - dispTemp = nil + tw=nil + tcol=nil else - dispTemp = tonumber(data) + -- generate the temperatur to display, once as it will not change + local dispTemp = tonumber(data) + collectgarbage() + mydofile("wordclock") + if (wc ~= nil) then + tw, tcol = wc.temp(dw, rgbBuffer, invertRows) + wc = nil + else + print("MQTT | wordclock failed") + end + end else -- Handle here the /cmd/# sublevel