Miami Mike's blog View Details
Archive for July, 2018
Posted by Miami Mike | Jul 01, 2018 @ 04:36 PM | 13,676 Views
Here's a Lua script and custom set of WAV files for OpenTX version 2.1 or 2.2 to speak the time of day in a natural-sounding format, such as "twelve o'clock PM" or "nine oh two AM."

The WAV files are in a folder in the root directory named SAYTIME, and saytim.lua is stored in /SCRIPTS/FUNCTIONS/.

On your Special Functions page, set saytim to be played with the Play Script function whenever a hardware or logical switch of your choice is true. For example, this will play the time of day when SA is switched to position SA↑:



Beginning with OpenTX version 2.2.1, saytim.lua can alternately be called with a Global Function.

The script and set of WAV files were revised on July 3, 2018 to allow for times from 12:00 AM to 12:59 AM. The revised script looks like this:
Code:
-- Function script saytim.lua by Miami Mike, July 3rd, 2018
local path, lastcall = "/SAYTIME/", 0
local function run_func()
	local newcall = false
	local time = getTime()
	if time > lastcall then
		newcall = true
	end
	lastcall = time + 10
	if newcall then
		local datetime = getDateTime()
		local hour, minute, ampm = datetime.hour, datetime.min, "am"
		if hour >= 12 then
			ampm = "pm"
			if hour >= 13 then
				hour = hour - 12
			end	
		end
		playFile(path .. "timeis.wav")
		playFile(path .. hour .. "h.wav")
		playFile(path .. minute .. ".wav")
		playFile(path .. ampm .. ".wav")
	end	
end
return {run=run_func}
Instructions are included in a file named readme.txt. Please post any problems or special requests below.