protected async override Task Initialize(ISocket parentSocket) { this.socket = parentSocket; this.write1 = new byte[1]; this.write2 = new byte[2]; this.read4 = new byte[4]; this.spi = await this.socket.CreateSpiDeviceAsync(new Windows.Devices.Spi.SpiConnectionSettings(parentSocket.NativeSpiChipSelectPin) { Mode = Windows.Devices.Spi.SpiMode.Mode0, ClockFrequency = 1000000 }); this.enable = await this.socket.CreateDigitalIOAsync(SocketPinNumber.Five, true); this.Write(Command.Clear, Register.Mode0); this.Write(Command.Clear, Register.Mode1); this.Write(Command.Clear, Register.Status); this.Write(Command.Clear, Register.Counter); this.Write(Command.Load, Register.Output); this.Mode = CountMode.Quad1; this.Write(Command.Write, Register.Mode1, Mode1.FourByte | Mode1.EnableCount); }
protected async override Task Initialize(ISocket parentSocket) { this.lcdRS = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Four, false); this.lcdE = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Three, false); this.lcdD4 = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Five, false); this.lcdD5 = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Seven, false); this.lcdD6 = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Nine, false); this.lcdD7 = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Six, false); this.backlight = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Eight, true); this.currentRow = 0; this.SendCommand(0x33); this.SendCommand(0x32); this.SendCommand(CharacterDisplay.DisplayOnCommand); this.SendCommand(CharacterDisplay.ClearDisplayCommand); Task.Delay(3).Wait(); }
protected async override Task Initialize(ISocket parentSocket) { this.red = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Four, false); this.green = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Five, false); this.blue = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Three, false); }
internal I2cDevice(DigitalIO sda, DigitalIO scl, Windows.Devices.I2c.I2cConnectionSettings settings) { this.sda = sda; this.scl = scl; this.start = false; this.writeAddress = (byte)(settings.SlaveAddress << 1); this.readAddress = (byte)((settings.SlaveAddress << 1) | 1); }
protected async override Task Initialize(ISocket parentSocket) { this.x = await parentSocket.CreateAnalogIOAsync(SocketPinNumber.Four); this.y = await parentSocket.CreateAnalogIOAsync(SocketPinNumber.Five); this.input = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Three); }
protected async override Task Initialize(ISocket parentSocket) { this.boards = 0; this.data = null; this.spi = await parentSocket.CreateSpiDeviceAsync(new Windows.Devices.Spi.SpiConnectionSettings(0) { Mode = Windows.Devices.Spi.SpiMode.Mode0, ClockFrequency = 1000 }); this.enable = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Three, false); this.clr = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Four, true); }
private DaisyLink(Socket socket, DaisyLinkModule module) { Ready = false; this.Socket = socket; this.ReservedCount = 0; this.NodeCount = 0; daisyLinkBus = I2CBusFactory.Create(socket, defaultI2cAddress, 10, i2cDataPin, i2cClockPin, module); // The link pin (port) is initialized as an input. It is only driven during initialization of the daisylinked modules. daisyLinkResetPort = DigitalIOFactory.Create(socket, daisyLinkPin, false, GlitchFilterMode.Off, ResistorMode.PullUp, module); daisyLinkInterruptPort = null; }
private static void test() { // per test Adc: definizione del convertitore analogico digitale DigitalConverterMCP3208 adc = new DigitalConverterMCP3208(); // per test IO digitale: definizione di canali di IO digitale const int chanLed1 = 40; const int chanLed2 = 38; const int chanButton1 = 37; const int chanButton2 = 35; DigitalIO pinIn1 = new DigitalIO(chanButton1, GpioPinDriveMode.Input); DigitalIO pinIn2 = new DigitalIO(chanButton2, GpioPinDriveMode.Input); DigitalIO pinOut1 = new DigitalIO(chanLed1, GpioPinDriveMode.Output); DigitalIO pinOut2 = new DigitalIO(chanLed2, GpioPinDriveMode.Output); // si può anche fare così: //DigitalIO pinIn1 = new DigitalIO(ConnectorPin.P1Pin37, GpioPinDriveMode.Input); //DigitalIO pinOut1 = new DigitalIO(ConnectorPin.P1Pin40, GpioPinDriveMode.Output); //DigitalIO pinIn2 = new DigitalIO(ConnectorPin.P1Pin35, GpioPinDriveMode.Input); //DigitalIO pinOut2 = new DigitalIO(ConnectorPin.P1Pin38, GpioPinDriveMode.Output); // definizioni per test output digitali su shift register OutShiftRegister shift = new OutShiftRegister(16, 25, 24, 23); Device_OnOffShift irrigator = new Device_OnOffShift(shift, 8); // ottavo pin dello shift register Device_OnOffShift humidifier = new Device_OnOffShift(shift, 2); // secondo pin dello shift register //TestAllDigitalInputs(pinTuttiIn); //return; while (true) { Console.CursorTop = 0; Console.Clear(); ReadAllAdc(); // test two digital inputs Console.WriteLine("Canale bottone 1: {0}, Canale bottone 2: {1} ", chanButton1, chanButton2); Console.WriteLine("Bottone 1: {0}, Bottone 2: {1} ", pinIn1.Read().ToString(), pinIn2.Read().ToString()); // test two digital outputs Console.WriteLine("\r\nCanale LED 1: {0}, Canale LED 2: {1} ", chanLed1, chanLed2); pinOut1.Write(pinIn1.Read()); pinOut2.Write(pinIn2.Read()); ActuateShiftRegister(); Thread.Sleep(500); } }
internal SpiDevice(DigitalIO chipSelect, DigitalIO masterOut, DigitalIO masterIn, DigitalIO clock, Windows.Devices.Spi.SpiConnectionSettings settings) { if (settings.DataBitLength != 8) { throw new NotSupportedException("Only 8 data bits are supported."); } this.chipSelect = chipSelect; this.masterOut = masterOut; this.masterIn = masterIn; this.clock = clock; this.clockEdge = (((int)settings.Mode) & 0x01) > 0; this.clockPolarity = (((int)settings.Mode) & 0x02) == 0; }
protected async override Task Initialize(ISocket parentSocket) { this.outputPin = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Four, false); this.inputPin = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Three, GpioPinEdge.FallingEdge | GpioPinEdge.RisingEdge); this.inputPin.ValueChanged += (s, e) => { if (e.Value) { this.Released?.Invoke(this, null); } else { this.Pressed?.Invoke(this, null); } }; }
internal SpiDevice(DigitalIO chipSelect, DigitalIO masterOut, DigitalIO masterIn, DigitalIO clock, Windows.Devices.Spi.SpiConnectionSettings settings) { if (settings.DataBitLength != 8) { throw new NotSupportedException("Only 8 data bits are supported."); } this.chipSelect = chipSelect; this.masterOut = masterOut; this.masterIn = masterIn; this.clock = clock; this.clockActiveState = (((int)settings.Mode) & 0x02) == 0; this.captureOnRisingEdge = ((((int)settings.Mode) & 0x01) == 0); this.clock.Write(!this.clockActiveState); this.masterIn.Read(); this.masterOut.Write(true); this.chipSelect.Write(true); }
/// <summary> /// Sends a reset pulse on the daisylink chain. This resets all DaisyLink nodes to INIT state, that is, waiting for a DaisyLink message. /// </summary> /// <remarks> /// It is recommended to reboot the mainboard after calling this method because communication to the DaisyLink nodes will fail. /// </remarks> internal void SendResetPulse() { lock (portLock) { if (daisyLinkInterruptPort != null) { daisyLinkInterruptPort.Interrupt -= daisyLinkInterruptPort_OnInterrupt; daisyLinkInterruptPort.Dispose(); // Ask hardware drivers to unreserve this pin daisyLinkInterruptPort = null; } if (daisyLinkResetPort == null) { daisyLinkResetPort = DigitalIOFactory.Create(Socket, daisyLinkPin, false, GlitchFilterMode.Off, ResistorMode.PullUp, null); } daisyLinkResetPort.Mode = IOMode.Output; // Should drive the neighbor bus high Thread.Sleep(2); // 2 milliseconds is definitely more than 1 ms daisyLinkResetPort.Mode = IOMode.Input; // Pull-downs should take the neighbor bus back low daisyLinkResetPort.Dispose(); // Remove this pin from the hardware's reserved pin list daisyLinkResetPort = null; } }
protected async override Task Initialize(ISocket parentSocket) { _outputPin = await parentSocket.CreateDigitalIOAsync((SocketPinNumber)5, false); }
protected async override Task Initialize(ISocket parentSocket) { this.input = await parentSocket.CreateAnalogIOAsync(SocketPinNumber.Three); this.enable = await parentSocket.CreateDigitalIOAsync(SocketPinNumber.Six, true); }