Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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 
59 #ifndef SITL
62  }
63 #endif //SITL
64 }
65 
66 void ezcurrent_read_event( void ) {
68  // Get electrical information from buffer
69  electrical.vsupply = ((uint16_t)( (((ezcurrent_i2c_trans.buf[3]) << 8) + ezcurrent_i2c_trans.buf[2]) * 0.01f) );
72  // Transaction has been read
74  } else if ( ezcurrent_i2c_trans.status == I2CTransFailed ) {
76  // ezcurrent_i2c_trans.slave_addr++;
77  }
78 }
79 
unsigned short uint16_t
Definition: types.h:16
#define I2CReceive(_p, _t, _s_addr, _len)
Definition: i2c.h:140
#define EZCURRENT_ADDR
Definition: ezcurrent.c:42
#define EZCURRENT_I2C_DEV
Definition: ezcurrent.c:45
uint16_t vsupply
Definition: electrical.h:8
void ezcurrent_read_event(void)
Definition: ezcurrent.c:66
uint8_t slave_addr
Definition: i2c.h:43
struct i2c_transaction ezcurrent_i2c_trans
Definition: ezcurrent.c:48
void ezcurrent_init(void)
Definition: ezcurrent.c:50
enum I2CTransactionStatus status
Definition: i2c.h:47
signed long int32_t
Definition: types.h:19
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
int32_t current
Definition: electrical.h:9
struct Electrical electrical
Definition: electrical.c:16
int32_t consumed
Definition: electrical.h:10
void ezcurrent_read_periodic(void)
Definition: ezcurrent.c:58