Paparazzi UAS  v5.15_devel-105-g9de12e2
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 {
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 
#define EZCURRENT_ADDR
Definition: ezcurrent.c:42
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
transaction successfully finished by I2C driver
Definition: i2c.h:57
#define EZCURRENT_I2C_DEV
Definition: ezcurrent.c:45
float vsupply
supply voltage in V
Definition: electrical.h:45
void ezcurrent_read_event(void)
Definition: ezcurrent.c:66
#define Int16FromBuf(_buf, _idx)
Definition: ezcurrent.c:64
struct i2c_transaction ezcurrent_i2c_trans
Definition: ezcurrent.c:48
transaction set to done by user level
Definition: i2c.h:59
Interface for electrical status: supply voltage, current, battery status, etc.
float charge
consumed electric charge in Ah
Definition: electrical.h:47
void ezcurrent_init(void)
Definition: ezcurrent.c:50
transaction failed
Definition: i2c.h:58
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
#define Uint16FromBuf(_buf, _idx)
Definition: ezcurrent.c:63
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:318
struct Electrical electrical
Definition: electrical.c:66
float current
current in A
Definition: electrical.h:46
void ezcurrent_read_periodic(void)
Definition: ezcurrent.c:56
Architecture independent I2C (Inter-Integrated Circuit Bus) API.