|
|
@ -17,15 +17,17 @@ using namespace iflytop; |
|
|
|
TMP117::TMP117(/* args */) {} |
|
|
|
TMP117::~TMP117() {} |
|
|
|
|
|
|
|
void TMP117::initializate(I2C_HandleTypeDef* i2c, ID_t id) { |
|
|
|
void TMP117::initializate(I2C_HandleTypeDef* i2c, i2c_reset_cb_t i2cResetCb, ID_t id) { |
|
|
|
m_i2c = i2c; |
|
|
|
m_id = id; |
|
|
|
m_lastCallStatus = HAL_OK; |
|
|
|
m_i2cResetCb = i2cResetCb; |
|
|
|
|
|
|
|
setConfiguration(0x0220); |
|
|
|
setTemperatureOffset(0x0000); |
|
|
|
} |
|
|
|
|
|
|
|
m_isOnlineWhenPowerOn = isOnline(); |
|
|
|
} |
|
|
|
bool TMP117::isOnline() { |
|
|
|
getTemperature(); |
|
|
|
return m_lastCallStatus == HAL_OK; |
|
|
@ -46,7 +48,6 @@ const char* TMP117::getLastCallStatusString() { |
|
|
|
return "UNKNOWN"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
float TMP117::getTemperature() { |
|
|
|
uint16_t ret = 0; |
|
|
|
readreg(TemperatureRegister, (uint16_t*)&ret); |
|
|
@ -74,13 +75,12 @@ bool TMP117::writereg(uint8_t regoff, uint16_t data) { |
|
|
|
suc = _writereg(regoff, data); |
|
|
|
if (suc) break; |
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
* TODO |
|
|
|
* 代码测试发现,当读取温度多次之后,会出现通信一直失败的现象(每30毫秒读一次,读5s左右),重启I2C之后可以恢复正常。 |
|
|
|
* 目前还没有找到原因,暂时在代码中通过重置I2C来解决这个问题。 |
|
|
|
*/ |
|
|
|
ZLOGW(TAG, "writereg fail, reset i2c"); |
|
|
|
HAL_I2C_DeInit(m_i2c); |
|
|
|
HAL_I2C_Init(m_i2c); |
|
|
|
// ZLOGW(TAG, "writereg fail, reset i2c");
|
|
|
|
if (m_i2cResetCb) m_i2cResetCb(); |
|
|
|
} |
|
|
|
HAL_Delay(1); |
|
|
|
return suc; |
|
|
@ -91,12 +91,11 @@ bool TMP117::readreg(uint8_t regoff, uint16_t* data) { |
|
|
|
suc = _readreg(regoff, data); |
|
|
|
if (suc) break; |
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
* TODO |
|
|
|
* 代码测试发现,当读取温度多次之后,会出现通信一直失败的现象(每30毫秒读一次,读5s左右),重启I2C之后可以恢复正常。 |
|
|
|
* 目前还没有找到原因,暂时在代码中通过重置I2C来解决这个问题。 |
|
|
|
*/ |
|
|
|
HAL_I2C_DeInit(m_i2c); |
|
|
|
HAL_I2C_Init(m_i2c); |
|
|
|
if (m_i2cResetCb) m_i2cResetCb(); |
|
|
|
} |
|
|
|
HAL_Delay(1); |
|
|
|
return suc; |
|
|
|