Calculate the amount of words

This commit is contained in:
ollo 2018-01-28 14:23:01 +01:00
parent cb5205d4af
commit 0038a7997e
2 changed files with 17 additions and 2 deletions

View File

@ -51,10 +51,11 @@ function displayTime()
words = display_timestat(time.hour, time.minute) words = display_timestat(time.hour, time.minute)
local charactersOfTime = display_countcharacters_de(words) local charactersOfTime = display_countcharacters_de(words)
local wordsOfTime = display_countwords_de(words)
ledBuf = generateLEDs(words, color, color1, color2, color3, color4, ledBuf = generateLEDs(words, color, color1, color2, color3, color4,
charactersOfTime) charactersOfTime)
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " in " .. charactersOfTime .. " chars") print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " in " .. charactersOfTime .. " chars " .. wordsOfTime .. " words")
-- Write the buffer to the LEDs -- Write the buffer to the LEDs
ws2812.write(ledBuf) ws2812.write(ledBuf)

View File

@ -139,7 +139,7 @@ end
-- @fn display_countcharacters_de -- @fn display_countcharacters_de
-- Count the amount of characters, used to describe the current time in words -- Count the amount of characters, used to describe the current time in words
-- @param words the same structure, as generated with the function @see display_timestat -- @param words the same structure, as generated with the function @see display_timestat
-- @return the amount of words, used to describe the time or <code>0</code> on errors -- @return the amount of characters, used to describe the time or <code>0</code> on errors
function display_countcharacters_de(words) function display_countcharacters_de(words)
local amount=0 local amount=0
if (words.itis == 1) then if (words.itis == 1) then
@ -214,3 +214,17 @@ function display_countcharacters_de(words)
return amount return amount
end end
-- @fn display_countcharacters_de
-- Count the amount of words, used to describe the current time in words
-- @param words the same structure, as generated with the function @see display_timestat
-- @return the amount of words, used to describe the time or <code>0</code> on errors
function display_countwords_de(words)
local amount = 0
for k,v in pairs(words) do
if (v ~= nil and v == 1) then
amount = amount + 1
end
end
return amount
end