2017 hongo b team
Fork of Alpha_Apper by
ApprI2CMaster.cpp
- Committer:
- Komazawa_sun
- Date:
- 2017-09-11
- Revision:
- 1:16f3ffabd868
- Parent:
- 0:11209e14c06c
File content as of revision 1:16f3ffabd868:
#include "ApprI2CMaster.h" ApprI2CMaster::ApprI2CMaster(beta_a::ID my_id_, beta_a::f_type my_type_, int addr_, I2C *master_) { _my_id = my_id_; _my_type = my_type_; _master = master_; _addr = addr_; res_data = 0; } void ApprI2CMaster::write(uint8_t data) { char data_array[3] = {}; data_array[0] = _my_id; data_array[1] = _my_type; data_array[2] = (char)data; _master->write(_addr, data_array, 3); } int ApprI2CMaster::read() { char buffer[3] = {}; _master->read(_addr, buffer, 3); if((beta_a::ID)buffer[0] == _my_id) { switch((beta_a::f_type)buffer[1]) { case beta_a::sig: res_data = (signed int)buffer[2]; break; case beta_a::unsig: res_data = (unsigned int)buffer[2]; break; }; } return res_data; }