예제 #1
0
        private void PeriodicRefreshTask(int intervalInMS, CancellationToken cancellationToken)
        {
            var rgbDisplay = GrovePiRgbLcdDisplay.BuildRgbLcdDisplayImpl();

            rgbDisplay.SetBacklightRgb(10, 10, 10);
            Task.Run(async() =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        foreach (var sensor in sensors.Where(sen => sen.RgbDisplay))
                        {
                            rgbDisplay.SetText(sensor.Name, sensor.Value.ToString("0.0") + " " + sensor.Unit);
                            if (!cancellationToken.IsCancellationRequested)
                            {
                                await Task.Delay(intervalInMS, cancellationToken);
                            }
                        }
                    }
                    catch (TaskCanceledException)
                    {
                        Console.WriteLine("IotProject PeriodicRefreshTask has been cancelled");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("IotProject error: " + ex.Message + " - " + ex.StackTrace);
                    }
                }
            });
        }
예제 #2
0
        public static void WriteLCD(string message)
        {
            var rgbDisplay = GrovePiRgbLcdDisplay.BuildRgbLcdDisplayImpl();

            rgbDisplay.SetText(message);
        }