private async void ProcessDraw() { try { var weather = await _weatherStationService.GetHistorical(); LayoutDrawElement[] result = (new LayoutDrawElement[_elements.Count]); for (int i = 0; i < _elements.Count; i++) { var element = _elements[i]; var values = weather.Union(new[] { await _weatherStationService.GetData() }).Select(m => element.GetFunc(m)).ToArray(); var currentValue = values.Last(); var currentString = element.TransformFunc(currentValue); result[i] = new LayoutDrawElement(element.Location, DrawTexts(currentString, element.Suffix, values, _layoutContext)); } DrawLayout?.Invoke(this, new DrawEventArgs(result)); } catch (Exception ex) { Debug.WriteLine($"Exception during weather station layout drawing: {ex}"); } }
public void DrawBitmap(LayoutDrawElement drawElement) { var value = _imagesToDevice.AddOrUpdate(drawElement.Location, (l) => drawElement, (l, b) => { b.BitmapRepresentation.Dispose(); return(drawElement); }); if (_counter == 0) { PerformDraw(); } }
public void ClearDevice() { _switchedLocations.Clear(); for (byte i = 0; i < _device.ButtonCount.Width; i++) { for (byte j = 0; j < _device.ButtonCount.Height; j++) { var location = new Location(i, j); var drawElement = new LayoutDrawElement(location, _device.CreateBitmap(_themeOptions)); DrawBitmap(drawElement); } } }
private async void ProcessDraw() { try { var from = DateTime.Now.Subtract(_options.ExpiredMeetingTolerance); var to = from.AddDays(2).Date; _appointments = _calendarServices.SelectMany(c => c.GetCalendar(from, to)).OrderBy(c => c.FromDateTime).ToArray(); var rows = _layoutContext.ButtonCount.Height; var columns = _layoutContext.ButtonCount.Width; LayoutDrawElement[] result = new LayoutDrawElement[columns * rows]; for (byte i = 0; i < Math.Min(_layoutContext.ButtonCount.Height, _appointments.Length); i++) { result[i * columns] = new LayoutDrawElement(new Location(0, i), DrawText(FormatDateTime(_appointments[i].FromDateTime, _appointments[i].ToDateTime), _layoutContext)); result[i * columns + 1] = new LayoutDrawElement(new Location(2, i), DrawText(_appointments[i].Location, _layoutContext)); result[i * columns + 2] = new LayoutDrawElement(new Location(1, i), DrawText(_appointments[i].Organiser, _layoutContext)); byte firstNameIndex = 3; byte textButtonCount = (byte)(columns - firstNameIndex); if (textButtonCount > 0) { using (var bitmap = new BitmapEx(_layoutContext.IconSize.Width * textButtonCount, _layoutContext.IconSize.Height)) { bitmap.MakeTransparent(); DefaultDrawingAlgs.DrawText(bitmap, _layoutContext.Options.Theme.FontFamily, _appointments[i].Subject, _layoutContext.Options.Theme.ForegroundColor); var elements = BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textButtonCount, 1), firstNameIndex, i, _layoutContext); int j = firstNameIndex; foreach (var e in elements) { result[i * columns + j] = e; j++; } } } } DrawLayout?.Invoke(this, new DrawEventArgs(result)); } catch (Exception ex) { Debug.WriteLine($"Exception during weather station layout drawing: {ex}"); } }
private async void ProcessDraw() { var weather = await GetData(); var rows = _layoutContext.ButtonCount.Height; LayoutDrawElement[] result = new LayoutDrawElement[_layoutContext.ButtonCount.Width * rows]; for (byte i = 0; i < Math.Min(_layoutContext.ButtonCount.Width, weather.Length); i++) { result[i * rows] = new LayoutDrawElement(new Location(i, 0), DrawIcon(weather[i], GetDescription(weather[i]), _layoutContext)); result[i * rows + 1] = new LayoutDrawElement(new Location(i, 1), DrawTexts(WeatherHelpers.TempToStr(weather[i].TemperatureMaxCelsius ?? 0), WeatherHelpers.TempToStr(weather[i].TemperatureMinCelsius ?? 0), _layoutContext)); if (_layoutContext.ButtonCount.Height > 2) { result[i * rows + 2] = new LayoutDrawElement(new Location(i, 2), DrawTexts(((int)(weather[i].PressureMPa ?? 0)).ToString(), weather[i].Humidity.ToString() + "%", _layoutContext)); } if (_layoutContext.ButtonCount.Height > 3) { result[i * rows + 3] = new LayoutDrawElement(new Location(i, 3), DrawTexts(((int)(weather[i].Rain ?? 0)).ToString(), weather[i].Wind, _layoutContext)); } } DrawLayout?.Invoke(this, new DrawEventArgs(result)); }