Xbee CountUp

Dependencies:   mbed

Fork of HeptaXbee_CountUp by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 07:55:03 2016 +0000
Revision:
1:715b80d2a02b
Parent:
0:0a7fa0911e6c
Xbee CountUp

Who changed what in which revision?

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