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

[BLE sample] Log sleep interval and encoding on boot #223

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions code/nrf-connect/samples/ble/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_ASSERT=y

# Application config - see all options in Kconfig.
# CONFIG_PRST_BLE_ENCODING_BTHOME_V2=y
# CONFIG_PRST_SLEEP_DURATION_MSEC=1000

# The amount of time it sleeps between sending data.
CONFIG_PRST_SLEEP_DURATION_MSEC=600000

# Choose one of the following encoding options:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would refrain from exhaustively listing options in the prj.conf file. Reasoning:

  • Why list some configs and not others?
  • Why only in prj.conf and not prj_debug.conf?
  • More importantly, this list will go stale once we add or remove some of these options.

A quick example and pointing to Kconfig for details is enough, as before.

CONFIG_PRST_BLE_ENCODING_BTHOME_V2=y
# CONFIG_PRST_BLE_ENCODING_BTHOME_V1=y
# CONFIG_PRST_BLE_ENCODING_BPARASITE_V2=y

# prstlib config - ser all options in prstlib/Kconfig.
# CONFIG_PRSTLIB_LOG_LEVEL_DBG=y
11 changes: 11 additions & 0 deletions code/nrf-connect/samples/ble/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ static int prst_loop(prst_sensors_t *sensors) {
int main(void) {
__ASSERT(!prst_init(), "Error in prst_init()");
prst_led_flash(2);

if (IS_ENABLED(CONFIG_PRST_BLE_ENCODING_BTHOME_V2)) {
Copy link
Owner

@rbaron rbaron Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will silently output nothing when new encoding schemes are introduced. We have this information at compile time, we can also avoid paying the binary size cost for all these strings.

static void dump_config() {

#if IS_ENABLED(CONFIG_PRST_BLE_ENCODING_BTHOME_V2)
// Only capitalize first letter.
  LOG_INFO("Payload encoding: BTHOME_V2");
#else if ...
...
#else
#error "Unhandled CONFIG_PRST_BLE_ENCODING_ choice in dump_config()"
#endif

  LOG_INF("Sleep duration: %d ms", CONFIG_PRST_SLEEP_DURATION_MSEC);
}

int main(void) {
  ...

  dump_config();

  ...
}

LOG_INF("Payload Encoding: BTHOME_V2");
} else if (IS_ENABLED(CONFIG_PRST_BLE_ENCODING_BTHOME_V1)) {
LOG_INF("Payload Encoding: BTHOME_V1");
} else if (IS_ENABLED(CONFIG_PRST_BLE_ENCODING_BPARASITE_V2)) {
LOG_INF("Payload Encoding: BPARASITE_V2");
}

LOG_INF("Sleep duration: %d", CONFIG_PRST_SLEEP_DURATION_MSEC);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit " ms"


prst_sensors_t sensors;
while (true) {
__ASSERT(!prst_loop(&sensors), "Error in prst_loop()");
Expand Down
Loading