ChargeControl

Dependencies:   mbed PowerControl SDFileSystem

Fork of ChargeControl by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 07:44:05 2016 +0000
Revision:
1:cbbad81dc88d
Parent:
0:0842f00470eb
ChargeControl

Who changed what in which revision?

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