Testato / SoftwareWire

Creates a software I2C/TWI bus on every pins
GNU General Public License v3.0
149 stars 33 forks source link

_timeout needs to be unsigned #6

Closed bperrybap closed 6 years ago

bperrybap commented 7 years ago

The _timeout variable needs to be unsigned long rather than long which is signed.

Koepel commented 7 years ago

Not really. It is better and nicer if it is an unsigned long, but it does not need to be unsigned long.

The substraction with millis() en previousMillis has to be with done with unsigned long. But the resulting compare can be done to a long or a integer as well. The 'long' means that the timeout for the Slave stretching the clock pulse is 25 days instead of 50 days. Since a normal number would be 100ms, I don't worry about it. The goal is to be compatible with the Arduino libraries, and they have a 'long' : https://www.arduino.cc/en/Serial/setTimeout , https://www.arduino.cc/en/Reference/StreamSetTimeout

If you don't mind, I keep the 'long' for now.

bperrybap commented 7 years ago

The overall goal is to eliminate the warning created by comparing signed vs unsigned values in the SoftwareWire.cpp code. You can do that by either

Koepel commented 7 years ago

I like that. I have applied two small fixes. The internal _timeout is now unsigned long, but the parameter timeout is still 'long', and a cast is added when copying to the internal _timeout. Thank you.