Skip to content

add BH1750 Sensor #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Raspberry.IO.Components/Sensors/Light/BH1750Connection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Raspberry.IO.InterIntegratedCircuit;
using Raspberry.Timers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Raspberry.IO.Components.Sensors.Light
{
namespace RPI.Sensor.Sensors.Light
{
public class BH1750Connection
{
public I2cDeviceConnection Connection { get; set; }
public BH1750Connection(I2cDeviceConnection connection)
{
Connection = connection;
}

public void SetOff()
{
Connection.Write(0x00);
}
public void SetOn()
{
Connection.Write(0x01);
}
public void Reset()
{
Connection.Write(0x07);
}

public double GetData()
{
Connection.Write(0x10);
HighResolutionTimer.Sleep(TimeSpanUtility.FromMicroseconds(150 * 1000));
byte[] readBuf = Connection.Read(2);

var valf = readBuf[0] << 8;
valf |= readBuf[1];
return valf / 1.2 * (69 / 69) / 1;

// var valf = ((readBuf[0] << 8) | readBuf[1]) / 1.2;
// return valf;

// return Math.Round(valf / (2 * 1.2), 2);

}

}
}

}