Example #1
0
        public async Task <bool> SetHeaterStatus(HeaterStatus heaterStatus)
        {
            bool returnValue = false;

            // ***
            // *** Get the current register
            // ***
            byte register = await this.GetRegister();

            // ***
            // *** Set the bit
            // ***
            register = RegisterConverter.SetBit(register, REGISTER_BIT_HEATER, heaterStatus == HeaterStatus.On);

            // ***
            // *** Write the register
            // ***
            await this.WriteRegister(register);

            // ***
            // *** Check the register
            // ***
            returnValue = (await this.GetHeaterStatus()) == heaterStatus;

            return(returnValue);
        }
Example #2
0
        public async Task <bool> SetResolution(Resolution resolution)
        {
            bool returnValue = false;

            // ***
            // *** Get the current register
            // ***
            byte register = await this.GetRegister();

            // ***
            // *** Set the bits
            // ***
            register = RegisterConverter.SetBit(register, REGISTER_BIT_RESOLUTION_HIGH, resolution == Resolution.Rh10Temp13 || resolution == Resolution.Rh11Temp11);
            register = RegisterConverter.SetBit(register, REGISTER_BIT_RESOLUTION_LOW, resolution == Resolution.Rh8Temp12 || resolution == Resolution.Rh11Temp11);

            // ***
            // *** Write the register
            // ***
            await this.WriteRegister(register);

            // ***
            // *** Check the register
            // ***
            returnValue = (await this.GetResolution()) == resolution;

            return(returnValue);
        }
Example #3
0
        /// <summary>
        /// Sets the value of a configuration bit at the given
        /// index.
        /// </summary>
        /// <param name="bitIndex">Specifies the configuration
        /// bit index from 0 to 15.</param>
        /// <param name="value">The value of the bit to set.</param>
        public virtual void SetConfigurationBit(int bitIndex, bool value)
        {
            // ***
            // *** Read the current configuration
            // ***
            byte[] config = this.ReadFromRegister(Mcp9808Register.Configuration);

            // ***
            // *** Set the selected bit
            // ***
            config[bitIndex > 7 ? 0 : 1] = RegisterConverter.SetBit(config[bitIndex > 7 ? 0 : 1], bitIndex % 8, value);

            // ***
            // *** Write the configuration back to the register
            // ***
            this.WriteToRegister(Mcp9808Register.Configuration, config[0], config[1]);
        }