Battery_hex

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaBattery_hex by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 06:55:26 2016 +0000
Revision:
1:4e0d741b4ae2
Parent:
0:30e193b92735
Battery hex

Who changed what in which revision?

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