mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-24 05:45:59 +08:00
[modules] minor cleanup of ezcurrent sensor
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<periodic fun="ezcurrent_read_periodic()" freq="1."/>
|
||||
<event fun="ezcurrent_read_event()"/>
|
||||
|
||||
<makefile>
|
||||
<makefile target="ap">
|
||||
<file name="ezcurrent.c"/>
|
||||
<!-- This disables the standard electrical monitoring system -->
|
||||
<define name="DISABLE_ELECTRICAL" description="Disable default electrical handling"/>
|
||||
|
||||
@@ -56,19 +56,23 @@ void ezcurrent_init( void ) {
|
||||
}
|
||||
|
||||
void ezcurrent_read_periodic( void ) {
|
||||
#ifndef SITL
|
||||
if (ezcurrent_i2c_trans.status == I2CTransDone) {
|
||||
I2CReceive(EZCURRENT_I2C_DEV, ezcurrent_i2c_trans, ezcurrent_i2c_trans.slave_addr, 10);
|
||||
}
|
||||
#endif //SITL
|
||||
}
|
||||
|
||||
#define Uint16FromBuf(_buf,_idx) ((uint16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
|
||||
#define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
|
||||
|
||||
void ezcurrent_read_event( void ) {
|
||||
if (ezcurrent_i2c_trans.status == I2CTransSuccess) {
|
||||
// Get electrical information from buffer
|
||||
electrical.vsupply = ((uint16_t)( (((ezcurrent_i2c_trans.buf[3]) << 8) + ezcurrent_i2c_trans.buf[2]) * 0.01f) );
|
||||
electrical.current = (((int32_t)(ezcurrent_i2c_trans.buf[9]) << 8) + (int32_t)(ezcurrent_i2c_trans.buf[8])) * 100;
|
||||
electrical.consumed = ((int32_t)(ezcurrent_i2c_trans.buf[7]) << 8) + (int32_t)(ezcurrent_i2c_trans.buf[6]);
|
||||
/* voltage of EzOSD sensor is provided in mV, convert to deciVolt */
|
||||
electrical.vsupply = Uint16FromBuf(ezcurrent_i2c_trans.buf, 2) / 100;
|
||||
/* consumed ? in mAh */
|
||||
electrical.consumed = Int16FromBuf(ezcurrent_i2c_trans.buf, 6);
|
||||
/* sensor provides current in 1e-1 Ampere, convert to mA */
|
||||
electrical.current = Int16FromBuf(ezcurrent_i2c_trans.buf, 8) * 100;
|
||||
|
||||
// Transaction has been read
|
||||
ezcurrent_i2c_trans.status = I2CTransDone;
|
||||
} else if ( ezcurrent_i2c_trans.status == I2CTransFailed ) {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
struct Electrical {
|
||||
|
||||
uint16_t vsupply; /* supply in decivolts */
|
||||
int32_t current; /* current in milliamps */
|
||||
int32_t consumed; /* consumption in mAh */
|
||||
uint16_t vsupply; ///< supply voltage in decivolts
|
||||
int32_t current; ///< current in milliamps
|
||||
int32_t consumed; ///< consumption in mAh
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user