public void DeviceRemoved(UsbDevice device)
 {
     Log.Info(TAG, "DeviceRemoved called");
     if (device == null)
     {
         // ugh, Android didn't tell us which device was removed, but if we only have one connected, we'll remove it
         if (Boards.Count == 1)
         {
             Boards[0].Disconnect();
             Boards.Clear();
         }
     }
     else
     {
         if (device.VendorId == 0x10c4 && device.ProductId == 0x8a7e)
         {
             TreehopperUsb removedBoard = Boards.FirstOrDefault(b => b.SerialNumber == device.SerialNumber);
             if (removedBoard != null)
             {
                 removedBoard.Disconnect();
                 Boards.Remove(removedBoard);
             }
         }
     }
 }
Beispiel #2
0
 internal Pin(TreehopperUsb board, byte pinNumber)
 {
     Board          = board;
     PinNumber      = pinNumber;
     ReferenceLevel = AdcReferenceLevel.Vref_3V3;
     Name           = "Pin " + pinNumber; // default name
 }
        /// \endcond

        private void StartWatcher()
        {
            //deviceWatcher = DeviceInformation.CreateWatcher(UsbDevice.GetDeviceSelector(0x04d8, 0xf426));
            deviceWatcher = DeviceInformation.CreateWatcher(
                UsbDevice.GetDeviceSelector(TreehopperUsb.Settings.Vid, TreehopperUsb.Settings.Pid));
            // Hook up handlers for the watcher events before starting the watcher

            handlerAdded = async(watcher, deviceInfo) =>
            {
                Debug.WriteLine("Device added: " + deviceInfo.Name);

                var newConnection = new UsbConnection(deviceInfo);

                var newBoard = new TreehopperUsb(newConnection);
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () => { Boards.Add(newBoard); });
            };
            deviceWatcher.Added += handlerAdded;

            handlerUpdated         = (watcher, deviceInfoUpdate) => { Debug.WriteLine("Device updated"); };
            deviceWatcher.Updated += handlerUpdated;

            handlerRemoved = async(watcher, deviceInfoUpdate) =>
            {
                Debug.WriteLine("Device removed");
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Boards.Where(board => ((UsbConnection)board.Connection).DevicePath == deviceInfoUpdate.Id)
                    .ToList()
                    .All(i =>
                    {
                        i.Disconnect();
                        Boards.Remove(i);
                        return(true);
                    }
                         );
                });
            };
            deviceWatcher.Removed += handlerRemoved;

            handlerEnumCompleted = (watcher, obj) => { Debug.WriteLine("Enum completed"); };
            deviceWatcher.EnumerationCompleted += handlerEnumCompleted;

            handlerStopped         = (watcher, obj) => { Debug.WriteLine("Device or something stopped"); };
            deviceWatcher.Stopped += handlerStopped;

            Debug.WriteLine("Starting the wutchah");
            deviceWatcher.Start();
        }
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action == UsbManager.ActionUsbDeviceDetached)
            {
                UsbDevice usbDevice = (UsbDevice)intent.GetParcelableExtra(UsbManager.ExtraDevice);
                DeviceRemoved(usbDevice);
            }

            if (intent.Action == UsbManager.ActionUsbDeviceAttached)
            {
                UsbDevice usbDevice = (UsbDevice)intent.GetParcelableExtra(UsbManager.ExtraDevice);
                createTreehopperFromDevice(usbDevice);
            }

            if (intent.Action == ActionUsbPermission)
            {
                lock (lockObject)
                {
                    UsbDevice device = (UsbDevice)intent.GetParcelableExtra(UsbManager.ExtraDevice);

                    if (intent.GetBooleanExtra(UsbManager.ExtraPermissionGranted, false))
                    {
                        if (device != null)
                        {
                            if (Boards.Count(b => b.SerialNumber == device.SerialNumber) > 0)
                            {
                                return;
                            }
                            var board = new TreehopperUsb(new UsbConnection(device, Manager));
                            Log.Info(TAG, "Got permission to add new board (name=" + board.Name + ", serial=" + board.SerialNumber + "). Total number of boards: " + Boards.Count);
                            Boards.Add(board);
                        }
                    }
                    else
                    {
                        Log.Debug(TAG, "permission denied for device " + device);
                    }
                }
            }
        }
Beispiel #5
0
 internal HardwareUart(TreehopperUsb device)
 {
     _device = device;
 }
 internal ParallelInterface(TreehopperUsb board)
 {
     _board = board;
 }
Beispiel #7
0
 internal HardwareSpi(TreehopperUsb device)
 {
     _device = device;
 }
Beispiel #8
0
 internal HardwarePwm(Pin pin)
 {
     _pin   = pin;
     _board = pin.Board;
 }
 internal HardwarePwmManager(TreehopperUsb treehopperUsb)
 {
     _board = treehopperUsb;
 }
        private readonly double _resolution = 0.25; // 0.25 microseconds / tick

        internal SoftPwmManager(TreehopperUsb board)
        {
            _board = board;
            _pins  = new Dictionary <int, SoftPwmPinConfig>();
        }