Skip to content

Commit

Permalink
Add write with no response
Browse files Browse the repository at this point in the history
  • Loading branch information
rojer committed Aug 5, 2020
1 parent 9262dc5 commit 3b818c3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ AllowShortFunctionsOnASingleLine: false
SpaceAfterCStyleCast: true
PointerBindsToType: false
DerivePointerBinding: false
IncludeBlocks: Preserve
4 changes: 2 additions & 2 deletions include/mgos_bt_gattc.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ bool mgos_bt_gattc_discover(int conn_id);
bool mgos_bt_gattc_disconnect(int conn_id);
bool mgos_bt_gattc_read(int conn_id, uint16_t handle);
bool mgos_bt_gattc_subscribe(int conn_id, uint16_t handle);
bool mgos_bt_gattc_write(int conn_id, uint16_t handle, const void *data,
int len);
bool mgos_bt_gattc_write(int conn_id, uint16_t handle, struct mg_str data,
bool resp_required);

#ifdef __cplusplus
}
Expand Down
11 changes: 6 additions & 5 deletions src/esp32/esp32_bt_gattc.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ bool mgos_bt_gattc_subscribe(int conn_id, uint16_t handle) {
return err == ESP_OK;
}

bool mgos_bt_gattc_write(int conn_id, uint16_t handle, const void *data,
int len) {
bool mgos_bt_gattc_write(int conn_id, uint16_t handle, struct mg_str data,
bool resp_required) {
if (esp32_bt_is_scanning()) return false;
struct conn *conn = find_by_conn_id(conn_id);
if (conn == NULL) return false;
esp_err_t err =
esp_ble_gattc_write_char(conn->iface, conn_id, handle, len, (void *) data,
ESP_GATT_WRITE_TYPE_RSP, 0);
esp_gatt_write_type_t wt =
(resp_required ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP);
esp_err_t err = esp_ble_gattc_write_char(conn->iface, conn_id, handle,
data.len, (void *) data.p, wt, 0);
LOG(LL_DEBUG, ("WRITE %d: %d", conn_id, err));
return err == ESP_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mgos_bt_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool mgos_bt_gattc_connect_js(const char *addr_s) {

bool mgos_bt_gattc_write_js(int conn_id, uint16_t handle,
const struct mg_str *data) {
return mgos_bt_gattc_write(conn_id, handle, data->p, data->len);
return mgos_bt_gattc_write(conn_id, handle, *data, true /* resp_required */);
}

static const struct mjs_c_struct_member gattc_discovery_result_arg_def[] = {
Expand Down

0 comments on commit 3b818c3

Please sign in to comment.