private void Ads1115ChannelChanged(object sender, ChannelReadingDone e)
        {
            var convertedDistance = _sharpSensorConverter.Convert(e.RawValue);
            var message           = $"Channel {e.Channel + 1} Message Received - Raw Value {e.RawValue} - Converted Distance {convertedDistance:F2} mm";

            _logInfoAction(message);

            switch (e.Channel)
            {
            case 0:
                UpdateUIAsync(() => channelOneMessages.Text = message).Wait();
                break;

            case 1:
                UpdateUIAsync(() => channelTwoMessages.Text = message).Wait();
                break;

            case 2:
                UpdateUIAsync(() => channelThreeMessages.Text = message).Wait();
                break;

            case 3:
                UpdateUIAsync(() => channelFourMessages.Text = message).Wait();
                break;
            }
        }
예제 #2
0
        private void Ads1115ChannelChanged(object sender, ChannelReadingDone e)
        {
            lock (_lock)
            {
                var convertedDistance = _sharpSensorConverter.Convert(e.RawValue);
                var message           = $"Device {e.SlaveAddress} Channel {e.Channel + 1} Message Received - Raw Value {e.RawValue} - Converted Distance {convertedDistance:F2} mm";
                _logInfoAction(message);

                MessageObject.Error = null;

                IRSensorReading reading;

                if (MessageObject.IRSensorReadings.ContainsKey(e.SlaveAddress))
                {
                    reading = MessageObject.IRSensorReadings[e.SlaveAddress];

                    reading.SlaveAddress     = e.SlaveAddress;
                    reading.IRSensorDistance = convertedDistance;
                    reading.IRSensorRaw      = e.RawValue;
                }
                else
                {
                    reading = new IRSensorReading
                    {
                        IRSensorDistance = convertedDistance,
                        IRSensorRaw      = e.RawValue,
                        SlaveAddress     = e.SlaveAddress
                    };

                    MessageObject.IRSensorReadings.Add(e.SlaveAddress, reading);
                }

                PostMessageToAPI();
            }
        }