1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +01:00

lowercase package name

This commit is contained in:
Karan Misra 2013-12-21 01:52:36 +05:30
parent 2cda6f6f71
commit c8d703cbdf
2 changed files with 18 additions and 18 deletions

View File

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/kid0m4n/go-rpi/i2c" "github.com/kid0m4n/go-rpi/i2c"
"github.com/kid0m4n/go-rpi/sensor/bh1750Fvi" "github.com/kid0m4n/go-rpi/sensor/bh1750fvi"
) )
func main() { func main() {
@ -14,7 +14,7 @@ func main() {
log.Panic(err) log.Panic(err)
} }
lightingSensor := bh1750Fvi.New(bh1750Fvi.High, bus) lightingSensor := bh1750fvi.New(bh1750fvi.High, bus)
defer lightingSensor.Close() defer lightingSensor.Close()
for { for {

View File

@ -1,5 +1,5 @@
// Package BH1750FVI allows interfacing with the BH1750FVI ambient light sensor through I2C protocol. // Package BH1750FVI allows interfacing with the BH1750FVI ambient light sensor through I2C protocol.
package bh1750Fvi package bh1750fvi
import ( import (
"log" "log"
@ -25,8 +25,8 @@ const (
pollDelay = 150 pollDelay = 150
) )
// A BH1750VI interface implements access to the sensor. // A BH1750FVI interface implements access to the sensor.
type BH1750VI interface { type BH1750FVI interface {
// Run starts continuous sensor data acquisition loop. // Run starts continuous sensor data acquisition loop.
Run() error Run() error
@ -40,7 +40,7 @@ type BH1750VI interface {
SetPollDelay(delay int) SetPollDelay(delay int)
} }
type bh1750vi struct { type bh1750fvi struct {
bus i2c.Bus bus i2c.Bus
mu *sync.RWMutex mu *sync.RWMutex
@ -61,31 +61,31 @@ var Default = New(High, i2c.Default)
// "H2" -> High resolution mode 2 (0.5lx), takes 120ms (only use for low light). // "H2" -> High resolution mode 2 (0.5lx), takes 120ms (only use for low light).
// New creates a new BH1750FVI interface according to the mode passed. // New creates a new BH1750FVI interface according to the mode passed.
func New(mode string, bus i2c.Bus) BH1750VI { func New(mode string, bus i2c.Bus) BH1750FVI {
switch mode { switch mode {
case High: case High:
return &bh1750vi{bus: bus, i2cAddr: sensorI2cAddr, operationCode: highResOpCode, mu: new(sync.RWMutex)} return &bh1750fvi{bus: bus, i2cAddr: sensorI2cAddr, operationCode: highResOpCode, mu: new(sync.RWMutex)}
case High2: case High2:
return &bh1750vi{bus: bus, i2cAddr: sensorI2cAddr, operationCode: highResMode2OpCode, mu: new(sync.RWMutex)} return &bh1750fvi{bus: bus, i2cAddr: sensorI2cAddr, operationCode: highResMode2OpCode, mu: new(sync.RWMutex)}
default: default:
return &bh1750vi{bus: bus, i2cAddr: sensorI2cAddr, operationCode: highResOpCode, mu: new(sync.RWMutex)} return &bh1750fvi{bus: bus, i2cAddr: sensorI2cAddr, operationCode: highResOpCode, mu: new(sync.RWMutex)}
} }
} }
// NewHighMode returns a BH1750FVI inteface on high resolution mode (1lx resolution) // NewHighMode returns a BH1750FVI inteface on high resolution mode (1lx resolution)
func NewHighMode(bus i2c.Bus) BH1750VI { func NewHighMode(bus i2c.Bus) BH1750FVI {
return New(High, bus) return New(High, bus)
} }
// NewHighMode returns a BH1750FVI inteface on high resolution mode2 (0.5lx resolution) // NewHighMode returns a BH1750FVI inteface on high resolution mode2 (0.5lx resolution)
func NewHigh2Mode(bus i2c.Bus) BH1750VI { func NewHigh2Mode(bus i2c.Bus) BH1750FVI {
return New(High2, bus) return New(High2, bus)
} }
func (d *bh1750vi) measureLighting() (lighting float64, err error) { func (d *bh1750fvi) measureLighting() (lighting float64, err error) {
err = d.bus.WriteByte(d.i2cAddr, d.operationCode) err = d.bus.WriteByte(d.i2cAddr, d.operationCode)
if err != nil { if err != nil {
log.Print("bh1750vi: Failed to initialize sensor") log.Print("bh1750fvi: Failed to initialize sensor")
return return
} }
time.Sleep(180 * time.Millisecond) time.Sleep(180 * time.Millisecond)
@ -100,7 +100,7 @@ func (d *bh1750vi) measureLighting() (lighting float64, err error) {
} }
// Lighting returns the ambient lighting in lx. // Lighting returns the ambient lighting in lx.
func (d *bh1750vi) Lighting() (lighting float64, err error) { func (d *bh1750fvi) Lighting() (lighting float64, err error) {
select { select {
case lighting = <-d.lightingReadings: case lighting = <-d.lightingReadings:
return return
@ -110,7 +110,7 @@ func (d *bh1750vi) Lighting() (lighting float64, err error) {
} }
// Run starts continuous sensor data acquisition loop. // Run starts continuous sensor data acquisition loop.
func (d *bh1750vi) Run() (err error) { func (d *bh1750fvi) Run() (err error) {
go func() { go func() {
d.quit = make(chan bool) d.quit = make(chan bool)
@ -138,7 +138,7 @@ func (d *bh1750vi) Run() (err error) {
} }
// Close. // Close.
func (d *bh1750vi) Close() { func (d *bh1750fvi) Close() {
if d.quit != nil { if d.quit != nil {
d.quit <- true d.quit <- true
} }
@ -146,7 +146,7 @@ func (d *bh1750vi) Close() {
} }
// SetPollDelay sets the delay between run of data acquisition loop. // SetPollDelay sets the delay between run of data acquisition loop.
func (d *bh1750vi) SetPollDelay(delay int) { func (d *bh1750fvi) SetPollDelay(delay int) {
d.poll = delay d.poll = delay
} }