Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ezcurrent.c
Go to the documentation of this file.
1 
38 #include "sensors/ezcurrent.h"
39 #include "mcu_periph/i2c.h"
40 #include "subsystems/electrical.h"
41 
42 #define EZCURRENT_ADDR 0xEF
43 
44 #ifndef EZCURRENT_I2C_DEV
45 #define EZCURRENT_I2C_DEV i2c1
46 #endif
47 
49 
50 void ezcurrent_init( void ) {
51  electrical.vsupply = 0;
52  electrical.current = 0;
53 
56 }
57 
61  }
62 }
63 
64 #define Uint16FromBuf(_buf,_idx) ((uint16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
65 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
66 
67 void ezcurrent_read_event( void ) {
69  /* voltage of EzOSD sensor is provided in mV, convert to deciVolt */
71  /* consumed ? in mAh */
73  /* sensor provides current in 1e-1 Ampere, convert to mA */
75 
76  // Transaction has been read
78  } else if ( ezcurrent_i2c_trans.status == I2CTransFailed ) {
80  // ezcurrent_i2c_trans.slave_addr++;
81  }
82 }
83 
#define EZCURRENT_ADDR
Definition: ezcurrent.c:42
#define EZCURRENT_I2C_DEV
Definition: ezcurrent.c:45
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:8
void ezcurrent_read_event(void)
Definition: ezcurrent.c:67
uint8_t slave_addr
Definition: i2c.h:79
#define Int16FromBuf(_buf, _idx)
Definition: ezcurrent.c:65
struct i2c_transaction ezcurrent_i2c_trans
Definition: ezcurrent.c:48
void ezcurrent_init(void)
Definition: ezcurrent.c:50
enum I2CTransactionStatus status
Definition: i2c.h:83
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
int32_t current
current in milliamps
Definition: electrical.h:9
#define Uint16FromBuf(_buf, _idx)
Definition: ezcurrent.c:64
int32_t consumed
consumption in mAh
Definition: electrical.h:10
void ezcurrent_read_periodic(void)
Definition: ezcurrent.c:58
bool_t i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Definition: i2c.c:95
struct Electrical electrical
Architecture independent I2C (Inter-Integrated Circuit Bus) API.