Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaYslmn committed May 4, 2023
2 parents e3f3403 + c6faec9 commit 0c5cae0
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 194 deletions.
5 changes: 5 additions & 0 deletions app/ASUSWmi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class ASUSWmi
public const int KB_Light_Up = 0xc4;
public const int KB_Light_Down = 0xc5;

public const int ChargerMode = 0x0012006C;

public const int ChargerUSB = 2;
public const int ChargerBarrel = 1;

public const uint CPU_Fan = 0x00110013;
public const uint GPU_Fan = 0x00110014;
public const uint Mid_Fan = 0x00110031;
Expand Down
102 changes: 55 additions & 47 deletions app/AnimeMatrix/AnimeMatrixDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Text;
using System.Globalization;
using System;
using System.Drawing;
using OSD;
using System.Diagnostics;

namespace Starlight.AnimeMatrix
{
Expand Down Expand Up @@ -107,9 +110,6 @@ public AnimeMatrixDevice()
MaxColumns = 33;
dx = 1;

//FullRows = 7;
//FullEvenRows = 3;

MaxRows = 55;
LedCount = 1245;

Expand Down Expand Up @@ -177,17 +177,8 @@ public static int FirstX(int y)
{
return (y + 1) / 2 - 3;
}
case AnimeType.GA402:
if (y < 11)
{
return 0;
}
else
{
return (y) / 2 - 5;
}
default:
throw new ArgumentException("Invalid anime type", nameof(_model));
return (int)Math.Ceiling(Math.Max(0, y - 11) / 2F);
}
}

Expand All @@ -197,10 +188,8 @@ public static int Width(int y)
{
case AnimeType.GA401:
return 33;
case AnimeType.GA402:
return 34;
default:
throw new ArgumentException("Invalid anime type", nameof(_model));
return 34;
}
}

Expand All @@ -221,36 +210,15 @@ public static int Pitch(int y)
default:
return 36 - y / 2;
}
case AnimeType.GA402:
return Width(y) - FirstX(y);
default:
throw new ArgumentException("Invalid anime type", nameof(_model));
return Width(y) - FirstX(y);
}
}

/*
public int XStart(int row)
{
return (int)Math.Ceiling(Math.Max(0, row - FullRows) / 2.0);
}
public int XEnd(int row)
{
if (row <= FullEvenRows)
{
if (row % 2 == 1) return MaxColumns + 2;
else return MaxColumns;
}
return MaxColumns;
}
*/

public int RowToLinearAddress(int y)
{
EnsureRowInRange(y);

int ret = 0;

for (var i = 0; i < y; i++)
ret += Pitch(i);

Expand All @@ -259,13 +227,10 @@ public int RowToLinearAddress(int y)

public void SetLedPlanar(int x, int y, byte value)
{
EnsureRowInRange(y);
if (!IsRowInRange(y)) return;

if (x >= FirstX(y) && x < Width(y))
{
SetLedLinear(RowToLinearAddress(y) - FirstX(y) + x + dx, value);
//Debug.Write((RowToLinearAddress(y) - FirstX(y) + x + dx).ToString() + " ");
}
}

public void WakeUp()
Expand Down Expand Up @@ -366,9 +331,9 @@ public void PresentClock()
int second = DateTime.Now.Second;

if (CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.Contains("H"))
PresentText(DateTime.Now.ToString("H" + ((second % 2 == 0)?":":" ") + "mm"));
PresentTextDiagonal(DateTime.Now.ToString("H" + ((second % 2 == 0)?":":" ") + "mm"));
else
PresentText(DateTime.Now.ToString("h" + ((second % 2 == 0) ? ":" : " ") + "mm"), DateTime.Now.ToString("tt"));
PresentTextDiagonal(DateTime.Now.ToString("h" + ((second % 2 == 0) ? ":" : " ") + "mmtt"));
}

public void PresentText(string text1, string text2 = "")
Expand Down Expand Up @@ -442,12 +407,55 @@ public void GenerateFrame(Image image, InterpolationMode interpolation = Interpo
}
}

private void EnsureRowInRange(int row)

public void SetLedDiagonal(int x, int y, byte color, int delta = 10)
{
//x+=delta;
y-=delta;

int dx = (x - y)/2;
int dy = x + y;
SetLedPlanar(dx, dy, color);
}

public void PresentTextDiagonal(string text)
{
if (row < 0 || row >= MaxRows)

Clear();

int maxX = (int)Math.Sqrt(MaxRows * MaxRows + MaxColumns * MaxColumns);

using (Bitmap bmp = new Bitmap(maxX, MaxRows))
{
throw new IndexOutOfRangeException($"Y-coordinate should fall in range of [0, {MaxRows - 1}].");
using (Graphics g = Graphics.FromImage(bmp))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.AntiAlias;

using (Font font = new Font("Calibri", 16F, GraphicsUnit.Pixel))
{
SizeF textSize = g.MeasureString(text, font);
g.DrawString(text, font, Brushes.White, 4, 0);
}
}

for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
var pixel = bmp.GetPixel(x, y);
var color = (pixel.R + pixel.G + pixel.B) / 3;
SetLedDiagonal(x, y, (byte)color);
}
}
}

Present();
}

private bool IsRowInRange(int row)
{
return (row >= 0 && row < MaxRows);
}

private bool IsAddressableLed(int address)
Expand Down
1 change: 1 addition & 0 deletions app/ControlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using WinFormsSliderBar;
using System.Drawing.Drawing2D;
using System.Windows.Forms.DataVisualization.Charting;
using System.Windows.Forms;

public static class ControlHelper
{
Expand Down
Loading

0 comments on commit 0c5cae0

Please sign in to comment.