Creating default values in library - how to share with loop()?

Status
Not open for further replies.

Constantin

Well-known member
Hi guys and gals,

In another attempt to demonstrate my ignorance in all things C, C++, etc. I wonder if one of you has an elegant solution for what I consider to be a simple problem but for which I do not have a elegant solution.

Specifically, I would like a library to maintain default values for UART transmission between Teensys - things like timeouts, retries, etc so that all programs that use the library use these values consistently. That lowers the probability that I'll screw something up later. (There always will be an better idiot to take on that challenge - just give me time!)

My only 'solution' so far is to declare a const/define in the library's UART.h file where a external global variable is imported from the program using the library. i.e.

Code:
public:
extern uint8_t UART_Transceive_Retries; // imported from program

private:  
const uint8_t _UART_Transceive_Retries = 5; // maintained locally

Then later on in the library's associated UART.cpp file begin() function declare
Code:
UART_Transceive_Retries = _UART_Transceive_Retries; // Set the global variable inside the program with private library const

This seems very clunky. Is there a better way?
 
Status
Not open for further replies.
Back
Top