Hepta UplinkData
Dependencies: mbed PowerControl SDFileSystem
Fork of Hepta_UplinkData by
hepta_sat/I2cBusDevice.h@4:4f34143d3f6e, 2016-12-23 (annotated)
- Committer:
- MEXT1
- Date:
- Fri Dec 23 04:44:57 2016 +0000
- Revision:
- 4:4f34143d3f6e
- Parent:
- 0:b96079b7d167
UplinkData
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomoya123 | 0:b96079b7d167 | 1 | #ifndef MBED_I2cBusDevice |
tomoya123 | 0:b96079b7d167 | 2 | #define MBED_I2cBusDevice |
tomoya123 | 0:b96079b7d167 | 3 | |
tomoya123 | 0:b96079b7d167 | 4 | #include "mbed.h" |
tomoya123 | 0:b96079b7d167 | 5 | |
tomoya123 | 0:b96079b7d167 | 6 | class I2cBusDevice { |
tomoya123 | 0:b96079b7d167 | 7 | public: |
tomoya123 | 0:b96079b7d167 | 8 | |
tomoya123 | 0:b96079b7d167 | 9 | I2cBusDevice( I2C *i2c, char dev_address ) { |
tomoya123 | 0:b96079b7d167 | 10 | bus = i2c; |
tomoya123 | 0:b96079b7d167 | 11 | device = dev_address; |
tomoya123 | 0:b96079b7d167 | 12 | } |
tomoya123 | 0:b96079b7d167 | 13 | |
tomoya123 | 0:b96079b7d167 | 14 | ~I2cBusDevice() { |
tomoya123 | 0:b96079b7d167 | 15 | } |
tomoya123 | 0:b96079b7d167 | 16 | |
tomoya123 | 0:b96079b7d167 | 17 | int write( char *data, int length ) { |
tomoya123 | 0:b96079b7d167 | 18 | return ( bus->write( device, data, length) ); |
tomoya123 | 0:b96079b7d167 | 19 | } |
tomoya123 | 0:b96079b7d167 | 20 | |
tomoya123 | 0:b96079b7d167 | 21 | int read( char *data, int length ) { |
tomoya123 | 0:b96079b7d167 | 22 | return ( bus->read( device, data, length) ); |
tomoya123 | 0:b96079b7d167 | 23 | } |
tomoya123 | 0:b96079b7d167 | 24 | |
tomoya123 | 0:b96079b7d167 | 25 | int read( char reg_ptr, char *data, int length ) { |
tomoya123 | 0:b96079b7d167 | 26 | if ( bus->write( device, ®_ptr, 1 ) ) |
tomoya123 | 0:b96079b7d167 | 27 | return ( 1 ); |
tomoya123 | 0:b96079b7d167 | 28 | |
tomoya123 | 0:b96079b7d167 | 29 | if ( bus->read( device, data, length ) ) |
tomoya123 | 0:b96079b7d167 | 30 | return ( 1 ); |
tomoya123 | 0:b96079b7d167 | 31 | |
tomoya123 | 0:b96079b7d167 | 32 | return ( 0 ); |
tomoya123 | 0:b96079b7d167 | 33 | } |
tomoya123 | 0:b96079b7d167 | 34 | |
tomoya123 | 0:b96079b7d167 | 35 | protected: |
tomoya123 | 0:b96079b7d167 | 36 | I2C *bus; |
tomoya123 | 0:b96079b7d167 | 37 | char device; |
tomoya123 | 0:b96079b7d167 | 38 | |
tomoya123 | 0:b96079b7d167 | 39 | private: |
tomoya123 | 0:b96079b7d167 | 40 | static char i2c_error; |
tomoya123 | 0:b96079b7d167 | 41 | } |
tomoya123 | 0:b96079b7d167 | 42 | ; |
tomoya123 | 0:b96079b7d167 | 43 | |
tomoya123 | 0:b96079b7d167 | 44 | #endif |