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

Allow other ESP debug port class types #4611

Merged
merged 1 commit into from
Apr 6, 2018

Conversation

bryceschober
Copy link
Contributor

My use case is that I have implemented an alternative DEBUG_ESP_PORT object inheriting from the Print class, so that I can embed the debug output in our own framing method by overriding the lowest-level write() functions. The pointer comparison added in #4467 broke the ability to provide a different object type. Casting to void pointers before the comparison restores that ability.

My use case basically looks like:

/** This class has an interface like Arduino's HardwareSerial
 *  Its intent is to wrap plain-ascii debug messages in framed packets appropriate for our application.
 *
 *  This also works well with the ESP8266 Arduino debug output methodology that depends on a
 *  command-line definition of which HardwareSerial instance its source libraries should print to.
 *  By building with "-DDEBUG_ESP_PORT=Debug" (see public global instance below), the debug output of the source
 *  libraries can be cleanly wrapped as we desire in our application.
 */
class SerialDebugOut: public Print {
    // My private members for our framing format
public:
    SerialDebugOut();
    ~SerialDebugOut();
    // Implement a look-alike of HardwareSerial's method
    void begin(unsigned long baud);
    // Implement a look-alike of HardwareSerial's method
    void setDebugOutput(bool en);
    // Implement the virtual method from the Print interface for single-character writes
    size_t write( uint8_t byte );
    // Implement the virtual method from the Print interface for character-buffer writes
    size_t write(const uint8_t *buffer, size_t size);
};
// A single global definition must be provided by the user application
extern SerialDebugOut Debug;

I'll admit it's not as ideal as making the HardwareSerial class more inheritable, but it does function well.

... by casting to void pointers before comparison to avoid compile error
@d-a-v d-a-v merged commit 3a110aa into esp8266:master Apr 6, 2018
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

Successfully merging this pull request may close these issues.

3 participants