bmxx80: add support for filters without using SenseContinuous (#74)

pull/77/head
Benjamin Godding 2 years ago committed by GitHub
parent 67ec1da964
commit 2cf8fa10c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -75,7 +75,7 @@ const (
// measurements are done.
type standby uint8
// Possible standby values, these determines the refresh rate.
// Possible standby values, these determine the refresh rate.
const (
s500us standby = 0
s10msBME standby = 6

@ -7,7 +7,7 @@ package bmxx80
import (
"errors"
"flag"
"io/ioutil"
"io"
"log"
"os"
"testing"
@ -1028,7 +1028,7 @@ func (s *spiFail) Connect(f physic.Frequency, mode spi.Mode, bits int) (spi.Conn
func TestMain(m *testing.M) {
flag.Parse()
if !testing.Verbose() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
os.Exit(m.Run())
}

@ -138,9 +138,12 @@ type Opts struct {
// Humidity sensing is only supported on BME280. The value is ignored on other
// devices.
Humidity Oversampling
// Filter is only used while using SenseContinuous() and is only supported on
// BMx280.
// Filter is only used while using SenseContinuous() or with a pre-set standby duration
// It is only supported on BMx280.
Filter Filter
// Standby Used with Filter to control the time between samples.
// If this is set we enable the filter on device creation and set the device mode to normal instead of sleep.
Standby time.Duration
}
func (o *Opts) delayTypical280() time.Duration {
@ -236,6 +239,8 @@ func (d *Dev) Sense(e *physic.Env) error {
}
if d.is280 {
// Skip setting mode to forced if we are already in normal mode
if d.opts.Filter == NoFilter || d.opts.Standby == 0 {
err := d.writeCommands([]byte{
// ctrl_meas
0xF4, byte(d.opts.Temperature)<<5 | byte(d.opts.Pressure)<<2 | byte(forced),
@ -249,6 +254,7 @@ func (d *Dev) Sense(e *physic.Env) error {
return d.wrap(err)
}
}
}
return d.sense280(e)
}
return d.sense180(e)
@ -388,6 +394,14 @@ func (d *Dev) makeDev(opts *Opts) error {
}
}
d.cal280 = newCalibration(tph[:], h[:])
standbyDuration := s1s
filter := NoFilter
startingMode := sleep
if d.opts.Filter != NoFilter && d.opts.Standby != 0 {
standbyDuration = chooseStandby(d.isBME, d.opts.Standby)
filter = d.opts.Filter
startingMode = normal
}
var b []byte
if d.isBME {
b = []byte{
@ -398,9 +412,9 @@ func (d *Dev) makeDev(opts *Opts) error {
// ctrl_hum
0xF2, byte(d.opts.Humidity),
// config
0xF5, byte(s1s)<<5 | byte(NoFilter)<<2,
0xF5, byte(standbyDuration)<<5 | byte(filter)<<2,
// As per page 25, ctrl_meas must be re-written last.
0xF4, byte(d.opts.Temperature)<<5 | byte(d.opts.Pressure)<<2 | byte(sleep),
0xF4, byte(d.opts.Temperature)<<5 | byte(d.opts.Pressure)<<2 | byte(startingMode),
}
} else {
// BMP280 doesn't have humidity to control.
@ -410,9 +424,9 @@ func (d *Dev) makeDev(opts *Opts) error {
// into normal but was not Halt'ed.
0xF4, byte(d.opts.Temperature)<<5 | byte(d.opts.Pressure)<<2 | byte(sleep),
// config
0xF5, byte(s1s)<<5 | byte(NoFilter)<<2,
0xF5, byte(standbyDuration)<<5 | byte(filter)<<2,
// As per page 25, ctrl_meas must be re-written last.
0xF4, byte(d.opts.Temperature)<<5 | byte(d.opts.Pressure)<<2 | byte(sleep),
0xF4, byte(d.opts.Temperature)<<5 | byte(d.opts.Pressure)<<2 | byte(startingMode),
}
}
return d.writeCommands(b)

@ -32,6 +32,6 @@
//
// The results of the calculations in the algorithm on page 15 are partly
// wrong. It looks like the original authors used non-integer calculations and
// some nubers were rounded. Take the results of the calculations with a grain
// some numbers were rounded. Take the results of the calculations with a grain
// of salt.
package bmxx80

Loading…
Cancel
Save