You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
5.2 KiB
127 lines
5.2 KiB
#include "BNO055.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "BNO055", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "BNO055", this, _LOG_ERROR, X )
|
|
|
|
sensorBNO::sensorBNO( config_setting_t *Settings ){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "BNO055" );
|
|
m_pBus = NULL;
|
|
m_pDevicePath = "/dev/i2c-1";
|
|
m_bDeviceAddress = 0x29;
|
|
m_eWorkMode = BNO_WM_CONFIG;
|
|
memset( &m_sID, 0, sizeof(BNO_ID_MAP) );
|
|
memset( &m_sDATA, 0, sizeof(BNO_DATA_MAP) );
|
|
memset( &m_sSTATUS, 0, sizeof(BNO_STATUS_MAP) );
|
|
memset( &m_sCONFIG, 0, sizeof(BNO_CONFIG_MAP) );
|
|
};
|
|
|
|
sensorBNO::~sensorBNO(){
|
|
if(m_pBus != NULL ) delete( m_pBus );
|
|
};
|
|
|
|
bool sensorBNO::create(){
|
|
#ifdef DEBUG
|
|
char tBuff[64];
|
|
#endif
|
|
if( m_pDevicePath == NULL ) return false;
|
|
if( m_pBus != NULL ) delete( m_pBus );
|
|
m_pBus = new i2cPort( m_pDevicePath, m_bDeviceAddress );
|
|
if( m_pBus!=NULL ){
|
|
if( m_pBus->readMZ( BNO_ID_OFFSET, (uint8_t *)&m_sID, sizeof(BNO_ID_MAP)) ){
|
|
#ifdef DEBUG
|
|
sprintf( tBuff, "BNO055 Chip ID: %02X", m_sID.CHIP_ID );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "ACC Chip ID: %02X", m_sID.ACC_ID );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "MAG Chip ID: %02X", m_sID.MAG_ID );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "GYRO Chip ID: %02X", m_sID.GYR_ID );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "SW Revision ID: %04X", m_sID.SW_REV_ID );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "Bootloader Version: %02X", m_sID.BL_REV_ID );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "Page ID: %d", m_sID.PAGE_ID );
|
|
LOG( tBuff );
|
|
#endif
|
|
BNO_CONFIG_MAP tCFG;
|
|
memset( &tCFG, 0 , sizeof(BNO_CONFIG_MAP) );
|
|
if( m_pBus->readMZ( BNO_CONFIG_OFFSET, (uint8_t *)&tCFG, sizeof(BNO_CONFIG_MAP)) ){
|
|
if(
|
|
tCFG.UNIT_SELECT != m_sCONFIG.UNIT_SELECT ||
|
|
tCFG.OP_MODE != m_sCONFIG.OP_MODE ||
|
|
tCFG.SYS_TRIGG != m_sCONFIG.SYS_TRIGG ||
|
|
tCFG.PWR_MODE != m_sCONFIG.PWR_MODE ||
|
|
tCFG.TEMP_SRC != m_sCONFIG.TEMP_SRC ||
|
|
tCFG.AXIS_MAP_CONF != m_sCONFIG.AXIS_MAP_CONF ||
|
|
tCFG.AXIS_MAP_SIGN != m_sCONFIG.AXIS_MAP_SIGN
|
|
) {
|
|
#ifdef DEBUG
|
|
LOG("Internal Config Differs!");
|
|
sprintf( tBuff, "Unit Select [0x%02X] is 0x%02X", m_sCONFIG.UNIT_SELECT, tCFG.UNIT_SELECT );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "Operation Mode [0x%02X] is 0x%02X", m_sCONFIG.OP_MODE, tCFG.OP_MODE );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "Power Mode [0x%02X] is 0x%02X", m_sCONFIG.PWR_MODE, tCFG.PWR_MODE );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "Sys Triggers [0x%02X] is 0x%02X", m_sCONFIG.SYS_TRIGG, tCFG.SYS_TRIGG );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "Tmp Sources [0x%02X] is 0x%02X", m_sCONFIG.TEMP_SRC, tCFG.TEMP_SRC );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "AXIS Map Config [0x%02X] is 0x%02X", m_sCONFIG.AXIS_MAP_CONF, tCFG.AXIS_MAP_CONF );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "AXIS Map SIGN [0x%02X] is 0x%02X", m_sCONFIG.AXIS_MAP_SIGN, tCFG.AXIS_MAP_SIGN );
|
|
LOG( tBuff );
|
|
#endif
|
|
return updateSettings();
|
|
} else return validate();
|
|
} else LOG_ERROR("Can not Read Module Statuses!");
|
|
} else LOG_ERROR("Can not communicate with module!");
|
|
} else LOG_ERROR("No I2C Bus Created!");
|
|
return false;
|
|
};
|
|
|
|
bool sensorBNO::validate(){
|
|
if( m_pBus!=NULL ){
|
|
if( m_pBus->readMZ( BNO_STATUS_OFFSET, (uint8_t *)&m_sSTATUS, sizeof(BNO_STATUS_MAP))) {
|
|
#ifdef DEBUG
|
|
char tBuff[64];
|
|
sprintf( tBuff, "Temperature: %02X", m_sSTATUS.temper );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "Calibration: %02X", m_sSTATUS.cal_status );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "ST Result: %02X", m_sSTATUS.st_result );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "INT Status: %02X", m_sSTATUS.int_status );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "CLC Status: %02X", m_sSTATUS.sys_clc_status );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "SYS Status: %02X", m_sSTATUS.system_status );
|
|
LOG( tBuff );
|
|
sprintf( tBuff, "SYS Error: %02X", m_sSTATUS.system_error );
|
|
LOG( tBuff );
|
|
#endif
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
};
|
|
|
|
BNO_DATA_MAP *sensorBNO::getData(){
|
|
|
|
return &m_sDATA;
|
|
};
|
|
|
|
bool sensorBNO::updateSettings(){
|
|
if( m_pBus!= NULL ){
|
|
|
|
if( m_pBus->writeMZ( BNO_CONFIG_OFFSET, (uint8_t *)&m_sCONFIG, sizeof(BNO_CONFIG_MAP)) ) {
|
|
return validate();
|
|
};
|
|
};
|
|
return false;
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|