コード例 #1
0
        public static bool TrySetBit(this I2CDevice device, I2CDevice.Configuration config, int timeout, byte register, byte bitNum, bool value)
        {
            byte oldValue;

            if (!device.TryGetRegister(config, timeout, register, out oldValue))
            {
                return(false);
            }

            byte newValue = (value == true ? (byte)(oldValue | (1 << bitNum)) : (byte)(oldValue & ~(1 << bitNum)));

            return(device.TrySetRegister(config, timeout, register, newValue));
        }
コード例 #2
0
        public static bool TrySetBits(this I2CDevice device, I2CDevice.Configuration config, int timeout, byte register, byte startBit, byte length, byte value)
        {
            byte oldValue;

            if (!device.TryGetRegister(config, timeout, register, out oldValue))
            {
                return(false);
            }
            byte mask = (byte)(((1 << length) - 1) << (startBit - length + 1));

            value   <<= (startBit - length + 1);
            value    &= mask;
            oldValue &= (byte)~mask;
            oldValue |= value;
            return(device.TrySetRegister(config, timeout, register, oldValue));
        }