Exemplo n.º 1
0
        private ReturnValues SendImageToFip(uint page, Bitmap fipImage)
        {
            if (_initOk)
            {
                if (fipImage == null)
                {
                    return(ReturnValues.E_INVALIDARG);
                }

                try
                {
                    fipImage.RotateFlip(RotateFlipType.Rotate180FlipX);

                    var bitmapData =
                        fipImage.LockBits(new Rectangle(0, 0, fipImage.Width, fipImage.Height),
                                          ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                    var intPtr = bitmapData.Scan0;
                    var local3 = bitmapData.Stride * fipImage.Height;
                    DirectOutputClass.SetImage(FipDevicePointer, page, 0, local3, intPtr);
                    fipImage.UnlockBits(bitmapData);
                    return(ReturnValues.S_OK);
                }
                catch (Exception ex)
                {
                    App.Log.Error(ex);
                }
            }

            return(ReturnValues.E_FAIL);
        }
Exemplo n.º 2
0
        private void EnumerateCallback(IntPtr device, IntPtr context)
        {
            try
            {
                var mGuid = Guid.Empty;

                DirectOutputClass.GetDeviceType(device, ref mGuid);

                App.Log.Info($"Adding new DirectOutput device {device} of type: {mGuid.ToString()}");

                //Called initially when enumerating FIPs.

                if (!IsFipDevice(device))
                {
                    return;
                }
                var fipPanel = new FipPanel(device);
                _fipPanels.Add(fipPanel);
                fipPanel.Initalize();
            }
            catch (Exception ex)
            {
                App.Log.Error(ex);
            }
        }
Exemplo n.º 3
0
        private ReturnValues AddPage(uint pageNumber, bool setActive)
        {
            var result = ReturnValues.E_FAIL;

            if (_initOk)
            {
                try
                {
                    if (_pageList.Contains(pageNumber))
                    {
                        return(ReturnValues.S_OK);
                    }

                    result = DirectOutputClass.AddPage(FipDevicePointer, (IntPtr)pageNumber, string.Concat("0x", FipDevicePointer.ToString(), " PageNo: ", pageNumber), setActive);
                    if (result == ReturnValues.S_OK)
                    {
                        App.Log.Info("Page: " + pageNumber + " added");

                        _pageList.Add(pageNumber);
                    }
                }
                catch (Exception ex)
                {
                    App.Log.Error(ex);
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        private bool IsFipDevice(IntPtr device)
        {
            var mGuid = Guid.Empty;

            DirectOutputClass.GetDeviceType(device, ref mGuid);

            return(string.Compare(mGuid.ToString(), "3E083CD8-6A37-4A58-80A8-3D6A2C07513E", true, CultureInfo.InvariantCulture) == 0);
        }
Exemplo n.º 5
0
 private void SetLed(uint ledNumber, bool state)
 {
     if (_ledState[ledNumber] != state)
     {
         DirectOutputClass.SetLed(FipDevicePointer, DEFAULT_PAGE,
                                  ledNumber, state);
         _ledState[ledNumber] = state;
     }
 }
Exemplo n.º 6
0
 public void Close()
 {
     try
     {
         foreach (var fipPanel in _fipPanels)
         {
             fipPanel.Shutdown();
         }
         if (InitOk)
         {
             //No need to deinit if init never worked. (e.g. missing Saitek Drivers)
             DirectOutputClass.Deinitialize();
             InitOk = false;
         }
     }
     catch (Exception ex)
     {
         App.Log.Error(ex);
     }
 }
Exemplo n.º 7
0
        public void Initalize()
        {
            // FIP = 3e083cd8-6a37-4a58-80a8-3d6a2c07513e

            // https://github.com/Raptor007/Falcon4toSaitek/blob/master/Raptor007's%20Falcon%204%20to%20Saitek%20Utility/DirectOutput.h
            //https://github.com/poiuqwer78/fip4j-core/tree/master/src/main/java/ch/poiuqwer/saitek/fip4j

            _pageCallbackDelegate       = PageCallback;
            _softButtonCallbackDelegate = SoftButtonCallback;

            var returnValues1 = DirectOutputClass.RegisterPageCallback(FipDevicePointer, _pageCallbackDelegate);

            if (returnValues1 != ReturnValues.S_OK)
            {
                App.Log.Error("FipPanel failed to init RegisterPageCallback. " + returnValues1);
            }
            var returnValues2 = DirectOutputClass.RegisterSoftButtonCallback(FipDevicePointer, _softButtonCallbackDelegate);

            if (returnValues2 != ReturnValues.S_OK)
            {
                App.Log.Error("FipPanel failed to init RegisterSoftButtonCallback. " + returnValues1);
            }

            var returnValues3 = DirectOutputClass.GetSerialNumber(FipDevicePointer, out SerialNumber);

            if (returnValues3 != ReturnValues.S_OK)
            {
                App.Log.Error("FipPanel failed to get Serial Number. " + returnValues1);
            }
            else
            {
                App.Log.Info("FipPanel Serial Number : " + SerialNumber);

                _initOk = true;

                AddPage(DEFAULT_PAGE, true);

                RefreshDevicePage();
            }
        }
Exemplo n.º 8
0
        public void Shutdown()
        {
            try
            {
                if (_pageList.Count > 0)
                {
                    do
                    {
                        if (_initOk)
                        {
                            DirectOutputClass.RemovePage(FipDevicePointer, _pageList[0]);
                        }

                        _pageList.Remove(_pageList[0]);
                    } while (_pageList.Count > 0);
                }
            }
            catch (Exception ex)
            {
                App.Log.Error(ex);
            }
        }
Exemplo n.º 9
0
        public bool Initialize()
        {
            InitOk = false;
            try
            {
                _deviceCallback    = DeviceCallback;
                _enumerateCallback = EnumerateCallback;

                var key = Registry.LocalMachine.OpenSubKey(DirectOutputKey);

                var value = key?.GetValue("DirectOutput");
                if (value is string)
                {
                    var retVal = DirectOutputClass.Initialize("fiphwinfo");
                    if (retVal != ReturnValues.S_OK)
                    {
                        App.Log.Error("FIPHandler failed to init DirectOutputClass. " + retVal);
                        return(false);
                    }

                    DirectOutputClass.RegisterDeviceCallback(_deviceCallback);

                    retVal = DirectOutputClass.Enumerate(_enumerateCallback);
                    if (retVal != ReturnValues.S_OK)
                    {
                        App.Log.Error("FIPHandler failed to Enumerate DirectOutputClass. " + retVal);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                App.Log.Error(ex);

                return(false);
            }
            InitOk = true;
            return(true);
        }