Skip to content

Commit

Permalink
BREAKING: Move mgos_net API to mgos_event
Browse files Browse the repository at this point in the history
`mgos_net_add_event_handler()` is removed in favor of `mgos_event`-based
API.

Example:
```c
static void my_net_ev_handler(int ev, void *evd, void *arg) {
  if (ev == MGOS_NET_EV_IP_ACQUIRED) {
    LOG(LL_INFO, ("Just got IP!"));
    // Fetch something very useful from somewhere
  }
  (void) evd;
  (void) arg;
}

// Somewhere else:
mgos_event_add_group_handler(MGOS_EVENT_GRP_NET, my_net_ev_handler, NULL);
```

PUBLISHED_FROM=3e468cd9d0698d49713e57429776c29c624b1325
  • Loading branch information
dimonomid authored and cesantabot committed Dec 22, 2017
1 parent f4f01b6 commit e13a371
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/esp32/esp32_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ enum cs_log_level ll_from_status(esp_bt_status_t status) {
return (status == ESP_BT_STATUS_SUCCESS ? LL_DEBUG : LL_ERROR);
}

static void mgos_bt_net_ev(enum mgos_net_event ev,
const struct mgos_net_event_data *ev_data,
void *arg) {
static void mgos_bt_net_ev(int ev, void *evd, void *arg) {
if (ev != MGOS_NET_EV_IP_ACQUIRED) return;
LOG(LL_INFO, ("Network is up, disabling Bluetooth"));
mgos_sys_config_set_bt_enable(false);
Expand Down Expand Up @@ -235,7 +233,7 @@ bool mgos_bt_common_init(void) {
}

if (!mgos_sys_config_get_bt_keep_enabled()) {
mgos_net_add_event_handler(mgos_bt_net_ev, NULL);
mgos_event_add_group_handler(MGOS_EVENT_GRP_NET, mgos_bt_net_ev, NULL);
}

LOG(LL_INFO, ("Bluetooth init ok, pairing %s, %d paired devices",
Expand Down

0 comments on commit e13a371

Please sign in to comment.