-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include begin procedure and change object constructor code #29
Comments
looks like a good idea, i'll think about it and let you know. |
@CFTechno can you provide an example of when pin control wouldn't be available at the time of global object creation? I don't see a problem with the change other than backwards compatibility, I am just trying to see what value it adds and in what circumstances. |
Please see the remarks made by Paul Stoffregen in Setup() is the only moment within a sketch dat you can be sure that all needed initialization is done. |
Fixing bogde#29 This allows to wrap the sensor for example into Makuna/Task which then allows to define the pins later than only during the initial setup.
@electrokean when you want to wrap the library like shown here for other sensors, then this is very useful 👍 |
Fixing #29, Travis CI integration and ESP8266 Fixes.
Just wanted to let you know that by [1], we let the constructor-based initialization go completely. So, it can't even be used by accident anymore. |
From what I understand the moment a global HX711 object is created can not be controlled by the programmer. As a consequence that object might be created before the control of the pins is available. I understand that that is the reason for a lot a libraries to include a "begin" routine like Serial,begin
Because the begin will be execute after the pin control is available that is the correct moment to set any pins is need. I therefore propose to change
HX711::HX711(byte
dout, byte pd_sck, byte gain) {PD_SCK = pd_sck;
DOUT = dout;
pinMode(PD_SCK, OUTPUT);
pinMode(DOUT, INPUT);
set_gain(gain);
}
`
into
HX711::HX711(byte dout, byte pd_sck) { PD_SCK = pd_sck; DOUT = dout; }
and include a new procedure begin like:
HX711::begin(byte gain) { pinMode(PD_SCK, OUTPUT); pinMode(DOUT, INPUT); set_gain(gain); }
Problem with this proposal is that it will break old code! so maybe not replace the new constructor routine such that those calling the constructor without the gain parameter will get the new constructor
The text was updated successfully, but these errors were encountered: