-
Notifications
You must be signed in to change notification settings - Fork 593
/
Copy pathWs28xx.cs
41 lines (36 loc) · 1.31 KB
/
Ws28xx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Device.Spi;
using Iot.Device.Graphics;
namespace Iot.Device.Ws28xx
{
/// <summary>
/// Represents base class for WS28XX LED drivers (i.e. WS2812B or WS2808)
/// </summary>
public class Ws28xx
{
/// <summary>
/// SPI device used for communication with the LED driver
/// </summary>
protected readonly SpiDevice _spiDevice;
/// <summary>
/// Backing image to be updated on the driver
/// </summary>
public RawPixelContainer Image { get; }
/// <summary>
/// Constructs Ws28xx instance
/// </summary>
/// <param name="spiDevice">SPI device used for communication with the LED driver.</param>
/// <param name="image">The bitmap that represents the screen or led strip.</param>
public Ws28xx(SpiDevice spiDevice, RawPixelContainer image)
{
_spiDevice = spiDevice ?? throw new ArgumentNullException(nameof(spiDevice));
Image = image;
}
/// <summary>
/// Sends backing image to the LED driver
/// </summary>
public void Update() => _spiDevice.Write(Image.Data);
}
}