Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding overloads for other integer types in Wire.write(). (Paul Stoff…

  • Loading branch information...
commit 6a6ed3d10ad1470283d7771906ce81ad97fa06f0 1 parent 6fa5f18
@damellis damellis authored
Showing with 4 additions and 0 deletions.
  1. +4 −0 libraries/Wire/Wire.h
View
4 libraries/Wire/Wire.h
@@ -61,6 +61,10 @@ class TwoWire : public Stream
void onReceive( void (*)(int) );
void onRequest( void (*)(void) );
+ inline size_t write(unsigned long n) { return write((uint8_t)n); }
+ inline size_t write(long n) { return write((uint8_t)n); }
+ inline size_t write(unsigned int n) { return write((uint8_t)n); }
+ inline size_t write(int n) { return write((uint8_t)n); }
using Print::write;
};

2 comments on commit 6a6ed3d

@jurriaan

great! no errors on 0x00 anymore

@eelsirhc

What happens if I write(-1) or write(0xABCD)? Is this the correct behavior when there is a function that can write multiple bytes using write(const uint8_t *data, size_t quantity)? For example, this overloading always returns 1 instead of the number of bytes in n.

A different method would be to write the entire value to the TWI (e.g., roughly the following)
inline size_t write(unsigned long n) { return write((uint8_t*)&n, sizeof(unsigned long)) ;}
but I don't see a reason why this would be preferable to raising an error (as it was before this change).

Please sign in to comment.
Something went wrong with that request. Please try again.