Thread Tools
This thread is privately moderated by Miami Mike, who may elect to delete unwanted replies.
Jul 01, 2018, 04:36 PM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
Announce

A Script That Speaks the Time of Day


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.

Last edited by Miami Mike; Jul 03, 2018 at 11:36 AM.
Sign up now
to remove ads between posts
Jul 01, 2018, 05:47 PM
Wid
Wid
Live Your Dreams
Wid's Avatar
Thanks Mike. Works great. Had a little trouble setting the special function since saytim was not listed as an option under "parameters". Was able to type it in after figuring out some weirdness with the dashes that were in the parameters column. Using OTX 2.1 and companion 2.1

Now that I have been successful once I guess it is time I learn to use Lua
Jul 01, 2018, 05:51 PM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
If you add a script to the SD card folder while the Editing model window is open, it won't show up until you close the window and open it again.
Jul 01, 2018, 06:05 PM
looking up, down under
scruffy1's Avatar
thanks for giving me the time of day; some people won't
Jul 01, 2018, 09:16 PM
Wid
Wid
Live Your Dreams
Wid's Avatar
Got it working fine as a special function for one model. I am having trouble getting it to work as a global function. "GF2 SC↓ LUA Script saytim ". Seems like it should work. What am I missing?
Jul 02, 2018, 07:04 AM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
If you're using OpenTX 2.2 and didn't check Global Functions on each model's Setup tab then that's your answer, because saytim seems to work fine as a Global Function in Companion 2.2 simulator. But if you're using OpenTX 2.1, it appears to have a bug where Play Script functions aren't called when set up as Global Functions, although other functions like Play Sound and Play Track work okay.

I didn't know about that until now because I haven't used Global Functions much, but I just tried saytim and a couple of other working function scripts and none of them even showed up on the Companion 2.1.9 simulator Debug Output screen when I tried to call them as Global Functions. I even tried my Taranis X9D+ running OpenTX 2.1.9 and saytim wouldn't work as a Global Function there either.

Maybe there's a workaround, but if there is I don't know about it. I can feel the pressure gradually increasing on us diehard Taranis X9D+ users to switch to OpenTX version 2.2.
Jul 02, 2018, 04:38 PM
Wid
Wid
Live Your Dreams
Wid's Avatar
Tried with Taranis Plus OTX 2.2.0 . Still no go with global function. Had "use global functions" checked on the test model. Were you using 2.2.0, 2.2.1, or 2.2.2? Doesn't seem like it should make a difference but maybe I need to move up to 2.2.1 or 2.2.2?
Jul 02, 2018, 05:28 PM
Registered User
Quote:
Originally Posted by Wid
Tried with Taranis Plus OTX 2.2.0 . Still no go with global function. Had "use global functions" checked on the test model. Were you using 2.2.0, 2.2.1, or 2.2.2? Doesn't seem like it should make a difference but maybe I need to move up to 2.2.1 or 2.2.2?
I had no problem making it a global function attached to a switch. It works fine for me, using 2.2.1. You need to enable the Global function in the Radio Settings screen (the gear on the tool bar)> Global Functions
Jul 02, 2018, 06:21 PM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
I found this discussion on GitHub. Apparently it may have been been deliberately disabled, but if so the developers don't know why, and then some time around the end of last November, during the development of 2.2, it was decided to enable it.

Or at least that's my impression. I'm not very good at following what goes on at GitHub.
Jul 02, 2018, 09:01 PM
Wid
Wid
Live Your Dreams
Wid's Avatar
Well that does sort of explain it. I too have trouble following github.
I have a global function for sound volume on S1 that is working . But the LUA script still won't run from global functions. I guess if that is what I want I need to upgrade the firmware. Should I go for 2.2.1 or 2.2.2? If 2.2.2 can I go directly from 2.2.0 or do I need to do 2.2.1 first then 2.2.2? Thanks for your research and help. It is nice to know it wasn't just me doing something stupid.
Jul 02, 2018, 09:21 PM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
If you have 2.2.0 now then I'm pretty sure you can upgrade directly to the latest stable version in a single step, but I haven't done it myself so I'm not an expert on that. You might want to first back up your otx file and SD card, upgrade Companion, make sure all of your models work right, and then flash your radio. I think you'll also have to upgrade your SD card contents, so that'll mean you'll have to reinstall saytim.lua, the SAYTIME folder, and everything else that you've added to the original contents of your SD card.
Jul 03, 2018, 02:44 AM
Wid
Wid
Live Your Dreams
Wid's Avatar
Companion made it easy to upgrade to 2.2.1 so that is what I did. Global functions Lua works now. But I noticed that 12:33 AM is reported as 33 AM (no 12).
Last edited by Wid; Jul 03, 2018 at 10:09 AM.
Jul 03, 2018, 08:02 AM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
Oops, I'm glad you caught that! In the SAYTIME folder, make a copy of 12h.wav and rename it to 0h.wav. Meanwhile, I'll put together an updated version of the zip file.

Thanks!
Jul 10, 2018, 09:50 AM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
Quote:
Originally Posted by pherz
I had no problem making it a global function attached to a switch. It works fine for me, using 2.2.1. You need to enable the Global function in the Radio Settings screen (the gear on the tool bar)> Global Functions
Actually you don't! I discovered that they still don't have it working right. If you set any function script to be activated as a Global Function, it will work with any model selected, no matter whether or not the Global Functions box is checked on that model's Setup page.

I reported it here.
Jul 14, 2018, 07:10 AM
e^(iπ) + 1 = 0
Miami Mike's Avatar
Thread OP
A fix is on the way.


Quick Reply
Message:
Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion LUA scripting - Technical discussion Fig Newton Radios 3035 Oct 16, 2019 08:05 AM
Download LuaPilot Telemetry Taranis Lua Script ilihack Radios 56 Sep 06, 2018 08:39 AM
Discussion L/D and Sink rate LUA script for OpenTx FabFlight Sailplane Talk 2 Mar 23, 2016 07:28 PM