Paparazzi UAS  v7.0_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 */
70  electrical.vsupply = (float)(Uint16FromBuf(ezcurrent_i2c_trans.buf, 2)) / 1000.f;
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 
struct Electrical electrical
Definition: electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
float current
current in A
Definition: electrical.h:47
float charge
consumed electric charge in Ah
Definition: electrical.h:48
float vsupply
supply voltage in V
Definition: electrical.h:45
#define Uint16FromBuf(_buf, _idx)
Definition: ezcurrent.c:63
void ezcurrent_read_periodic(void)
Definition: ezcurrent.c:56
#define EZCURRENT_I2C_DEV
Definition: ezcurrent.c:45
void ezcurrent_init(void)
Definition: ezcurrent.c:50
#define EZCURRENT_ADDR
Definition: ezcurrent.c:42
struct i2c_transaction ezcurrent_i2c_trans
Definition: ezcurrent.c:48
void ezcurrent_read_event(void)
Definition: ezcurrent.c:66
#define Int16FromBuf(_buf, _idx)
Definition: ezcurrent.c:64
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
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
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
@ I2CTransFailed
transaction failed
Definition: i2c.h:58
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
I2C transaction structure.
Definition: i2c.h:93
Architecture independent I2C (Inter-Integrated Circuit Bus) API.