Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Ssd1306 Device Binding #188

Merged
merged 36 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6f5f9cb
Initial check in of Ssd1306 binding
shaggygi Dec 29, 2018
8f8aa00
Reference projects
shaggygi Dec 29, 2018
4bdcb47
Added SPI/I2C logic
shaggygi Dec 30, 2018
7bdf83d
Correction for SendData
shaggygi Dec 30, 2018
86196cc
Updated links
shaggygi Dec 31, 2018
1651261
Initial check in of Ssd1306 binding
shaggygi Dec 29, 2018
1e00d7d
Reference projects
shaggygi Dec 29, 2018
672e471
Added SPI/I2C logic
shaggygi Dec 30, 2018
b39ce39
Correction for SendData
shaggygi Dec 30, 2018
b1d890e
Updated links
shaggygi Dec 31, 2018
144dd11
Merge branch 'Ssd1306-device-binding' of https://github.com/shaggygi/…
shaggygi Dec 31, 2018
1d1481e
Added spacing
shaggygi Dec 31, 2018
55937d5
Added validation to arguments
shaggygi Jan 21, 2019
e35feac
Removed old command structure
shaggygi Jan 24, 2019
d6544d4
Removed unneeded info in proj file
shaggygi Jan 31, 2019
9a044d2
Removed SPI and added sample
shaggygi Feb 1, 2019
c0c7a78
Add image link
shaggygi Feb 1, 2019
0ccc3f8
Consolidate compile files
shaggygi Feb 1, 2019
5b32555
Simplified Control byte update
shaggygi Feb 1, 2019
b1b0a02
Changed Value to Id
shaggygi Feb 1, 2019
7efda48
Removed unneeded validation and tests
shaggygi Feb 1, 2019
8d37132
Updated ranges
shaggygi Feb 1, 2019
fe7d8ea
Removed unused usings
shaggygi Feb 1, 2019
6ca1d13
Updated tests to Facts where needed
shaggygi Feb 1, 2019
0de48cb
Removed continuation bit for better separation
shaggygi Feb 2, 2019
42b528b
Added summaries
shaggygi Feb 2, 2019
d7701a2
Relocated enums
shaggygi Feb 4, 2019
0241283
Added connection type checklist
shaggygi Feb 4, 2019
6cad88e
Updated based on feedback
shaggygi Feb 8, 2019
30cb5e8
Added basic font
shaggygi Feb 10, 2019
282b5e1
Added sample to get IP address
shaggygi Feb 11, 2019
0d95705
Added range helper
shaggygi Feb 12, 2019
8e43f1c
Add checks based on feedback
shaggygi Feb 12, 2019
a867380
Added check and exception
shaggygi Feb 13, 2019
be6c474
Added device to binding list
shaggygi Feb 13, 2019
5891001
Merge branch 'master' into Ssd1306-device-binding
shaggygi Feb 13, 2019
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
26 changes: 26 additions & 0 deletions src/devices/Ssd1306/Command/ActivateScroll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Iot.Device.Ssd1306.Command
{
public class ActivateScroll : ICommand
{
/// <summary>
/// This command starts the motion of scrolling and should only be issued
/// after the scroll setup parameters have been defined by the scrolling
/// setup commands :26h/27h/29h/2Ah. The setting in the last scrolling setup
/// command overwrites the setting in the previous scrolling setup commands.
/// </summary>
public ActivateScroll()
{
}

public byte Value => 0x2F;

public byte[] GetBytes()
{
return new byte[] { Value };
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Iot.Device.Ssd1306.Command
{
public class ContinuousVerticalAndHorizontalScrollSetup : ICommand
{
/// <summary>
/// This command consists of 6 consecutive bytes to set up the continuous vertical
/// scroll parameters and determines the scrolling start page, end page, scrolling
/// speed and vertical scrolling offset.
/// </summary>
/// <param name="scrollType">Vertical/Horizontal scroll type.</param>
/// <param name="startPageAddress">Start page address with a range of 0-7.</param>
/// <param name="frameFrequencyType">Frame frequency type with a range of 0-7.</param>
/// <param name="endPageAddress">End page address with a range of 0-7.</param>
/// <param name="verticalScrollingOffset">Vertical scrolling offset with a range of 0-63.</param>
public ContinuousVerticalAndHorizontalScrollSetup(
VerticalHorizontalScrollType scrollType,
PageAddress startPageAddress,
FrameFrequencyType frameFrequencyType,
PageAddress endPageAddress,
byte verticalScrollingOffset)
{
switch (scrollType)
{
case VerticalHorizontalScrollType.Right:
case VerticalHorizontalScrollType.Left:
break;
default:
throw new ArgumentException("The vertical/horizontal scroll type is invalid.", nameof(scrollType));
}

switch (startPageAddress)
{
case PageAddress.Page0:
case PageAddress.Page1:
case PageAddress.Page2:
case PageAddress.Page3:
case PageAddress.Page4:
case PageAddress.Page5:
case PageAddress.Page6:
case PageAddress.Page7:
break;
default:
throw new ArgumentException("The start page address is invalid.", nameof(startPageAddress));
}

switch (frameFrequencyType)
{
case FrameFrequencyType.Frames5:
case FrameFrequencyType.Frames64:
case FrameFrequencyType.Frames128:
case FrameFrequencyType.Frames256:
case FrameFrequencyType.Frames3:
case FrameFrequencyType.Frames4:
case FrameFrequencyType.Frames25:
case FrameFrequencyType.Frames2:
break;
default:
throw new ArgumentException("The frame frequency type is invalid.", nameof(frameFrequencyType));
}

switch (endPageAddress)
{
case PageAddress.Page0:
case PageAddress.Page1:
case PageAddress.Page2:
case PageAddress.Page3:
case PageAddress.Page4:
case PageAddress.Page5:
case PageAddress.Page6:
case PageAddress.Page7:
break;
default:
throw new ArgumentException("The end page address is invalid.", nameof(endPageAddress));
}

if (verticalScrollingOffset > 0x3F)
{
throw new ArgumentException("The vertical scrolling offset is invalid.", nameof(verticalScrollingOffset));
}

ScrollType = scrollType;
StartPageAddress = startPageAddress;
FrameFrequencyType = frameFrequencyType;
EndPageAddress = endPageAddress;
VerticalScrollingOffset = verticalScrollingOffset;
}

public byte Value => (byte)ScrollType;

/// <summary>
/// Vertical/Horizontal scroll type.
/// </summary>
public VerticalHorizontalScrollType ScrollType { get; }

/// <summary>
/// Start page address with a range of 0-7.
/// </summary>
public PageAddress StartPageAddress { get; }

/// <summary>
/// Frame frequency type with a range of 0-7.
/// </summary>
public FrameFrequencyType FrameFrequencyType { get; }

/// <summary>
/// End page address with a range of 0-7.
/// </summary>
public PageAddress EndPageAddress { get; }

/// <summary>
/// Vertical scrolling offset with a range of 0-63.
/// </summary>
public byte VerticalScrollingOffset { get; }

public byte[] GetBytes()
{
return new byte[] { Value, 0x00, (byte)StartPageAddress, (byte)FrameFrequencyType, (byte)EndPageAddress, VerticalScrollingOffset };
}

public enum VerticalHorizontalScrollType
{
Right = 0x29,
Left = 0x2A
}
}
}
24 changes: 24 additions & 0 deletions src/devices/Ssd1306/Command/DeactivateScroll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Iot.Device.Ssd1306.Command
{
public class DeactivateScroll : ICommand
{
/// <summary>
/// This command stops the motion of scrolling. After sending 2Eh command to deactivate
/// the scrolling action, the ram data needs to be rewritten.
/// </summary>
public DeactivateScroll()
{
}

public byte Value => 0x2E;

public byte[] GetBytes()
{
return new byte[] { Value };
}
}
}
30 changes: 30 additions & 0 deletions src/devices/Ssd1306/Command/EntireDisplayOn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Iot.Device.Ssd1306.Command
{
public class EntireDisplayOn : ICommand
{
/// <summary>
/// This command turns the entire display on or off.
/// </summary>
/// <param name="entireDisplay">Resume to RAM content display when FALSE and turns entire dislay on when TRUE.</param>
public EntireDisplayOn(bool entireDisplay)
{
EntireDisplay = entireDisplay;
}

public byte Value => (byte)(EntireDisplay ? 0xA5 : 0xA4);

/// <summary>
/// Resume to RAM content display when FALSE and turns entire dislay on when TRUE.
/// </summary>
public bool EntireDisplay { get; }

public byte[] GetBytes()
{
return new byte[] { Value };
}
}
}
18 changes: 18 additions & 0 deletions src/devices/Ssd1306/Command/FrameFrequencyType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Iot.Device.Ssd1306.Command
{
public enum FrameFrequencyType
{
Frames2 = 0x07,
Frames3 = 0x04,
Frames4 = 0x05,
Frames5 = 0x00,
Frames25 = 0x06,
Frames64 = 0x01,
Frames128 = 0x02,
Frames256 = 0x03
}
}
118 changes: 118 additions & 0 deletions src/devices/Ssd1306/Command/HorizontalScrollSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Iot.Device.Ssd1306.Command
{
public class HorizontalScrollSetup : ICommand
{
/// <summary>
/// This command consists of consecutive bytes to set up the horizontal scroll parameters
/// and determines the scrolling start page, end page and scrolling speed.
/// </summary>
/// <param name="scrollType">Horizontal scroll type.</param>
/// <param name="startPageAddress">Start page address with a range of 0-7.</param>
/// <param name="frameFrequencyType">Frame frequency type with a range of 0-7.</param>
/// <param name="endPageAddress">End page address with a range of 0-7.</param>
public HorizontalScrollSetup(
HorizontalScrollType scrollType,
PageAddress startPageAddress,
FrameFrequencyType frameFrequencyType,
PageAddress endPageAddress)
{
switch (scrollType)
{
case HorizontalScrollType.Right:
case HorizontalScrollType.Left:
break;
default:
throw new ArgumentException("The horizontal scroll type is invalid.", nameof(scrollType));
}

switch (startPageAddress)
{
case PageAddress.Page0:
case PageAddress.Page1:
case PageAddress.Page2:
case PageAddress.Page3:
case PageAddress.Page4:
case PageAddress.Page5:
case PageAddress.Page6:
case PageAddress.Page7:
break;
default:
throw new ArgumentException("The start page address is invalid.", nameof(startPageAddress));
}

switch (frameFrequencyType)
{
case FrameFrequencyType.Frames5:
case FrameFrequencyType.Frames64:
case FrameFrequencyType.Frames128:
case FrameFrequencyType.Frames256:
case FrameFrequencyType.Frames3:
case FrameFrequencyType.Frames4:
case FrameFrequencyType.Frames25:
case FrameFrequencyType.Frames2:
break;
default:
throw new ArgumentException("The frame frequency type is invalid.", nameof(frameFrequencyType));
}

switch (endPageAddress)
{
case PageAddress.Page0:
case PageAddress.Page1:
case PageAddress.Page2:
case PageAddress.Page3:
case PageAddress.Page4:
case PageAddress.Page5:
case PageAddress.Page6:
case PageAddress.Page7:
break;
default:
throw new ArgumentException("The end page address is invalid.", nameof(endPageAddress));
}

ScrollType = scrollType;
StartPageAddress = startPageAddress;
FrameFrequencyType = frameFrequencyType;
EndPageAddress = endPageAddress;
}

public byte Value => (byte)ScrollType;

/// <summary>
/// Horizontal scroll type.
/// </summary>
public HorizontalScrollType ScrollType { get; }

/// <summary>
/// Start page address with a range of 0-7.
/// </summary>
public PageAddress StartPageAddress { get; }

/// <summary>
/// Frame frequency type with a range of 0-7.
/// </summary>
public FrameFrequencyType FrameFrequencyType { get; }

/// <summary>
/// End page address with a range of 0-7.
/// </summary>
public PageAddress EndPageAddress { get; }

public byte[] GetBytes()
{
return new byte[] { Value, 0x00, (byte)StartPageAddress, (byte)FrameFrequencyType, (byte)EndPageAddress, 0x00, 0xFF };
}

public enum HorizontalScrollType
{
Right = 0x26,
Left = 0x27
}
}
}
13 changes: 13 additions & 0 deletions src/devices/Ssd1306/Command/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Iot.Device.Ssd1306.Command
{
public interface ICommand
{
byte Value { get; }

byte[] GetBytes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do end up changing the way we get the bytes of the command in order to use Span and cheaper operations, we should probably expose the Length of bytes from this interface as well.

}
}
23 changes: 23 additions & 0 deletions src/devices/Ssd1306/Command/NoOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Iot.Device.Ssd1306.Command
{
public class NoOperation : ICommand
{
/// <summary>
/// This command is a no operation command.
/// </summary>
public NoOperation()
{
}

public byte Value => 0xE3;

public byte[] GetBytes()
{
return new byte[] { Value };
}
}
}
Loading