Beispiel #1
0
        public void can_enable_disable_specific_bit()
        {
            // Arrange
            var deviceId    = 32;
            var deviceState = 0;
            var i2c         = Substitute.For <II2c>();

            i2c.When(x => x.WriteToDevice(Arg.Any <int>(), Arg.Any <byte>(), Arg.Any <byte>()))
            .Do(x => deviceState = x.ArgAt <byte>(2));

            var powerOutput = new ShinyMcpExpander(i2c);

            // Act
            powerOutput.SetState(BuildOutputDescriptor(deviceId, "O1"), true);  // 1000 0000
            powerOutput.SetState(BuildOutputDescriptor(deviceId, "O3"), true);  // 1010 0000
            powerOutput.SetState(BuildOutputDescriptor(deviceId, "O6"), true);  // 1010 0100
            powerOutput.SetState(BuildOutputDescriptor(deviceId, "O3"), false); // 1000 0100 => 132

            // Assert
            Assert.Equal(132, deviceState);
            i2c.Received().WriteToDevice(deviceId, 0x15, 132);
        }
Beispiel #2
0
        public void initializes_output_before_setting_state()
        {
            // Arrange
            var deviceId    = 32;
            var i2c         = Substitute.For <II2c>();
            var powerOutput = new ShinyMcpExpander(i2c);

            // Act
            powerOutput.SetState(BuildOutputDescriptor(deviceId, "N1"), true);

            // Assert
            i2c.Received().WriteToDevice(deviceId, 0x00, 0x00);
            i2c.Received().WriteToDevice(deviceId, 0x01, 0x00);
            i2c.Received().WriteToDevice(deviceId, 0x14, 0x02);
        }
Beispiel #3
0
        public void can_set_and_read_state()
        {
            // Arrange
            var deviceId    = 32;
            var i2c         = Substitute.For <II2c>();
            var powerOutput = new ShinyMcpExpander(i2c);

            // Act
            powerOutput.SetState(BuildOutputDescriptor(deviceId, "O3"), true);  // 0000 0100

            // Assert
            Assert.Equal(false, powerOutput.GetState(BuildOutputDescriptor(deviceId, "O1")));
            Assert.Equal(false, powerOutput.GetState(BuildOutputDescriptor(deviceId, "O2")));
            Assert.Equal(true, powerOutput.GetState(BuildOutputDescriptor(deviceId, "O3")));
            Assert.Equal(false, powerOutput.GetState(BuildOutputDescriptor(deviceId, "O4")));
        }