From 65240ee6038eb15a34309efa3c3bf4e94e1e4b78 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 24 Jun 2023 19:30:39 +0200 Subject: [PATCH] raw voltage values --- components/BLEh | 2 +- main/Alim1000W.c | 17 +++++++++++++++++ main/BLE.c | 18 ------------------ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/components/BLEh b/components/BLEh index c879e0d..6a651ce 160000 --- a/components/BLEh +++ b/components/BLEh @@ -1 +1 @@ -Subproject commit c879e0dd70ae36d9db3c6d50ef0c62bc9259055d +Subproject commit 6a651ce129cf9d0ce562aa676cbdd9789ff6011e diff --git a/main/Alim1000W.c b/main/Alim1000W.c index 3266d46..97ce248 100644 --- a/main/Alim1000W.c +++ b/main/Alim1000W.c @@ -1,6 +1,7 @@ #include #include +#include "BLE_UUID.h" #include "esp_attr.h" #include "esp_err.h" #include "esp_log.h" @@ -9,6 +10,7 @@ #include "freertos/projdefs.h" #include "freertos/task.h" #include "freertos/portmacro.h" +#include "host/ble_uuid.h" #include "spinlock.h" #include "esp_adc/adc_continuous.h" @@ -22,6 +24,7 @@ #include "sdkconfig.h" #include "BLEh.h" +#include "simple_gatt_value_server.h" #include "BLE.h" @@ -108,7 +111,21 @@ void app_main(void){ nvs_flash_init(); + uint32_t raw_mv_meas[ADC_IN_PIN_NUM]; + + struct char_pres_format mv_char_pres_format = { + .format = FORMAT_UINT32, + .unit = VOLTS_UNIT_UUID, + .exponent = -3, + .namespc = 1, + .descrH = NSP_DESC_MAIN & 0xff, + .descrL = (NSP_DESC_MAIN>>8) & 0xff, + }; + + simple_gatt_value_server(&raw_mv_meas, sizeof(uint32_t), ADC_IN_PIN_NUM, mv_char_pres_format, &gatt_svcs[RAW_VALUES_SVC_ID], BLE_UUID16_DECLARE(VOLTAGE_CHAR)); + set_gatt_services(gatt_svcs, SVCS_NUM); + initBLE("ALIM"); ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(adc_handle, &adc_event, NULL)); diff --git a/main/BLE.c b/main/BLE.c index 528a4a7..77e0d99 100644 --- a/main/BLE.c +++ b/main/BLE.c @@ -23,24 +23,6 @@ struct ble_gatt_svc_def gatt_svcs[] = { [RAW_VALUES_SVC_ID] = { .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = BLE_UUID16_DECLARE(METROLOGY_SERVICE), - .characteristics = (struct ble_gatt_chr_def[]){ - [0] = { - .uuid = BLE_UUID16_DECLARE(VOLTAGE_CHAR), - .access_cb = gatt_char_access_placeholder, - .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, - .min_key_size = 0, - .arg = NULL, - .descriptors = (struct ble_gatt_dsc_def[]){ - [0] = { - .uuid = BLE_UUID16_DECLARE(CHAR_PRES_FORMAT), - .att_flags = BLE_GATT_CHR_F_READ, - .access_cb = gatt_char_access_placeholder, - }, - { 0 }, - }, - }, - { 0 }, - }, }, [CONFIGURATION_SVC_ID] = { .type = BLE_GATT_SVC_TYPE_PRIMARY,