-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathSeesawTouch.cs
29 lines (26 loc) · 1.13 KB
/
SeesawTouch.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
// 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.Buffers.Binary;
namespace Iot.Device.Seesaw
{
/// <summary>
/// The Seesaw Touch class.
/// </summary>
public partial class Seesaw : IDisposable
{
/// <summary>
/// Reads the analog value on an capacitive touch-enabled pin.
/// </summary>
/// <param name="pinId">The number of the pin to read.</param>
/// <returns>An analogue value betweeen 0 and 1023 that represents the capacitance read from the pin.</returns>
public ushort TouchRead(byte pinId)
{
if (!HasModule(SeesawModule.Touch))
{
throw new InvalidOperationException($"The hardware on I2C Bus {I2cDevice.ConnectionSettings.BusId}, Address 0x{I2cDevice.ConnectionSettings.DeviceAddress:X2} does not support Adafruit SeeSaw touch functionality");
}
return BinaryPrimitives.ReadUInt16BigEndian(Read(SeesawModule.Touch, SeesawFunction.TouchChannelOffset + pinId, 2, 1000));
}
}
}