address changes

This commit is contained in:
Mestery 2023-04-10 14:51:07 +02:00 committed by GitHub
parent 220b4dad7f
commit 17ae017f89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 32 deletions

View file

@ -1040,31 +1040,8 @@
#if defined(RADIOLIB_DEBUG) #if defined(RADIOLIB_DEBUG)
#if defined(RADIOLIB_BUILD_ARDUINO) #if defined(RADIOLIB_BUILD_ARDUINO)
// https://github.com/esp8266/Arduino/blob/65579d29081cb8501e4d7f786747bf12e7b37da2/cores/esp8266/Print.cpp#L50 #define RADIOLIB_DEBUG_PRINT(...) Module::serialPrintf(__VA_ARGS__)
size_t serialPrintf(const char *format, ...) { #define RADIOLIB_DEBUG_PRINTLN(M, ...) Module::serialPrintf(M "\n", ##__VA_ARGS__)
va_list arg;
va_start(arg, format);
char temp[64];
char* buffer = temp;
size_t len = vsnprintf(temp, sizeof(temp), format, arg);
va_end(arg);
if (len > sizeof(temp) - 1) {
buffer = new char[len + 1];
if (!buffer) {
return 0;
}
va_start(arg, format);
vsnprintf(buffer, len + 1, format, arg);
va_end(arg);
}
len = RADIOLIB_DEBUG_PORT.write((const uint8_t*) buffer, len);
if (buffer != temp) {
delete[] buffer;
}
return len;
}
#define RADIOLIB_DEBUG_PRINT(...) serialPrintf(__VA_ARGS__)
#define RADIOLIB_DEBUG_PRINTLN(M, ...) serialPrintf(M "\n", ##__VA_ARGS__)
#else #else
#if !defined(RADIOLIB_DEBUG_PRINT) #if !defined(RADIOLIB_DEBUG_PRINT)
#define RADIOLIB_DEBUG_PRINT(...) fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__) #define RADIOLIB_DEBUG_PRINT(...) fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__)

View file

@ -161,9 +161,9 @@ int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t
} }
#if defined(RADIOLIB_DEBUG) && defined(RADIOLIB_BUILD_ARDUINO) #if defined(RADIOLIB_DEBUG) && defined(RADIOLIB_BUILD_ARDUINO)
#define DEBUG_BIN(x) RADIOLIB_DEBUG_PORT.println(x, BIN) #define RADIOLIB_DEBUG_PRINT_BIN(x) RADIOLIB_DEBUG_PORT.println(x, BIN)
#else // no bin representation, fallback to hex #else // no bin representation, fallback to hex
#define DEBUG_BIN(x) RADIOLIB_DEBUG_PRINTLN("%X", x) #define RADIOLIB_DEBUG_PRINT_BIN(x) RADIOLIB_DEBUG_PRINTLN("%X", x)
#endif #endif
// check failed, print debug info // check failed, print debug info
@ -171,15 +171,15 @@ int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t
RADIOLIB_DEBUG_PRINTLN("address:\t0x%X", reg); RADIOLIB_DEBUG_PRINTLN("address:\t0x%X", reg);
RADIOLIB_DEBUG_PRINTLN("bits:\t\t%d %d", msb, lsb); RADIOLIB_DEBUG_PRINTLN("bits:\t\t%d %d", msb, lsb);
RADIOLIB_DEBUG_PRINT("value:\t\t0b"); RADIOLIB_DEBUG_PRINT("value:\t\t0b");
DEBUG_BIN(value); RADIOLIB_DEBUG_PRINT_BIN(value);
RADIOLIB_DEBUG_PRINT("current:\t0b"); RADIOLIB_DEBUG_PRINT("current:\t0b");
DEBUG_BIN(currentValue); RADIOLIB_DEBUG_PRINT_BIN(currentValue);
RADIOLIB_DEBUG_PRINT("mask:\t\t0b"); RADIOLIB_DEBUG_PRINT("mask:\t\t0b");
DEBUG_BIN(mask); RADIOLIB_DEBUG_PRINT_BIN(mask);
RADIOLIB_DEBUG_PRINT("new:\t\t0b"); RADIOLIB_DEBUG_PRINT("new:\t\t0b");
DEBUG_BIN(newValue); RADIOLIB_DEBUG_PRINT_BIN(newValue);
RADIOLIB_DEBUG_PRINT("read:\t\t0b"); RADIOLIB_DEBUG_PRINT("read:\t\t0b");
DEBUG_BIN(readValue); RADIOLIB_DEBUG_PRINT_BIN(readValue);
RADIOLIB_DEBUG_PRINTLN(); RADIOLIB_DEBUG_PRINTLN();
return(RADIOLIB_ERR_SPI_WRITE_FAILED); return(RADIOLIB_ERR_SPI_WRITE_FAILED);
@ -757,6 +757,32 @@ void Module::regdump(uint16_t start, size_t len) {
#endif #endif
} }
#if defined(RADIOLIB_DEBUG) and defined(RADIOLIB_BUILD_ARDUINO)
// https://github.com/esp8266/Arduino/blob/65579d29081cb8501e4d7f786747bf12e7b37da2/cores/esp8266/Print.cpp#L50
size_t Module::serialPrintf(const char* format, ...) {
va_list arg;
va_start(arg, format);
char temp[64];
char* buffer = temp;
size_t len = vsnprintf(temp, sizeof(temp), format, arg);
va_end(arg);
if (len > sizeof(temp) - 1) {
buffer = new char[len + 1];
if (!buffer) {
return 0;
}
va_start(arg, format);
vsnprintf(buffer, len + 1, format, arg);
va_end(arg);
}
len = RADIOLIB_DEBUG_PORT.write((const uint8_t*)buffer, len);
if (buffer != temp) {
delete[] buffer;
}
return len;
}
#endif
void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
// This can be on the stack, setRfSwitchTable copies the contents // This can be on the stack, setRfSwitchTable copies the contents
const RADIOLIB_PIN_TYPE pins[] = { const RADIOLIB_PIN_TYPE pins[] = {

View file

@ -704,6 +704,10 @@ class Module {
*/ */
void regdump(uint16_t start, size_t len); void regdump(uint16_t start, size_t len);
#if defined(RADIOLIB_DEBUG) and defined(RADIOLIB_BUILD_ARDUINO)
static size_t serialPrintf(const char* format, ...);
#endif
#if !defined(RADIOLIB_GODMODE) #if !defined(RADIOLIB_GODMODE)
private: private:
#endif #endif