Catch Standby event. (1 Viewer)

KXE_DENMARK

Portal Member
May 10, 2006
14
0
Aarhus Denmark
Hi all..

I am writing a small plugin that I want to use to turn off myt TV set when I put my MediaCenter PC to sleep (standby). My TV set has the ability to get remotely controlled via a serial connection. This part I have covered Very Happy

I usually do this from the standby menu in MediaPortal.

Can anybody help my in how to catch that standby has been selected ?

Thanx in advance..
 

MJGraf

Retired Team Member
  • Premium Supporter
  • January 13, 2006
    2,478
    1,385
    Hi KXE_DENMARK,

    This sounds great! Unfortunately I'm not a programmer (anymore) and hence can't help you with your question...

    But I have been looking for something like this for ages! Only problem: My TV set does not have a serial connection. What I need is something to send 1 or 2 commands via my MCE-Blaster to switch TV and Amp off. After resuming I would need 3 commands (TV on, Amp on, switch TV to AV-in).

    Do you think this is hard to implement? If you can't (or don't want to) do this, it would be great to keep your plugin flexible enough so that anyone else could add the IR-Feature.

    Keep up the good work!

    cheers,

    /Michael
     

    mPod

    Portal Pro
    January 26, 2005
    2,084
    3
    Berlin
    Home Country
    Germany Germany
    See MediaPortal.cs, lines 573 and below. A windows message gets fired as soon as a powerbroadcast occurs. This one you catch with your WndProc and evaluate it. Your plugin has to be an IPluginReceiver for that.

    Have fun!
     

    wewe

    Portal Pro
    August 3, 2005
    362
    0
    63
    Herxheim
    Home Country
    Germany Germany
    okay I am having one question and one tip:

    Question:
    If the MCE-Blaster is the same as the Hauppauge IR Blaster then it is a IR emitter that you stick in front of the IR receiver of the device you want to control. I am having that set up to control an external Settup Box from MP ... works great! The question: how can you fire commends to three devices with one sender????

    Tip:
    I am having a master/slave power supply. TV, STB and Suround Booster are plugged to the slave plugs. When I switch on the PC (which is connected to the master plug) all the other devices are started. Works great! Okay still one problem: the TV set needs to be switched to an other input ... therefore I am looking for a solution. But three senders :?

    thanks+regards
    WeWe
     

    MJGraf

    Retired Team Member
  • Premium Supporter
  • January 13, 2006
    2,478
    1,385
    Hi Wewe,

    yes, I think, they are similar. But my MCE-Blaster has two plugin possibilities for two IR emitters and my TV power cord is plugged into my receiver - finally I only need 2 emitters which I have :)

    But nevertheless: if this does not work, there are solutions that seem to have much more powerful ir emitters and hence you only need one of them to control all the devices in one room (just don't remember the name...)

    cheers,

    /Michael
     

    magnuje2

    Portal Member
    May 11, 2006
    23
    0
    ok, ive got something like this working with a MCE IR transmitter (comes with the standard remote) and my amp.

    I used the myscripts plugin and wrote a code that uses handles built in MP to listen after media changes.

    If there is a change, let's say a movie or music is played, it turns my amp on by running a little program called MCEIR (i think) followed with parameters to a file containing a learned remote command ( amp on for instance).
    This handle can also show you what type of media that is played and the code could act differently for let's say music and movies. Different settings on your amp perhaps, or turn on TV for movies but not for music

    MP have a MSDN like API (somewhere on the forum. exe file) where all sorts of triggers could be found so combined with the IR learning possibilities of MCEIR you can do all sorts of things. I dont know if there is a handle for standby mode, but it should be.

    MCEIR.EXE (i think, it's not on this PC) uses another program to create the IR files, so it's pretty simple in use.

    Anyway, i can't get myscript working with RC3 but if anyone manage this i would be happy to share my code with you
     

    MJGraf

    Retired Team Member
  • Premium Supporter
  • January 13, 2006
    2,478
    1,385
    Hey magnuje2!

    This is great news! Didn't know it is possible to control the IR emitter part with an external program...
    The best solution in my eyes would be if there was something like an option in the setup program where you can define external programs to be executed when a certain message like "shutdown to standby" or "wakeup from standby" or even "start fullscreen TV" is sent.

    Question to the Devs: Would this be possible and would someone be interested in coding this?

    Keep up the good work,

    /Michael
     

    magnuje2

    Portal Member
    May 11, 2006
    23
    0
    A plugin like this should be fairly easy to impliment . This could open for all sorts of cool things in MP. I have seen a command line program for X-10 devices, so with the code below you could easily implement a system that dims your lights if a movie is played, but not for music, and dims it up again when you press pause.

    To find these handles you could just search after "handle" (i think) in the MSDN.

    i don't have the MCEIR program on this PC but if anyone wan't to impliment this i would be happy to send them over.

    so, anyway. Here's the myscript code. The on.bat and off.bat are the programs i run and just contains a MCEIR.EXE cammand with some parameters and the learned IR file.

    This script will turn your amp on if media is played and turn it off when you press stop (Not when media ended but this is easy. Just add another trigger). Hope this will be of some help:

    <xml>
    <MyScript>
    <This>
    <Name>Amplifier</Name>
    <Description>Turns on the amp when needed</Description>
    <Author>Magnus</Author>
    <Version>1</Version>
    <Code>using System;
    using System.Diagnostics;
    using System.Windows.Forms;
    using MediaPortal.MyScript;
    using MediaPortal.GUI.Library;
    using MediaPortal.Dialogs;
    using MyScript;
    using MediaPortal.Player;
    using System.Threading;



    class Main : Script
    {


    public void Start()
    {
    g_Player.PlayBackStarted += new g_Player.StartedHandler(Started);
    g_Player.PlayBackStopped += new g_Player.StoppedHandler(Stopped);

    }

    public void Stop()
    {
    g_Player.PlayBackStarted -= new g_Player.StartedHandler(Started);
    g_Player.PlayBackStopped -= new g_Player.StoppedHandler(Stopped);
    }

    private void Started(g_Player.MediaType type, string filename)
    {

    Process p=null;
    try
    {
    string targetDir;
    targetDir = string.Format(@"C:\IR");
    p= new Process();
    p.StartInfo.WorkingDirectory = targetDir;
    p.StartInfo.FileName = "on.bat";

    p.StartInfo.Arguments = string.Format("Test");
    p.StartInfo.CreateNoWindow = true;
    p.Start();
    p.WaitForExit();
    }
    catch (Exception ex)
    {
    Console.WriteLine("Exception Occurred :{0},{1}",
    ex.Message,ex.StackTrace.ToString());
    }



    }

    private void Stopped(g_Player.MediaType type, int tid, string filename)
    {


    Process p=null;
    try
    {
    string targetDir;
    targetDir = string.Format(@"C:\IR");
    p= new Process();
    p.StartInfo.WorkingDirectory = targetDir;
    p.StartInfo.FileName = "off.bat";

    p.StartInfo.Arguments = string.Format("Test");
    p.StartInfo.CreateNoWindow = true;
    p.Start();
    p.WaitForExit();
    }
    catch (Exception ex)
    {
    Console.WriteLine("Exception Occurred :{0},{1}",
    ex.Message,ex.StackTrace.ToString());
    }


    }


    }</Code>
    <ExternalCodeFile>
    <Language>C#</Language>
    <AutoStart>Application</AutoStart>
    <WarningLevel>4</WarningLevel>
    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
    <IncludeDebugInformation>False</IncludeDebugInformation>
    <AdditionalAssemblies>
    </MyScript>
     

    Users who are viewing this thread

    Top Bottom