mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Changing Wire API to inherit from Stream.
Renaming send() to write(), receive() to read(), etc.
This commit is contained in:
@ -124,7 +124,7 @@ uint8_t TwoWire::endTransmission(void)
|
||||
// must be called in:
|
||||
// slave tx event callback
|
||||
// or after beginTransmission(address)
|
||||
void TwoWire::send(uint8_t data)
|
||||
void TwoWire::write(uint8_t data)
|
||||
{
|
||||
if(transmitting){
|
||||
// in master transmitter mode
|
||||
@ -147,12 +147,12 @@ void TwoWire::send(uint8_t data)
|
||||
// must be called in:
|
||||
// slave tx event callback
|
||||
// or after beginTransmission(address)
|
||||
void TwoWire::send(uint8_t* data, uint8_t quantity)
|
||||
void TwoWire::write(const uint8_t *data, size_t quantity)
|
||||
{
|
||||
if(transmitting){
|
||||
// in master transmitter mode
|
||||
for(uint8_t i = 0; i < quantity; ++i){
|
||||
send(data[i]);
|
||||
for(size_t i = 0; i < quantity; ++i){
|
||||
write(data[i]);
|
||||
}
|
||||
}else{
|
||||
// in slave send mode
|
||||
@ -164,23 +164,15 @@ void TwoWire::send(uint8_t* data, uint8_t quantity)
|
||||
// must be called in:
|
||||
// slave tx event callback
|
||||
// or after beginTransmission(address)
|
||||
void TwoWire::send(char* data)
|
||||
void TwoWire::write(const char *data)
|
||||
{
|
||||
send((uint8_t*)data, strlen(data));
|
||||
}
|
||||
|
||||
// must be called in:
|
||||
// slave tx event callback
|
||||
// or after beginTransmission(address)
|
||||
void TwoWire::send(int data)
|
||||
{
|
||||
send((uint8_t)data);
|
||||
write((uint8_t*)data, strlen(data));
|
||||
}
|
||||
|
||||
// must be called in:
|
||||
// slave rx event callback
|
||||
// or after requestFrom(address, numBytes)
|
||||
uint8_t TwoWire::available(void)
|
||||
int TwoWire::available(void)
|
||||
{
|
||||
return rxBufferLength - rxBufferIndex;
|
||||
}
|
||||
@ -188,11 +180,9 @@ uint8_t TwoWire::available(void)
|
||||
// must be called in:
|
||||
// slave rx event callback
|
||||
// or after requestFrom(address, numBytes)
|
||||
uint8_t TwoWire::receive(void)
|
||||
int TwoWire::read(void)
|
||||
{
|
||||
// default to returning null char
|
||||
// for people using with char strings
|
||||
uint8_t value = '\0';
|
||||
int value = -1;
|
||||
|
||||
// get each successive byte on each call
|
||||
if(rxBufferIndex < rxBufferLength){
|
||||
@ -203,6 +193,25 @@ uint8_t TwoWire::receive(void)
|
||||
return value;
|
||||
}
|
||||
|
||||
// must be called in:
|
||||
// slave rx event callback
|
||||
// or after requestFrom(address, numBytes)
|
||||
int TwoWire::peek(void)
|
||||
{
|
||||
int value = -1;
|
||||
|
||||
if(rxBufferIndex < rxBufferLength){
|
||||
value = rxBuffer[rxBufferIndex];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void TwoWire::flush(void)
|
||||
{
|
||||
// XXX: to be implemented.
|
||||
}
|
||||
|
||||
// behind the scenes function that is called when data is received
|
||||
void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
|
||||
{
|
||||
|
Reference in New Issue
Block a user