-
Notifications
You must be signed in to change notification settings - Fork 598
/
Copy pathSegmentHelpers.cs
41 lines (37 loc) · 1.23 KB
/
SegmentHelpers.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.Collections.Generic;
using System.Device.Gpio;
using System.Linq;
using Iot.Device.Display;
namespace Display
{
internal static class SegmentHelpers
{
// Dictionary allows key-based lookup
private static readonly Dictionary<Segment, int> SegIndex = new Dictionary<Segment, int>()
{
{ Segment.Top, 0 },
{ Segment.TopRight, 1 },
{ Segment.BottomRight, 2 },
{ Segment.Bottom, 3 },
{ Segment.BottomLeft, 4 },
{ Segment.TopLeft, 5 },
{ Segment.Middle, 6 },
{ Segment.Dot, 7 }, // DP is required for each digit but set independently
};
public static ReadOnlySpan<PinValue> GetPinValuesFromSegment(Segment segments)
{
var pinValues = Enumerable.Repeat(PinValue.Low, 8).ToArray();
foreach (var kvp in SegIndex)
{
if (segments.HasFlag(kvp.Key))
{
pinValues[kvp.Value] = 1;
}
}
return pinValues;
}
}
}