Background can be changed via MQTT
This commit is contained in:
		| @@ -54,7 +54,7 @@ end | |||||||
| local data={} | local data={} | ||||||
|  |  | ||||||
| -- Module displaying of the words | -- Module displaying of the words | ||||||
| local generateLEDs = function(words, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars) | local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars) | ||||||
|  -- 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 | ||||||
| @@ -103,9 +103,14 @@ local generateLEDs = function(words, colorFg, colorMin1, colorMin2, colorMin3, c | |||||||
|  end |  end | ||||||
|  data.drawnCharacters=0 |  data.drawnCharacters=0 | ||||||
|  local charsPerLine=11 |  local charsPerLine=11 | ||||||
|  |   | ||||||
|  -- 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) | ||||||
|  |  | ||||||
|  |  if (colorBg ~= nil) then | ||||||
|  |   space = colorBg | ||||||
|  |  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 | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								main.lua
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.lua
									
									
									
									
									
								
							| @@ -72,7 +72,7 @@ function displayTime() | |||||||
|             invertRows=true |             invertRows=true | ||||||
|         end |         end | ||||||
|         local characters = displayword.countChars(words) |         local characters = displayword.countChars(words) | ||||||
|         ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows, characters) |         ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters) | ||||||
|      end |      end | ||||||
|      displayword = nil |      displayword = nil | ||||||
|      if (ledBuf ~= nil) then |      if (ledBuf ~= nil) then | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								mqtt.lua
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								mqtt.lua
									
									
									
									
									
								
							| @@ -16,15 +16,21 @@ function registerMqtt() | |||||||
|         elseif (data == "OFF") then |         elseif (data == "OFF") then | ||||||
|           briPercent=0 |           briPercent=0 | ||||||
|           m:publish(mqttPrefix .. "/clock", "OFF", 0, 0) |           m:publish(mqttPrefix .. "/clock", "OFF", 0, 0) | ||||||
| 	elseif (data:sub(1,1) == "#" and data:len() == 7) then | 	    elseif (data:sub(1,1) == "#" and data:len() == 7) then | ||||||
| 		red = tonumber(data:sub(2,3), 16) | 		  red = tonumber(data:sub(2,3), 16) | ||||||
|                 green = tonumber(data:sub(4,5), 16) |           green = tonumber(data:sub(4,5), 16) | ||||||
|                 blue = tonumber(data:sub(6,7), 16) |           blue = tonumber(data:sub(6,7), 16) | ||||||
|                 colorBg=string.char(red, green, blue) |           colorBg=string.char(red, green, blue) | ||||||
|  |           print("Updated BG: " .. tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue) ) | ||||||
|  |           if (displayTime~= nil) then | ||||||
|  |             displayTime() | ||||||
|  |           end | ||||||
|         else |         else | ||||||
|           if (tonumber(data) >= 0 and tonumber(data) <= 100) then |           if (tonumber(data) >= 0 and tonumber(data) <= 100) then | ||||||
|             briPercent=tonumber(data) |             briPercent=tonumber(data) | ||||||
|             m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0) |             m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0) | ||||||
|  |           else | ||||||
|  |             print "Unknown MQTT command" | ||||||
|           end |           end | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user