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); }
private void SetupFan(StateMachine stateMachine, IArea room, HSREL5 hsrel5) { var fanPort0 = hsrel5.GetOutput(4); var fanPort1 = hsrel5.GetOutput(5); stateMachine.AddOffState().WithOutput(fanPort0, BinaryState.Low).WithOutput(fanPort1, BinaryState.Low); stateMachine.AddState(new StatefulComponentState("1")).WithOutput(fanPort0, BinaryState.High).WithOutput(fanPort1, BinaryState.Low); stateMachine.AddState(new StatefulComponentState("2")).WithOutput(fanPort0, BinaryState.High).WithOutput(fanPort1, BinaryState.High); stateMachine.TryTurnOff(); }
public UpperBathroomConfiguration(Controller controller, CCToolsBoardController ccToolsController) { if (controller == null) { throw new ArgumentNullException(nameof(controller)); } if (ccToolsController == null) { throw new ArgumentNullException(nameof(ccToolsController)); } _controller = controller; _hsrel5 = ccToolsController.CreateHSREL5(Device.UpperBathroomHSREL5, new I2CSlaveAddress(61)); _input5 = controller.Device <HSPE16InputOnly>(Device.Input5); }
public void CCTools_Write_HSRel5_State() { var i2cBus = new TestI2CBus(DeviceIdFactory.EmptyId); var hsrel5 = new HSREL5(DeviceIdFactory.EmptyId, new I2CSlaveAddress(66), i2cBus); hsrel5[HSREL5Pin.Relay0].Write(BinaryState.High); i2cBus.LastUsedI2CSlaveAddress.ShouldBeEquivalentTo(new I2CSlaveAddress(66)); i2cBus.I2CDevice.LastWrittenBytes.Length.ShouldBeEquivalentTo(1); // The bits are inverted using a hardware inverter. This requires checking // against inverted values too. i2cBus.I2CDevice.LastWrittenBytes[0].ShouldBeEquivalentTo(254); hsrel5[HSREL5Pin.Relay4].Write(BinaryState.High); i2cBus.LastUsedI2CSlaveAddress.ShouldBeEquivalentTo(new I2CSlaveAddress(66)); i2cBus.I2CDevice.LastWrittenBytes.Length.ShouldBeEquivalentTo(1); // The bits are inverted using a hardware inverter. This requires checking // against inverted values too. i2cBus.I2CDevice.LastWrittenBytes[0].ShouldBeEquivalentTo(238); }
public void CCTools_Write_HSRel5_State() { var i2CBus = new TestI2CBusService(); var hsrel5 = new HSREL5("Test", new I2CSlaveAddress(66), i2CBus, new TestLogger()); hsrel5[HSREL5Pin.Relay0].Write(BinaryState.High); Assert.AreEqual(new I2CSlaveAddress(66), i2CBus.LastUsedI2CSlaveAddress); Assert.AreEqual(1, i2CBus.LastWrittenBytes.Length); // The bits are inverted using a hardware inverter. This requires checking // against inverted values too. Assert.AreEqual(254, i2CBus.LastWrittenBytes[0]); hsrel5[HSREL5Pin.Relay4].Write(BinaryState.High); Assert.AreEqual(new I2CSlaveAddress(66), i2CBus.LastUsedI2CSlaveAddress); Assert.AreEqual(1, i2CBus.LastWrittenBytes.Length); // The bits are inverted using a hardware inverter. This requires checking // against inverted values too. Assert.AreEqual(238, i2CBus.LastWrittenBytes[0]); }
public UpperBathroomFanAdapter(HSREL5 hsrel5) { _relay1 = hsrel5[HSREL5Pin.Relay4]; _relay2 = hsrel5[HSREL5Pin.GPIO0]; }