From bc0830f81d5d422dff32e93547d45516c10ee500 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 26 Jun 2023 15:34:48 +0200 Subject: [PATCH] configuration write handler --- components/BLEh | 2 +- main/Alim1000W.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/components/BLEh b/components/BLEh index 544c26f..a15c1ca 160000 --- a/components/BLEh +++ b/components/BLEh @@ -1 +1 @@ -Subproject commit 544c26fdfda6d679f07192b2358de1cefc998859 +Subproject commit a15c1ca68e8bc601ae82f5b9184a5742e741ccee diff --git a/main/Alim1000W.c b/main/Alim1000W.c index d6b2f6c..4ea2cf8 100644 --- a/main/Alim1000W.c +++ b/main/Alim1000W.c @@ -69,6 +69,31 @@ void on_char_read_handler(int svc_ind, int chr_ind, void** value, size_t* value_ } } +int on_char_write_handler(int svc_ind, int chr_ind, struct os_mbuf* os){ + ESP_LOGI(TAG, "char write handler"); + uint32_t val; + + int rc = 0; + + switch(svc_ind){ + case CONFIGURATION_SVC_ID: + switch (chr_ind){ + case SWITCHING_FREQUENCY_CHR_ID: + ; + rc = gatt_svr_chr_write_get_data(os, sizeof(val), sizeof(val), &val, NULL); + switching_frequency = val; + break; + case DUTY_CYCLE_CHR_ID: + rc = gatt_svr_chr_write_get_data(os, sizeof(val), sizeof(val), &val, NULL); + duty_cycle = val; + break; + } + break; + } + + return rc; +} + void app_main(void){ adc_continuous_handle_cfg_t adc_h_conf = { .conv_frame_size = SOC_ADC_DIGI_DATA_BYTES_PER_CONV, @@ -174,7 +199,8 @@ void app_main(void){ gatt_value_server_handle_t calc_meas_serve_handle = simple_gatt_value_server(calc_meas, sizeof(uint32_t), ADC_IN_PIN_NUM, calc_meas_formats, &gatt_svcs[CALC_VALUES_SVC_ID], CALC_VALUES_SVC_ID, calc_meas_char_uuid); - add_on_char_read_handler(on_char_read_handler); + set_on_char_read_handler(on_char_read_handler); + set_on_char_write_handler(on_char_write_handler); set_gatt_services(gatt_svcs, SVCS_NUM);