Example #1
0
        public void TestButtonPress()
        {
            var i2C = new FtdiI2cCore(0, Logger, (byte)GpioPin.Pin8);

            var mpsseInit = i2C.SetupMpsse();

            Assert.IsTrue(mpsseInit, "Mpsse could not init!");

            var statsUpdatedEvent = new ManualResetEvent(false);

            var buttonCore = new GpioButtonCore(new I2CWrapper2(i2C, Logger), GpioPin.Pin8);
            var pressed    = false;

            buttonCore.PressState += (sender, state) =>
            {
                pressed = state == GpioPressState.Pressed;
                if (pressed)
                {
                    statsUpdatedEvent.Set();
                }
            };

            try
            {
                buttonCore.Initialize();
                statsUpdatedEvent.WaitOne(10000, false);

                Assert.IsTrue(pressed, "Button was not pressed!");
            }
            finally
            {
                buttonCore.UnInitialize();
            }
        }
Example #2
0
        public void I2CScanDevices()
        {
            var i2C = new FtdiI2cCore(0, Logger);

            i2C.SetupMpsse();

            i2C.ScanDevicesAndQuit();
        }
Example #3
0
        /// <summary>
        /// Get the Oled ready for testing.
        /// </summary>
        /// <returns></returns>
        private static OledCore GetOledForTesting()
        {
            // Create the I2C Controller
            var i2C = new FtdiI2cCore(DeviceIndexForTesting, Logger);

            // Init the Mpsse
            i2C.SetupMpsse();

            // Create the Oled Object, with the wrapper for the I2C and the logger.
            // Set the defaults for the testing screen used
            var oled = new OledCore(new I2CWrapper2(i2C, Logger), 128, 64, logger: Logger,
                                    screenDriver: DefaultTestScreenDriver);

            // Init the Oled (setup params, clear display, etc)
            var init = oled.Initialise();

            Assert.IsTrue(init, "Oled Failed Init.");

            return(oled);
        }
Example #4
0
        public async Task AutoReconnect()
        {
            // Create the I2C Controller
            var ftdi = new FtdiI2cCore(DeviceIndexForTesting, Logger);

            ftdi.InitCommandRegister(() =>
            {
                if (!ftdi.SetupMpsse())
                {
                    Assert.Fail("Could not Init Mpsse on FTDI chip");
                    return(false);
                }

                return(true);
            });

            var oled = new OledCore(new I2CWrapper2(ftdi, Logger), 128, 64, logger: Logger,
                                    screenDriver: DefaultTestScreenDriver);

            oled.InitCommandRegister(() =>
            {
                var r = oled.Initialise();
                Assert.IsTrue(r, "Failed to init oled");
                return(r);
            });

            oled.InitCommandRegister(() =>
            {
                oled.WriteString(0, 0, "My Test 1", 1.6);
                oled.UpdateDirtyBytes();
                return(true);
            });


            ftdi.InitAutoReconnectStart();

            Assert.IsTrue(ftdi.Ready, "Failed to init ftdi");

            // Delay so it can be tested.
            await Task.Delay(TimeSpan.FromSeconds(10));
        }