Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aHidEvent"></param>
        public void OnHidEvent(object aSender, Hid.Event aHidEvent)
        {
            HidListener.LogInfo("\n" + aHidEvent.ToString());

            if (aHidEvent.IsRepeat)
            {
                HidListener.LogInfo("HID: Repeat");
            }

            _actions = null;
            _actions = new List <MediaPortal.InputDevices.HidUsageAction.ConditionalAction>();
            HidUsageAction usageAction;

            // Check if we have mappings for this usage ID (page/collection).
            if (_usageActions.TryGetValue(aHidEvent.UsageId, out usageAction))
            {
                //Alright we do handle this usage ID
                //Try mapping actions to each of our usage
                if (aHidEvent.IsGeneric)
                {
                    foreach (ushort usage in aHidEvent.Usages)
                    {
                        HidListener.LogInfo("HID: try mapping usage 0x{0}", usage.ToString("X4"));
                        HidUsageAction.ConditionalAction action = usageAction.GetAction(usage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat, aHidEvent.HasModifierShift, aHidEvent.HasModifierControl, aHidEvent.HasModifierAlt, aHidEvent.HasModifierWindows);
                        _actions.Add(action);
                        if (_shouldRaiseAction)
                        {
                            usageAction.ExecuteActionIfNeeded(action);
                        }
                    }

                    //Do some extra checks if our device is a gamepad
                    if (aHidEvent.Device != null && aHidEvent.Device.IsGamePad)
                    {
                        //Check if dpad needs to be handled too
                        HidListener.LogInfo("HID: try mapping dpad {0}", aHidEvent.GetDirectionPadState());
                        const int KDPadButtonOffset             = 1000; //This is our magic dpad button offset. Should be good enough as it leaves us with 998 genuine buttons.
                        ushort    dpadFakeUsage                 = (ushort)(KDPadButtonOffset + (int)aHidEvent.GetDirectionPadState());
                        HidUsageAction.ConditionalAction action = usageAction.GetAction(dpadFakeUsage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat, aHidEvent.HasModifierShift, aHidEvent.HasModifierControl, aHidEvent.HasModifierAlt, aHidEvent.HasModifierWindows);
                        _actions.Add(action);
                        if (_shouldRaiseAction)
                        {
                            usageAction.ExecuteActionIfNeeded(action);
                        }
                    }
                }
                else if (aHidEvent.IsKeyboard && aHidEvent.IsButtonDown && !GUIWindowManager.NeedsTextInput)
                {
                    //Keyboard handling
                    ushort virtualKey = aHidEvent.RawInput.keyboard.VKey;
                    HidListener.LogInfo("HID: try mapping virtual code 0x{0}", virtualKey.ToString("X4"));
                    HidUsageAction.ConditionalAction action = usageAction.GetAction(virtualKey.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat, aHidEvent.HasModifierShift, aHidEvent.HasModifierControl, aHidEvent.HasModifierAlt, aHidEvent.HasModifierWindows);
                    _actions.Add(action);
                    if (_shouldRaiseAction)
                    {
                        usageAction.ExecuteActionIfNeeded(action);
                    }
                }
            }
        }
Exemple #2
0
        public void OnHidEventRepeat(HidEvent aHidEvent)
        {
            //Broadcast our events
            //OnHidEvent(this, aHidEvent);

            if (aHidEvent.IsStray) //Defensive
            {
                return;
            }

            HidListener.LogInfo("HID: Repeat");

            HidUsageAction usageAction;

            if (_usageActions.TryGetValue(aHidEvent.UsageId, out usageAction))
            {
                //Alright we do handle this usage ID
                //Try mapping actions to each of our usage
                foreach (var usage in aHidEvent.Usages)
                {
                    HidListener.LogInfo("HID: try mapping usage {0}", usage.ToString("X4"));
                    usageAction.MapAction(usage, aHidEvent.IsBackground, true);
                }
            }
        }
Exemple #3
0
        public static bool WndProc(ref Message msg, out Action action, out char key, out Keys keyCode)
        {
            action  = null;
            key     = (char)0;
            keyCode = Keys.A;

            if (CentareaRemote.WndProc(ref msg))
            {
                return(true);
            }

            if (HidListener.WndProc(ref msg, out action, out key, out keyCode))
            {
                return(true);
            }

            if (HCWRemote.WndProc(msg))
            {
                return(true);
            }

            if (FireDTVRemote.WndProc(ref msg, out action, out key, out keyCode))
            {
                return(true);
            }

            if (MCE2005Remote.WndProc(msg))
            {
                return(true);
            }

            return(false);
        }
Exemple #4
0
        public List <MediaPortal.InputDevices.HidUsageAction.ConditionalAction> ProcessInput(Message aMessage, bool shouldRaiseAction = true)
        {
            var result   = new List <MediaPortal.InputDevices.HidUsageAction.ConditionalAction>();
            var hidEvent = new HidEvent(aMessage, OnHidEventRepeat);

            if (HidListener.Verbose) //Avoid string conversion if not needed
            {
                Log.Info("\n" + hidEvent.ToString());
            }

            if (!hidEvent.IsValid || !hidEvent.IsGeneric)
            {
                HidListener.LogInfo("HID: Skipping HID message.");
                return(null);
            }

            //
            if (hidEvent.Usages[0] == 0)
            {
                //This is a key up event
                //We need to discard any events belonging to the same page and collection
                for (var i = (_hidEvents.Count - 1); i >= 0; i--)
                {
                    if (_hidEvents[i].UsageId == hidEvent.UsageId)
                    {
                        _hidEvents[i].Dispose();
                        _hidEvents.RemoveAt(i);
                    }
                }
            }
            else
            {
                //Keep that event until we get a key up message
                _hidEvents.Add(hidEvent);
            }

            //Broadcast our events
            //OnHidEvent(this, hidEvent);

            HidUsageAction usageAction;

            if (_usageActions.TryGetValue(hidEvent.UsageId, out usageAction))
            {
                //Alright we do handle this usage ID
                //Try mapping actions to each of our usage
                foreach (ushort usage in hidEvent.Usages)
                {
                    HidListener.LogInfo("HID: try mapping usage {0}", usage.ToString("X4"));
                    result.Add(usageAction.GetAction(usage.ToString(), hidEvent.IsBackground, false));
                    if (shouldRaiseAction)
                    {
                        usageAction.MapAction(usage, hidEvent.IsBackground, false);
                    }
                }
                return(result);
            }
            return(null);
        }
Exemple #5
0
 public static void Init()
 {
     if (_initialized)
     {
         Log.Info("Remotes: Init was called before Stop - stopping devices now");
         Stop();
     }
     _initialized = true;
     //diRemote.Init(); // Disable DirectX Input (not compatible with NET4 and later)
     X10Remote.Init();
     CentareaRemote.Init();
     HidListener.Init(GUIGraphicsContext.ActiveForm);
     MCE2005Remote.Init(GUIGraphicsContext.ActiveForm);
     FireDTVRemote.Init(GUIGraphicsContext.ActiveForm);
     HCWRemote.Init(GUIGraphicsContext.ActiveForm);
     IrTrans.Init(GUIGraphicsContext.ActiveForm);
 }
 public static void Init()
 {
     if (_initialized)
     {
         Log.Info("Remotes: Init was called before Stop - stopping devices now");
         Stop();
     }
     _initialized = true;
     diRemote.Init();
     X10Remote.Init();
     CentareaRemote.Init();
     HidListener.Init(GUIGraphicsContext.ActiveForm);
     MCE2005Remote.Init(GUIGraphicsContext.ActiveForm);
     FireDTVRemote.Init(GUIGraphicsContext.ActiveForm);
     HCWRemote.Init(GUIGraphicsContext.ActiveForm);
     IrTrans.Init(GUIGraphicsContext.ActiveForm);
 }
Exemple #7
0
        public static void Stop()
        {
            if (!_initialized)
            {
                Log.Info("Remotes: Stop was called without Init - exiting");
                return;
            }

            HidListener.DeInit();
            MCE2005Remote.DeInit();
            FireDTVRemote.DeInit();
            CentareaRemote.DeInit();
            HCWRemote.DeInit();
            IrTrans.DeInit();
            //diRemote.Stop(); // Disable DirectX Input (not compatible with NET4 and later)

            _initialized = false;
        }
        public static void Stop()
        {
            if (!_initialized)
            {
                Log.Info("Remotes: Stop was called without Init - exiting");
                return;
            }

            HidListener.DeInit();
            MCE2005Remote.DeInit();
            FireDTVRemote.DeInit();
            CentareaRemote.DeInit();
            HCWRemote.DeInit();
            IrTrans.DeInit();
            diRemote.Stop();

            _initialized = false;
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aHidEvent"></param>
        public void OnHidEvent(object aSender, Hid.Event aHidEvent)
        {
            if (aHidEvent.IsRepeat)
            {
                HidListener.LogInfo("HID: Repeat");
            }

            _actions = null;
            _actions = new List <MediaPortal.InputDevices.HidUsageAction.ConditionalAction>();
            HidUsageAction usageAction;

            if (_usageActions.TryGetValue(aHidEvent.UsageId, out usageAction))
            {
                //Alright we do handle this usage ID
                //Try mapping actions to each of our usage
                foreach (ushort usage in aHidEvent.Usages)
                {
                    HidListener.LogInfo("HID: try mapping usage {0}", usage.ToString("X4"));
                    _actions.Add(usageAction.GetAction(usage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat));
                    if (_shouldRaiseAction)
                    {
                        usageAction.MapAction(usage, aHidEvent.IsBackground, aHidEvent.IsRepeat);
                    }
                }

                //Do some extra checks if our device is a gamepad
                if (aHidEvent.Device.IsGamePad)
                {
                    //Check if dpad needs to be handled too
                    HidListener.LogInfo("HID: try mapping dpad {0}", aHidEvent.GetDirectionPadState());
                    const int KDPadButtonOffset = 1000; //This is our magic dpad button offset. Should be good enough as it leaves us with 998 genuine buttons.
                    ushort    dpadFakeUsage     = (ushort)(KDPadButtonOffset + (int)aHidEvent.GetDirectionPadState());
                    _actions.Add(usageAction.GetAction(dpadFakeUsage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat));
                    if (_shouldRaiseAction)
                    {
                        usageAction.MapAction(dpadFakeUsage, aHidEvent.IsBackground, aHidEvent.IsRepeat);
                    }
                }
            }
        }
        /// <summary>
        /// Execute the given conditional action if needed.
        /// </summary>
        /// <param name="aAction">The action we want to conditionally execute.</param>
        /// <param name="aProcessId">Process-ID for close/kill commands.</param>
        /// <returns></returns>
        public bool ExecuteActionIfNeeded(ConditionalAction aAction, int aProcessId = -1)
        {
            if (aAction == null)
            {
                return(false);
            }

            HidListener.LogInfo("Action: {0} / {1} / {2} / {3}", aAction.Condition, aAction.ConProperty, aAction.Command, aAction.CmdProperty);

            Action action;

            if (aAction.Sound != string.Empty)
            {
                Util.Utils.PlaySound(aAction.Sound, false, true);
            }
            if (aAction.Focus && !GUIGraphicsContext.HasFocus)
            {
                GUIGraphicsContext.ResetLastActivity();
                var msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
                //GUIWindowManager.SendThreadMessage(msg);
                GUIGraphicsContext.SendMessage(msg);
                return(true);
            }
            switch (aAction.Command)
            {
            case "ACTION": // execute Action x
                var key = new Key(aAction.CmdKeyChar, aAction.CmdKeyCode);

                HidListener.LogInfo("Executing: key {0} / {1} / Action: {2} / {3}", aAction.CmdKeyChar, aAction.CmdKeyCode,
                                    aAction.CmdProperty,
                                    ((Action.ActionType)Convert.ToInt32(aAction.CmdProperty)).ToString());

                action = new Action(key, (Action.ActionType)Convert.ToInt32(aAction.CmdProperty), 0, 0);
                GUIGraphicsContext.OnAction(action);
                break;

            case "KEY": // send Key x
                SendKeys.SendWait(aAction.CmdProperty);
                break;

            case "WINDOW": // activate Window x
                GUIGraphicsContext.ResetLastActivity();
                GUIMessage msg;
                if ((Convert.ToInt32(aAction.CmdProperty) == (int)GUIWindow.Window.WINDOW_HOME) ||
                    (Convert.ToInt32(aAction.CmdProperty) == (int)GUIWindow.Window.WINDOW_SECOND_HOME))
                {
                    GUIWindow.Window newHome = _basicHome ? GUIWindow.Window.WINDOW_SECOND_HOME : GUIWindow.Window.WINDOW_HOME;
                    // do we prefer to use only one home screen?
                    if (_useOnlyOneHome)
                    {
                        // skip if we are already in there
                        if (GUIWindowManager.ActiveWindow == (int)newHome)
                        {
                            break;
                        }
                    }
                    // we like both
                    else
                    {
                        // if already in one home switch to the other
                        switch (GUIWindowManager.ActiveWindow)
                        {
                        case (int)GUIWindow.Window.WINDOW_HOME:
                            newHome = GUIWindow.Window.WINDOW_SECOND_HOME;
                            break;

                        case (int)GUIWindow.Window.WINDOW_SECOND_HOME:
                            newHome = GUIWindow.Window.WINDOW_HOME;
                            break;
                        }
                    }
                    msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)newHome, 0, null);
                }
                else
                {
                    msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
                                         Convert.ToInt32(aAction.CmdProperty),
                                         0, null);
                }

                GUIWindowManager.SendThreadMessage(msg);
                break;

            case "TOGGLE": // toggle Layer 1/2
                if (_currentLayer == 1)
                {
                    _currentLayer = 2;
                }
                else
                {
                    _currentLayer = 1;
                }
                break;

            case "POWER": // power down commands

                if ((aAction.CmdProperty == "STANDBY") || (aAction.CmdProperty == "HIBERNATE"))
                {
                    GUIGraphicsContext.ResetLastActivity();
                }

                switch (aAction.CmdProperty)
                {
                case "EXIT":
                    action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "REBOOT":
                    action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "SHUTDOWN":
                    action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "STANDBY":
                    action = new Action(Action.ActionType.ACTION_SUSPEND, 1, 0); //1 = ignore prompt
                    GUIGraphicsContext.OnAction(action);
                    break;

                case "HIBERNATE":
                    action = new Action(Action.ActionType.ACTION_HIBERNATE, 1, 0); //1 = ignore prompt
                    GUIGraphicsContext.OnAction(action);
                    break;
                }
                break;

            case "PROCESS":
            {
                GUIGraphicsContext.ResetLastActivity();
                if (aProcessId > 0)
                {
                    var proc = Process.GetProcessById(aProcessId);
                    if (null != proc)
                    {
                        switch (aAction.CmdProperty)
                        {
                        case "CLOSE":
                            proc.CloseMainWindow();
                            break;

                        case "KILL":
                            proc.Kill();
                            break;
                        }
                    }
                }
            }
            break;

            default:
                return(false);
            }
            return(true);
        }
Exemple #11
0
        /// <summary>
        ///   Get mappings for a given button code based on the current conditions
        /// </summary>
        /// <param name="btnCode">Button code (ref: XML file)</param>
        /// <returns>Mapping</returns>
        public ConditionalAction GetAction(string btnCode, bool aIsBackground, bool aIsRepeat)
        {
            Button            button = null;
            ConditionalAction found  = null;

            foreach (var btn in _buttons)
            {
                if (btnCode == btn.Code)
                {
                    if (aIsBackground && !btn.Background)
                    {
                        //We don't proceed button while in background unless they are marked as supporting background
                        HidListener.LogInfo("HID: button not supported while in background");
                        return(null);
                    }

                    if (aIsRepeat && !btn.Repeat)
                    {
                        //We don't proceed button repeat unless otherwise specified
                        HidListener.LogInfo("HID: button does not support repeat");
                        return(null);
                    }

                    button = btn;
                    break;
                }
            }
            if (button != null)
            {
                foreach (var map in button.Actions)
                {
                    if ((map.Layer == 0) || (map.Layer == _currentLayer))
                    {
                        switch (map.Condition)
                        {
                        case "*": // wildcard, no further condition
                            found = map;
                            break;

                        case "WINDOW": // Window-ID = x
                            if ((!GUIWindowManager.IsOsdVisible &&
                                 (GUIWindowManager.ActiveWindowEx == Convert.ToInt32(map.ConProperty))) ||
                                ((int)GUIWindowManager.VisibleOsd == Convert.ToInt32(map.ConProperty)))
                            {
                                found = map;
                            }
                            break;

                        case "FULLSCREEN": // Fullscreen = true/false
                            if ((GUIGraphicsContext.IsFullScreenVideo == Convert.ToBoolean(map.ConProperty)) &&
                                !GUIWindowManager.IsRouted && !GUIWindowManager.IsOsdVisible)
                            {
                                found = map;
                            }
                            break;

                        case "PLAYER": // Playing TV/DVD/general
                            if (!GUIWindowManager.IsRouted)
                            {
                                switch (map.ConProperty)
                                {
                                case "TV":
                                    if (g_Player.IsTimeShifting || g_Player.IsTV || g_Player.IsTVRecording)
                                    {
                                        found = map;
                                    }
                                    break;

                                case "DVD":
                                    if (g_Player.IsDVD)
                                    {
                                        found = map;
                                    }
                                    break;

                                case "MUSIC":
                                    if (g_Player.Playing && g_Player.IsMusic)
                                    {
                                        found = map;
                                    }
                                    break;

                                case "MEDIA":
                                    if (g_Player.Playing)
                                    {
                                        found = map;
                                    }
                                    break;
                                }
                            }
                            break;
                        }
                        if (found != null)
                        {
                            return(found);
                        }
                    }
                }
            }
            return(null);
        }