Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions devices/ePaper/Buffers/FrameBuffer2BitPerPixel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Drawing;

using Iot.Device.EPaper.Enums;
using nanoFramework.UI;

namespace Iot.Device.EPaper.Buffers
{
Expand All @@ -15,7 +14,7 @@ namespace Iot.Device.EPaper.Buffers
/// </summary>
public sealed class FrameBuffer2BitPerPixel : IFrameBuffer
{
private System.Drawing.Point _startPoint;
private Point _startPoint;

/// <inheritdoc/>>
public int Height { get; }
Expand All @@ -24,7 +23,7 @@ public sealed class FrameBuffer2BitPerPixel : IFrameBuffer
public int Width { get; }

/// <inheritdoc/>
public System.Drawing.Point StartPoint
public Point StartPoint
{
get => _startPoint;
set
Expand Down Expand Up @@ -70,7 +69,7 @@ public byte this[int index]
}

/// <inheritdoc/>
public byte this[System.Drawing.Point point]
public byte this[Point point]
{
get => throw new NotSupportedException();
set => throw new NotSupportedException();
Expand Down Expand Up @@ -124,11 +123,11 @@ public void Clear(Color color)
/// <inheritdoc/>>
public void Fill(Color color)
{
Fill(new System.Drawing.Point(0, 0), Width, Height, color);
Fill(new Point(0, 0), Width, Height, color);
}

/// <inheritdoc/>
public void Fill(System.Drawing.Point start, int width, int height, Color color)
public void Fill(Point start, int width, int height, Color color)
{
if (!IsPointWithinFrameBuffer(start))
{
Expand Down Expand Up @@ -163,7 +162,7 @@ public void Fill(System.Drawing.Point start, int width, int height, Color color)
/// into a <see cref="Color"/> struct. We don't know what color <see cref="ColorBuffer"/>
/// represents in the actual display hardware.
/// </remarks>
public Color GetPixel(System.Drawing.Point point)
public Color GetPixel(Point point)
{
throw new InvalidOperationException();
}
Expand All @@ -173,8 +172,8 @@ public Color GetPixel(System.Drawing.Point point)
/// </summary>
/// <param name="point">The pixel position.</param>
/// <returns>True if pixel is a color other than black/white, otherwise; false.</returns>
/// <remarks>Make sure to consider the result of <see cref="IsBlackPixel(System.Drawing.Point)"/> as this is not enough on its own.</remarks>
public bool IsColoredPixel(System.Drawing.Point point)
/// <remarks>Make sure to consider the result of <see cref="IsBlackPixel(Point)"/> as this is not enough on its own.</remarks>
public bool IsColoredPixel(Point point)
{
return ColorBuffer.GetPixel(point) == Color.White; // white indicates the pixel value is 1 (on)
}
Expand All @@ -184,7 +183,7 @@ public bool IsColoredPixel(System.Drawing.Point point)
/// </summary>
/// <param name="point">The pixel position.</param>
/// <returns>True if pixel is black color, otherwise; false.</returns>
public bool IsBlackPixel(System.Drawing.Point point)
public bool IsBlackPixel(Point point)
{
return IsColoredPixel(point) == false
&& BlackBuffer.GetPixel(point) == Color.Black;
Expand All @@ -195,14 +194,14 @@ public bool IsBlackPixel(System.Drawing.Point point)
/// </summary>
/// <param name="point">The pixel position.</param>
/// <returns>True if pixel is white color, otherwise; false.</returns>
/// <remarks>Make sure to consider the result of <see cref="IsColoredPixel(System.Drawing.Point)"/> as this is not enough on its own.</remarks>
public bool IsWhitePixel(System.Drawing.Point point)
/// <remarks>Make sure to consider the result of <see cref="IsColoredPixel(Point)"/> as this is not enough on its own.</remarks>
public bool IsWhitePixel(Point point)
{
return IsBlackPixel(point) == false;
}

/// <inheritdoc/>
public void SetPixel(System.Drawing.Point point, Color pixelColor)
public void SetPixel(Point point, Color pixelColor)
{
if (!IsPointWithinFrameBuffer(point))
{
Expand Down Expand Up @@ -231,17 +230,17 @@ public void SetPixel(System.Drawing.Point point, Color pixelColor)
/// <inheritdoc/>>
public void WriteBuffer(IFrameBuffer buffer)
{
WriteBuffer(buffer, new System.Drawing.Point(0, 0));
WriteBuffer(buffer, new Point(0, 0));
}

/// <inheritdoc/>>
public void WriteBuffer(IFrameBuffer buffer, System.Drawing.Point destinationStart)
public void WriteBuffer(IFrameBuffer buffer, Point destinationStart)
{
WriteBuffer(buffer, new System.Drawing.Point(0, 0), new System.Drawing.Point(buffer.Width, buffer.Height), destinationStart);
WriteBuffer(buffer, new Point(0, 0), new Point(buffer.Width, buffer.Height), destinationStart);
}

/// <inheritdoc/>
public void WriteBuffer(IFrameBuffer buffer, System.Drawing.Point start, System.Drawing.Point end, System.Drawing.Point destinationStart)
public void WriteBuffer(IFrameBuffer buffer, Point start, Point end, Point destinationStart)
{
if (buffer is FrameBuffer1BitPerPixel buffer1bpp)
{
Expand All @@ -261,14 +260,14 @@ public void WriteBuffer(IFrameBuffer buffer, System.Drawing.Point start, System.
}

/// <inheritdoc/>
public bool IsPointWithinFrameBuffer(System.Drawing.Point point)
public bool IsPointWithinFrameBuffer(Point point)
{
return point.X >= StartPoint.X && point.X < (StartPoint.X + Width)
&& point.Y >= StartPoint.Y && point.Y < (StartPoint.Y + Height);
}

/// <inheritdoc/>>
public bool IsRangeWithinFrameBuffer(System.Drawing.Point start, System.Drawing.Point end)
public bool IsRangeWithinFrameBuffer(Point start, Point end)
{
return IsPointWithinFrameBuffer(start) && IsPointWithinFrameBuffer(end);
}
Expand Down
33 changes: 16 additions & 17 deletions devices/ePaper/Buffers/FrameBufferBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Drawing;

using Iot.Device.EPaper.Enums;
using nanoFramework.UI;

namespace Iot.Device.EPaper.Buffers
{
Expand Down Expand Up @@ -57,7 +56,7 @@ public virtual int BufferByteCount
public abstract ColorFormat ColorFormat { get; }

/// <inheritdoc/>
public virtual System.Drawing.Point StartPoint { get; set; }
public virtual Point StartPoint { get; set; }

/// <inheritdoc/>
public virtual int CurrentFramePage
Expand All @@ -79,7 +78,7 @@ public virtual byte this[int index]
}

/// <inheritdoc/>
public virtual byte this[System.Drawing.Point point]
public virtual byte this[Point point]
{
get => this[GetFrameBufferIndexForPoint(point)];
set
Expand Down Expand Up @@ -134,45 +133,45 @@ public void Clear()
/// <inheritdoc/>>
public void WriteBuffer(IFrameBuffer buffer)
{
WriteBuffer(buffer, new System.Drawing.Point(0, 0), new System.Drawing.Point(buffer.Width, buffer.Height), new System.Drawing.Point(0, 0));
WriteBuffer(buffer, new Point(0, 0), new Point(buffer.Width, buffer.Height), new Point(0, 0));
}

/// <inheritdoc/>>
public void WriteBuffer(IFrameBuffer buffer, System.Drawing.Point destinationStart)
public void WriteBuffer(IFrameBuffer buffer, Point destinationStart)
{
WriteBuffer(buffer, new System.Drawing.Point(0, 0), new System.Drawing.Point(buffer.Width, buffer.Height), destinationStart);
WriteBuffer(buffer, new Point(0, 0), new Point(buffer.Width, buffer.Height), destinationStart);
}

/// <inheritdoc/>>
public virtual void WriteBuffer(IFrameBuffer buffer, System.Drawing.Point start, System.Drawing.Point end, System.Drawing.Point destinationStart)
public virtual void WriteBuffer(IFrameBuffer buffer, Point start, Point end, Point destinationStart)
{
WriteBufferSlow(buffer, start, end, destinationStart);
}

/// <inheritdoc/>>
public void Fill(Color color)
{
Fill(new System.Drawing.Point(0, 0), Width, Height, color);
Fill(new Point(0, 0), Width, Height, color);
}

/// <inheritdoc/>>
public abstract void Fill(System.Drawing.Point start, int width, int height, Color color);
public abstract void Fill(Point start, int width, int height, Color color);

/// <inheritdoc/>>
public abstract Color GetPixel(System.Drawing.Point point);
public abstract Color GetPixel(Point point);

/// <inheritdoc/>>
public abstract void SetPixel(System.Drawing.Point point, Color pixelColor);
public abstract void SetPixel(Point point, Color pixelColor);

/// <inheritdoc/>>
public virtual bool IsPointWithinFrameBuffer(System.Drawing.Point point)
public virtual bool IsPointWithinFrameBuffer(Point point)
{
return point.X >= StartPoint.X && point.X < (StartPoint.X + Width)
&& point.Y >= StartPoint.Y && point.Y < (StartPoint.Y + Height);
}

/// <inheritdoc/>>
public virtual bool IsRangeWithinFrameBuffer(System.Drawing.Point start, System.Drawing.Point end)
public virtual bool IsRangeWithinFrameBuffer(Point start, Point end)
{
return IsPointWithinFrameBuffer(start) && IsPointWithinFrameBuffer(end);
}
Expand All @@ -182,7 +181,7 @@ public virtual bool IsRangeWithinFrameBuffer(System.Drawing.Point start, System.
/// </summary>
/// <param name="point">The point to get its index within <see cref="Buffer"/>.</param>
/// <returns>The index within the <see cref="Buffer"/> for the byte that contains the specified pixe location.</returns>
protected int GetFrameBufferIndexForPoint(System.Drawing.Point point)
protected int GetFrameBufferIndexForPoint(Point point)
{
return GetFrameBufferIndexForPoint(point.X, point.Y);
}
Expand All @@ -203,7 +202,7 @@ protected int GetFrameBufferIndexForPoint(int x, int y)
/// </summary>
/// <param name="point">The point within the frame buffer.</param>
/// <returns>A byte mask pattern with the pixel bit flipped to 1.</returns>
protected byte GetPointByteMask(System.Drawing.Point point)
protected byte GetPointByteMask(Point point)
{
return (byte)(128 >> (point.X & 7));
}
Expand All @@ -216,13 +215,13 @@ protected byte GetPointByteMask(System.Drawing.Point point)
/// <param name="start">The starting point to copy from and write to.</param>
/// <param name="end">The point at which copying from the buffer will stop.</param>
/// <param name="destinationStart">The start point to begin writing to.</param>
protected virtual void WriteBufferSlow(IFrameBuffer buffer, System.Drawing.Point start, System.Drawing.Point end, System.Drawing.Point destinationStart)
protected virtual void WriteBufferSlow(IFrameBuffer buffer, Point start, Point end, Point destinationStart)
{
for (var x = start.X; x < buffer.Width; x++)
{
for (var y = start.Y; y < buffer.Height; y++)
{
var currentPoint = new System.Drawing.Point(x, y);
var currentPoint = new Point(x, y);
SetPixel(currentPoint, buffer.GetPixel(currentPoint));
}
}
Expand Down
19 changes: 9 additions & 10 deletions devices/ePaper/Buffers/IFrameBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Drawing;

using Iot.Device.EPaper.Enums;
using nanoFramework.UI;

namespace Iot.Device.EPaper.Buffers
{
Expand All @@ -26,7 +25,7 @@ public interface IFrameBuffer
/// <summary>
/// Gets or sets the position from which this frame's area starts.
/// </summary>
System.Drawing.Point StartPoint { get; set; }
Point StartPoint { get; set; }

/// <summary>
/// Gets or sets the current frame page index which this frame instance is covering.
Expand Down Expand Up @@ -65,21 +64,21 @@ public interface IFrameBuffer
/// </summary>
/// <param name="point">The point to get the byte containing the pixel.</param>
/// <returns>A byte that contains the pixel specified by the point.</returns>
byte this[System.Drawing.Point point] { get; set; }
byte this[Point point] { get; set; }

/// <summary>
/// Gets the pixel at the specified position.
/// </summary>
/// <param name="point">The position to get the pixel from.</param>
/// <returns><see cref="Color"/> representing the specified pixel.</returns>
Color GetPixel(System.Drawing.Point point);
Color GetPixel(Point point);

/// <summary>
/// Sets the value of the pixel at the specified position.
/// </summary>
/// <param name="point">The position to set the pixel.</param>
/// <param name="pixelColor">The pixel color value to use.</param>
void SetPixel(System.Drawing.Point point, Color pixelColor);
void SetPixel(Point point, Color pixelColor);

/// <summary>
/// Fill the entire frame buffer using the specified color.
Expand All @@ -94,7 +93,7 @@ public interface IFrameBuffer
/// <param name="width">The width of the area.</param>
/// <param name="height">The height of the area.</param>
/// <param name="color">The color value to use.</param>
void Fill(System.Drawing.Point start, int width, int height, Color color);
void Fill(Point start, int width, int height, Color color);

/// <summary>
/// Copies the entire specified <see cref="IFrameBuffer"/> into the current frame buffer.
Expand All @@ -107,7 +106,7 @@ public interface IFrameBuffer
/// </summary>
/// <param name="buffer">The <see cref="IFrameBuffer" /> to copy from.</param>
/// <param name="destinationStart">The start point to begin writing to.</param>
void WriteBuffer(IFrameBuffer buffer, System.Drawing.Point destinationStart);
void WriteBuffer(IFrameBuffer buffer, Point destinationStart);

/// <summary>
/// Copies the specified <see cref="IFrameBuffer"/> into the current frame buffer.
Expand All @@ -116,7 +115,7 @@ public interface IFrameBuffer
/// <param name="start">The start position to copy from.</param>
/// <param name="end">The point at which copying from the buffer will stop.</param>
/// <param name="destinationStart">The start point to begin writing to.</param>
void WriteBuffer(IFrameBuffer buffer, System.Drawing.Point start, System.Drawing.Point end, System.Drawing.Point destinationStart);
void WriteBuffer(IFrameBuffer buffer, Point start, Point end, Point destinationStart);

/// <summary>
/// Resets the current frame buffer to its default starting values (all pixels set to 0).
Expand All @@ -134,14 +133,14 @@ public interface IFrameBuffer
/// </summary>
/// <param name="point">The point to check.</param>
/// <returns>True if the point is within this frame's area, otherwise; false.</returns>
bool IsPointWithinFrameBuffer(System.Drawing.Point point);
bool IsPointWithinFrameBuffer(Point point);

/// <summary>
/// Checks if the specified range of points is within the current frame buffer.
/// </summary>
/// <param name="start">The starting point of the range.</param>
/// <param name="end">The end point of the range.</param>
/// <returns>True if the range is within this frame's area, otherwise; false.</returns>
bool IsRangeWithinFrameBuffer(System.Drawing.Point start, System.Drawing.Point end);
bool IsRangeWithinFrameBuffer(Point start, Point end);
}
}
16 changes: 11 additions & 5 deletions devices/ePaper/Drivers/IePaperDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Drawing;

using System.Threading;
using Iot.Device.EPaper.Buffers;
using nanoFramework.UI;

Expand Down Expand Up @@ -55,12 +55,14 @@ public interface IEPaperDisplay : IDisposable
/// <summary>
/// Initiates the full refresh sequence on the display.
/// </summary>
void PerformFullRefresh();
/// <returns>True if the screen sucessfully refresh. False otherwise (still busy after a predefined waiting time).</returns>
bool PerformFullRefresh();

/// <summary>
/// Initiates the partial refresh sequence on the display if the panel supports it.
/// </summary>
void PerformPartialRefresh();
/// <returns>True if the screen sucessfully refresh. False otherwise (still busy after a predefined waiting time).</returns>
bool PerformPartialRefresh();

/// <summary>
/// Sets the drawing position on the display.
Expand Down Expand Up @@ -92,7 +94,11 @@ public interface IEPaperDisplay : IDisposable
/// <summary>
/// Blocks the current thread until the display is in idle mode again.
/// </summary>
void WaitReady();
/// <param name="waitingTime">The maximum time to wait in ms before exiting the method. -1 to wait infinitely.</param>
/// <param name="cancellationToken">The <see cref="CancellationTokenSource"/> to be able to cancel the waiting time.</param>
/// <returns>True if it returns before the <see cref="CancellationTokenSource"/> expires, false otherwise.</returns>
/// <remarks>If _waitingTime_ is set to -1, _cancellationToken_ could not be null, and a exception will be throw.</remarks>
bool WaitReady(int waitingTime, CancellationTokenSource cancellationToken);

/// <summary>
/// Begins a frame draw operation with frame paging support.
Expand All @@ -109,7 +115,7 @@ public interface IEPaperDisplay : IDisposable
/// <summary>
/// Moves the current buffers to the next frame page and returns true if successful.
/// </summary>
/// <returns>True if the next frame page is available and the internal buffers have moved to it, otherwise; false.</returns>
/// <returns>True if the next frame page is available and the internal buffers have moved to it, false otherwise.</returns>
bool NextFramePage();

/// <summary>
Expand Down
Loading