Re-run macro until condition X is true/false

If you have a question or need help, this is the place to be.
Post Reply
Mordred
Posts: 13
Joined: Sun Jan 31, 2010 1:24 am

Re-run macro until condition X is true/false

Post by Mordred » Wed Mar 14, 2018 2:10 am

My situation is that I've got a macro to launch Kodi. This macro gets fired in response to a keypress on the remote, which is sent by a manual keypress and also as part of the "Watch Kodi" remote activity which also turns on my TV and receiver.

The problem is that if Event Ghost launches Kodi before the TV device is attached, it will come up windowed, or stretched, or not respond to most EG keypresses. There's also a lot of variability here. If everything is off it can take anywhere from 10-25 seconds or so for HTPC to attach to the device. If I was watching TV, and then click the Watch Kodi activity, it's already attached and so I don't want to wait anytime. The input will get switched and then Kodi should launch immediately.

I've added some macros to enable and disable the Start Program: Kodi action when a device is attached and detached, and that works to at least prevent Kodi from opening in a bad state, but what I really want is for EG to keep running the current macro until the device is attached, launch Kodi and then stop.

I've tried all sorts of sub macros and Jumps, but it either only runs once or I end up in endless loops and EG becomes unresponsive (even with 2 second waits between retries). Is there anyway to do this without Python?

If I have to use Python are there some examples on how this would work?

cvben
Posts: 38
Joined: Wed Jun 07, 2017 8:30 pm

Re: Re-run macro until condition X is true/false

Post by cvben » Wed Mar 14, 2018 2:34 am

Maybe a silly question, but have you tried running kodi with some cmd arguments?
The arguments aren't annoyingly hard to find, but it looks like "-fs" is for fullscreen.

Then these might be useful too:

--standalone runs in a stand alone environment without a window

--legacy-res Enables screen resolutions such as PAL, NTSC, etc.

cvben
Posts: 38
Joined: Wed Jun 07, 2017 8:30 pm

Re: Re-run macro until condition X is true/false

Post by cvben » Wed Mar 14, 2018 2:43 am

Also, how is the TV connected, you could try looking at the HID plugin.

Or the device might throw an event like "System.DeviceAttached [u'\\\\?\\DISPLAY#GSM0001#4&279bcb2c&0&UID198147#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}']" in the log you might be able to use.

Mordred
Posts: 13
Joined: Sun Jan 31, 2010 1:24 am

Re: Re-run macro until condition X is true/false

Post by Mordred » Wed Mar 14, 2018 2:55 am

Kodi is setup correctly, and launches in full screen when the TV and receiver are already on. The problem is when the device is not attached it just doesn't work properly. Besides it not always opening in full screen, EG somehow doesn't think Kodi has the focus even though it does. I have to manually switch to a different window, and then back to Kodi before EG thinks it's got the focus again and re-enables my Kodi specific command folder.

I'm using the System.DeviceAttached event to enable the "Start Program: Kodi" portion of my macro. I just want some way to get the macro to repeat until I see a System.DeviceAttached event (or the device is already attached).

blaher
Experienced User
Posts: 481
Joined: Thu Nov 17, 2011 1:27 am

Re: Re-run macro until condition X is true/false

Post by blaher » Wed Mar 14, 2018 3:21 am

https://imgur.com/a/ixwbG might give you some ideas.

Basically you set one macro as the default for when the TV is off, so it takes a long time. And then you have a shorter macro which launches stuff immediately, and is only enabled after your screen is attached/TV turned on.

User avatar
kgschlosser
Site Admin
Posts: 4308
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Re-run macro until condition X is true/false

Post by kgschlosser » Wed Mar 14, 2018 5:48 am

it is not a good idea to use the System.Attached event that is generated by a TV..

I will explain..

The problem is the EDID data lane. the EDID is what transfers information to whatever the device is connected to. In this case it tells Your videocard what is attached. and what modes it supports. and all of that kind of stuff. and This information is then sent over to Windows.

The problem is how TV's are built. On initial power on the EDID becomes active and Windows then Gets the notification that there is a new Monitor connected. Now this is where it is a crap shoot. it can sometimes do this and sometimes it won't and the number of times is also kind of random. But when the TV then turns on the back lighting for the screen this is such an inrush for the Power supply the internal voltage of the TV drops. Now in most cases this would not be an issue. But with Windows and the sensitivity of the EDID data lane voltage. and then if you throw in a long HDMI. the PC will think the TV disconnected. until the inrush flattens out and the caps on the TV's power supply charge back up. Then there voltage on the EDID comes back up. and the PC things the monitor got attached again. If you are right on the line with the voltage you can have all kinds of goofy issues.

My recommendation is this. if you want to have a nice consistent TV to PC connection. get a UPS for your TV. does't have to be huge. maybe a 600VA this will ensure that you TV always has a nice consistent 120+ volts (US) this will make sure that low line voltage will not add to the problems. Then get an HDMI cable that has a super low resistance and is shielded to the max. One that has a nice outer braided shielding.


We can set something up that will give you a more solid event. maybe something that gets triggered if your screen resolution changes. Or possibly if your default sound card changes.

we can also handle the focus issue using the Task Monitor + plugin. This plugin allows for all kinds of window control. including but not limited to making sure the window is set into focus (this will cause windows to issue a focus change notification). For whatever reason Windows behaves very differently in respect to a program running in full screen mode. I do not know why it does. but it does.

If your TV does what i described above then we need is a concrete event for the TV getting connected. or we have to set up a couple of timers.
the focus thing is not an issue. If you use that plugin I mentioned.
If you like the work I have been doing then feel free to Image

Post Reply