示例#1
0
        private static void OnHotPlug(KHOT_HANDLE hotHandle,
                                      KLST_DEVINFO_HANDLE deviceInfo,
                                      KLST_SYNC_FLAG plugType)
        {
            string plugText;

            int totalPluggedDeviceCount = (int) hotHandle.GetContext().ToInt64();
            if (totalPluggedDeviceCount == int.MaxValue)
            {
                Console.WriteLine("OnHotPlug is being called for the first time on handle:{0}", hotHandle.Pointer);
                totalPluggedDeviceCount = 0;
            }

            switch (plugType)
            {
                case KLST_SYNC_FLAG.ADDED:
                    plugText = "Arrival";
                    totalPluggedDeviceCount++;
                    break;
                case KLST_SYNC_FLAG.REMOVED:
                    plugText = "Removal";
                    totalPluggedDeviceCount--;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("plugType");
            }

            hotHandle.SetContext(new IntPtr(totalPluggedDeviceCount));

            Console.WriteLine("\n[OnHotPlug] Device {0}:{1} \n",
                              plugText,
                              deviceInfo);
            Console.WriteLine("Total Plugged Device Count: {0}",
                              totalPluggedDeviceCount);
        }
示例#2
0
        private static void OnHotPlug(KHOT_HANDLE hotHandle,
                                      KLST_DEVINFO_HANDLE deviceInfo,
                                      KLST_SYNC_FLAG plugType)
        {
            LinkDevice d;
            int        totalPluggedDeviceCount = (int)hotHandle.GetContext().ToInt64();

            if (totalPluggedDeviceCount == int.MaxValue)
            {
                // OnHotPlug is being called for the first time on handle: hotHandle.Pointer.
                totalPluggedDeviceCount = 0;
            }
            switch (plugType)
            {
            case KLST_SYNC_FLAG.ADDED:     // Arrival.
                totalPluggedDeviceCount++;
                lock (Manager.UsbConnectionLock) {
                    if (Settings.DebugLevel > 4)
                    {
                        Log.d(TAG, "OnHotPlug.Added: " + UsbLinkDevice.DeviceInfoToString(deviceInfo));
                    }
                    if (UsbPermissionValidator.CheckAllowed(deviceInfo.Common.Vid, deviceInfo.Common.Pid))
                    {
                        UsbLinkDevice.TryOpeningDevice(deviceInfo);
                    }
                    else
                    {
                        if (Settings.DebugLevel > 4)
                        {
                            Log.d(TAG, "OnHotPlug.Added: Not allowed: " + UsbLinkDevice.DeviceInfoToString(deviceInfo));
                        }
                    }
                }
                break;

            case KLST_SYNC_FLAG.REMOVED:     // Removal.
                totalPluggedDeviceCount--;
                lock (Manager.UsbConnectionLock) {
                    if (Settings.DebugLevel > 4)
                    {
                        Log.d(TAG, "OnHotPlug.Removed: " + UsbLinkDevice.DeviceInfoToString(deviceInfo));
                    }
                    d = LinkManager.Manager.FindDevice(UsbLinkDevice.GetDevIdFromHandle(deviceInfo));
                    UsbLinkDevice u = d as UsbLinkDevice;
                    if (u != null)
                    {
                        u.Disconnect(deviceInfo);                // Disconnect device but keep in Active list.
                    }
                }
                break;

            default:
                return;
            }
            hotHandle.SetContext(new IntPtr(totalPluggedDeviceCount));
        }
示例#3
0
        protected override void WndProc(ref Message m)
        {
            /* When using the HotK UserHwnd and UserMsg, the add/remove events are seperated into to different messages.
             * Removal = UserMsg + 0
             * Arrival = UserMsg + 1
             */
            if (m.Msg == WM_USER_HOT_REMOVAL || m.Msg == WM_USER_HOT_ARRIVAL)
            {
                KHOT_HANDLE         hotHandle  = new KHOT_HANDLE(m.WParam);
                KLST_DEVINFO_HANDLE deviceInfo = new KLST_DEVINFO_HANDLE(m.LParam);
                KLST_SYNC_FLAG      plugType   = (m.Msg == WM_USER_HOT_REMOVAL) ? KLST_SYNC_FLAG.REMOVED : KLST_SYNC_FLAG.ADDED;

                OnHotPlugInvoked(hotHandle, deviceInfo, plugType);
                return;
            }
            base.WndProc(ref m);
        }
示例#4
0
 private void OnHotPlugInvoked(KHOT_HANDLE hotHandle, KLST_DEVINFO_HANDLE deviceInfo, KLST_SYNC_FLAG plugType)
 {
     string symbolicLink = deviceInfo.SymbolicLink;
     switch (plugType)
     {
         case KLST_SYNC_FLAG.ADDED:
             int iRow = dgvDevices.Rows.Add(new object[] {symbolicLink, deviceInfo.DeviceDesc, deviceInfo.DeviceID});
             dgvDevices.Rows[iRow].Cells[1].ToolTipText = deviceInfo.ToString();
             dgvDevices.Rows[iRow].Cells[2].ToolTipText = deviceInfo.Common.ToString();
             break;
         case KLST_SYNC_FLAG.REMOVED:
             foreach (DataGridViewRow row in dgvDevices.Rows)
             {
                 if (row.Cells[0].Value as string != symbolicLink) continue;
                 dgvDevices.Rows.Remove(row);
                 break;
             }
             break;
         default:
             throw new ArgumentOutOfRangeException("plugType");
     }
 }
示例#5
0
        private static void OnHotPlug(KHOT_HANDLE hotHandle,
                                      KLST_DEVINFO_HANDLE deviceInfo,
                                      KLST_SYNC_FLAG plugType)
        {
            string plugText;

            int totalPluggedDeviceCount = (int)hotHandle.GetContext().ToInt64();

            if (totalPluggedDeviceCount == int.MaxValue)
            {
                Console.WriteLine("OnHotPlug is being called for the first time on handle:{0}", hotHandle.Pointer);
                totalPluggedDeviceCount = 0;
            }

            switch (plugType)
            {
            case KLST_SYNC_FLAG.ADDED:
                plugText = "Arrival";
                totalPluggedDeviceCount++;
                break;

            case KLST_SYNC_FLAG.REMOVED:
                plugText = "Removal";
                totalPluggedDeviceCount--;
                break;

            default:
                throw new ArgumentOutOfRangeException("plugType");
            }

            hotHandle.SetContext(new IntPtr(totalPluggedDeviceCount));

            Console.WriteLine("\n[OnHotPlug] Device {0}:{1} \n",
                              plugText,
                              deviceInfo);
            Console.WriteLine("Total Plugged Device Count: {0}",
                              totalPluggedDeviceCount);
        }
示例#6
0
        private void OnHotPlug(KHOT_HANDLE hotHandle,
                               KLST_DEVINFO_HANDLE deviceInfo,
                               KLST_SYNC_FLAG plugType)
        {
            string plugText;

            int totalPluggedDeviceCount = (int)hotHandle.GetContext().ToInt64();

            if (totalPluggedDeviceCount == int.MaxValue)
            {
                Console.WriteLine("OnHotPlug is being called for the first time on handle:{0}", hotHandle.Pointer);
                totalPluggedDeviceCount = 0;
            }

            switch (plugType)
            {
            case KLST_SYNC_FLAG.ADDED:
                plugText = "Arrival";
                totalPluggedDeviceCount++;
                if (deviceInfo.DeviceID.Contains("VID_2DC4&PID_0200"))
                {
                    bool deviceFound = false;
                    setUI(HUD_STATE.Application);
                    DarwinDevice = new StmTestParameters(SIX15_VID, SIX15_PID, 0, 0x02, 512, null, -1, 4, 0);

                    if (DarwinDevice != null)
                    {
                        // Find and configure the device.
                        if (!DarwinDevice.ConfigureDevice(out pipeInfo, out usb, out interfaceDescriptor))
                        {
                            DarwinDevice = new StmTestParameters(SIX15_VID, SIX15_PID, 0, 0x06, 128, null, -1, 4, 0);

                            if (!DarwinDevice.ConfigureDevice(out pipeInfo, out usb, out interfaceDescriptor))
                            {
                                Console.WriteLine("Device not connected");
                                setUI(HUD_STATE.NotDetected);
                            }
                            else
                            {
                                Console.WriteLine("IS NEXT GEN FIRMWARE");
                                isNextGen   = true;
                                deviceFound = true;
                            }
                        }
                        else
                        {
                            deviceFound = true;
                        }

                        if (deviceFound)
                        {
                            if (DarwinDevice.TransferBufferSize == -1)
                            {
                                DarwinDevice.TransferBufferSize = pipeInfo.MaximumPacketSize * 512;
                            }

                            Console.WriteLine("Darwin Device Connected");

                            int[] pipeTimeoutMS = new[] { 0 };
                            usb.SetPipePolicy((byte)DarwinDevice.PipeId,
                                              (int)PipePolicyType.PIPE_TRANSFER_TIMEOUT,
                                              Marshal.SizeOf(typeof(int)),
                                              pipeTimeoutMS);
                        }
                    }
                }
                else if (deviceInfo.DeviceID.Contains("VID_0483&PID_5740"))
                {
                    setUI(HUD_STATE.Bootloader);
                    DarwinDevice = new StmTestParameters(STM_VID, STM_PID, 0, 0x01, 512, null, -1, 4, 0);

                    if (DarwinDevice != null)
                    {
                        // Find and configure the device.
                        if (!DarwinDevice.ConfigureDevice(out pipeInfo, out usb, out interfaceDescriptor))
                        {
                            Console.WriteLine("Device not connected");
                            setUI(HUD_STATE.NotDetected);
                        }
                        else
                        {
                            if (DarwinDevice.TransferBufferSize == -1)
                            {
                                DarwinDevice.TransferBufferSize = pipeInfo.MaximumPacketSize * 512;
                            }

                            Console.WriteLine("Darwin Device Connected");

                            int[] pipeTimeoutMS = new[] { 0 };
                            usb.SetPipePolicy((byte)DarwinDevice.PipeId,
                                              (int)PipePolicyType.PIPE_TRANSFER_TIMEOUT,
                                              Marshal.SizeOf(typeof(int)),
                                              pipeTimeoutMS);
                        }
                    }
                }
                break;

            case KLST_SYNC_FLAG.REMOVED:
                plugText = "Removal";
                totalPluggedDeviceCount--;
                if (deviceInfo.DeviceID.Contains("VID_2DC4&PID_0200"))
                {
                    if (DarwinDevice != null)
                    {
                        if (isNextGen)
                        {
                            usb.FlushPipe(EP_DISP);
                        }
                        else
                        {
                            usb.FlushPipe(EP_CDC);
                        }

                        DarwinDevice.Free();
                        usb.Free();
                        DarwinDevice = null;
                        setUI(HUD_STATE.NotDetected);
                    }
                    else if (deviceInfo.DeviceID.Contains("VID_0483&PID_5740"))
                    {
                        usb.FlushPipe(EP_CDC_BL);
                        DarwinDevice.Free();
                        usb.Free();
                        DarwinDevice = null;
                        setUI(HUD_STATE.NotDetected);
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("plugType");
            }

            hotHandle.SetContext(new IntPtr(totalPluggedDeviceCount));

            Console.WriteLine("\n[OnHotPlug] Device {0}:{1} \n",
                              plugText,
                              deviceInfo);
            Console.WriteLine("Total Plugged Device Count: {0}",
                              totalPluggedDeviceCount);
        }
示例#7
0
        private void OnHotPlugInvoked(KHOT_HANDLE hotHandle, KLST_DEVINFO_HANDLE deviceInfo, KLST_SYNC_FLAG plugType)
        {
            string symbolicLink = deviceInfo.SymbolicLink;

            switch (plugType)
            {
            case KLST_SYNC_FLAG.ADDED:
                int iRow = dgvDevices.Rows.Add(new object[] { symbolicLink, deviceInfo.DeviceDesc, deviceInfo.DeviceID });
                dgvDevices.Rows[iRow].Cells[1].ToolTipText = deviceInfo.ToString();
                dgvDevices.Rows[iRow].Cells[2].ToolTipText = deviceInfo.Common.ToString();
                break;

            case KLST_SYNC_FLAG.REMOVED:
                foreach (DataGridViewRow row in dgvDevices.Rows)
                {
                    if (row.Cells[0].Value as string != symbolicLink)
                    {
                        continue;
                    }
                    dgvDevices.Rows.Remove(row);
                    break;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("plugType");
            }
        }