Compare commits
3 Commits
01b03d2463
...
615637e24c
| Author | SHA1 | Date | |
|---|---|---|---|
| 615637e24c | |||
| 6dd232fb83 | |||
| 3ba29199c4 |
@@ -1,5 +1,5 @@
|
||||
file(GLOB_RECURSE srcs "main.c" "src/*.c")
|
||||
|
||||
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")
|
||||
|
||||
@@ -4,12 +4,16 @@
|
||||
/* Includes */
|
||||
/* ESP APIs */
|
||||
#include "esp_random.h"
|
||||
#include "dht.h"
|
||||
|
||||
/* Defines */
|
||||
#define HEART_RATE_TASK_PERIOD (1000 / portTICK_PERIOD_MS)
|
||||
#define DHT_GPIO_PIN 23
|
||||
#define DHT_SENSOR_TIPO DHT_TYPE_DHT11
|
||||
|
||||
/* Public function declarations */
|
||||
uint8_t get_heart_rate(void);
|
||||
void update_heart_rate(void);
|
||||
uint8_t get_temp(void);
|
||||
void update_temp(void);
|
||||
void init_sensor(void);
|
||||
|
||||
#endif // HEART_RATE_H
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "common.h"
|
||||
#include "gap.h"
|
||||
#include "gatt_svc.h"
|
||||
#include "heart_rate.h"
|
||||
#include "temp.h"
|
||||
#include "led.h"
|
||||
|
||||
/* Library function declarations */
|
||||
@@ -59,8 +59,8 @@ static void heart_rate_task(void *param) {
|
||||
/* Loop forever */
|
||||
while (1) {
|
||||
/* Update heart rate value every 1 second */
|
||||
update_heart_rate();
|
||||
ESP_LOGI(TAG, "heart rate updated to %d", get_heart_rate());
|
||||
update_temp();
|
||||
ESP_LOGI(TAG, "heart rate updated to %d", get_temp());
|
||||
|
||||
/* Send heart rate indication if enabled */
|
||||
send_heart_rate_indication();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Includes */
|
||||
#include "gatt_svc.h"
|
||||
#include "common.h"
|
||||
#include "heart_rate.h"
|
||||
#include "temp.h"
|
||||
#include "led.h"
|
||||
|
||||
/* Private function declarations */
|
||||
@@ -87,7 +87,7 @@ static int heart_rate_chr_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
/* Verify attribute handle */
|
||||
if (attr_handle == heart_rate_chr_val_handle) {
|
||||
/* 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,
|
||||
sizeof(heart_rate_chr_val));
|
||||
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
|
||||
@@ -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
20
main/src/temp.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user