Testato / SoftwareWire

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

empty constructor #1

Closed Fire7 closed 8 years ago

Fire7 commented 8 years ago

Possibility to initialize port when we need it

Testato commented 8 years ago

Thanks

Koepel commented 8 years ago

The constructor does not change the pins and does not initialize them. The pins are remembered in the object, that's all. It was designed this way. Only the SoftwareWire.begin() starts to use the pins, and after SoftwareWire.end() the pins can be used for others things. That is the same as the Arduino Wire library. Before the Arduino Wire.begin(), the pins are not used and not initialized. Fire7, do you still think a empty constructor is needed ? What happens if the functions are used without setting the pins for SDA and SCL ?

Fire7 commented 8 years ago

@Koepel , what if I use this class in external library ? So I don't know pins (and the count of it) at the moment I initialize another class. It is only for this functionality.

Koepel commented 8 years ago

Then it is not about initializing the hardware pins, but about initializing the SoftwareWire object, but I see your point. Could the SoftwareWire functions be called after the empty constructor is called ? Should I add a check, for example if both _sdaPin and _sclPin are zero and ignore those calls ? When an Object is created, is the contents defined as all zero as with normal declared variables in 'c' ? I think I have some testing to do.

Could you give an example of such usage ? The SoftwareWire is not an Arduino Stream object, therefor it might be different if used in another class. I'm testing the SoftwareWire at the moment against the Arduino Wire library for every possibility, even when it is used in the wrong way, for example a beginTransmission before a requestFrom.

Fire7 commented 8 years ago

Sorry for a delay (lol :D). Here is an example. I've modified original driver: https://github.com/Fire7/Adafruit_TCS34725_SoftI2C/blob/master/Adafruit_TCS34725softi2c.h#L144 So, while library is initilizating we need only the SoftwareWire object without constants of SDA / SCL pins ( and it won't use any features of SoftwareWire library while SDA, SCL pins are unknown).

Empty constructor here is inly wrapper for usage in external libraries like I did. :)