1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-04 20:37:46 +02:00
This commit is contained in:
Max Matveev 2016-02-06 00:14:45 -08:00
parent 7054cdbeea
commit fef92bd936
2 changed files with 85 additions and 0 deletions

50
sensor/npa700/npa700.go Normal file
View file

@ -0,0 +1,50 @@
// Package npa700 allows interfacing with GE NPA-700 pressure sensor. This sensor
// has the ability to provide compensated temperature and pressure readings.
package npa700
import (
"github.com/zlowred/embd"
"sync"
)
// NPA700 represents a Bosch BMP180 barometric sensor.
type NPA700 struct {
Bus embd.I2CBus
RawTemperature int16
RawPressure int16
mu sync.Mutex
}
// New returns a handle to a BMP180 sensor.
func New(bus embd.I2CBus) *NPA700 {
return &NPA700{Bus: bus}
}
func (sensor *NPA700) Read() error {
sensor.mu.Lock()
defer sensor.mu.Unlock()
data, err := sensor.Bus.ReadBytes(0x28, 4)
if err != nil {
return err
}
sensor.RawPressure = (int16(data[0]) << 8) + int16(data[1])
sensor.RawTemperature = (int16(data[2]) << 3) + (int16(data[3]) >> 5)
return nil
}
func (sensor *NPA700) Celsius() float32 {
return float32(sensor.RawTemperature) * 200. / 2048. - 50.
}
func (sensor *NPA700) Fahrenheit() float32 {
return (float32(sensor.RawTemperature) * 200. / 2048. - 50.) * 1.8 + 32.
}
func (sensor *NPA700) Pascals(offset float32, minValue float32, maxValue float32, minPressure float32, maxPressure float32) float32 {
return minPressure + (float32(sensor.RawPressure) + offset - minValue) / (maxValue - minValue) * (maxPressure - minPressure)
}