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 sprintf #821

Merged
merged 26 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3532cd3
add support for sprintf_P printPrettyDetails
dstroy0 Jan 12, 2022
049aa73
add support for sprintf_P
dstroy0 Jan 12, 2022
ebd1f2c
trigger Arduino CI
2bndy5 Jan 13, 2022
ab0c1f6
trigger Arduino CI (for real this time)
2bndy5 Jan 13, 2022
22e4a0e
trigger Arduino CI for PR sync events
2bndy5 Jan 13, 2022
f85cb2e
allow build CI to be manually triggered via gh cli
2bndy5 Jan 13, 2022
093b55c
indent example code
dstroy0 Jan 13, 2022
84f57c8
autoack sprintfPrettyDetails behavior
dstroy0 Jan 13, 2022
8e869a2
include stdio and indent example
dstroy0 Jan 13, 2022
12fe922
documentation
dstroy0 Jan 13, 2022
cb95561
documentation typos
dstroy0 Jan 13, 2022
1e0c87a
add documentation to sprintfPrettyDetails
dstroy0 Jan 13, 2022
ff0fa84
trigger CI on PR target events
2bndy5 Jan 13, 2022
72bd633
Merge branch 'master' of https://github.com/dstroy0/RF24
dstroy0 Jan 13, 2022
c80d082
add sprintf_P directive
dstroy0 Jan 13, 2022
17876d9
update documentation
dstroy0 Jan 13, 2022
64f2dcc
add comment
dstroy0 Jan 13, 2022
e4b7320
add new function to sphinx docs
2bndy5 Jan 13, 2022
d5d936a
Merge branch 'master' of https://github.com/dstroy0/RF24 into pr/821
2bndy5 Jan 13, 2022
3fcb517
documentation typo
dstroy0 Jan 13, 2022
3f6b9cf
Merge branch 'master' of https://github.com/dstroy0/RF24
dstroy0 Jan 13, 2022
45cf6b9
documentation typo
dstroy0 Jan 13, 2022
5cf71cf
fix indentation and formatting
2bndy5 Jan 13, 2022
97a87ce
add sprintfDets to py wrapper (needs HW test)
2bndy5 Jan 14, 2022
0b53887
review changes
2bndy5 Jan 17, 2022
1a68d3d
fix hyperlink in docs
2bndy5 Jan 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/build_arduino.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Arduino CLI build

on:
pull_request_target:
types: [opened, reopened, synchronize]
pull_request:
types: [opened, reopened]
types: [opened, reopened, synchronized]
paths:
- ".github/workflows/build_arduino.yml"
- "examples/**"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Linux build

on:
pull_request_target:
types: [opened, reopened, synchronize]
pull_request:
types: [opened, reopened]
paths:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build_platformIO.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: PlatformIO build

on:
pull_request_target:
types: [opened, reopened, synchronize]
pull_request:
types: [opened, reopened]
types: [opened, reopened, synchronized]
paths:
- ".github/workflows/build_platformIO.yml"
- "library.json"
Expand Down
206 changes: 204 additions & 2 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "nRF24L01.h"
#include "RF24_config.h"
#include "RF24.h"

#include <stdio.h>

/****************************************************************************/

Expand Down Expand Up @@ -473,7 +473,6 @@ void RF24::print_status(uint8_t _status)

/****************************************************************************/


void RF24::print_observe_tx(uint8_t value)
{
printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"), value, (value >> PLOS_CNT) & 0x0F, (value >> ARC_CNT) & 0x0F);
Expand All @@ -498,6 +497,20 @@ void RF24::print_byte_register(const char* name, uint8_t reg, uint8_t qty)

/****************************************************************************/

void RF24::sprintf_byte_register(char *out_buffer, uint8_t reg, uint8_t qty)
{
uint8_t i = 0;
char sprintf_buffer[4] = {'\0'};
while (qty--) {
sprintf_P(sprintf_buffer, PSTR("%02x"), read_register(reg++));
out_buffer[i+0] = sprintf_buffer[0];
out_buffer[i+1] = sprintf_buffer[1];
i=i+2;
}
}

/****************************************************************************/

void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
{

Expand All @@ -520,6 +533,27 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
printf_P(PSTR("\r\n"));
}

/****************************************************************************/

void RF24::sprintf_address_register(char *out_buffer, uint8_t reg, uint8_t qty)
{
uint8_t i = 0;
char sprintf_buffer[4] = {'\0'};
uint8_t *read_buffer = new uint8_t[addr_width];
while (qty--) {
read_register(reg++ & REGISTER_MASK, read_buffer, addr_width);

uint8_t* bufptr = read_buffer + addr_width;
while (--bufptr >= read_buffer) {
sprintf_P(sprintf_buffer, PSTR("%02x"), *bufptr);
out_buffer[i] = sprintf_buffer[0];
out_buffer[i + 1] = sprintf_buffer[1];
i=i+2;
}
}
delete[] read_buffer;
}

#endif // !defined(MINIMAL)

/****************************************************************************/
Expand Down Expand Up @@ -783,6 +817,174 @@ void RF24::printPrettyDetails(void) {
}
}
}

/****************************************************************************/

void RF24::sprintfPrettyDetails(char *debugging_information)
{
const char *format_string = PSTR("================ SPI Configuration ================\n"
"CSN Pin\t\t\t= %d\n"
"CE Pin\t\t\t= %d\n"
"SPI Frequency\t\t= %d Mhz\n"
"================ NRF Configuration ================\n"
"Channel\t\t\t= %u (~ %u MHz)\n"
"RF Data Rate\t\t"
PRIPSTR
"\n"
"RF Power Amplifier\t"
PRIPSTR
"\n"
"RF Low Noise Amplifier\t"
PRIPSTR
"\n"
"CRC Length\t\t"
PRIPSTR
"\n"
"Address Length\t\t= %d bytes\n"
"Static Payload Length\t= %d bytes\n"
"Auto Retry Delay\t= %d microseconds\n"
"Auto Retry Attempts\t= %d maximum\n"
"Packets lost on\n current channel\t= %d\r\n"
"Retry attempts made for\n last transmission\t= %d\r\n"
"Multicast\t\t"
PRIPSTR
"\n"
"Custom ACK Payload\t"
PRIPSTR
"\n"
"Dynamic Payloads\t"
PRIPSTR
"\n"
"Auto Acknowledgment\t"
PRIPSTR
"\n"
"Primary Mode\t\t= %cX\n"
"TX address\t\t= 0x"
PRIPSTR
"\n"
"pipe 0 ("
PRIPSTR
") bound\t= 0x"
PRIPSTR
"\n"
"pipe 1 ("
PRIPSTR
") bound\t= 0x"
PRIPSTR
"\n"
"pipe 2 ("
PRIPSTR
") bound\t= 0x"
PRIPSTR
"\n"
"pipe 3 ("
PRIPSTR
") bound\t= 0x"
PRIPSTR
"\n"
"pipe 4 ("
PRIPSTR
") bound\t= 0x"
PRIPSTR
"\n"
"pipe 5 ("
PRIPSTR
") bound\t= 0x"
PRIPSTR
);

char tx_address_char_array[16] = {'\0'};
sprintf_address_register(tx_address_char_array, TX_ADDR);

char pipe_address_char_2d_array[6][16] = {'\0'};
char pipe_address_char_array[16] = {'\0'};
bool isOpen_array[6] = {false};

uint8_t openPipes = read_register(EN_RXADDR);
for (uint8_t i = 0; i < 6; ++i) {
bool isOpen = openPipes & _BV(i);
isOpen_array[i] = isOpen;
if (i < 2) {
sprintf_address_register(pipe_address_char_array, static_cast<uint8_t>(RX_ADDR_P0 + i));
for (uint8_t j = 0; j < 16; j++) {
pipe_address_char_2d_array[i][j] = pipe_address_char_array[j];
}
for (uint8_t j = 0; j < 16; j++) {
pipe_address_char_array[j] = '\0';
}
}
else {
sprintf_byte_register(pipe_address_char_array, static_cast<uint8_t>(RX_ADDR_P0 + i));
for (uint8_t j = 0; j < 16; j++) {
pipe_address_char_2d_array[i][j] = pipe_address_char_array[j];
}
for (uint8_t j = 0; j < 16; j++) {
pipe_address_char_array[j] = '\0';
}
}
}

char autoack_status_char_array[11] = {'\0'};
uint8_t autoAck = read_register(EN_AA);
if (autoAck == 0x3F || autoAck == 0) {
// all pipes have the same configuration about auto-ack feature
sprintf_P(autoack_status_char_array,
PSTR(""
PRIPSTR
""),
(char *)(pgm_read_ptr(&rf24_feature_e_str_P[static_cast<bool>(autoAck) * 1]))
);
}
else {
// representation per pipe
sprintf_P(autoack_status_char_array,
PSTR("= 0b%c%c%c%c%c%c"),
static_cast<char>(static_cast<bool>(autoAck & _BV(ENAA_P5)) + 48),
static_cast<char>(static_cast<bool>(autoAck & _BV(ENAA_P4)) + 48),
static_cast<char>(static_cast<bool>(autoAck & _BV(ENAA_P3)) + 48),
static_cast<char>(static_cast<bool>(autoAck & _BV(ENAA_P2)) + 48),
static_cast<char>(static_cast<bool>(autoAck & _BV(ENAA_P1)) + 48),
static_cast<char>(static_cast<bool>(autoAck & _BV(ENAA_P0)) + 48)
);
}

sprintf_P(debugging_information,
format_string,
csn_pin,
ce_pin,
static_cast<uint8_t>(spi_speed / 1000000),
getChannel(),
static_cast<uint16_t>(getChannel() + 2400),
(char *)(pgm_read_ptr(&rf24_datarate_e_str_P[getDataRate()])),
(char *)(pgm_read_ptr(&rf24_pa_dbm_e_str_P[getPALevel()])),
(char *)(pgm_read_ptr(&rf24_feature_e_str_P[(read_register(RF_SETUP) & 1) * 1])),
(char *)(pgm_read_ptr(&rf24_crclength_e_str_P[getCRCLength()])),
((read_register(SETUP_AW) & 3) + 2),
getPayloadSize(),
((read_register(SETUP_RETR) >> ARD) * 250 + 250),
(read_register(SETUP_RETR) & 0x0F),
(read_register(OBSERVE_TX) >> 4),
(read_register(OBSERVE_TX) & 0x0F),
(char *)(pgm_read_ptr(&rf24_feature_e_str_P[static_cast<bool>(read_register(FEATURE) & _BV(EN_DYN_ACK)) * 2])),
(char *)(pgm_read_ptr(&rf24_feature_e_str_P[static_cast<bool>(read_register(FEATURE) & _BV(EN_ACK_PAY)) * 1])),
(char *)(pgm_read_ptr(&rf24_feature_e_str_P[(read_register(DYNPD) && (read_register(FEATURE) &_BV(EN_DPL))) * 1])),
(autoack_status_char_array),
(read_register(NRF_CONFIG) & _BV(PRIM_RX) ? 'R' : 'T'),
(tx_address_char_array),
((char *)(pgm_read_ptr(&rf24_feature_e_str_P[isOpen_array[0] + 3]))),
(pipe_address_char_2d_array[0]),
((char *)(pgm_read_ptr(&rf24_feature_e_str_P[isOpen_array[1] + 3]))),
(pipe_address_char_2d_array[1]),
((char *)(pgm_read_ptr(&rf24_feature_e_str_P[isOpen_array[2] + 3]))),
(pipe_address_char_2d_array[2]),
((char *)(pgm_read_ptr(&rf24_feature_e_str_P[isOpen_array[3] + 3]))),
(pipe_address_char_2d_array[3]),
((char *)(pgm_read_ptr(&rf24_feature_e_str_P[isOpen_array[4] + 3]))),
(pipe_address_char_2d_array[4]),
((char *)(pgm_read_ptr(&rf24_feature_e_str_P[isOpen_array[5] + 3]))),
(pipe_address_char_2d_array[5])
);
}
#endif // !defined(MINIMAL)

/****************************************************************************/
Expand Down
Loading