File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Raspberry.IO.Components/Sensors/Light Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ using Raspberry . IO . InterIntegratedCircuit ;
2
+ using Raspberry . Timers ;
3
+ using System ;
4
+ using System . Collections . Generic ;
5
+ using System . Linq ;
6
+ using System . Text ;
7
+
8
+ namespace Raspberry . IO . Components . Sensors . Light
9
+ {
10
+ namespace RPI . Sensor . Sensors . Light
11
+ {
12
+ public class BH1750Connection
13
+ {
14
+ public I2cDeviceConnection Connection { get ; set ; }
15
+ public BH1750Connection ( I2cDeviceConnection connection )
16
+ {
17
+ Connection = connection ;
18
+ }
19
+
20
+ public void SetOff ( )
21
+ {
22
+ Connection . Write ( 0x00 ) ;
23
+ }
24
+ public void SetOn ( )
25
+ {
26
+ Connection . Write ( 0x01 ) ;
27
+ }
28
+ public void Reset ( )
29
+ {
30
+ Connection . Write ( 0x07 ) ;
31
+ }
32
+
33
+ public double GetData ( )
34
+ {
35
+ Connection . Write ( 0x10 ) ;
36
+ HighResolutionTimer . Sleep ( TimeSpanUtility . FromMicroseconds ( 150 * 1000 ) ) ;
37
+ byte [ ] readBuf = Connection . Read ( 2 ) ;
38
+
39
+ var valf = readBuf [ 0 ] << 8 ;
40
+ valf |= readBuf [ 1 ] ;
41
+ return valf / 1.2 * ( 69 / 69 ) / 1 ;
42
+
43
+ // var valf = ((readBuf[0] << 8) | readBuf[1]) / 1.2;
44
+ // return valf;
45
+
46
+ // return Math.Round(valf / (2 * 1.2), 2);
47
+
48
+ }
49
+
50
+ }
51
+ }
52
+
53
+ }
You can’t perform that action at this time.
0 commit comments