Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ApprI2CSlave.cpp
- Committer:
- Komazawa_sun
- Date:
- 2017-09-08
- Revision:
- 0:4eb718005c1b
- Child:
- 1:946468f68668
File content as of revision 0:4eb718005c1b:
#include "ApprI2CSlave.h"
ApprI2CSlave::ApprI2CSlave(alpha_a::ID my_id_, alpha_a::f_type my_type_, int addr_, I2CSlave *slave_)
{
_my_id = my_id_;
_my_type = my_type_;
_slave = slave_;
_slave->address(addr_);
}
void ApprI2CSlave::write(uint8_t data)
{
char data_array[3] = {};
data_array[0] = _my_id;
data_array[1] = _my_type;
data_array[2] = (char)data;
if(I2CSlave::ReadAddressed == _slave->receive())
_slave->write(data_array, 3);
}
int ApprI2CSlave::read()
{
char buffer[3] = {};
int res_data = 0;
printf("%d\r\n",_slave->receive());
if(I2CSlave::WriteAddressed == _slave->receive())
_slave->read(buffer, 3);
if((alpha_a::ID)buffer[0] == _my_id)
{
switch((alpha_a::f_type)buffer[1])
{
case alpha_a::sig:
res_data = (signed int)buffer[2];
break;
case alpha_a::unsig:
res_data = (unsigned int)buffer[2];
break;
};
return res_data;
}
else
{
return res_data;
}
}