a
INA226.hpp@2:8950b0f31d73, 2012-11-24 (annotated)
- Committer:
- tosihisa
- Date:
- Sat Nov 24 18:37:00 2012 +0000
- Revision:
- 2:8950b0f31d73
- Parent:
- 1:e0ebc6af5e04
- Child:
- 3:e0ddd1dfa2cc
wrote class comment.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tosihisa | 1:e0ebc6af5e04 | 1 | /** |
tosihisa | 1:e0ebc6af5e04 | 2 | * @section LICENSE |
tosihisa | 0:3a05c5755625 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
tosihisa | 1:e0ebc6af5e04 | 4 | * Copyright (C) 2012 tosihisa |
tosihisa | 1:e0ebc6af5e04 | 5 | * |
tosihisa | 1:e0ebc6af5e04 | 6 | * @section DESCRIPTION |
tosihisa | 1:e0ebc6af5e04 | 7 | * INA226 - Bi-Directional CURRENT/POWER MONITOR with I2C |
tosihisa | 1:e0ebc6af5e04 | 8 | * http://strawberry-linux.com/catalog/items?code=12031 |
tosihisa | 1:e0ebc6af5e04 | 9 | * |
tosihisa | 0:3a05c5755625 | 10 | */ |
tosihisa | 0:3a05c5755625 | 11 | #ifndef __INA226_INCLUDE // { |
tosihisa | 0:3a05c5755625 | 12 | #define __INA226_INCLUDE |
tosihisa | 0:3a05c5755625 | 13 | #include "mbed.h" |
tosihisa | 2:8950b0f31d73 | 14 | /** |
tosihisa | 2:8950b0f31d73 | 15 | * INA226 Class. |
tosihisa | 2:8950b0f31d73 | 16 | */ |
tosihisa | 0:3a05c5755625 | 17 | class INA226 { |
tosihisa | 0:3a05c5755625 | 18 | public: |
tosihisa | 1:e0ebc6af5e04 | 19 | /** |
tosihisa | 1:e0ebc6af5e04 | 20 | * Constructor. |
tosihisa | 1:e0ebc6af5e04 | 21 | * |
tosihisa | 1:e0ebc6af5e04 | 22 | * @param i2c_ instance of I2C. |
tosihisa | 1:e0ebc6af5e04 | 23 | * @param addr_ I2C slave address. |
tosihisa | 1:e0ebc6af5e04 | 24 | * @param freq_ I2C frequency. |
tosihisa | 1:e0ebc6af5e04 | 25 | */ |
tosihisa | 0:3a05c5755625 | 26 | INA226(I2C &i2c_,int addr_ = 0x80,int freq_ = 100000); |
tosihisa | 1:e0ebc6af5e04 | 27 | /** |
tosihisa | 1:e0ebc6af5e04 | 28 | * Check INA226 exist. |
tosihisa | 1:e0ebc6af5e04 | 29 | * |
tosihisa | 1:e0ebc6af5e04 | 30 | * @param none |
tosihisa | 1:e0ebc6af5e04 | 31 | * @return 0:NOT EXIST / !0:EXIST |
tosihisa | 1:e0ebc6af5e04 | 32 | */ |
tosihisa | 0:3a05c5755625 | 33 | int isExist(void); |
tosihisa | 1:e0ebc6af5e04 | 34 | /** |
tosihisa | 1:e0ebc6af5e04 | 35 | * INA226 raw level read. |
tosihisa | 1:e0ebc6af5e04 | 36 | * |
tosihisa | 1:e0ebc6af5e04 | 37 | * @param pointer_addr INA226 pointer address. |
tosihisa | 1:e0ebc6af5e04 | 38 | * @param val_ read value. |
tosihisa | 1:e0ebc6af5e04 | 39 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 40 | */ |
tosihisa | 0:3a05c5755625 | 41 | int rawRead(char pointer_addr,unsigned short *val_); |
tosihisa | 1:e0ebc6af5e04 | 42 | /** |
tosihisa | 1:e0ebc6af5e04 | 43 | * INA226 raw level write. |
tosihisa | 1:e0ebc6af5e04 | 44 | * |
tosihisa | 1:e0ebc6af5e04 | 45 | * @param pointer_addr INA226 pointer address. |
tosihisa | 1:e0ebc6af5e04 | 46 | * @param val_ write value. |
tosihisa | 1:e0ebc6af5e04 | 47 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 48 | */ |
tosihisa | 0:3a05c5755625 | 49 | int rawWrite(char pointer_addr,unsigned short val_); |
tosihisa | 1:e0ebc6af5e04 | 50 | /** |
tosihisa | 1:e0ebc6af5e04 | 51 | * Get voltage. |
tosihisa | 1:e0ebc6af5e04 | 52 | * |
tosihisa | 1:e0ebc6af5e04 | 53 | * @param V_ read value; |
tosihisa | 1:e0ebc6af5e04 | 54 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 55 | */ |
tosihisa | 0:3a05c5755625 | 56 | int getVoltage(double *V_); |
tosihisa | 1:e0ebc6af5e04 | 57 | /** |
tosihisa | 1:e0ebc6af5e04 | 58 | * Get current. |
tosihisa | 1:e0ebc6af5e04 | 59 | * |
tosihisa | 1:e0ebc6af5e04 | 60 | * @param I_ read value; |
tosihisa | 1:e0ebc6af5e04 | 61 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 62 | */ |
tosihisa | 0:3a05c5755625 | 63 | int getCurrent(double *I_); |
tosihisa | 1:e0ebc6af5e04 | 64 | /** |
tosihisa | 1:e0ebc6af5e04 | 65 | * Set current calibration. |
tosihisa | 1:e0ebc6af5e04 | 66 | * |
tosihisa | 1:e0ebc6af5e04 | 67 | * @param val write value; |
tosihisa | 1:e0ebc6af5e04 | 68 | * @return 0:Read OK / !0:Read NG |
tosihisa | 1:e0ebc6af5e04 | 69 | */ |
tosihisa | 0:3a05c5755625 | 70 | int setCurrentCalibration(unsigned short val = 0x0A00); |
tosihisa | 0:3a05c5755625 | 71 | |
tosihisa | 0:3a05c5755625 | 72 | private: |
tosihisa | 0:3a05c5755625 | 73 | I2C &i2c; |
tosihisa | 0:3a05c5755625 | 74 | int i2c_addr; |
tosihisa | 0:3a05c5755625 | 75 | int freq; |
tosihisa | 0:3a05c5755625 | 76 | }; |
tosihisa | 0:3a05c5755625 | 77 | #endif // } |