2017 hongo b team
Dependencies: Beta_Apper_beta ctrl
Fork of I2C by
I2CTransporter.cpp@4:1b723a5b64d0, 2017-09-11 (annotated)
- Committer:
- Komazawa_sun
- Date:
- Mon Sep 11 04:57:57 2017 +0000
- Revision:
- 4:1b723a5b64d0
- Parent:
- 0:45f0d9b73179
????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Komazawa_sun | 0:45f0d9b73179 | 1 | #include "I2CTransporter.h" |
Komazawa_sun | 0:45f0d9b73179 | 2 | |
Komazawa_sun | 0:45f0d9b73179 | 3 | I2CTransporter::I2CTransporter(I2C *master_) |
Komazawa_sun | 0:45f0d9b73179 | 4 | { |
Komazawa_sun | 0:45f0d9b73179 | 5 | _master = master_; |
Komazawa_sun | 0:45f0d9b73179 | 6 | address = 0; |
Komazawa_sun | 0:45f0d9b73179 | 7 | target_array = NULL; |
Komazawa_sun | 0:45f0d9b73179 | 8 | Transport_Began = false; |
Komazawa_sun | 0:45f0d9b73179 | 9 | } |
Komazawa_sun | 0:45f0d9b73179 | 10 | |
Komazawa_sun | 0:45f0d9b73179 | 11 | void I2CTransporter::transport_begin(int addr_, char *target_array_, int data_size_) |
Komazawa_sun | 0:45f0d9b73179 | 12 | { |
Komazawa_sun | 0:45f0d9b73179 | 13 | address = addr_ ; |
Komazawa_sun | 0:45f0d9b73179 | 14 | target_array = target_array_; |
Komazawa_sun | 0:45f0d9b73179 | 15 | data_size = data_size_; |
Komazawa_sun | 0:45f0d9b73179 | 16 | Transport_Began = true; |
Komazawa_sun | 0:45f0d9b73179 | 17 | } |
Komazawa_sun | 0:45f0d9b73179 | 18 | |
Komazawa_sun | 0:45f0d9b73179 | 19 | bool I2CTransporter::read() |
Komazawa_sun | 0:45f0d9b73179 | 20 | { |
Komazawa_sun | 0:45f0d9b73179 | 21 | if(Transport_Began == true) |
Komazawa_sun | 0:45f0d9b73179 | 22 | { |
Komazawa_sun | 0:45f0d9b73179 | 23 | return _master->read(address, target_array, data_size) == 0 |
Komazawa_sun | 0:45f0d9b73179 | 24 | ? true |
Komazawa_sun | 0:45f0d9b73179 | 25 | : false; |
Komazawa_sun | 0:45f0d9b73179 | 26 | } |
Komazawa_sun | 0:45f0d9b73179 | 27 | else |
Komazawa_sun | 0:45f0d9b73179 | 28 | { |
Komazawa_sun | 0:45f0d9b73179 | 29 | return false; |
Komazawa_sun | 0:45f0d9b73179 | 30 | } |
Komazawa_sun | 0:45f0d9b73179 | 31 | } |
Komazawa_sun | 0:45f0d9b73179 | 32 | |
Komazawa_sun | 0:45f0d9b73179 | 33 | bool I2CTransporter::write() |
Komazawa_sun | 0:45f0d9b73179 | 34 | { |
Komazawa_sun | 0:45f0d9b73179 | 35 | if(Transport_Began == true) |
Komazawa_sun | 0:45f0d9b73179 | 36 | { |
Komazawa_sun | 0:45f0d9b73179 | 37 | return _master->write(address, target_array, data_size) == 0 |
Komazawa_sun | 0:45f0d9b73179 | 38 | ? true |
Komazawa_sun | 0:45f0d9b73179 | 39 | : false; |
Komazawa_sun | 0:45f0d9b73179 | 40 | } |
Komazawa_sun | 0:45f0d9b73179 | 41 | else |
Komazawa_sun | 0:45f0d9b73179 | 42 | { |
Komazawa_sun | 0:45f0d9b73179 | 43 | return false; |
Komazawa_sun | 0:45f0d9b73179 | 44 | } |
Komazawa_sun | 0:45f0d9b73179 | 45 | } |
Komazawa_sun | 0:45f0d9b73179 | 46 | |
Komazawa_sun | 0:45f0d9b73179 | 47 | void I2CTransporter::transport_end() |
Komazawa_sun | 0:45f0d9b73179 | 48 | { |
Komazawa_sun | 0:45f0d9b73179 | 49 | if(Transport_Began == true) |
Komazawa_sun | 0:45f0d9b73179 | 50 | { |
Komazawa_sun | 0:45f0d9b73179 | 51 | address = 0; |
Komazawa_sun | 0:45f0d9b73179 | 52 | target_array = NULL; |
Komazawa_sun | 0:45f0d9b73179 | 53 | data_size = 0; |
Komazawa_sun | 0:45f0d9b73179 | 54 | Transport_Began = false; |
Komazawa_sun | 0:45f0d9b73179 | 55 | } |
Komazawa_sun | 0:45f0d9b73179 | 56 | else |
Komazawa_sun | 0:45f0d9b73179 | 57 | { |
Komazawa_sun | 0:45f0d9b73179 | 58 | } |
Komazawa_sun | 0:45f0d9b73179 | 59 | } |