Compare commits

...

3 Commits

Author SHA1 Message Date
615637e24c add dht dependency 2025-12-02 20:07:04 +01:00
6dd232fb83 rename heart variables and function 2025-12-01 12:18:38 +01:00
3ba29199c4 rename files 2025-12-01 11:22:29 +01:00
6 changed files with 32 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
file(GLOB_RECURSE srcs "main.c" "src/*.c") file(GLOB_RECURSE srcs "main.c" "src/*.c")
idf_component_register(SRCS "${srcs}" idf_component_register(SRCS "${srcs}"
PRIV_REQUIRES bt nvs_flash esp_driver_gpio PRIV_REQUIRES bt nvs_flash esp_driver_gpio dht
INCLUDE_DIRS "./include") INCLUDE_DIRS "./include")

View File

@@ -4,12 +4,16 @@
/* Includes */ /* Includes */
/* ESP APIs */ /* ESP APIs */
#include "esp_random.h" #include "esp_random.h"
#include "dht.h"
/* Defines */ /* Defines */
#define HEART_RATE_TASK_PERIOD (1000 / portTICK_PERIOD_MS) #define HEART_RATE_TASK_PERIOD (1000 / portTICK_PERIOD_MS)
#define DHT_GPIO_PIN 23
#define DHT_SENSOR_TIPO DHT_TYPE_DHT11
/* Public function declarations */ /* Public function declarations */
uint8_t get_heart_rate(void); uint8_t get_temp(void);
void update_heart_rate(void); void update_temp(void);
void init_sensor(void);
#endif // HEART_RATE_H #endif // HEART_RATE_H

View File

@@ -2,7 +2,7 @@
#include "common.h" #include "common.h"
#include "gap.h" #include "gap.h"
#include "gatt_svc.h" #include "gatt_svc.h"
#include "heart_rate.h" #include "temp.h"
#include "led.h" #include "led.h"
/* Library function declarations */ /* Library function declarations */
@@ -59,8 +59,8 @@ static void heart_rate_task(void *param) {
/* Loop forever */ /* Loop forever */
while (1) { while (1) {
/* Update heart rate value every 1 second */ /* Update heart rate value every 1 second */
update_heart_rate(); update_temp();
ESP_LOGI(TAG, "heart rate updated to %d", get_heart_rate()); ESP_LOGI(TAG, "heart rate updated to %d", get_temp());
/* Send heart rate indication if enabled */ /* Send heart rate indication if enabled */
send_heart_rate_indication(); send_heart_rate_indication();

View File

@@ -1,7 +1,7 @@
/* Includes */ /* Includes */
#include "gatt_svc.h" #include "gatt_svc.h"
#include "common.h" #include "common.h"
#include "heart_rate.h" #include "temp.h"
#include "led.h" #include "led.h"
/* Private function declarations */ /* Private function declarations */
@@ -87,7 +87,7 @@ static int heart_rate_chr_access(uint16_t conn_handle, uint16_t attr_handle,
/* Verify attribute handle */ /* Verify attribute handle */
if (attr_handle == heart_rate_chr_val_handle) { if (attr_handle == heart_rate_chr_val_handle) {
/* Update access buffer value */ /* Update access buffer value */
heart_rate_chr_val[1] = get_heart_rate(); heart_rate_chr_val[1] = get_temp();
rc = os_mbuf_append(ctxt->om, &heart_rate_chr_val, rc = os_mbuf_append(ctxt->om, &heart_rate_chr_val,
sizeof(heart_rate_chr_val)); sizeof(heart_rate_chr_val));
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;

View File

@@ -1,11 +0,0 @@
/* Includes */
#include "common.h"
#include "heart_rate.h"
/* Private variables */
static uint8_t heart_rate;
/* Public functions */
uint8_t get_heart_rate(void) { return heart_rate; }
void update_heart_rate(void) { heart_rate = 60 + (uint8_t)(esp_random() % 21); }

20
main/src/temp.c Normal file
View File

@@ -0,0 +1,20 @@
/* Includes */
#include "common.h"
#include "temp.h"
#include "driver/gpio.h"
/* Private variables */
static uint8_t heart_rate;
/* Public functions */
uint8_t get_temp(void) { return heart_rate; }
void update_temp(void) { heart_rate = 60 + (uint8_t)(esp_random() % 21); }
void init_sensor(void) {
// DHT PULL up resistor config
gpio_set_direction(DHT_GPIO_PIN, GPIO_MODE_INPUT);
gpio_pullup_en(DHT_GPIO_PIN);
printf("DHT sensor config init, pull up resistor and pin: %d\n", DHT_GPIO_PIN);
}