Skip to content
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

Closed
CFTechno opened this issue Feb 21, 2016 · 5 comments
Closed

Include begin procedure and change object constructor code #29

CFTechno opened this issue Feb 21, 2016 · 5 comments

Comments

@CFTechno
Copy link

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

@bogde
Copy link
Owner

bogde commented Feb 21, 2016

looks like a good idea, i'll think about it and let you know.

@electrokean
Copy link

@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.

@CFTechno
Copy link
Author

Please see the remarks made by Paul Stoffregen in
http://forum.arduino.cc/index.php?topic=45794.0
and
http://forum.arduino.cc/index.php?topic=78114.0

Setup() is the only moment within a sketch dat you can be sure that all needed initialization is done.

SirUli pushed a commit to SirUli/HX711 that referenced this issue Jun 21, 2016
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.
@SirUli
Copy link
Contributor

SirUli commented Jun 21, 2016

@electrokean when you want to wrap the library like shown here for other sensors, then this is very useful 👍

bogde added a commit that referenced this issue Sep 2, 2016
Fixing #29, Travis CI integration and ESP8266 Fixes.
@bogde bogde closed this as completed Oct 2, 2016
bogde added a commit that referenced this issue Nov 24, 2016
Reflect issue #29 within the docs.
@amotl
Copy link
Contributor

amotl commented Feb 17, 2019

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.

[1] https://github.com/hiveeyes/HX711/tree/spring-cleaning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants