private void Init(SpiConnectionSettings settings) { SetSpiMode(settings.Mode); SetBitsPerWord(settings.BitsPerWord); SetMaxSpeed(settings.MaxSpeed); SetDelay(settings.Delay); }
protected override void EstablishContext() { settings = new SpiConnectionSettings { BitsPerWord = BITS_PER_WORD, Delay = DELAY, Mode = SPI_MODE, MaxSpeed = SPEED_IN_HZ }; controlDevice = A.Fake<IControlDevice>(); }
public static void Main(string[] args) { try { Console.WriteLine("Starting application"); var driver = new MemoryGpioConnectionDriver(); var lcdSpiSettings = new SpiConnectionSettings(); lcdSpiSettings.BitsPerWord = 8; lcdSpiSettings.MaxSpeed = 3932160; lcdSpiSettings.Delay = 0; lcdSpiSettings.Mode = SpiMode.Mode0; var adsSpiSettings = new SpiConnectionSettings(); adsSpiSettings.BitsPerWord = 8; adsSpiSettings.MaxSpeed = 3932160; adsSpiSettings.Delay = 0; adsSpiSettings.Mode = SpiMode.Mode1; var spi0 = new NativeSpiConnection("/dev/spidev0.0", lcdSpiSettings); var spi1 = new NativeSpiConnection("/dev/spidev0.1", adsSpiSettings); var lcdRegisterSelectGpio = ConnectorPin.P1Pin11; driver.In(lcdRegisterSelectGpio).Read(); var lcdRegisterSelectOut = driver.Out(lcdRegisterSelectGpio); var lcdResetGpio = ConnectorPin.P1Pin16; var lcdResetOut = driver.Out(lcdResetGpio); using (var deviceConnection = new Ti430BoostAds1118Connection(spi0, spi1, lcdRegisterSelectOut, lcdResetOut)) { deviceConnection.InitializeLcd(); deviceConnection.DisplayStringOnLcd(LcdLine.FirstLine, "Hello!"); Thread.Sleep(500); deviceConnection.ClearLcd(); var temp = deviceConnection.GetMeasurement(); deviceConnection.DisplayStringOnLcd(LcdLine.SecondLine, string.Format("TEMP: {0} C", temp)); } } catch (Exception ex) { Console.WriteLine("Exception caught!"); Console.WriteLine("Exception Message: {0}", ex.Message); Console.WriteLine("Stack Trace: {0}", ex.StackTrace); } }
/// <summary> /// Creates a new instance of the <see cref="NativeSpiConnection"/> class and initializes it. /// </summary> /// <param name="deviceFilePath">Full path to the SPI device file (e.g. /dev/spidev0.0).</param> /// <param name="settings">Connection settings</param> public NativeSpiConnection(string deviceFilePath, SpiConnectionSettings settings) : this(new SpiControlDevice(new UnixFile(deviceFilePath, UnixFileMode.ReadWrite)), settings) { }
/// <summary> /// Creates a new instance of the <see cref="NativeSpiConnection"/> class and initializes it. /// </summary> /// <param name="deviceFile">A control device (IOCTL) to the device file (e.g. /dev/spidev0.0).</param> /// <param name="settings">Connection settings</param> public NativeSpiConnection(ISpiControlDevice deviceFile, SpiConnectionSettings settings) : this(deviceFile) { Init(settings); }
/// <summary> /// Set up the MCP23S17 for the PiFace Digital board /// </summary> private void InitPiFace() { InputPins = new PiFaceInputPin[8]; for (int pinNo = 0; pinNo < 8; pinNo++) { InputPins[pinNo] = new PiFaceInputPin(pinNo); } OutputPins = new PiFaceOutputPin[8]; for (int pinNo = 0; pinNo < 8; pinNo++) { OutputPins[pinNo] = new PiFaceOutputPin(pinNo); } if (spiConnection == null) { SpiConnectionSettings spiSettings = new SpiConnectionSettings { BitsPerWord = 8, Delay = 1, MaxSpeed = 5000000, Mode = SpiMode.Mode0 }; spiConnection = new NativeSpiConnection(driverName, spiSettings); } Write(mcp23s17Register.IOCON, IOCON_SEQOP); SetAllOutputPins(0); // initialize output and input pins Write(mcp23s17Register.IODIRA, All_Pins_Output); Write(mcp23s17Register.IODIRB, All_Pins_Input); // set resistor on all input pins to pull up Write(mcp23s17Register.GPPUB, 0xFF); // set outputs UpdatePiFaceOutputPins(); // Create re-usable buffer for polling input pins CreateReusableBufferForInputPolling(); // Get the initial software input pin state and compare to actual inputs CachedInputState = PiFaceInputPin.AllPinState(InputPins); PollInputPins(); }