-
Notifications
You must be signed in to change notification settings - Fork 1
/
BH1750FVI.cs
58 lines (46 loc) · 1.29 KB
/
BH1750FVI.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Magellanic.I2C;
using System;
using System.Threading.Tasks;
namespace Magellanic.Sensors.BH1750FVI
{
public class BH1750FVI : AbstractI2CDevice
{
private byte I2C_ADDRESS;
public BH1750FVI(AddPinConnection pinConnection)
{
I2C_ADDRESS = (byte)pinConnection;
}
public override byte[] GetDeviceId()
{
throw new NotImplementedException();
}
public override byte GetI2cAddress()
{
return I2C_ADDRESS;
}
public int GetLightLevel()
{
var readBuffer = new byte[2];
this.Slave.WriteRead(new byte[] { I2C_ADDRESS }, readBuffer);
var lightLevel = readBuffer[0] << 8 | readBuffer[1];
return (int)(lightLevel / 1.2f);
}
public void PowerOff()
{
this.Slave.Write(new byte[] { 0x00 });
}
public void PowerOn()
{
this.Slave.Write(new byte[] { 0x01 });
}
public void Reset()
{
this.Slave.Write(new byte[] { 0x07 });
}
public void SetMode(MeasurementMode measurementMode)
{
this.Slave.Write(new byte[] { (byte)measurementMode });
Task.Delay(10).Wait();
}
}
}