/// <summary> /// Initialization function for PL1167 /// /// </summary> /// <param name="ui8CS"></param> public void Initialize(byte ui8CS) { //CS_Pin = ui8CS; //Init SPI //pinMode(ui8CS_Pin, OUTPUT); spiConnection = new NativeSpiConnection("/dev/spidev0.0", new SpiConnectionSettings() { Mode = SpiMode.Mode1 }); //Init PL1167 #if PL1167_EXPLICIT_RESET //pinMode(PL1167_EXPLICIT_RESET_PIN, OUTPUT); //digitalWrite(PL1167_EXPLICIT_RESET_PIN, LOW); //delay(50); //digitalWrite(PL1167_EXPLICIT_RESET_PIN, HIGH); #endif //delay(10); // Delay for oscillator locking //pinMode(PL1167_PKT_PIN, INPUT); //attachInterrupt(0, vfISR, RISING); // Initialize Arduino interrupt InitRadioModule(); // Initialize registers of PL1167 //delay(50); SetRadioChannel(channel); // Set RF channel ResetFIFOPointerReg(C_RXFIFOPOINTER); SetRXMode(); }
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); } }
protected override void EstablishContext() { // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; controlDevice = A.Fake<ISpiControlDevice>(); controlDevice .CallsTo(device => device.Control(A<uint>.Ignored, ref controlStructure)) .WithAnyArguments() .Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); buffer = A.Fake<ISpiTransferBuffer>(); buffer .CallsTo(b => b.ControlStructure) .Returns(controlStructure); }
protected override void EstablishContext() { controlDevice = A.Fake<ISpiControlDevice>(); controlDevice .CallsTo(device => device.Control(A<uint>.Ignored, A<SpiTransferControlStructure[]>.Ignored)) .Returns(IOCTL_PINVOKE_RESULT_CODE); connection = new NativeSpiConnection(controlDevice); // SPI control structure we expect to see during the P/Invoke call controlStructure = new SpiTransferControlStructure { BitsPerWord = BITS_PER_WORD, Length = 5, Delay = DELAY, ChipSelectChange = 1, Speed = SPEED_IN_HZ }; buffer = A.Fake<ISpiTransferBuffer>(); buffer .CallsTo(b => b.ControlStructure) .Returns(controlStructure); // setup fake collection to return our "prepared" fake buffer collection = A.Fake<ISpiTransferBufferCollection>(); collection .CallsTo(c => c.Length) .Returns(1); collection .CallsTo(c => c.GetEnumerator()) .ReturnsLazily(call => new List<ISpiTransferBuffer>{buffer}.GetEnumerator()); }
protected override void EstablishContext() { settings = new SpiConnectionSettings { BitsPerWord = BITS_PER_WORD, Delay = DELAY, Mode = SPI_MODE, MaxSpeed = SPEED_IN_HZ }; controlDevice = A.Fake<ISpiControlDevice>(); connection = new NativeSpiConnection(controlDevice, settings); }
protected override void BecauseOf() { connection = new NativeSpiConnection(controlDevice, settings); }