Skip to content

Commit

Permalink
Added Ssd1306 Device Binding (#188)
Browse files Browse the repository at this point in the history
* Initial check in of Ssd1306 binding

* Reference projects

* Added SPI/I2C logic

* Correction for SendData

* Updated links

* Initial check in of Ssd1306 binding

* Reference projects

* Added SPI/I2C logic

* Correction for SendData

* Updated links

* Added spacing

* Added validation to arguments

* Removed old command structure

* Removed unneeded info in proj file

* Removed SPI and added sample

* Add image link

* Consolidate compile files

* Simplified Control byte update

* Changed Value to Id

* Removed unneeded validation and tests

* Updated ranges

* Removed unused usings

* Updated tests to Facts where needed

* Removed continuation bit for better separation

* Added summaries

* Relocated enums

* Added connection type checklist

* Updated based on feedback

* Added basic font

* Added sample to get IP address

* Added range helper

* Add checks based on feedback

* Added check and exception

* Added device to binding list
  • Loading branch information
shaggygi authored and joperezr committed Feb 14, 2019
1 parent 353df03 commit e952939
Show file tree
Hide file tree
Showing 68 changed files with 2,817 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/devices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Our vision: the majority of .NET bindings are written completely in .NET languag
* [Servo -- Servomotor Controller](Servo/README.md)
* [Si7021 -- Temperature & Humidity Sensor](Si7021/README.md)
* [SoftPwm -- Software PWM](SoftPwm/README.md)
* [Ssd1306 -- OLED Display Controller](Ssd1306/README.md)

## Binding Distribution

Expand Down
33 changes: 33 additions & 0 deletions src/devices/Ssd1306/Command/ActivateScroll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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()
{
}

/// <summary>
/// The value that represents the command.
/// </summary>
public byte Id => 0x2F;

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
public byte[] GetBytes()
{
return new byte[] { Id };
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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)
{
if (verticalScrollingOffset > 0x3F)
{
throw new ArgumentException("The vertical scrolling offset is invalid.", nameof(verticalScrollingOffset));
}

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

/// <summary>
/// The value that represents the command.
/// </summary>
public byte Id => (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; }

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
public byte[] GetBytes()
{
return new byte[] { Id, 0x00, (byte)StartPageAddress, (byte)FrameFrequencyType, (byte)EndPageAddress, VerticalScrollingOffset };
}

public enum VerticalHorizontalScrollType
{
/// <summary>
/// Vertical and right horizontal scroll.
/// </summary>
Right = 0x29,
/// <summary>
/// Vertical and left horizontal scroll.
/// </summary>
Left = 0x2A
}
}
}
31 changes: 31 additions & 0 deletions src/devices/Ssd1306/Command/DeactivateScroll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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()
{
}

/// <summary>
/// The value that represents the command.
/// </summary>
public byte Id => 0x2E;

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
public byte[] GetBytes()
{
return new byte[] { Id };
}
}
}
37 changes: 37 additions & 0 deletions src/devices/Ssd1306/Command/EntireDisplayOn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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;
}

/// <summary>
/// The value that represents the command.
/// </summary>
public byte Id => (byte)(EntireDisplay ? 0xA5 : 0xA4);

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

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
public byte[] GetBytes()
{
return new byte[] { Id };
}
}
}
87 changes: 87 additions & 0 deletions src/devices/Ssd1306/Command/HorizontalScrollSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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
}

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)
{
ScrollType = scrollType;
StartPageAddress = startPageAddress;
FrameFrequencyType = frameFrequencyType;
EndPageAddress = endPageAddress;
}

/// <summary>
/// The value that represents the command.
/// </summary>
public byte Id => (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; }

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
public byte[] GetBytes()
{
return new byte[] { Id, 0x00, (byte)StartPageAddress, (byte)FrameFrequencyType, (byte)EndPageAddress, 0x00, 0xFF };
}

public enum HorizontalScrollType
{
/// <summary>
/// Right horizontal scroll.
/// </summary>
Right = 0x26,
/// <summary>
/// Left horizontal scroll.
/// </summary>
Left = 0x27
}
}
}
20 changes: 20 additions & 0 deletions src/devices/Ssd1306/Command/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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
{
/// <summary>
/// The value that represents the command.
/// </summary>
byte Id { get; }

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
byte[] GetBytes();
}
}
30 changes: 30 additions & 0 deletions src/devices/Ssd1306/Command/NoOperation.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 NoOperation : ICommand
{
/// <summary>
/// This command is a no operation command.
/// </summary>
public NoOperation()
{
}

/// <summary>
/// The value that represents the command.
/// </summary>
public byte Id => 0xE3;

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
public byte[] GetBytes()
{
return new byte[] { Id };
}
}
}
44 changes: 44 additions & 0 deletions src/devices/Ssd1306/Command/SetChargePump.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 SetChargePump : ICommand
{
/// <summary>
/// This command controls the switching capacitor regulator circuit.
/// </summary>
/// <param name="enableChargePump">Determines if charge pump is enabled while the display is on.</param>
public SetChargePump(bool enableChargePump = false)
{
EnableChargePump = enableChargePump;
}

/// <summary>
/// The value that represents the command.
/// </summary>
public byte Id => 0x8D;

/// <summary>
/// Determines if charge pump is enabled while the display is on.
/// </summary>
public bool EnableChargePump { get; }

/// <summary>
/// Gets the bytes that represent the command.
/// </summary>
/// <returns>The bytes that represent the command.</returns>
public byte[] GetBytes()
{
byte enableChargePump = 0x10;

if (EnableChargePump)
{
enableChargePump = 0x14;
}

return new byte[] { Id, enableChargePump };
}
}
}
Loading

0 comments on commit e952939

Please sign in to comment.