Merged
This commit is contained in:
commit
c3638989cd
23
Readme.md
23
Readme.md
@ -30,19 +30,30 @@ Determine the IP address of your clock and execute the following script:
|
|||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Hardware Setup
|
## Hardware Setup
|
||||||
|
Mandatory:
|
||||||
* GPIO2 LEDs
|
* GPIO2 LEDs
|
||||||
* GPIO0 Bootloader (at start)
|
* GPIO0 Bootloader (at start)
|
||||||
* GPIO0 factory reset (long during operation)
|
* GPIO0 factory reset (long during operation)
|
||||||
|
Optinal:
|
||||||
|
* ADC VT93N2, 48k light resistor
|
||||||
|
|
||||||
## MQTT Interface
|
## MQTT Interface
|
||||||
|
### Status
|
||||||
|
* **basetopic**/brightness **Current brightness in percent**
|
||||||
|
* **basetopic**/background **Current background color**
|
||||||
|
* **basetopic**/row1 **Current background color**
|
||||||
|
|
||||||
|
### Commands
|
||||||
* **basetopic**/cmd/single
|
* **basetopic**/cmd/single
|
||||||
* ON Set brightness to 100%
|
* ON **Set brightness to 100%**
|
||||||
* OFF Set brightness to 0%
|
* OFF **Set brightness to 0%**
|
||||||
* 0-100 Set brightness to given value
|
* 0-100 **Set brightness to given value**
|
||||||
* #rrggbb Bacground color is set to hex representation of red, green and blue
|
* #rrggbb **Background color is set to hex representation of red, green and blue**
|
||||||
* 0-255,0-255,0-255 Background color is set to decimal representation of red, green an blue
|
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
|
||||||
* **basetopic**/cmd/telnet
|
* **basetopic**/cmd/telnet
|
||||||
* ignored Stop MQTT server and start telnetserver at port 23
|
* ignored **Stop MQTT server and start telnetserver at port 23**
|
||||||
|
* **basetopic**/cmd/row1
|
||||||
|
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
|
||||||
|
|
||||||
## OpenHAB2
|
## OpenHAB2
|
||||||
Tested MQTT with binding-mqtt 2.5.x
|
Tested MQTT with binding-mqtt 2.5.x
|
||||||
|
@ -54,7 +54,7 @@ end
|
|||||||
local data={}
|
local data={}
|
||||||
|
|
||||||
-- Module displaying of the words
|
-- Module displaying of the words
|
||||||
local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars)
|
local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars, row1bgColor)
|
||||||
-- Set the local variables needed for the colored progress bar
|
-- Set the local variables needed for the colored progress bar
|
||||||
if (words == nil) then
|
if (words == nil) then
|
||||||
return nil
|
return nil
|
||||||
@ -107,14 +107,20 @@ local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, col
|
|||||||
-- Space / background has no color by default
|
-- Space / background has no color by default
|
||||||
local space=string.char(0,0,0)
|
local space=string.char(0,0,0)
|
||||||
|
|
||||||
|
-- Background color must always be set
|
||||||
if (colorBg ~= nil) then
|
if (colorBg ~= nil) then
|
||||||
space = colorBg
|
space = colorBg
|
||||||
|
else
|
||||||
|
colorBg = space
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set the foreground color as the default color
|
-- Set the foreground color as the default color
|
||||||
local buf=data.colorFg
|
local buf=data.colorFg
|
||||||
local line=space
|
local line=space
|
||||||
-- line 1----------------------------------------------
|
-- line 1----------------------------------------------
|
||||||
|
if (row1bgColor ~= nil) then
|
||||||
|
space = row1bgColor
|
||||||
|
end
|
||||||
if (words.it==1) then
|
if (words.it==1) then
|
||||||
buf=drawLEDs(data,2) -- ES
|
buf=drawLEDs(data,2) -- ES
|
||||||
else
|
else
|
||||||
@ -135,6 +141,11 @@ if (words.fiveMin== 1) then
|
|||||||
buf= buf .. space:rep(4)
|
buf= buf .. space:rep(4)
|
||||||
end
|
end
|
||||||
-- line 2-- even row (so inverted) --------------------
|
-- line 2-- even row (so inverted) --------------------
|
||||||
|
if (row2bgColor ~= nil) then
|
||||||
|
space = row2bgColor
|
||||||
|
else
|
||||||
|
space = colorBg
|
||||||
|
end
|
||||||
if (words.tenMin == 1) then
|
if (words.tenMin == 1) then
|
||||||
line= drawLEDs(data,4) -- ZEHN
|
line= drawLEDs(data,4) -- ZEHN
|
||||||
else
|
else
|
||||||
|
3
main.lua
3
main.lua
@ -72,7 +72,8 @@ function displayTime()
|
|||||||
invertRows=true
|
invertRows=true
|
||||||
end
|
end
|
||||||
local characters = displayword.countChars(words)
|
local characters = displayword.countChars(words)
|
||||||
ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters)
|
ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters,
|
||||||
|
row1bgColor)
|
||||||
end
|
end
|
||||||
displayword = nil
|
displayword = nil
|
||||||
if (ledBuf ~= nil) then
|
if (ledBuf ~= nil) then
|
||||||
|
24
mqtt.lua
24
mqtt.lua
@ -37,6 +37,28 @@ function handleSingleCommand(client, topic, data)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Parse MQTT data and extract color
|
||||||
|
-- @param data MQTT information
|
||||||
|
-- @param row string of the row e.g. "row1" used to publish current state
|
||||||
|
function parseBgColor(data, row)
|
||||||
|
local red=nil
|
||||||
|
local green=nil
|
||||||
|
local blue=nil
|
||||||
|
if (data:sub(1,1) == "#") then
|
||||||
|
red = tonumber(data:sub(2,3), 16)
|
||||||
|
green = tonumber(data:sub(4,5), 16)
|
||||||
|
blue = tonumber(data:sub(6,7), 16)
|
||||||
|
else
|
||||||
|
red, green, blue = string.match(data, "(%d+),(%d+),(%d+)")
|
||||||
|
end
|
||||||
|
if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then
|
||||||
|
m:publish(mqttPrefix .. "/"..row, tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0)
|
||||||
|
return string.char(green * briPercent / 100, red * briPercent / 100, blue * briPercent / 100)
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- MQTT extension
|
-- MQTT extension
|
||||||
function registerMqtt()
|
function registerMqtt()
|
||||||
m = mqtt.Client("wordclock", 120)
|
m = mqtt.Client("wordclock", 120)
|
||||||
@ -58,6 +80,8 @@ function registerMqtt()
|
|||||||
collectgarbage()
|
collectgarbage()
|
||||||
mydofile("telnet")
|
mydofile("telnet")
|
||||||
startTelnetServer()
|
startTelnetServer()
|
||||||
|
elseif (string.match(topic, "row1$")) then
|
||||||
|
row1bgColor = parseBgColor(data, "row1")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user