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

Add support for setting output stream #65

Open
arduino12 opened this issue May 7, 2023 · 2 comments
Open

Add support for setting output stream #65

arduino12 opened this issue May 7, 2023 · 2 comments

Comments

@arduino12
Copy link

Hi,

This library is awesome! many thanks!

I use it with my ESP32-S3 MCU- it have multiple UART peripherals (many Serial instances in the Arduino environment)..
I specifically use the Virtual Serial Port (VCP) with USBSerial.begin(0); // baudrate have no meaning on VCP...
and USBSerial.println("LoRa!"); for example.
(Also Arduino Micro and Arduino Mega2560 have many Serial instances).

My problem is with the hard-coded Serial.print in this library - I cannot set it to print to other Serial instances..

  1. I think the best solution is replacing all Serial.print with _stream.print, and add:
    LT.setLogStream(Stream &stream); that allows setting the output stream like I did here.

  2. Another option is using a macro in the .h file like (replacing all Serial.print with SERIAL_DEV.print):

#ifndef SERIAL_DEV
	#define SERIAL_DEV	Serial
#endif
...
SERIAL_DEV.println(...);

So users can choose to define their own stream like:

#define SERIAL_DEV	USBSerial
#include <SX128XLT.h>

But this one isn't very elegant..

  1. Another option is like the first one - but every function that print something will get the stream as an argument-
    So no need to add another LT.setLogStream function - but I think its better to just save an internal stream pointer..

Many libraries allows setting the I2C or SPI or UART streams, I also see an open PR 33 for SPI.

@StuartsProjects
Copy link
Owner

I currently have no plans at present to make such a change.

Whilst the change itself might not be seen as time consuming, it would have to be made for the SX126x, SX127X and SX128X libraries. Checking that the change had been implemented correctly and that examples performed correctly would take a considerable amount of testing.

@arduino12
Copy link
Author

I have SX1280 so I can test its examples, maybe other who sees this issue and want that feature can offer testing :)

But if you go with my #2 implementing option (using a macro) - it is 100% backwards compatible down to the final compiled .hex file-
So testing can be done by comparing the compiled binaries before and after the change and make sure they are the same using a script (that script can be re-used to make sure all examples compiles after every small commit as well).
(I once wrote similar script using Arduino cli).

Anyway thanks for your quick reply!

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

2 participants