probonopd / WirelessPrinting

Print wirelessly from Cura, PrusaSlicer or Slic3r to your 3D printer connected to an ESP8266 or ESP32 module
352 stars 65 forks source link

[Question] Doubt about code #47

Closed GMagician closed 5 years ago

GMagician commented 5 years ago
  while (serverClient.available()) { // get data from Client
    Serial.write(serverClient.read());

shouldn't this while code be:

  while (serverClient && serverClient.available()) { // get data from Client
    Serial.write(serverClient.read());
probonopd commented 5 years ago

Not sure whether serverClient can be false when serverClient.available()) is true - but why not try and see what happens.

GMagician commented 5 years ago

I think that until you don't assign it with serverClient = telnetServer.available(); it may be null so you call an available method from a non existent class instance

probonopd commented 5 years ago

Please try it out and let me know if it works for you, specifically if it makes any difference/improves anything. Thanks for your contribution.

GMagician commented 5 years ago

Actually I don't have any system ready yet. I'm analyzing code at the moment and I found some things I usually "write" in different ways and I'll propose a PR to see if such "way of" coding may be of your interest

GMagician commented 5 years ago

I'm also not used to program arduino, it seems like c/c++ but I don't know if exacly the same..for example parseTemp function should return nulll, not "" when temp is not found but maybe arduino compiler is different from my c knowledges

GMagician commented 5 years ago

And again why don't you use

while (!okFound) {
  yield();

instead of

while (okFound == false) {
  yield();

other form is compact, but maybe I'm completely in wrong way....

probonopd commented 5 years ago

Both should do the same thing. But why change it if it works ;-)

GMagician commented 5 years ago

That's true but I'm used to think about shorter things you have to read and easier is to understand :-)

probonopd commented 5 years ago

Some people think == false is more explicit and hence easier to understand, but I am indifferent here