tici: BMX055 magnetometer& temperature sensor (#2212)
* BMX055 Magnetometer support
* add temp sensor
old-commit-hash: f55e79e46a
commatwo_master
parent
4f622a1dbb
commit
8ee4ac45fe
8 changed files with 146 additions and 11 deletions
@ -0,0 +1,44 @@ |
||||
#include <cassert> |
||||
#include "common/swaglog.h" |
||||
#include "common/timing.h" |
||||
|
||||
#include "bmx055_temp.hpp" |
||||
#include "bmx055_accel.hpp" |
||||
|
||||
|
||||
BMX055_Temp::BMX055_Temp(I2CBus *bus) : I2CSensor(bus) {} |
||||
|
||||
int BMX055_Temp::init(){ |
||||
int ret = 0; |
||||
uint8_t buffer[1]; |
||||
|
||||
ret = read_register(BMX055_ACCEL_I2C_REG_ID, buffer, 1); |
||||
if(ret < 0){ |
||||
LOGE("Reading chip ID failed: %d", ret); |
||||
goto fail; |
||||
} |
||||
|
||||
if(buffer[0] != BMX055_ACCEL_CHIP_ID){ |
||||
LOGE("Chip ID wrong. Got: %d, Expected %d", buffer[0], BMX055_ACCEL_CHIP_ID); |
||||
ret = -1; |
||||
goto fail; |
||||
} |
||||
|
||||
fail: |
||||
return ret; |
||||
} |
||||
|
||||
void BMX055_Temp::get_event(cereal::SensorEventData::Builder &event){ |
||||
uint64_t start_time = nanos_since_boot(); |
||||
uint8_t buffer[1]; |
||||
int len = read_register(BMX055_ACCEL_I2C_REG_TEMP, buffer, sizeof(buffer)); |
||||
assert(len == sizeof(buffer)); |
||||
|
||||
float temp = 23.0f + int8_t(buffer[0]) / 2.0f; |
||||
|
||||
event.setSource(cereal::SensorEventData::SensorSource::BMX055); |
||||
event.setVersion(1); |
||||
event.setType(SENSOR_TYPE_AMBIENT_TEMPERATURE); |
||||
event.setTimestamp(start_time); |
||||
event.setTemperature(temp); |
||||
} |
@ -0,0 +1,13 @@ |
||||
#pragma once |
||||
|
||||
#include "sensors/i2c_sensor.hpp" |
||||
#include "sensors/bmx055_accel.hpp" |
||||
|
||||
|
||||
class BMX055_Temp : public I2CSensor { |
||||
uint8_t get_device_address() {return BMX055_ACCEL_I2C_ADDR;} |
||||
public: |
||||
BMX055_Temp(I2CBus *bus); |
||||
int init(); |
||||
void get_event(cereal::SensorEventData::Builder &event); |
||||
}; |
Loading…
Reference in new issue