jeelabs / jeelib

JeeLib for Arduino IDE: Ports, RF12, and RF69 drivers from JeeLabs
https://jeelabs.org/202x/sw/jeelib/
The Unlicense
490 stars 215 forks source link

Ports.cpp updated to flush serial pending data before powerdown #96

Closed pakozm closed 8 years ago

pakozm commented 8 years ago

This commit updates Sleepy::powerDown method to check Serial object and forcing a flush before sleeping the MCU. Without flushing, UART communication for debugging is almost impossible.

jcw commented 8 years ago

Thanks - I like the idea. This does pull in the Serial code, but I assume it's not such a big deal.

JohnOH commented 8 years ago

On balance I would probably not add the flush to Sleepy. Recognising that the power down will upset the flow of pending print operations I still see it as the responsibility of the sketch to handle the prerequisites before powering down. Moving the flush into sleepy passes the accountability and possibly the understanding of actions taken inside the sketch to the library.

jcw commented 8 years ago

Ah, good point - hadn't thought of the indeterminism. I agree - if this is to be added to JeeLib, I would rather see something like this:

void Sleepy::flushAndPowerDown () {
    Serial.flush();
    powerDown();
}

That way, both the implicit link to serial and the implied delay will be clearer (and optional).

pakozm commented 8 years ago

Thanks for your comments. I think it can be changed to introduce a new method as @jcw says, this way the user is acknowledge of the expected behavior. I will change the pull-request.

jcw commented 8 years ago

Thanks, Francisco.