Fix Nano 33 BLE drivers (#351)

Fix HTS221, LPS22HB and APDS9960 drivers and their examples for Arduino Nano 33 BLE:

* Update hts221_nano_33_ble.go
* Update lps22hb_nano_33_ble.go
* Update apds9960_nano_33_ble.go
This commit is contained in:
Alan Wang
2021-12-20 16:57:37 +08:00
committed by GitHub
parent 43099c5d5f
commit bee7422c3a
14 changed files with 151 additions and 160 deletions
+14 -12
View File
@@ -14,18 +14,12 @@ type Device struct {
Address uint8
}
// Connected returns whether LPS22HB has been found.
// It does a "who am I" request and checks the response.
func (d *Device) Connected() bool {
data := []byte{0}
d.bus.ReadRegister(d.Address, LPS22HB_WHO_AM_I_REG, data)
return data[0] == 0xB1
}
// Configure sets up the LPS22HB device for communication.
func (d *Device) Configure() {
// set to block update mode
d.bus.WriteRegister(d.Address, LPS22HB_CTRL1_REG, []byte{0x02})
// New creates a new LPS22HB connection. The I2C bus must already be
// configured.
//
// This function only creates the Device object, it does not touch the device.
func New(bus drivers.I2C) Device {
return Device{bus: bus, Address: LPS22HB_ADDRESS}
}
// ReadPressure returns the pressure in milli pascals (mPa).
@@ -42,6 +36,14 @@ func (d *Device) ReadPressure() (pressure int32, err error) {
return int32(pValue * 1000), nil
}
// Connected returns whether LPS22HB has been found.
// It does a "who am I" request and checks the response.
func (d *Device) Connected() bool {
data := []byte{0}
d.bus.ReadRegister(d.Address, LPS22HB_WHO_AM_I_REG, data)
return data[0] == 0xB1
}
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000).
func (d *Device) ReadTemperature() (temperature int32, err error) {
d.waitForOneShot()