Esempio n. 1
0
        private async Task FlipConfigurationBit(DhtTiny.ConfigBit bit)
        {
            try
            {
                // ***
                // *** Stop the timer.
                // ***
                _timer.Stop();

                // ***
                // *** Wait for the timer event to finish.
                // ***
                _busy.WaitOne();

                // ***
                // *** Get the current configuration bits.
                // ***
                byte configurationBits = await _dhtTiny.GetConfigurationAsync();

                // ***
                // *** Determine the value of the bit.
                // ***
                bool isEnabled = _dhtTiny.GetConfigurationBit(configurationBits, bit);

                // ***
                // *** Set the new configuration bit.
                // ***
                await _dhtTiny.SetConfigurationAsync((byte)bit, !isEnabled);
            }
            catch (Exception ex)
            {
                ExceptionEvent.Publish(ex);
            }
            finally
            {
                // ***
                // *** Start the timer.
                // ***
                _timer.Start();
            }
        }