Skip to content

Commit

Permalink
use a newCalibration func like in bmp180 (google#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinte17 authored and maruel committed Apr 24, 2017
1 parent 087433a commit 91f2830
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions devices/bme280/bme280.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,8 @@ func (d *Dev) makeDev(opts *Opts) error {
return err
}

d.c.t1 = uint16(tph[0]) | uint16(tph[1])<<8
d.c.t2 = int16(tph[2]) | int16(tph[3])<<8
d.c.t3 = int16(tph[4]) | int16(tph[5])<<8
d.c.p1 = uint16(tph[6]) | uint16(tph[7])<<8
d.c.p2 = int16(tph[8]) | int16(tph[9])<<8
d.c.p3 = int16(tph[10]) | int16(tph[11])<<8
d.c.p4 = int16(tph[12]) | int16(tph[13])<<8
d.c.p5 = int16(tph[14]) | int16(tph[15])<<8
d.c.p6 = int16(tph[16]) | int16(tph[17])<<8
d.c.p7 = int16(tph[18]) | int16(tph[19])<<8
d.c.p8 = int16(tph[20]) | int16(tph[21])<<8
d.c.p9 = int16(tph[22]) | int16(tph[23])<<8
d.c.h1 = uint8(tph[25])

d.c.h2 = int16(h[0]) | int16(h[1])<<8
d.c.h3 = uint8(h[2])
d.c.h4 = int16(h[3])<<4 | int16(h[4])&0xF
d.c.h5 = int16(h[4])>>4 | int16(h[5])<<4
d.c.h6 = int8(h[6])
d.c = newCalibration(tph[:], h[:])

return nil
}

Expand Down Expand Up @@ -332,6 +315,31 @@ func (d *Dev) writeCommands(b []byte) error {
// https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf
// Page 23

// newCalibration parses calibration data from both buffers.
func newCalibration(tph, h []byte) (c calibration) {
c.t1 = uint16(tph[0]) | uint16(tph[1])<<8
c.t2 = int16(tph[2]) | int16(tph[3])<<8
c.t3 = int16(tph[4]) | int16(tph[5])<<8
c.p1 = uint16(tph[6]) | uint16(tph[7])<<8
c.p2 = int16(tph[8]) | int16(tph[9])<<8
c.p3 = int16(tph[10]) | int16(tph[11])<<8
c.p4 = int16(tph[12]) | int16(tph[13])<<8
c.p5 = int16(tph[14]) | int16(tph[15])<<8
c.p6 = int16(tph[16]) | int16(tph[17])<<8
c.p7 = int16(tph[18]) | int16(tph[19])<<8
c.p8 = int16(tph[20]) | int16(tph[21])<<8
c.p9 = int16(tph[22]) | int16(tph[23])<<8
c.h1 = uint8(tph[25])

c.h2 = int16(h[0]) | int16(h[1])<<8
c.h3 = uint8(h[2])
c.h4 = int16(h[3])<<4 | int16(h[4])&0xF
c.h5 = int16(h[4])>>4 | int16(h[5])<<4
c.h6 = int8(h[6])

return c
}

type calibration struct {
t1 uint16
t2, t3 int16
Expand Down

0 comments on commit 91f2830

Please sign in to comment.