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