Added clock

This commit is contained in:
2026-08-08 01:26:33 +01:00
parent 838e253ab1
commit a1f746fce1
3 changed files with 81 additions and 23 deletions

View File

@@ -13,36 +13,27 @@ public class MatrixRenderer
}
//
public async Task DrawAndSendFrameAsync(float currentTemp, int currentWater)
public async Task DrawAndSendFrameAsync(float currentTemp, int currentWater, DateTime currentTime)
//public async Task DrawAndSendFrameAsync(string currentTemp)
{
// 1. Create a 64x64 canvas
using SKBitmap bitmap = new SKBitmap(_width, _height, SKColorType.Rgba8888, SKAlphaType.Premul);
using SKCanvas canvas = new SKCanvas(bitmap);
// 2. Clear background to black
canvas.Clear(SKColors.Black);
// 3. Draw something (e.g., Temperature Text)
// --- DRAW CLOCK ---
using SKPaint clockPaint = new SKPaint { Color = SKColors.Cyan, IsAntialias = false };
using SKTypeface typeface = SKTypeface.FromFamilyName("monospace");
using SKFont clockFont = new SKFont(typeface, 16);
string timeFormat = (currentTime.Second % 2 == 0) ? "HH:mm" : "HH mm";
string timeString = currentTime.ToString(timeFormat);
canvas.DrawText(timeString, 4, 16, SKTextAlign.Left, clockFont, clockPaint);
// Paint now only handles the color and rendering style
using SKPaint textPaint = new SKPaint
{
Color = SKColors.Orange,
IsAntialias = false // Keep crisp pixels for LED matrices
};
// Font handles the typography
using SKFont textFont = new SKFont
{
Size = 16
};
// DrawText now takes the string, X, Y, the font, and the paint
//canvas.DrawText($"{currentTemp:F1}c", 4, 32, textFont, textPaint);
// DrawText now takes the string, X, Y, alignment, the font, and the paint
canvas.DrawText($"{currentTemp:F1}c", 4, 12, SKTextAlign.Left, textFont, textPaint);
canvas.DrawText($"{currentWater:F1}%", 4, 32, SKTextAlign.Left, textFont, textPaint);
// --- DRAW TEMPERATURE ---
using SKPaint textPaint = new SKPaint { Color = SKColors.Orange, IsAntialias = false };
using SKFont textFont = new SKFont { Size = 16 };
canvas.DrawText($"{currentTemp:F1}c", 4, 30, SKTextAlign.Left, textFont, textPaint);
canvas.DrawText($"{currentWater:F1}%", 4, 50, SKTextAlign.Left, textFont, textPaint);
// 4. Convert 32-bit RGBA to 24-bit RGB for WLED
byte[] rgbaBytes = bitmap.Bytes;