Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
ezcurrent.c
Go to the documentation of this file.
1 
38 #include "sensors/ezcurrent.h"
39 #include "mcu_periph/i2c.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 {
54 }
55 
57 {
60  }
61 }
62 
63 #define Uint16FromBuf(_buf,_idx) ((uint16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
64 #define Int16FromBuf(_buf,_idx) ((int16_t)((_buf[_idx+1]<<8) | _buf[_idx]))
65 
67 {
69  /* voltage of EzOSD sensor is provided in mV */
71  /* consumed electric charge in mAh */
72  electrical.charge = (float)(Int16FromBuf(ezcurrent_i2c_trans.buf, 6)) / 1000.f;
73  /* sensor provides current in 1e-1 Ampere */
75 
76  // Transaction has been read
80  // ezcurrent_i2c_trans.slave_addr++;
81  }
82 }
83 
electrical.h
i2c_transaction::buf
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
EZCURRENT_I2C_DEV
#define EZCURRENT_I2C_DEV
Definition: ezcurrent.c:45
ezcurrent_read_event
void ezcurrent_read_event(void)
Definition: ezcurrent.c:66
Int16FromBuf
#define Int16FromBuf(_buf, _idx)
Definition: ezcurrent.c:64
I2CTransFailed
@ I2CTransFailed
transaction failed
Definition: i2c.h:58
Electrical::vsupply
float vsupply
supply voltage in V
Definition: electrical.h:45
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
Electrical::charge
float charge
consumed electric charge in Ah
Definition: electrical.h:47
Uint16FromBuf
#define Uint16FromBuf(_buf, _idx)
Definition: ezcurrent.c:63
ezcurrent.h
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
ezcurrent_i2c_trans
struct i2c_transaction ezcurrent_i2c_trans
Definition: ezcurrent.c:48
f
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)
Definition: wedgebug.c:204
i2c_transaction
I2C transaction structure.
Definition: i2c.h:93
i2c_transaction::slave_addr
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
ezcurrent_read_periodic
void ezcurrent_read_periodic(void)
Definition: ezcurrent.c:56
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
ezcurrent_init
void ezcurrent_init(void)
Definition: ezcurrent.c:50
electrical
struct Electrical electrical
Definition: electrical.c:66
EZCURRENT_ADDR
#define EZCURRENT_ADDR
Definition: ezcurrent.c:42
i2c.h
i2c_receive
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition: i2c.c:334
Electrical::current
float current
current in A
Definition: electrical.h:46