protected override void EstablishContext()
        {
            controlDeviceMock = new Mock <ISpiControlDevice>();
            controlDevice     = controlDeviceMock.Object;
            controlDeviceMock.Setup(x => x.Control(It.IsAny <uint>(), ref It.Ref <SpiTransferControlStructure> .IsAny)).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
            };

            bufferMock = new Mock <ISpiTransferBuffer>();
            buffer     = bufferMock.Object;
            bufferMock.Setup(x => x.ControlStructure).Returns(controlStructure);

            // setup fake collection to return our "prepared" fake buffer
            collectionMock = new Mock <ISpiTransferBufferCollection>();
            collection     = collectionMock.Object;
            collectionMock.Setup(x => x.Length).Returns(1);
            collectionMock.Setup(x => x.GetEnumerator()).Returns(new List <ISpiTransferBuffer> {
                buffer
            }.GetEnumerator());
        }
        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);
        }
        public ITransceiverSpiConnection Create(ConnectorPin slaveSelectPin, ConnectorPin resetPin, string spiPath = "/dev/spidev0.0")
        {
            NativeSpiConnection spiConnection = new NativeSpiConnection(new SpiControlDevice(new UnixFile(spiPath, UnixFileMode.ReadWrite)));

            spiConnection.SetDelay(0);
            spiConnection.SetMaxSpeed(500000);
            spiConnection.SetBitsPerWord(8);

            IGpioConnectionDriver driver = GpioConnectionSettings.DefaultDriver;

            return(new TransceiverSpiConnection(spiConnection, driver.Out(slaveSelectPin), driver.Out(resetPin)));
        }
Ejemplo n.º 5
0
        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
            };

            controlDeviceMock = new Mock <ISpiControlDevice>();
            controlDevice     = controlDeviceMock.Object;
            controlDeviceMock.Setup(x => x.Control(It.IsAny <uint>(), ref It.Ref <SpiTransferControlStructure> .IsAny)).Returns(IOCTL_PINVOKE_RESULT_CODE);

            connection = new NativeSpiConnection(controlDevice);

            bufferMock = new Mock <ISpiTransferBuffer>();
            buffer     = bufferMock.Object;
            bufferMock.Setup(x => buffer.ControlStructure).Returns(controlStructure);
        }
        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>();
            A.CallTo(() => controlDevice.Control(A <uint> .Ignored, ref controlStructure))
            .WithAnyArguments()
            .Returns(IOCTL_PINVOKE_RESULT_CODE);

            connection = new NativeSpiConnection(controlDevice);

            buffer = A.Fake <ISpiTransferBuffer>();
            A.CallTo(() => buffer.ControlStructure)
            .Returns(controlStructure);
        }
 protected override void BecauseOf()
 {
     connection = new NativeSpiConnection(controlDevice, settings);
 }