public 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); }
private void EnumerateCallback(IntPtr device, IntPtr context) { try { var mGuid = Guid.Empty; DirectOutputClass.GetDeviceType(device, ref mGuid); Console.WriteLine($"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) { Console.WriteLine(ex); } }
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); }
//public void RefreshDevicePages() //{ // for (var index = 0; index < _fipPanels.Count; index++) // { // var fipPanel = _fipPanels[index]; // fipPanel.RefreshDevicePage(); // } //} 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); }
//private void OnImageLoad(object sender, HtmlImageLoadEventArgs e) //{ // try // { // var image = new Bitmap(ChartImageDisplayWidth, ChartImageDisplayHeight); // using (var graphics = Graphics.FromImage(image)) // { // if (HWInfo.SensorTrends.ContainsKey(e.Src)) // { // graphics.DrawLines(_scrollPen, HWInfo.SensorTrends[e.Src].Read(ChartImageDisplayWidth, ChartImageDisplayHeight)); // } // graphics.DrawRectangle(_whitePen, // new Rectangle(0, 0, ChartImageDisplayWidth - 1, ChartImageDisplayHeight - 1)); // graphics.DrawString(HWInfo.SensorTrends[e.Src].MaxV(), _drawFont, _whiteBrush, (float)1, (float)1); // graphics.DrawString(HWInfo.SensorTrends[e.Src].MinV(), _drawFont, _whiteBrush, (float)1, (float)ChartImageDisplayHeight - 17); // } // e.Callback(image); // } // catch // { // var image = new Bitmap(1, 1); // e.Callback(image); // } //} private void SetLed(uint ledNumber, bool state) { if (_ledState[ledNumber] != state) { DirectOutputClass.SetLed(FipDevicePointer, DEFAULT_PAGE, ledNumber, state); _ledState[ledNumber] = state; } }
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) { Console.WriteLine(ex); } }
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) { Console.WriteLine("FIPHandler failed to init DirectOutputClass. " + retVal); return(false); } DirectOutputClass.RegisterDeviceCallback(_deviceCallback); retVal = DirectOutputClass.Enumerate(_enumerateCallback); if (retVal != ReturnValues.S_OK) { Console.WriteLine("FIPHandler failed to Enumerate DirectOutputClass. " + retVal); return(false); } } } catch (Exception ex) { Console.WriteLine(ex); return(false); } InitOk = true; Console.WriteLine("Number of devices: " + _fipPanels.Count); numPanels = _fipPanels.Count; return(true); }
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(); } }
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); } }