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

Include user context in sx127x struct #20

Open
wants to merge 1 commit 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
17 changes: 17 additions & 0 deletions include/sx127x.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ struct sx127x_t {

bool use_implicit_header;

void* user_context;

void (*rx_callback)(sx127x *, uint8_t *, uint16_t);

void (*tx_callback)(sx127x *);
Expand Down Expand Up @@ -372,6 +374,21 @@ struct sx127x_t {
*/
int sx127x_create(void *spi_device, sx127x *result);

/**
* @brief Set user context
*
* @param user_context Callback context that can be retrieved in callbacks
* @param device Pointer to variable to hold the device handle
*/
void sx127x_set_user_context(void *user_context, sx127x *device);

/**
* @brief Get user context
*
* @param device Pointer to variable to hold the device handle
*/
void* sx127x_get_user_context(sx127x *device);

/**
* @brief Set operating mode.
*
Expand Down
10 changes: 10 additions & 0 deletions src/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,16 @@ int sx127x_create(void *spi_device, sx127x *result) {
return SX127X_OK;
}

void sx127x_set_user_context(void *user_context, sx127x *device)
{
device->user_context = user_context;
}

void* sx127x_get_user_context(sx127x *device)
{
return device->user_context;
}

int sx127x_set_opmod(sx127x_mode_t opmod, sx127x_modulation_t modulation, sx127x *device) {
// enforce DIO mappings for RX and TX
if (modulation == SX127x_MODULATION_LORA) {
Expand Down