Skip to content

Commit

Permalink
Use configurable line feed for debug output (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Feb 11, 2025
1 parent e86fb27 commit e087449
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/BuildOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
//#define RADIOLIB_CLOCK_DRIFT_MS (0)
#endif

#if !defined(RADIOLIB_LINE_FEED)
#define RADIOLIB_LINE_FEED "\r\n"
#endif

#if ARDUINO >= 100
// Arduino build
#include "Arduino.h"
Expand Down Expand Up @@ -471,9 +475,9 @@
#if RADIOLIB_DEBUG
#if defined(RADIOLIB_BUILD_ARDUINO)
#define RADIOLIB_DEBUG_PRINT(...) rlb_printf(__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN(M, ...) rlb_printf(M "\n", ##__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN(M, ...) rlb_printf(M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINT_LVL(LEVEL, M, ...) rlb_printf(LEVEL "" M, ##__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) rlb_printf(LEVEL "" M "\n", ##__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) rlb_printf(LEVEL "" M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__)

// some platforms do not support printf("%f"), so it has to be done this way
#define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL); RADIOLIB_DEBUG_PORT.print(VAL, DECIMALS)
Expand All @@ -483,8 +487,8 @@
#define RADIOLIB_DEBUG_PRINT_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M, ##__VA_ARGS__)
#endif
#if !defined(RADIOLIB_DEBUG_PRINTLN)
#define RADIOLIB_DEBUG_PRINTLN(M, ...) fprintf(RADIOLIB_DEBUG_PORT, M "\n", ##__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M "\n", ##__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN(M, ...) fprintf(RADIOLIB_DEBUG_PORT, M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M "" RADIOLIB_LINE_FEED, ##__VA_ARGS__)
#endif
#define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL "%.3f", VAL)
#endif
Expand Down Expand Up @@ -545,12 +549,12 @@
#define RADIOLIB_VALUE_TO_STRING(x) #x
#define RADIOLIB_VALUE(x) RADIOLIB_VALUE_TO_STRING(x)

#define RADIOLIB_INFO "\nRadioLib Info\nVersion: \"" \
#define RADIOLIB_INFO "" RADIOLIB_LINE_FEED "RadioLib Info" RADIOLIB_LINE_FEED "Version: \"" \
RADIOLIB_VALUE(RADIOLIB_VERSION_MAJOR) "." \
RADIOLIB_VALUE(RADIOLIB_VERSION_MINOR) "." \
RADIOLIB_VALUE(RADIOLIB_VERSION_PATCH) "." \
RADIOLIB_VALUE(RADIOLIB_VERSION_EXTRA) "\"\n" \
"Platform: " RADIOLIB_VALUE(RADIOLIB_PLATFORM) "\n" \
RADIOLIB_VALUE(RADIOLIB_VERSION_EXTRA) "\"" RADIOLIB_LINE_FEED \
"Platform: " RADIOLIB_VALUE(RADIOLIB_PLATFORM) "" RADIOLIB_LINE_FEED \
"Compiled: " RADIOLIB_VALUE(__DATE__) " " RADIOLIB_VALUE(__TIME__)

/*!
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Si443x/Si443x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ int16_t Si443x::updateClockRecovery() {
uint16_t rxOsr_fixed = (uint16_t)rxOsr;

// print that whole mess
RADIOLIB_DEBUG_BASIC_PRINTLN("%X\n%X\n%X", bypass, decRate, manch);
RADIOLIB_DEBUG_BASIC_PRINTLN("%X %X %X", bypass, decRate, manch);
RADIOLIB_DEBUG_BASIC_PRINT_FLOAT((double)rxOsr, 2);
RADIOLIB_DEBUG_BASIC_PRINTLN("\t%d\t%X\n%lu\t%lX\n%d\t%X", rxOsr_fixed, rxOsr_fixed, (long unsigned int)ncoOff, (long unsigned int)ncoOff, crGain, crGain);
RADIOLIB_DEBUG_BASIC_PRINTLN("\t%d\t%X" RADIOLIB_LINE_FEED "%lu\t%lX" RADIOLIB_LINE_FEED "%d\t%X", rxOsr_fixed, rxOsr_fixed, (long unsigned int)ncoOff, (long unsigned int)ncoOff, crGain, crGain);

// update oversampling ratio
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5);
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/Morse/Morse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int MorseClient::read(uint8_t* symbol, uint8_t* len, float low, float high) {
if((pauseLen >= low*(float)letterSpace) && (pauseLen <= high*(float)letterSpace)) {
return(RADIOLIB_MORSE_CHAR_COMPLETE);
} else if(pauseLen > wordSpace) {
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("\n<space>");
RADIOLIB_DEBUG_PROTOCOL_PRINTLN(RADIOLIB_LINE_FEED "<space>");
return(RADIOLIB_MORSE_WORD_COMPLETE);
}

Expand Down Expand Up @@ -164,7 +164,7 @@ size_t MorseClient::write(uint8_t b) {
// letter space
standby();
mod->waitForMicroseconds(mod->hal->micros(), letterSpace*1000 - dotLength*1000);
RADIOLIB_DEBUG_PROTOCOL_PRINT_NOTAG("\n");
RADIOLIB_DEBUG_PROTOCOL_PRINT_NOTAG(RADIOLIB_LINE_FEED);

return(1);
}
Expand Down

0 comments on commit e087449

Please sign in to comment.