Skip to content

Commit

Permalink
Merge pull request #711 from WildernessLabs/gc9a01_fix
Browse files Browse the repository at this point in the history
GC9A01 reset fix + minor MicroGraphics cleanup
  • Loading branch information
jorgedevs authored Jul 25, 2023
2 parents c48821d + 1d73239 commit 4124027
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,6 @@ public void DrawCircleQuadrant(int centerX, int centerY, int radius, int quadran
{
if (quadrant < 0 || quadrant > 3) { throw new ArgumentOutOfRangeException("DrawCircleQuadrant: quadrant must be between 0 & 3 inclusive"); }

PenColor = color;

if (filled)
{
DrawCircleQuadrantFilled(centerX, centerY, radius, quadrant, color, centerBetweenPixels);
Expand Down Expand Up @@ -1205,11 +1203,11 @@ public void DrawRoundedRectangle(int x, int y, int width, int height, int corner
DrawCircleQuadrant(x + width - cornerRadius - 1, y + height - cornerRadius - 1, cornerRadius, 3, color, false);

//lines
DrawLine(x + cornerRadius, y - 1, x + width - cornerRadius, y - 1);
DrawLine(x + cornerRadius, y + height, x + width - cornerRadius, y + height);
DrawLine(x + cornerRadius, y - 1, x + width - cornerRadius, y - 1, color);
DrawLine(x + cornerRadius, y + height, x + width - cornerRadius, y + height, color);

DrawLine(x, y + cornerRadius, x, y + height - cornerRadius);
DrawLine(x + width - 1, y + cornerRadius, x + width - 1, y + height - cornerRadius);
DrawLine(x, y + cornerRadius, x, y + height - cornerRadius, color);
DrawLine(x + width - 1, y + cornerRadius, x + width - 1, y + height - cornerRadius, color);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public Gc9a01(ISpiBus spiBus,
/// </summary>
protected override void Initialize()
{
if (resetPort != null)
{
resetPort.State = false;
DelayMs(10);
resetPort.State = true;
DelayMs(120);
}

SendCommand(0xEF);
SendCommand(0xEB);
SendData(0x14);
Expand Down Expand Up @@ -104,7 +112,7 @@ protected override void Initialize()

SendCommand(0xB6);
SendData(0x00);
SendData(0x20);
SendData(0x20); //0x00

SendCommand(0x3A);
SendData(0x05);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ public override Task Initialize()
var display = new Gc9a01
(
spiBus: spiBus,
chipSelectPin: Device.Pins.D02,
chipSelectPin: Device.Pins.A02,
dcPin: Device.Pins.D01,
resetPin: Device.Pins.D00
);

graphics = new MicroGraphics(display)
{
IgnoreOutOfBoundsPixels = true,
CurrentFont = new Font12x20()
CurrentFont = new Font12x20(),
Rotation = RotationType._180Degrees
};

return base.Initialize();
Expand All @@ -40,10 +41,9 @@ public override Task Initialize()
public override Task Run()
{
graphics.Clear();
graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red);
graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false);
graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false);
graphics.DrawText(5, 5, "Meadow F7");
graphics.DrawCircle(120, 120, 100, Meadow.Foundation.Color.Cyan, false);
graphics.DrawRoundedRectangle(50, 50, 140, 140, 50, Meadow.Foundation.Color.BlueViolet, false);
graphics.DrawText(120, 120, "Meadow F7", alignmentH: HorizontalAlignment.Center, alignmentV: VerticalAlignment.Center);
graphics.Show();

return base.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AnalogInputPort : AnalogPortBase, IAnalogInputPort
private readonly int supplyVoltage;
private readonly object _lock = new object();

private readonly List<Voltage> buffer = new List<Voltage>();
private readonly Voltage[] buffer;

/// <summary>
/// Is the port sampling
Expand Down Expand Up @@ -60,7 +60,7 @@ public class AnalogInputPort : AnalogPortBase, IAnalogInputPort
/// <summary>
/// The voltage sampling buffer
/// </summary>
public IList<Voltage> VoltageSampleBuffer => buffer;
public Voltage[] VoltageSampleBuffer => buffer;

/// <summary>
/// The sampling interval
Expand All @@ -76,6 +76,7 @@ public AnalogInputPort(SerialWombatBase controller, IPin pin, IAnalogChannelInfo
SampleCount = sampleCount;

this.controller = controller;
buffer = new Voltage[sampleCount];

supplyVoltage = (int)(controller.GetSupplyVoltage().Millivolts);
ReferenceVoltage = new Voltage(supplyVoltage, Voltage.UnitType.Millivolts);
Expand All @@ -91,14 +92,7 @@ public Task<Voltage> Read()
var data = controller.ReadPublicData((byte)Pin.Key);
Voltage = new Voltage((data * supplyVoltage) >> 16, Voltage.UnitType.Millivolts);

if (buffer.Count == 0)
{
buffer.Add(Voltage);
}
else
{
buffer[0] = Voltage;
}
buffer[0] = Voltage;

return Task.FromResult(Voltage);
}
Expand Down

0 comments on commit 4124027

Please sign in to comment.