public void CCTools_Read_HSPE16InputOnly_State() { // The hardware board contains pull-up resistors. This means that the inputs are inverted internally // and the test must respect this. var i2CBus = new TestI2CBusService(); i2CBus.I2CDevice.BufferForNextRead = new byte[] { 255, 255 }; var deviceMessageBrokerService = new TestDeviceMessageBrokerService(); var hspe16 = new HSPE16InputOnly("Test", new I2CSlaveAddress(32), i2CBus, deviceMessageBrokerService, new TestLogger()); hspe16.FetchState(); Assert.AreEqual(new I2CSlaveAddress(32), i2CBus.LastUsedI2CSlaveAddress); Assert.AreEqual(BinaryState.Low, hspe16[HSPE16Pin.GPIO0].Read()); i2CBus.I2CDevice.BufferForNextRead = new byte[] { 0, 255 }; hspe16.FetchState(); Assert.AreEqual(new I2CSlaveAddress(32), i2CBus.LastUsedI2CSlaveAddress); Assert.AreEqual(BinaryState.High, hspe16[HSPE16Pin.GPIO0].Read()); i2CBus.I2CDevice.BufferForNextRead = new byte[] { 255, 127 }; hspe16.FetchState(); Assert.AreEqual(new I2CSlaveAddress(32), i2CBus.LastUsedI2CSlaveAddress); Assert.AreEqual(BinaryState.Low, hspe16[HSPE16Pin.GPIO0].Read()); Assert.AreEqual(BinaryState.High, hspe16[HSPE16Pin.GPIO15].Read()); }
public void CCTools_Read_HSPE16InputOnly_State() { // The hardware board contains pull-up resistors. This means that the inputs are inverted internally // and the test must respect this. var i2cBus = new TestI2CBus(DeviceIdFactory.EmptyId); i2cBus.I2CDevice.BufferForNextRead = new byte[] { 255, 255 }; var hspe16 = new HSPE16InputOnly(DeviceIdFactory.EmptyId, new I2CSlaveAddress(32), i2cBus); hspe16.FetchState(); i2cBus.LastUsedI2CSlaveAddress.ShouldBeEquivalentTo(new I2CSlaveAddress(32)); hspe16[HSPE16Pin.GPIO0].Read().ShouldBeEquivalentTo(BinaryState.Low); i2cBus.I2CDevice.BufferForNextRead = new byte[] { 0, 255 }; hspe16.FetchState(); i2cBus.LastUsedI2CSlaveAddress.ShouldBeEquivalentTo(new I2CSlaveAddress(32)); hspe16[HSPE16Pin.GPIO0].Read().ShouldBeEquivalentTo(BinaryState.High); i2cBus.I2CDevice.BufferForNextRead = new byte[] { 255, 127 }; hspe16.FetchState(); i2cBus.LastUsedI2CSlaveAddress.ShouldBeEquivalentTo(new I2CSlaveAddress(32)); hspe16[HSPE16Pin.GPIO0].Read().ShouldBeEquivalentTo(BinaryState.Low); hspe16[HSPE16Pin.GPIO15].Read().ShouldBeEquivalentTo(BinaryState.High); }
public IDevice CreateDevice(CCToolsDeviceType type, string id, int address) { if (id == null) { throw new ArgumentNullException(nameof(id)); } var i2CSlaveAddress = new I2CSlaveAddress(address); IDevice deviceInstance; switch (type) { case CCToolsDeviceType.HSPE16_InputOnly: { deviceInstance = new HSPE16InputOnly(id, i2CSlaveAddress, _i2CBusService, _log); break; } case CCToolsDeviceType.HSPE16_OutputOnly: { deviceInstance = new HSPE16OutputOnly(id, i2CSlaveAddress, _i2CBusService, _log); break; } case CCToolsDeviceType.HSPE8_InputOnly: { deviceInstance = new HSPE8InputOnly(id, i2CSlaveAddress, _i2CBusService, _log); break; } case CCToolsDeviceType.HSPE8_OutputOnly: { deviceInstance = new HSPE8OutputOnly(id, i2CSlaveAddress, _i2CBusService, _log); break; } case CCToolsDeviceType.HSRel5: { deviceInstance = new HSREL5(id, i2CSlaveAddress, _i2CBusService, _log); break; } case CCToolsDeviceType.HSRel8: { deviceInstance = new HSREL8(id, i2CSlaveAddress, _i2CBusService, _log); break; } case CCToolsDeviceType.HSRT16: { deviceInstance = new HSRT16(id, i2CSlaveAddress, _i2CBusService, _log); break; } default: throw new NotSupportedException(); } return(deviceInstance); }