forked from DexterInd/GoPiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorcs.cs
More file actions
37 lines (32 loc) · 1.01 KB
/
Copy pathSensorcs.cs
File metadata and controls
37 lines (32 loc) · 1.01 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GoPiGo.Sensors
{
public abstract class Sensor<TSensorType> where TSensorType : class
{
protected readonly IGoPiGo Device;
protected readonly Pin Pin;
internal Sensor(IGoPiGo device, Pin pin, PinMode pinMode)
{
if (device == null) throw new ArgumentNullException(nameof(device));
device.PinMode(Pin, pinMode);
Device = device;
Pin = pin;
}
internal Sensor(IGoPiGo device, Pin pin)
{
if (device == null) throw new ArgumentNullException(nameof(device));
Device = device;
Pin = pin;
}
public SensorStatus CurrentState => (SensorStatus)Device.DigitalRead(Pin);
public TSensorType ChangeState(SensorStatus newState)
{
Device.DigitalWrite(Pin, (byte)newState);
return this as TSensorType;
}
}
}