From fc5d338648756d4c1254eea0695244dd9d6dd643 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Wed, 11 Dec 2024 22:38:37 -0800 Subject: [PATCH 1/8] Minor cleanup --- .../Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs | 5 ----- .../Graphics.MicroGraphics/Driver/Buffers/BufferIndexed4.cs | 5 ----- 2 files changed, 10 deletions(-) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs index b2514d129..32720845c 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs @@ -184,11 +184,6 @@ public byte GetColorIndexForPixel(int x, int y) return value; } - Color GetClosestColor(Color color) - { - return IndexedColors[GetIndexForColor(color)]; - } - int GetIndexForColor(Color color) { if (IndexedColors == null || IndexedColors.All(x => x == null)) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed4.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed4.cs index 2f7a3be53..eb3ff3ad8 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed4.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed4.cs @@ -194,11 +194,6 @@ public byte GetColorIndexForPixel(int x, int y) return color; } - Color GetClosestColor(Color color) - { - return IndexedColors[GetIndexForColor(color)]; - } - int GetIndexForColor(Color color) { if (IndexedColors == null || IndexedColors.All(x => x == null)) From 57e17e3ffe37be6933adb42e8748ac7d46809faf Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Wed, 11 Dec 2024 22:38:51 -0800 Subject: [PATCH 2/8] Remove using --- .../Samples/Epd5in65f_Sample/MeadowApp.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/MeadowApp.cs index 0ac146ca3..0e8d639c7 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd5in65f_Sample/MeadowApp.cs @@ -1,6 +1,5 @@ using Meadow; using Meadow.Devices; -using Meadow.Foundation; using Meadow.Foundation.Displays; using Meadow.Foundation.Graphics; using System.Threading.Tasks; From 32049a89e8591ae62d354a53099eb44800a65a8b Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Wed, 11 Dec 2024 23:30:59 -0800 Subject: [PATCH 3/8] Add 2bbIndex buffer support to PixelBufferBase --- .../Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs index 9424aef08..3caa04eb1 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs @@ -36,6 +36,7 @@ public int BitDepth { ColorMode.Format1bpp => 1, ColorMode.Format2bpp => 2, + ColorMode.Format2bppIndexed => 2, ColorMode.Format4bppGray => 4, ColorMode.Format4bppIndexed => 4, ColorMode.Format8bppGray => 8, From 0cf0f732d5e1624ad1b6e00e7ef5ce91e8a2dd68 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Wed, 11 Dec 2024 23:31:18 -0800 Subject: [PATCH 4/8] Add WaveShare Epg2in15g driver (WIP) --- .../Driver/Drivers/Epd2in15g.cs | 356 ++++++++++++++++++ .../Epd2in15g_Sample/Epd2in15g_Sample.csproj | 15 + .../Samples/Epd2in15g_Sample/MeadowApp.cs | 51 +++ Source/Meadow.Foundation.sln | 9 + 4 files changed, 431 insertions(+) create mode 100644 Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs create mode 100644 Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/Epd2in15g_Sample.csproj create mode 100644 Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/MeadowApp.cs diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs new file mode 100644 index 000000000..497b48c93 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs @@ -0,0 +1,356 @@ +using Meadow; +using Meadow.Foundation; +using Meadow.Foundation.Displays; +using Meadow.Foundation.Graphics.Buffers; +using Meadow.Hardware; +using Meadow.Peripherals.Displays; +using System; + +namespace Displays.ePaperWaveShare.Drivers +{ + /// + /// Represents a WaveShare color ePaper color display + /// 296x160, 2.15" e-Ink four-color display, SPI interface + /// + public class Epd2in15g : EPaperBase, IPixelDisplay + { + /// + public ColorMode ColorMode => ColorMode.Format2bppIndexed; + + /// + public ColorMode SupportedColorModes => ColorMode.Format2bppIndexed; + + /// + public IPixelBuffer PixelBuffer => imageBuffer; + + /// + public Color EnabledColor => Color.Black; + + /// + public Color DisabledColor => Color.White; + + /// + /// Buffer to hold display data + /// + protected readonly BufferIndexed2 imageBuffer; + + /// + public int Width => 160; + + /// + public int Height => 296; + + /// + /// Create a new Epd2in15g ePaper display object + /// + /// SPI bus connected to display + /// Chip select pin + /// Data command pin + /// Reset pin + /// Busy pin + public Epd2in15g(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, IPin busyPin) : + this(spiBus, + chipSelectPin.CreateDigitalOutputPort(), + dcPin.CreateDigitalOutputPort(), + resetPin.CreateDigitalOutputPort(), + busyPin.CreateDigitalInputPort()) + { + } + + /// + /// Create a new Epd2in15g ePaper display object + /// + /// SPI bus connected to display + /// Chip select output port + /// Data command output port + /// Reset output port + /// Busy input port + public Epd2in15g(ISpiBus spiBus, + IDigitalOutputPort chipSelectPort, + IDigitalOutputPort dataCommandPort, + IDigitalOutputPort resetPort, + IDigitalInputPort busyPort) + { + this.dataCommandPort = dataCommandPort; + this.chipSelectPort = chipSelectPort; + this.resetPort = resetPort; + this.busyPort = busyPort; + + spiComms = new SpiCommunications(spiBus, chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); + + Console.WriteLine("Epd2in15g constructor"); + imageBuffer = new BufferIndexed2(Width, Height); + Console.WriteLine("Epd2in15g constructor done"); + + //set the indexed colors + imageBuffer.IndexedColors[0] = Color.Black; + imageBuffer.IndexedColors[1] = Color.White; + imageBuffer.IndexedColors[2] = Color.Yellow; + imageBuffer.IndexedColors[3] = Color.Red; + + imageBuffer.Clear(); + + Initialize(); + } + + void Initialize() + { + Reset(); + + SendCommand(0x4D); + SendData(0x78); + + SendCommand(0x00); //0x00 + SendData(0x0F); + SendData(0x29); // D5=0 + + SendCommand(0x01); //0x01 + SendData(0x07); + SendData(0x00); + + SendCommand(0x03); //0x03 + SendData(0x10); + SendData(0x54); + SendData(0x44); + + SendCommand(0x06); //0x06 + SendData(0x0F); + SendData(0x0A); + SendData(0x2F); + SendData(0x25); + SendData(0x22); + SendData(0x2E); + SendData(0x21); + + SendCommand(0x30); + SendData(0x02); + + SendCommand(0x41); //0x41 + SendData(0x00); + + SendCommand(0x50); //0x50 + SendData(0x37); + + SendCommand(0x60); //0x60 + SendData(0x02); + SendData(0x02); + + SendCommand(0x61); //0x61 + SendData(Width / 256); + SendData(Width % 256); + SendData(Height / 256); + SendData(Height % 256); + + SendCommand(0x65); //0x65 + SendData(0x00); + SendData(0x00); + SendData(0x00); + SendData(0x00); + + SendCommand(0XE7); // 0XE7 + SendData(0x1C); + + SendCommand(0xE3); //0xE3 + SendData(0x22); + + SendCommand(0xE0); //0xE0 + SendData(0x00); + + SendCommand(0xB4); + SendData(0xD0); + SendCommand(0xB5); + SendData(0x03); + + SendCommand(0xE9); + SendData(0x01); + + SendCommand(0x04); + WaitForBusyState(true); + } + + /// + /// Clear display buffer + /// + /// force display update + public void Clear(bool updateDisplay = false) + { + imageBuffer.Clear(); + + if (updateDisplay) + { + Show(); + } + } + + /// + /// Clear the display + /// + /// Color to set the display + public void Fill(Color color) + { + imageBuffer.Fill(color); + } + + /// + /// Fill the display buffer with a color + /// + /// x location in pixels to start fill + /// y location in pixels to start fill + /// w in pixels to fill + /// h in pixels to fill + /// color to fill + public void Fill(int x, int y, int width, int height, Color color) + { + imageBuffer.Fill(x, y, width, height, color); + } + + /// + /// Clear the display + /// + public void Clear() + { + imageBuffer.Clear(); + } + + /// + /// Draw the display buffer to screen + /// + public void Show() + { + Console.WriteLine("Show"); + + var w = (Width % 4 == 0) ? (Width / 4) : (Width / 4 + 1); + var h = Height; + + SendCommand(0x10); + for (int j = 0; j < h; j++) + { + for (int i = 0; i < w; i++) + { + SendData(PixelBuffer.Buffer[i + j * w]); + } + } + + DisplayOn(); + } + + void DisplayOn() + { + SendCommand(0x12); + SendData(0x00); + WaitForBusyState(true); + } + + /// + /// Transfer part of the contents of the buffer to the display + /// bounded by left, top, right and bottom + /// + public void Show(int left, int top, int right, int bottom) + { + Show(); + } + + /// + /// Clear the display + /// + /// The color used to fill the display buffer + /// Update the display once the buffer has been cleared when true + public void Fill(Color fillColor, bool updateDisplay = false) + { + Fill(fillColor); + + if (updateDisplay) + { + Show(); + } + } + + /// + /// Draw a single pixel at the specified color + /// + /// x position in pixels + /// y position in pixels + /// The Meadow Foundation color of the pixel + public void DrawPixel(int x, int y, Color color) + { + imageBuffer.SetPixel(x, y, color); + } + + /// + /// Enable or disable a single pixel (used for 1bpp displays) + /// + /// x position in pixels + /// y position in pixels + /// On if true, off if false + public void DrawPixel(int x, int y, bool enabled) + { + imageBuffer.SetPixel(x, y, enabled ? EnabledColor : DisabledColor); + } + + /// + /// Invert the color of a single pixel + /// + /// x position in pixels + /// y position in pixels + public void InvertPixel(int x, int y) + { + imageBuffer.InvertPixel(x, y); + } + + /// + /// Draw a buffer to the display + /// + public void WriteBuffer(int x, int y, IPixelBuffer displayBuffer) + { + imageBuffer.WriteBuffer(x, y, displayBuffer); + } + + /// + /// Wait until the display busy state is set + /// + protected virtual void WaitForBusyState(bool state) + { + int count = 0; + + if (busyPort is null) + { + DelayMs(1000); + return; + } + + while (busyPort.State != state && count < 1000) + { + DelayMs(5); + count++; + } + } + + /// + /// Reset the display + /// + protected override void Reset() + { + if (resetPort != null) + { + resetPort.State = true; + DelayMs(200); + resetPort.State = false; + DelayMs(2); + resetPort.State = true; + DelayMs(200); + } + } + + /// + /// Enter deep sleep mode + /// call reset to wake display + /// + public void Sleep() + { + SendCommand(0x02); // POWER_OFF + SendData(0X00); + SendCommand(0x07); // DEEP_SLEEP + SendData(0XA5); + } + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/Epd2in15g_Sample.csproj b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/Epd2in15g_Sample.csproj new file mode 100644 index 000000000..aa6fbe7fb --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/Epd2in15g_Sample.csproj @@ -0,0 +1,15 @@ + + + https://github.com/WildernessLabs/Meadow.Foundation + Wilderness Labs, Inc + Wilderness Labs, Inc + true + netstandard2.1 + Library + App + + + + + + diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/MeadowApp.cs new file mode 100644 index 000000000..d4d571840 --- /dev/null +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Samples/Epd2in15g_Sample/MeadowApp.cs @@ -0,0 +1,51 @@ +using Displays.ePaperWaveShare.Drivers; +using Meadow; +using Meadow.Devices; +using Meadow.Foundation.Graphics; +using System.Threading.Tasks; + +namespace Displays.ePaper.EpdColor_Sample +{ + public class MeadowApp : App + { + // + + MicroGraphics graphics; + + public override Task Initialize() + { + Resolver.Log.Info("Initialize ..."); + + var display = new Epd2in15g( + spiBus: Device.CreateSpiBus(), + chipSelectPin: Device.Pins.A04, + dcPin: Device.Pins.A03, + resetPin: Device.Pins.A02, + busyPin: Device.Pins.A01); + + graphics = new MicroGraphics(display); + + return Task.CompletedTask; + } + + public override Task Run() + { + Resolver.Log.Info("Run"); + + graphics.Clear(); + + graphics.CurrentFont = new Font12x16(); + graphics.DrawText(0, 0, "Meadow F7", Color.Black, scaleFactor: ScaleFactor.X2); + graphics.DrawText(0, 50, "Yellow", Color.Yellow, scaleFactor: ScaleFactor.X2); + graphics.DrawText(0, 100, "Red", Color.Red, scaleFactor: ScaleFactor.X2); + + graphics.Show(); + + Resolver.Log.Info("Run complete"); + + return Task.CompletedTask; + } + + // + } +} \ No newline at end of file diff --git a/Source/Meadow.Foundation.sln b/Source/Meadow.Foundation.sln index 7d69dddc4..d6fecd275 100644 --- a/Source/Meadow.Foundation.sln +++ b/Source/Meadow.Foundation.sln @@ -1629,6 +1629,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICs.IOExpanders.Ads1263", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ads1263_Sample", "Meadow.Foundation.Peripherals\ICs.IOExpanders.Ads1263\Samples\Ads1263_Sample\Ads1263_Sample.csproj", "{3A402704-9390-4492-93D4-B377BE8F034C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Epd2in15g_Sample", "Meadow.Foundation.Peripherals\Displays.ePaperWaveShare\Samples\Epd2in15g_Sample\Epd2in15g_Sample.csproj", "{EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -3937,6 +3939,12 @@ Global {3A402704-9390-4492-93D4-B377BE8F034C}.Release|Any CPU.ActiveCfg = Release|Any CPU {3A402704-9390-4492-93D4-B377BE8F034C}.Release|Any CPU.Build.0 = Release|Any CPU {3A402704-9390-4492-93D4-B377BE8F034C}.Release|Any CPU.Deploy.0 = Release|Any CPU + {EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B}.Release|Any CPU.Build.0 = Release|Any CPU + {EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4748,6 +4756,7 @@ Global {BEAD51B2-CF51-4836-ACBA-0911841E00F6} = {6D5016B9-7BF5-4E9D-BBA4-A621BAE0E638} {B414A340-EA69-4CD3-AB8B-D0B3835527B2} = {6D5016B9-7BF5-4E9D-BBA4-A621BAE0E638} {3A402704-9390-4492-93D4-B377BE8F034C} = {BEAD51B2-CF51-4836-ACBA-0911841E00F6} + {EA8D8CA1-BB32-49D6-88CF-9EB50ABDC44B} = {7311794D-7D2F-47E8-A5B0-C216CBD64A13} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AF7CA16F-8C38-4546-87A2-5DAAF58A1520} From 31b5a878cd2e7391572f6e19bfa5ae94da4bbf16 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 12 Dec 2024 18:23:45 -0800 Subject: [PATCH 5/8] Cleanup --- .../Driver/Drivers/Epd2in15g.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs index 497b48c93..a9bd43b57 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs @@ -4,7 +4,6 @@ using Meadow.Foundation.Graphics.Buffers; using Meadow.Hardware; using Meadow.Peripherals.Displays; -using System; namespace Displays.ePaperWaveShare.Drivers { @@ -78,9 +77,7 @@ public Epd2in15g(ISpiBus spiBus, spiComms = new SpiCommunications(spiBus, chipSelectPort, DefaultSpiBusSpeed, DefaultSpiBusMode); - Console.WriteLine("Epd2in15g constructor"); imageBuffer = new BufferIndexed2(Width, Height); - Console.WriteLine("Epd2in15g constructor done"); //set the indexed colors imageBuffer.IndexedColors[0] = Color.Black; @@ -217,8 +214,6 @@ public void Clear() /// public void Show() { - Console.WriteLine("Show"); - var w = (Width % 4 == 0) ? (Width / 4) : (Width / 4 + 1); var h = Height; @@ -228,6 +223,11 @@ public void Show() for (int i = 0; i < w; i++) { SendData(PixelBuffer.Buffer[i + j * w]); + //SendData(0xFF); //all red 11 (3) + //SendData(0x00); //black 00 (0) + //SendData(0x01); //thin white thick black + //SendData(0x55);// 0101 0101 all white 01 (1) + //SendData(0xAA); // 1010 1010 all yellow 10 (2) } } From 992c9136f2ea3b0462b6926f9ed9d99d0ed36fe2 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 12 Dec 2024 18:24:03 -0800 Subject: [PATCH 6/8] Fix color distance calc with zeros --- .../Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs index 3caa04eb1..216124b4c 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/PixelBufferBase.cs @@ -527,6 +527,11 @@ public T Crop(int startX, int startY, int cropWidth, int cropHeight) /// The distance as a float public float GetColorDistance(Color color1, Color color2) { + if (color1 == color2) + { + return 0; + } + var rDeltaSquared = MathF.Pow(MathF.Abs(color1.R - color2.R), 2); var gDeltaSquared = MathF.Pow(MathF.Abs(color1.G - color2.G), 2); var bDeltaSquared = MathF.Pow(MathF.Abs(color1.B - color2.B), 2); From 4499ae6db93da33fdd3e39a4cadf316a4301377b Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 12 Dec 2024 18:29:54 -0800 Subject: [PATCH 7/8] Fix bit packing for 4 color ePaper displays --- .../Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs index 32720845c..da14db400 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferIndexed2.cs @@ -47,7 +47,7 @@ public BufferIndexed2() : base() { } public override void Fill(Color color) { byte colorValue = (byte)GetIndexForColor(color); - Buffer[0] = (byte)(colorValue << 2 | colorValue << 4 | colorValue << 6); + Buffer[0] = (byte)(colorValue | colorValue << 2 | colorValue << 4 | colorValue << 6); int arrayMidPoint = Buffer.Length / 2; int copyLength; @@ -121,7 +121,7 @@ public override void SetPixel(int x, int y, Color color) public void SetPixel(int x, int y, int colorIndex) { int byteIndex = (y * Width + x) >> 2; // divide by 4 to find the byte - int pixelOffset = (x & 0x03) << 1; // (x % 4)*2 bits offset + int pixelOffset = (3 - (x & 0x03)) << 1; // Reverse offset calculation // Clear current 2 bits Buffer[byteIndex] &= (byte)~(0x03 << pixelOffset); @@ -199,6 +199,7 @@ int GetIndexForColor(Color color) if (IndexedColors[i] != null) { double distance = GetColorDistance(color, IndexedColors[i]); + if (distance < shortestDistance) { shortestDistance = distance; From 5088b56a967894792d741f08ea544dfbb12160d8 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 12 Dec 2024 22:46:37 -0800 Subject: [PATCH 8/8] Cleanup --- .../Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs index a9bd43b57..a65b70227 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.ePaperWaveShare/Driver/Drivers/Epd2in15g.cs @@ -223,11 +223,6 @@ public void Show() for (int i = 0; i < w; i++) { SendData(PixelBuffer.Buffer[i + j * w]); - //SendData(0xFF); //all red 11 (3) - //SendData(0x00); //black 00 (0) - //SendData(0x01); //thin white thick black - //SendData(0x55);// 0101 0101 all white 01 (1) - //SendData(0xAA); // 1010 1010 all yellow 10 (2) } }