private async Task <GSI.AnalogIO> AnalogIOCreator(Socket socket, SocketPinNumber pinNumber)
        {
            if (!this.analogMap.ContainsKey(socket.Number))
            {
                throw new UnsupportedPinModeException();
            }
            if (!this.analogMap[socket.Number].ContainsKey(pinNumber))
            {
                throw new UnsupportedPinModeException();
            }

            var channel = this.analogMap[socket.Number][pinNumber];

            if (this.analogSharedMap.ContainsKey(channel))
            {
                var shared = this.analogSharedMap[channel];

                if (shared.Item1 == 0)
                {
                    using (var gpio = await GNI.DigitalIO.CreateInterfaceAsync(shared.Item2)) {
                        gpio.SetDriveMode(GpioPinDriveMode.Input);
                    }
                }
                else
                {
                    this.gpios[shared.Item1 - 1].SetDriveMode(shared.Item2, GpioPinDriveMode.Input);
                }
            }

            return(new IndirectedAnalogIO(channel, this.analog));
        }
Exemple #2
0
        public async Task <DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber, WD.Gpio.GpioPinEdge interruptType)
        {
            var result = await this.CreateDigitalIOAsync(pinNumber);

            result.InterruptType = interruptType;

            return(result);
        }
Exemple #3
0
        public async Task <AnalogIO> CreateAnalogIOAsync(SocketPinNumber pinNumber, double initialVoltage)
        {
            var result = await this.CreateAnalogIOAsync(pinNumber);

            result.DriveMode = WD.Gpio.GpioPinDriveMode.Output;
            result.Voltage   = initialVoltage;

            return(result);
        }
Exemple #4
0
        public async Task <DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber, bool initialValue)
        {
            var result = await this.CreateDigitalIOAsync(pinNumber);

            result.DriveMode = WD.Gpio.GpioPinDriveMode.Output;
            result.Value     = initialValue;

            return(result);
        }
Exemple #5
0
        public async Task <PwmOutput> CreatePwmOutputAsync(SocketPinNumber pinNumber)
        {
            this.EnsureTypeIsSupported(SocketType.P);

            if (this.PwmOutputCreator != null)
            {
                return(await this.PwmOutputCreator(this, pinNumber));
            }

            return(new NativeInterfaces.PwmOutput());
        }
Exemple #6
0
        public async Task <AnalogIO> CreateAnalogIOAsync(SocketPinNumber pinNumber)
        {
            this.EnsureTypeIsSupported(SocketType.A);

            AnalogIO result;

            if (this.AnalogIOCreator != null)
            {
                result = await this.AnalogIOCreator(this, pinNumber);
            }
            else
            {
                result = new NativeInterfaces.AnalogIO();
            }

            result.DriveMode = WD.Gpio.GpioPinDriveMode.Input;

            return(result);
        }
Exemple #7
0
        public async Task <DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber)
        {
            DigitalIO result;

            if (this.nativePins.ContainsKey(pinNumber))
            {
                result = new NativeInterfaces.DigitalIO(await NativeInterfaces.DigitalIO.CreateInterfaceAsync(this.nativePins[pinNumber]));
            }
            else if (this.DigitalIOCreator != null)
            {
                result = await this.DigitalIOCreator(this, pinNumber);
            }
            else
            {
                throw new UnsupportedPinModeException();
            }

            result.DriveMode = WD.Gpio.GpioPinDriveMode.Input;

            return(result);
        }
        private Task <GSI.PwmOutput> PwmOutputCreator(Socket socket, SocketPinNumber pinNumber)
        {
            if (!this.pwmMap.ContainsKey(socket.Number))
            {
                throw new UnsupportedPinModeException();
            }
            if (!this.pwmMap[socket.Number].ContainsKey(pinNumber))
            {
                throw new UnsupportedPinModeException();
            }

            var channel = this.pwmMap[socket.Number][pinNumber];
            var shared  = this.pwmSharedMap[channel];

            this.gpios[shared.Item1 - 1].SetDriveMode(shared.Item2, GpioPinDriveMode.Input);

            this.gpios[shared.Item3 - 1].SetDriveMode(shared.Item4, GpioPinDriveMode.Output);
            this.gpios[shared.Item3 - 1].Write(shared.Item4, false);

            return(Task.FromResult <GSI.PwmOutput>(new IndirectedPwmOutput(channel, this.pwm)));
        }
        private Task <GSI.DigitalIO> DigitalIOCreator(Socket socket, SocketPinNumber pinNumber)
        {
            if (!this.gpioMap.ContainsKey(socket.Number))
            {
                throw new UnsupportedPinModeException();
            }
            if (!this.gpioMap[socket.Number].ContainsKey(pinNumber))
            {
                throw new UnsupportedPinModeException();
            }

            var pin = this.gpioMap[socket.Number][pinNumber];

            if (this.pwmMap.ContainsKey(socket.Number) && this.pwmMap[socket.Number].ContainsKey(pinNumber))
            {
                var channel = this.pwmMap[socket.Number][pinNumber];
                var shared  = this.pwmSharedMap[channel];

                this.gpios[shared.Item3 - 1].SetDriveMode(shared.Item4, GpioPinDriveMode.Output);
                this.gpios[shared.Item3 - 1].Write(shared.Item4, true);
            }

            return(Task.FromResult <GSI.DigitalIO>(new IndirectedDigitalIO(pin.Item2, this.gpios[pin.Item1 - 1])));
        }
Exemple #10
0
		public async Task<DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber, bool initialValue) {
			var result = await this.CreateDigitalIOAsync(pinNumber);

			result.DriveMode = WD.Gpio.GpioPinDriveMode.Output;
			result.Value = initialValue;

			return result;
		}
Exemple #11
0
		public async Task<DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber) {
			DigitalIO result;

            if (this.nativePins.ContainsKey(pinNumber)) {
                result = new NativeInterfaces.DigitalIO(await NativeInterfaces.DigitalIO.CreateInterfaceAsync(this.nativePins[pinNumber]));
            }
            else if (this.DigitalIOCreator != null) {
                result = await this.DigitalIOCreator(this, pinNumber);
            }
            else {
                throw new UnsupportedPinModeException();
            }

			result.DriveMode = WD.Gpio.GpioPinDriveMode.Input;

			return result;
		}
Exemple #12
0
		public async Task<DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber, WD.Gpio.GpioPinEdge interruptType) {
			var result = await this.CreateDigitalIOAsync(pinNumber);

			result.InterruptType = interruptType;

			return result;
		}
Exemple #13
0
        public async Task <SpiDevice> CreateSpiDeviceAsync(WD.Spi.SpiConnectionSettings connectionSettings, SocketPinNumber chipSelectPinNumber, SocketPinNumber masterOutPinNumber, SocketPinNumber masterInPinNumber, SocketPinNumber clockPinNumber)
        {
            if (chipSelectPinNumber == SocketPinNumber.Six && masterOutPinNumber == SocketPinNumber.Seven && masterInPinNumber == SocketPinNumber.Eight && clockPinNumber == SocketPinNumber.Nine && this.IsTypeSupported(SocketType.S))
            {
                return(await this.CreateSpiDeviceAsync(connectionSettings));
            }

            var chipSelect = await this.CreateDigitalIOAsync(chipSelectPinNumber);

            var masterOut = await this.CreateDigitalIOAsync(masterOutPinNumber);

            var masterIn = await this.CreateDigitalIOAsync(masterInPinNumber);

            var clock = await this.CreateDigitalIOAsync(clockPinNumber);

            return(new SoftwareInterfaces.SpiDevice(chipSelect, masterOut, masterIn, clock, connectionSettings));
        }
Exemple #14
0
		public void SetNativePin(SocketPinNumber pinNumber, int nativePinNumber) {
			this.nativePins[pinNumber] = nativePinNumber;
		}
Exemple #15
0
		public async Task<PwmOutput> CreatePwmOutputAsync(SocketPinNumber pinNumber) {
			this.EnsureTypeIsSupported(SocketType.P);

			if (this.PwmOutputCreator != null)
				return await this.PwmOutputCreator(this, pinNumber);

			return new NativeInterfaces.PwmOutput();
		}
Exemple #16
0
		public async Task<SpiDevice> CreateSpiDeviceAsync(WD.Spi.SpiConnectionSettings connectionSettings, SocketPinNumber chipSelectPinNumber, SocketPinNumber masterOutPinNumber, SocketPinNumber masterInPinNumber, SocketPinNumber clockPinNumber) {
			if (chipSelectPinNumber == SocketPinNumber.Six && masterOutPinNumber == SocketPinNumber.Seven && masterInPinNumber == SocketPinNumber.Eight && clockPinNumber == SocketPinNumber.Nine && this.IsTypeSupported(SocketType.S))
				return await this.CreateSpiDeviceAsync(connectionSettings);

			var chipSelect = await this.CreateDigitalIOAsync(chipSelectPinNumber);
			var masterOut = await this.CreateDigitalIOAsync(masterOutPinNumber);
			var masterIn = await this.CreateDigitalIOAsync(masterInPinNumber);
			var clock = await this.CreateDigitalIOAsync(clockPinNumber);

			return new SoftwareInterfaces.SpiDevice(chipSelect, masterOut, masterIn, clock, connectionSettings);
		}
Exemple #17
0
		private byte GetChannel(Socket socket, SocketPinNumber pin) {
			return (byte)((socket.Number - 1) * 3 + ((int)pin - 3));
		}
Exemple #18
0
        private async Task<AnalogIO> AnalogIOCreator(Socket socket, SocketPinNumber pinNumber) {
            if (!this.analogMap.ContainsKey(socket.Number)) throw new UnsupportedPinModeException();
            if (!this.analogMap[socket.Number].ContainsKey(pinNumber)) throw new UnsupportedPinModeException();

            var channel = this.analogMap[socket.Number][pinNumber];

            if (this.analogSharedMap.ContainsKey(channel)) {
                var shared = this.analogSharedMap[channel];

                if (shared.Item1 == 0) {
                    using (var gpio = await NativeInterfaces.DigitalIO.CreateInterfaceAsync(shared.Item2)) {
                        gpio.SetDriveMode(GpioPinDriveMode.Input);
                    }
                }
                else {
                    this.gpios[shared.Item1 - 1].SetDriveMode(shared.Item2, GpioPinDriveMode.Input);
                }
            }

            return new IndirectedAnalogIO(channel, this.analog);
        }
Exemple #19
0
 public async Task <GSI.AnalogIO> CreateAnalogIOAsync(SocketPinNumber pinNumber, double initialVoltage) => await this.socket.CreateAnalogIOAsync(pinNumber, initialVoltage);
Exemple #20
0
 public void SetNativePin(SocketPinNumber pinNumber, int nativePinNumber)
 {
     this.nativePins[pinNumber] = nativePinNumber;
 }
Exemple #21
0
 public async Task <GSI.AnalogIO> CreateAnalogIOAsync(SocketPinNumber pinNumber) => await this.socket.CreateAnalogIOAsync(pinNumber);
Exemple #22
0
 public async Task <GSI.DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber, bool initialValue) => await this.socket.CreateDigitalIOAsync(pinNumber, initialValue);
Exemple #23
0
 public async Task <GSI.DigitalIO> CreateDigitalIOAsync(SocketPinNumber pinNumber) => await this.socket.CreateDigitalIOAsync(pinNumber);
Exemple #24
0
		public async Task<AnalogIO> CreateAnalogIOAsync(SocketPinNumber pinNumber) {
			this.EnsureTypeIsSupported(SocketType.A);

			AnalogIO result;

			if (this.AnalogIOCreator != null) {
				result = await this.AnalogIOCreator(this, pinNumber);
			}
			else {
				result = new NativeInterfaces.AnalogIO();
			}

			result.DriveMode = WD.Gpio.GpioPinDriveMode.Input;

			return result;
		}
Exemple #25
0
        private Task<PwmOutput> PwmOutputCreator(Socket socket, SocketPinNumber pinNumber) {
            if (!this.pwmMap.ContainsKey(socket.Number)) throw new UnsupportedPinModeException();
            if (!this.pwmMap[socket.Number].ContainsKey(pinNumber)) throw new UnsupportedPinModeException();

            var channel = this.pwmMap[socket.Number][pinNumber];
            var shared = this.pwmSharedMap[channel];

            this.gpios[shared.Item1 - 1].SetDriveMode(shared.Item2, GpioPinDriveMode.Input);

            this.gpios[shared.Item3 - 1].SetDriveMode(shared.Item4, GpioPinDriveMode.Output);
            this.gpios[shared.Item3 - 1].Write(shared.Item4, false);

            return Task.FromResult<PwmOutput>(new IndirectedPwmOutput(channel, this.pwm));
        }
Exemple #26
0
		public async Task<AnalogIO> CreateAnalogIOAsync(SocketPinNumber pinNumber, double initialVoltage) {
			var result = await this.CreateAnalogIOAsync(pinNumber);

			result.DriveMode = WD.Gpio.GpioPinDriveMode.Output;
			result.Voltage = initialVoltage;

			return result;
		}
Exemple #27
0
 private CY8C9560A.Pin GetPin(Socket socket, SocketPinNumber pin)
 {
     return(this.map[(int)socket.Number - 1][pin]);
 }
Exemple #28
0
		public async Task<I2cDevice> CreateI2cDeviceAsync(WD.I2c.I2cConnectionSettings connectionSettings, SocketPinNumber sdaPinNumber, SocketPinNumber sclPinNumber) {
			if (sdaPinNumber == SocketPinNumber.Eight && sclPinNumber == SocketPinNumber.Nine && this.IsTypeSupported(SocketType.I))
				return await this.CreateI2cDeviceAsync(connectionSettings);

			var sda = await this.CreateDigitalIOAsync(sdaPinNumber);
			var scl = await this.CreateDigitalIOAsync(sclPinNumber);

			return new SoftwareInterfaces.I2cDevice(sda, scl, connectionSettings);
		}
Exemple #29
0
 private byte GetChannel(Socket socket, SocketPinNumber pin)
 {
     return((byte)((socket.Number - 1) * 3 + ((int)pin - 3)));
 }
Exemple #30
0
 public async Task <GSI.PwmOutput> CreatePwmOutputAsync(SocketPinNumber pinNumber) => await this.socket.CreatePwmOutputAsync(pinNumber);
Exemple #31
0
        public async Task <I2cDevice> CreateI2cDeviceAsync(WD.I2c.I2cConnectionSettings connectionSettings, SocketPinNumber sdaPinNumber, SocketPinNumber sclPinNumber)
        {
            if (sdaPinNumber == SocketPinNumber.Eight && sclPinNumber == SocketPinNumber.Nine && this.IsTypeSupported(SocketType.I))
            {
                return(await this.CreateI2cDeviceAsync(connectionSettings));
            }

            var sda = await this.CreateDigitalIOAsync(sdaPinNumber);

            var scl = await this.CreateDigitalIOAsync(sclPinNumber);

            return(new SoftwareInterfaces.I2cDevice(sda, scl, connectionSettings));
        }
Exemple #32
0
        private Task<DigitalIO> DigitalIOCreator(Socket socket, SocketPinNumber pinNumber) {
            if (!this.gpioMap.ContainsKey(socket.Number)) throw new UnsupportedPinModeException();
            if (!this.gpioMap[socket.Number].ContainsKey(pinNumber)) throw new UnsupportedPinModeException();

            var pin = this.gpioMap[socket.Number][pinNumber];

            if (this.pwmMap.ContainsKey(socket.Number) && this.pwmMap[socket.Number].ContainsKey(pinNumber)) {
                var channel = this.pwmMap[socket.Number][pinNumber];
                var shared = this.pwmSharedMap[channel];

                this.gpios[shared.Item3 - 1].SetDriveMode(shared.Item4, GpioPinDriveMode.Output);
                this.gpios[shared.Item3 - 1].Write(shared.Item4, true);
            }

            return Task.FromResult<DigitalIO>(new IndirectedDigitalIO(pin.Item2, this.gpios[pin.Item1 - 1]));
        }
Exemple #33
0
		private CY8C9560A.Pin GetPin(Socket socket, SocketPinNumber pin) {
			return this.map[(int)socket.Number - 1][pin];
		}