Example #1
0
 internal Pin(TreehopperUSB board, byte pinNumber)
 {
     this.board     = board;
     this.PinNumber = pinNumber;
     interruptMode  = PinInterruptMode.NoInterrupt;
     SoftPwm        = new SoftPwm(Board, this);
 }
Example #2
0
 private bool PassesFilter(TreehopperUSB board)
 {
     if (SerialFilterIsEnabled && board.SerialNumber != SerialFilter)
     {
         return(false);
     }
     if (NameFilterIsEnabled && board.Name != NameFilter)
     {
         return(false);
     }
     return(true);
 }
Example #3
0
 internal I2c(TreehopperUSB device)
 {
     this.device = device;
 }
Example #4
0
        void myNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            if (PollingTimerIsEnabled)
            {
                return;
            }
            if (e.Device.IdVendor != vid || e.Device.IdProduct != pid)
            {
                return;
            }

            if (e.EventType == EventType.DeviceArrival) // board added
            {
                foreach (UsbRegistry regDevice in UsbDevice.AllDevices)
                {
                    if (regDevice.Device != null)
                    {
                        if (regDevice.Vid == vid || regDevice.Pid == pid)
                        {
                            bool isInBoardList = false;
                            foreach (var board in Boards)
                            {
                                if (regDevice.Device.Info.SerialString == board.SerialNumber)
                                {
                                    isInBoardList = true;
                                }
                            }
                            if (!isInBoardList)
                            {
                                Debug.WriteLine("Adding board");
                                Boards.Add(new TreehopperUSB(regDevice.Device));
                            }
                        }

                        // This code only works under WinUSB, since e.Device.SerialNumber is empty in LibUsb
//						if (regDevice.Device.Info.SerialString.Length > 0)
//						{
//							if (regDevice.Device.Info.SerialString == e.Device.SerialNumber)
//							{
//								TreehopperBoard board = new TreehopperBoard(regDevice.Device);
//								if (PassesFilter(board))
//									Boards.Add(board);
//							}
//						}
                    }
                }
            }
            else if (e.EventType == EventType.DeviceRemoveComplete)  // board removed
            {
                TreehopperUSB boardToRemove = null;
                foreach (var board in Boards)
                {
                    bool deviceExists = false;
//					var deviceList = UsbDevice.AllDevices.ToList ();
//					foreach (UsbRegistry regDevice in deviceList) {
//						if (board.SerialNumber == regDevice.Device.Info.SerialString) {
//							deviceExists = true;
//						}
//					}
                    if (!deviceExists)
                    {
                        boardToRemove = board;
                    }
                }

                if (boardToRemove != null)
                {
                    Boards.Remove(boardToRemove);
                    boardToRemove.Close();
                    Debug.WriteLine("Removed board " + boardToRemove);
                }
                // This code only works on Windows. LibUsb doesn't get access to the serial number.

                /*
                 * var board = Boards.Where(x => x.SerialNumber == e.Device.SerialNumber).ToList();
                 * if(board.Count > 0)
                 * {
                 * board[0].Dispose();
                 * Boards.Remove(board[0]);
                 * }
                 */
            }
        }
Example #5
0
        private void Scan()
        {
            // get a list of all current devices attached to the computer


            // Go through the list of existing Boards and remove any that no longer exist.
            List <TreehopperUSB> BoardsToRemove = new List <TreehopperUSB>();

            foreach (var board in Boards.ToList())
            {
                bool boardExistsInDeviceList = false;
                foreach (UsbRegistry regDevice in UsbDevice.AllDevices)
                {
                    if (regDevice.Vid == vid && regDevice.Pid == pid)
                    {
                        if (regDevice.Device != null)
                        {
                            TreehopperUSB newBoard = new TreehopperUSB(regDevice.Device);
                            if (newBoard.Equals(board))
                            {
                                boardExistsInDeviceList = true;
                            }
                        }
                        else
                        { // If this property reads null, it's probably because the board is open.
                            boardExistsInDeviceList = true;
                        }
                    }
                }
                if (!boardExistsInDeviceList)
                {
                    BoardsToRemove.Add(board);
                }
            }

            foreach (var board in BoardsToRemove)
            {
                Boards.Remove(board);
                Debug.WriteLine("New board list has " + Boards.Count + " Boards");
            }


            // Now add any new boards
            foreach (UsbRegistry regDevice in UsbDevice.AllDevices)
            {
                if (regDevice.Vid == vid && regDevice.Pid == pid)
                {
                    if (regDevice.Device != null)
                    {
                        TreehopperUSB newBoard = new TreehopperUSB(regDevice.Device);
                        if (PassesFilter(newBoard))
                        {
                            // add the board to the list if it doesn't already exist
                            bool alreadyInList = false;
                            foreach (var board in Boards)
                            {
                                if (board.Equals(newBoard))
                                {
                                    alreadyInList = true;
                                }
                            }
                            if (!alreadyInList)
                            {
                                Boards.Add(newBoard);
                                Debug.WriteLine("Adding " + newBoard.ToString() + ". New board list has " + Boards.Count + " Boards");
                            }
                        }
                    }
                }
            }
        }
Example #6
0
 internal AnalogOut(TreehopperUSB board)
 {
     Board = board;
 }
 internal SoftPwmManager(TreehopperUSB board)
 {
     this.board = board;
     pins       = new Dictionary <int, SoftPwmPinConfig>();
 }
Example #8
0
 internal Spi(TreehopperUSB device)
 {
     this.device = device;
 }