protected async override Task Initialize(ISocket parentSocket) { this.analog = new ADS7830(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); this.gpio = new CY8C9560A(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(CY8C9560A.GetAddress(false, false, false, false, false, true, false))), null); this.map = this.CreatePinMap(); Socket socket; for (var i = 0; i < 8; i++) { socket = this.CreateSocket(i + 1); socket.AddSupportedTypes(SocketType.Y); if (i < 2) { socket.AddSupportedTypes(SocketType.A); } else if (i > 2) { socket.AddSupportedTypes(SocketType.P); } socket.DigitalIOCreator = (indirectedSocket, indirectedPin) => Task.FromResult <GSI.DigitalIO>(new IndirectedDigitalIO(this.GetPin(indirectedSocket, indirectedPin), this.gpio)); socket.AnalogIOCreator = (indirectedSocket, indirectedPin) => Task.FromResult <GSI.AnalogIO>(new IndirectedAnalogIO(this.GetChannel(indirectedSocket, indirectedPin), this.GetPin(indirectedSocket, indirectedPin), this.analog, this.gpio)); socket.PwmOutputCreator = (indirectedSocket, indirectedPin) => Task.FromResult <GSI.PwmOutput>(new IndirectedPwmOutput(this.GetPin(indirectedSocket, indirectedPin), this.gpio)); } }
public IndirectedAnalogIO(byte channel, CY8C9560A.Pin pin, ADS7830 ads, CY8C9560A cy8) { this.ads = ads; this.channel = channel; this.cy8 = cy8; this.cy8.SetInput(pin); }
/// <summary> /// Creates a new instance of the FEZ HAT. /// </summary> /// <returns>The new instance.</returns> public static FEZHAT Create() { //var gpioController = GpioController.GetDefault(); //var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector(FEZHAT.I2cDeviceName)))[0]; var hat = new FEZHAT(); if (i2cBus == null) { i2cBus = new Mono.Linux.I2C.I2CBus(0x01); } //I2CDevice i2c_accelerometer = Pi.I2C.AddDevice(MMA8453.GetAddress(false)); var i2c_accelerometer = new Mono.Linux.I2C.I2CDevice(i2cBus, MMA8453.GetAddress(false)); hat.accelerometer = new MMA8453(i2c_accelerometer); //I2CDevice i2c_analog = Pi.I2C.AddDevice(ADS7830.GetAddress(false, false)); var i2c_analog = new Mono.Linux.I2C.I2CDevice(i2cBus, ADS7830.GetAddress(false, false)); hat.analog = new ADS7830(i2c_analog); //I2CDevice i2c_pwm = Pi.I2C.AddDevice(PCA9685.GetAddress(true, true, true, true, true, true)); var i2c_pwm = new Mono.Linux.I2C.I2CDevice(i2cBus, PCA9685.GetAddress(true, true, true, true, true, true)); hat.pwm = new PCA9685(i2c_pwm, Pi.Gpio.Pin23);//Pi.Gpio.Pin13);x hat.pwm.OutputEnabled = true; hat.pwm.Frequency = 1500; //mapping wiring pi vs gpio win iot hat.dio16 = Pi.Gpio.Pin27; //Pi.Gpio.Pin16;x hat.dio26 = Pi.Gpio.Pin25; //Pi.Gpio.Pin26;x hat.dio24 = Pi.Gpio.Pin05; //Pi.Gpio.Pin24;x hat.dio18 = Pi.Gpio.Pin01; //Pi.Gpio.Pin18;x hat.dio22 = Pi.Gpio.Pin03; //Pi.Gpio.Pin22;x hat.dio16.PinMode = GpioPinDriveMode.Input; hat.dio26.PinMode = GpioPinDriveMode.Input; hat.dio24.PinMode = GpioPinDriveMode.Output; hat.dio18.PinMode = GpioPinDriveMode.Input; hat.dio22.PinMode = GpioPinDriveMode.Input; hat.motorEnable = Pi.Gpio.Pin26;//Pi.Gpio.Pin12;x hat.motorEnable.PinMode = GpioPinDriveMode.Output; hat.motorEnable.Write(GpioPinValue.High); hat.MotorA = new Motor(hat.pwm, 14, Pi.Gpio.Pin02, Pi.Gpio.Pin04); //Pi.Gpio.Pin27, Pi.Gpio.Pin23);x hat.MotorB = new Motor(hat.pwm, 13, Pi.Gpio.Pin22, Pi.Gpio.Pin21); //Pi.Gpio.Pin06, Pi.Gpio.Pin05);x hat.D2 = new RgbLed(hat.pwm, 1, 0, 2); hat.D3 = new RgbLed(hat.pwm, 4, 3, 15); hat.S1 = new Servo(hat.pwm, 9); hat.S2 = new Servo(hat.pwm, 10); return(hat); }
/// <summary>Constructs a new HubAP5 module.</summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public HubAP5(int socketNumber) { Socket socket = Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported('I', this); this.io60 = new IO60P16(socket); this.ads = new ADS7830(socket); this.socketMap = new Hashtable(); this.typeMap = new string[8] { "AY", "AY", "Y", "PY", "PY", "PY", "PY", "PY" }; this.pinMap = new byte[56] { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, //Socket 1 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, //Socket 2 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, //Socket 3 0x20, 0x21, 0x22, 0x23, 0x74, 0x75, 0x76, //Socket 4 0x14, 0x15, 0x16, 0x17, 0x71, 0x72, 0x73, //Socket 5 0x10, 0x11, 0x12, 0x13, 0x66, 0x67, 0x70, //Socket 6 0x04, 0x05, 0x06, 0x07, 0x63, 0x64, 0x65, //Socket 7 0x00, 0x01, 0x02, 0x03, 0x60, 0x61, 0x62 //Socket 8 }; for (int i = 0; i < 8; i++) { this.sockets[i] = Socket.SocketInterfaces.CreateUnnumberedSocket("Hub AP5 " + (i + 1).ToString()); this.sockets[i].SupportedTypes = this.typeMap[i].ToCharArray(); for (int j = 3; j <= 9; j++) { this.sockets[i].CpuPins[j] = Socket.UnnumberedPin; } this.socketMap[this.sockets[i].SocketNumber] = i; this.sockets[i].DigitalInputIndirector = (indirectedSocket, indirectedPin, glitchFilterMode, resistorMode, module) => new DigitalInputImplementation(this.GetPin(indirectedSocket, indirectedPin), glitchFilterMode, resistorMode, this.io60); this.sockets[i].DigitalOutputIndirector = (indirectedSocket, indirectedPin, initialState, module) => new DigitalOutputImplementation(this.GetPin(indirectedSocket, indirectedPin), initialState, this.io60); this.sockets[i].DigitalIOIndirector = (indirectedSocket, indirectedPin, initialState, glitchFilterMode, resistorMode, module) => new DigitalIOImplementation(this.GetPin(indirectedSocket, indirectedPin), initialState, glitchFilterMode, resistorMode, this.io60); this.sockets[i].AnalogInputIndirector = (indirectedSocket, indirectedPin, module) => new AnalogInputImplementation(this.GetPin(indirectedSocket, indirectedPin), this.ads, this.io60); this.sockets[i].PwmOutputIndirector = (indirectedSocket, indirectedPin, invert, module) => new PwmOutputImplementation(this.GetPin(indirectedSocket, indirectedPin), invert, this.io60); this.sockets[i].InterruptIndirector = (indirectedSocket, indirectedPin, glitchFilterMode, resistorMode, interruptMode, module) => new InterruptInputImplementation(this.GetPin(indirectedSocket, indirectedPin), glitchFilterMode, resistorMode, interruptMode, this.io60); Socket.SocketInterfaces.RegisterSocket(this.sockets[i]); } }
public AnalogInputImplementation(byte pin, ADS7830 ads, IO60P16 io60) { this.ads = ads; this.io60 = io60; this.pin = pin; this.active = false; var channels = new byte[12] { 0x50, 0, 0x51, 1, 0x52, 2, 0x40, 3, 0x41, 4, 0x42, 5 }; for (int i = 0; i < 12; i += 2) { if (channels[i] == this.pin) { this.channel = channels[i + 1]; } } }
public IndirectedAnalogIO(int channel, ADS7830 analog) { this.channel = channel; this.analog = analog; }
protected async override Task Initialize() { this.gpioMap = FEZCream.CreateGpioMap(); this.analogMap = FEZCream.CreateAnalogMap(); this.pwmMap = FEZCream.CreatePwmMap(); this.analogSharedMap = FEZCream.CreateAnalogSharedMap(); this.pwmSharedMap = FEZCream.CreatePwmSharedMap(); this.analog = new ADS7830(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); this.pwm = new PCA9685(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true)))); this.gpios = new PCA9535[2]; this.gpios[0] = new PCA9535(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(PCA9535.GetAddress(true, true, false))), await GNI.DigitalIO.CreateInterfaceAsync(22)); this.gpios[1] = new PCA9535(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(PCA9535.GetAddress(true, false, true))), await GNI.DigitalIO.CreateInterfaceAsync(26)); for (var i = 2; i <= 7; i++) { this.gpios[0].SetDriveMode(i, GpioPinDriveMode.Output); this.gpios[0].Write(i, true); } Socket socket; socket = this.CreateSocket(1); socket.AddSupportedTypes(SocketType.I); socket.SetNativePin(SocketPinNumber.Three, 18); socket.NativeI2cDeviceId = "I2C1"; socket.DigitalIOCreator = this.DigitalIOCreator; socket = this.CreateSocket(2); socket.AddSupportedTypes(SocketType.U); socket.NativeSerialDeviceId = "COM1"; socket.DigitalIOCreator = this.DigitalIOCreator; socket = this.CreateSocket(3); socket.AddSupportedTypes(SocketType.S, SocketType.X); socket.SetNativePin(SocketPinNumber.Three, 24); socket.SetNativePin(SocketPinNumber.Four, 25); socket.SetNativePin(SocketPinNumber.Five, 13); socket.NativeSpiDeviceId = "SPI0"; socket.NativeSpiChipSelectPin = 0; socket = this.CreateSocket(4); socket.AddSupportedTypes(SocketType.Y); socket.SetNativePin(SocketPinNumber.Three, 6); socket.DigitalIOCreator = this.DigitalIOCreator; socket = this.CreateSocket(5); socket.AddSupportedTypes(SocketType.A); socket.SetNativePin(SocketPinNumber.Three, 12); socket.DigitalIOCreator = this.DigitalIOCreator; socket.AnalogIOCreator = this.AnalogIOCreator; socket = this.CreateSocket(6); socket.AddSupportedTypes(SocketType.A); socket.SetNativePin(SocketPinNumber.Three, 16); socket.DigitalIOCreator = this.DigitalIOCreator; socket.AnalogIOCreator = this.AnalogIOCreator; socket = this.CreateSocket(7); socket.AddSupportedTypes(SocketType.P, SocketType.Y); socket.SetNativePin(SocketPinNumber.Three, 5); socket.DigitalIOCreator = this.DigitalIOCreator; socket.PwmOutputCreator = this.PwmOutputCreator; socket = this.CreateSocket(8); socket.AddSupportedTypes(SocketType.P, SocketType.Y); socket.SetNativePin(SocketPinNumber.Three, 27); socket.DigitalIOCreator = this.DigitalIOCreator; socket.PwmOutputCreator = this.PwmOutputCreator; socket = this.CreateSocket(9); socket.AddSupportedTypes(SocketType.I); socket.SetNativePin(SocketPinNumber.Three, 23); socket.NativeI2cDeviceId = "I2C1"; socket.DigitalIOCreator = this.DigitalIOCreator; }
/// <summary> /// Creates a new instance of the FEZ HAT. /// </summary> /// <returns>The new instance.</returns> public static async Task <FEZHAT> CreateAsync() { var gpioController = GpioController.GetDefault(); var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector(FEZHAT.I2cDeviceName)))[0]; var hat = new FEZHAT(); hat.accelerometer = new MMA8453(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(MMA8453.GetAddress(false)))); hat.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); hat.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true))), gpioController.OpenPin(13)); hat.pwm.OutputEnabled = true; hat.pwm.Frequency = 1500; hat.dio16 = gpioController.OpenPin(16); hat.dio26 = gpioController.OpenPin(26); hat.dio24 = gpioController.OpenPin(24); hat.dio18 = gpioController.OpenPin(18); hat.dio22 = gpioController.OpenPin(22); hat.dio16.SetDriveMode(GpioPinDriveMode.Input); hat.dio26.SetDriveMode(GpioPinDriveMode.Input); hat.dio24.SetDriveMode(GpioPinDriveMode.Output); hat.dio18.SetDriveMode(GpioPinDriveMode.Input); hat.dio22.SetDriveMode(GpioPinDriveMode.Input); hat.motorEnable = gpioController.OpenPin(12); hat.motorEnable.SetDriveMode(GpioPinDriveMode.Output); hat.motorEnable.Write(GpioPinValue.High); hat.MotorA = new Motor(hat.pwm, 14, 27, 23); hat.MotorB = new Motor(hat.pwm, 13, 6, 5); hat.D2 = new RgbLed(hat.pwm, 1, 0, 2); hat.D3 = new RgbLed(hat.pwm, 4, 3, 15); hat.S1 = new Servo(hat.pwm, 9); hat.S2 = new Servo(hat.pwm, 10); return(hat); }
public static async Task <FEZUtilityShield> CreateAsync() { if (null == instance) { GpioController gpioController; instance = new FEZUtilityShield(); gpioController = await GpioController.GetDefaultAsync().AsTask().ConfigureAwait(false); DeviceInformation i2cController; i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector("I2C1")).AsTask().ConfigureAwait(false))[0]; instance.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); instance.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true)))); instance.gpio = new PCA9535(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9535.GetAddress(true, true, false))), gpioController.OpenPin(22)); } return(instance); }
/// <summary> /// Creates a new instance of the FEZ Utility. /// </summary> /// <returns>The new instance.</returns> public static async Task <FEZUtility> CreateAsync() { var gpioController = GpioController.GetDefault(); var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector("I2C1")))[0]; var hat = new FEZUtility(); hat.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); hat.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true)))); hat.gpio = new PCA9535(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9535.GetAddress(true, true, false))), gpioController.OpenPin(22)); hat.gpio.Write((int)Led.Led1, false); hat.gpio.Write((int)Led.Led2, false); hat.gpio.SetDriveMode((int)Led.Led1, GpioPinDriveMode.Output); hat.gpio.SetDriveMode((int)Led.Led2, GpioPinDriveMode.Output); return(hat); }