Battery

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaBattery by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 06:37:27 2016 +0000
Revision:
1:166ddf929155
Parent:
0:d53e9c6fc771
HeptaBattery

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomoya123 0:d53e9c6fc771 1 #ifndef MBED_I2cBusDevice
tomoya123 0:d53e9c6fc771 2 #define MBED_I2cBusDevice
tomoya123 0:d53e9c6fc771 3
tomoya123 0:d53e9c6fc771 4 #include "mbed.h"
tomoya123 0:d53e9c6fc771 5
tomoya123 0:d53e9c6fc771 6 class I2cBusDevice {
tomoya123 0:d53e9c6fc771 7 public:
tomoya123 0:d53e9c6fc771 8
tomoya123 0:d53e9c6fc771 9 I2cBusDevice( I2C *i2c, char dev_address ) {
tomoya123 0:d53e9c6fc771 10 bus = i2c;
tomoya123 0:d53e9c6fc771 11 device = dev_address;
tomoya123 0:d53e9c6fc771 12 }
tomoya123 0:d53e9c6fc771 13
tomoya123 0:d53e9c6fc771 14 ~I2cBusDevice() {
tomoya123 0:d53e9c6fc771 15 }
tomoya123 0:d53e9c6fc771 16
tomoya123 0:d53e9c6fc771 17 int write( char *data, int length ) {
tomoya123 0:d53e9c6fc771 18 return ( bus->write( device, data, length) );
tomoya123 0:d53e9c6fc771 19 }
tomoya123 0:d53e9c6fc771 20
tomoya123 0:d53e9c6fc771 21 int read( char *data, int length ) {
tomoya123 0:d53e9c6fc771 22 return ( bus->read( device, data, length) );
tomoya123 0:d53e9c6fc771 23 }
tomoya123 0:d53e9c6fc771 24
tomoya123 0:d53e9c6fc771 25 int read( char reg_ptr, char *data, int length ) {
tomoya123 0:d53e9c6fc771 26 if ( bus->write( device, &reg_ptr, 1 ) )
tomoya123 0:d53e9c6fc771 27 return ( 1 );
tomoya123 0:d53e9c6fc771 28
tomoya123 0:d53e9c6fc771 29 if ( bus->read( device, data, length ) )
tomoya123 0:d53e9c6fc771 30 return ( 1 );
tomoya123 0:d53e9c6fc771 31
tomoya123 0:d53e9c6fc771 32 return ( 0 );
tomoya123 0:d53e9c6fc771 33 }
tomoya123 0:d53e9c6fc771 34
tomoya123 0:d53e9c6fc771 35 protected:
tomoya123 0:d53e9c6fc771 36 I2C *bus;
tomoya123 0:d53e9c6fc771 37 char device;
tomoya123 0:d53e9c6fc771 38
tomoya123 0:d53e9c6fc771 39 private:
tomoya123 0:d53e9c6fc771 40 static char i2c_error;
tomoya123 0:d53e9c6fc771 41 }
tomoya123 0:d53e9c6fc771 42 ;
tomoya123 0:d53e9c6fc771 43
tomoya123 0:d53e9c6fc771 44 #endif