public NativeSpi(Socket socket, Socket.SocketInterfaces.SpiConfiguration configuration, Socket.SocketInterfaces.SpiSharing sharing, Cpu.Pin chipSelectPin, Module module, Microsoft.SPOT.Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) _hardwareInstance.Interface = new Microsoft.SPOT.Hardware.SPI(_configuration); }
public NativeSpi(Socket socket, SpiConfiguration configuration, SpiSharing sharing, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Module module, Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _busyPin = busyPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, busyPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) _hardwareInstance.Interface = new Hardware.SPI(_configuration); }
public NativeSpi(Socket socket, Socket.SocketInterfaces.SpiConfiguration configuration, Socket.SocketInterfaces.SpiSharing sharing, Cpu.Pin chipSelectPin, Module module, Microsoft.SPOT.Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) { _hardwareInstance.Interface = new Microsoft.SPOT.Hardware.SPI(_configuration); } }
public NativeSpi(Socket socket, SpiConfiguration configuration, SpiSharing sharing, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Module module, Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _busyPin = busyPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, busyPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) { _hardwareInstance.Interface = new Hardware.SPI(_configuration); } }
private static HardwareInstance GetAndUseInstance(Socket socket, Socket.SocketInterfaces.SpiSharing sharing, Module module, Microsoft.SPOT.Hardware.SPI.SPI_module spiModule) { if (spiModule == Socket.SocketInterfaces.SPIMissing) { // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case... throw Socket.InvalidSocketException.FunctionalityException(socket, "SPI"); } HardwareInstance foundInstance = null; for (int i = 0; i < Instances.Count; i++) { HardwareInstance instance = (HardwareInstance)Instances[i]; if (instance.Module == spiModule) { foundInstance = instance; } } if (foundInstance == null) { Instances.Add(foundInstance = new HardwareInstance(spiModule)); } if (foundInstance.Users == 0) { socket.ReservePin(Socket.Pin.Seven, module); socket.ReservePin(Socket.Pin.Eight, module); socket.ReservePin(Socket.Pin.Nine, module); } else { if (foundInstance.Sharing != Socket.SocketInterfaces.SpiSharing.Shared) { throw new Exception("SPI bus " + spiModule + " is already reserved, cannot instantiate it again."); } if (foundInstance.Sharing == Socket.SocketInterfaces.SpiSharing.Exclusive) { throw new Exception("SPI bus " + spiModule + " is already shared among " + foundInstance.Users + " users, cannot instantiate it for exclusive use."); } } lock (foundInstance) { foundInstance.Users++; foundInstance.Sharing = sharing; } return(foundInstance); }
public void UpdateSoftware(HardwareInstance hardwareInstance) { for (int i = 0; i < CurrentRobot.SoftwareList.Count; i++) { var hardwares = CurrentRobot.SoftwareList[i].Software.HardwareList;//需要的硬件 for (int j = 0; j < hardwares.Length; j++) { if (hardwares[j].name.Equals(hardwareInstance.Hardware.name, System.StringComparison.CurrentCultureIgnoreCase)) { if (hardwareInstance.Level < CurrentRobot.SoftwareList[i].Level) { CurrentRobot.SoftwareList.RemoveAt(i); i--; break; } } } } GlobalObjectManager.Instance.ComputerController.UpdateSoftwareText(); }
private static HardwareInstance GetAndUseInstance(Socket socket, SpiSharing sharing, Module module, Hardware.SPI.SPI_module spiModule) { if (spiModule == Socket.SocketInterfaces.SPIMissing) { // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case... throw Socket.InvalidSocketException.FunctionalityException(socket, "SPI"); } HardwareInstance foundInstance = null; for (int i = 0; i < Instances.Count; i++) { HardwareInstance instance = (HardwareInstance)Instances[i]; if (instance.Module == spiModule) foundInstance = instance; } if (foundInstance == null) Instances.Add(foundInstance = new HardwareInstance(spiModule)); if (foundInstance.Users == 0) { socket.ReservePin(Socket.Pin.Seven, module); socket.ReservePin(Socket.Pin.Eight, module); socket.ReservePin(Socket.Pin.Nine, module); } else { if (foundInstance.Sharing != SocketInterfaces.SpiSharing.Shared) throw new Exception("SPI bus " + spiModule + " is already reserved, cannot instantiate it again."); if (foundInstance.Sharing == SocketInterfaces.SpiSharing.Exclusive) throw new Exception("SPI bus " + spiModule + " is already shared among " + foundInstance.Users + " users, cannot instantiate it for exclusive use."); } lock (foundInstance) { foundInstance.Users++; foundInstance.Sharing = sharing; } return foundInstance; }