Compare commits
No commits in common. "732834ce248033bace137e3e296314d50b151845" and "53a9f358fa527bd9db29d84c6f42f93d3752e162" have entirely different histories.
732834ce24
...
53a9f358fa
5 changed files with 14 additions and 30 deletions
|
@ -7,12 +7,10 @@
|
||||||
#define PUMPS_ERR_OUT_IDX (1)
|
#define PUMPS_ERR_OUT_IDX (1)
|
||||||
#define GPIO_PUMP_PIN_SEL ((1ULL<<pump_gpio_map[0]) | (1ULL<<pump_gpio_map[1]) | (1ULL<<pump_gpio_map[2]) | (1ULL<<pump_gpio_map[3]));
|
#define GPIO_PUMP_PIN_SEL ((1ULL<<pump_gpio_map[0]) | (1ULL<<pump_gpio_map[1]) | (1ULL<<pump_gpio_map[2]) | (1ULL<<pump_gpio_map[3]));
|
||||||
|
|
||||||
// Pins with Weak Pull-Downs 2, 4, 12, 13
|
static uint8_t pump_gpio_map[] = { 27, 26, 25, 33 };
|
||||||
static uint8_t pump_gpio_map[] = { 12, 13, 2, 4 };
|
|
||||||
|
|
||||||
void pumps_run();
|
void pumps_run();
|
||||||
void pumps_stop();
|
void pumps_stop();
|
||||||
uint8_t pumps_io_init();
|
|
||||||
uint8_t pumps_init();
|
uint8_t pumps_init();
|
||||||
|
|
||||||
uint8_t pumps_set_duration(uint8_t idx, uint8_t time);
|
uint8_t pumps_set_duration(uint8_t idx, uint8_t time);
|
||||||
|
|
|
@ -138,7 +138,8 @@ static const struct ble_gatt_svc_def service_defs[] = {
|
||||||
{ 0 } // no more services
|
{ 0 } // no more services
|
||||||
};
|
};
|
||||||
|
|
||||||
static int gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, void *dst, uint16_t *len) {
|
static int gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
|
||||||
|
void *dst, uint16_t *len) {
|
||||||
uint16_t om_len;
|
uint16_t om_len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -158,7 +159,6 @@ static int gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max
|
||||||
static int svc_access_system(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
|
static int svc_access_system(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
|
||||||
uint16_t uuid16 = ble_uuid_u16(ctxt->chr->uuid);
|
uint16_t uuid16 = ble_uuid_u16(ctxt->chr->uuid);
|
||||||
uint8_t value = 0;
|
uint8_t value = 0;
|
||||||
uint16_t vlen = 0;
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "0x%02X access: %d", uuid16, ctxt->op);
|
ESP_LOGI(TAG, "0x%02X access: %d", uuid16, ctxt->op);
|
||||||
|
|
||||||
|
@ -168,11 +168,9 @@ static int svc_access_system(uint16_t conn_handle, uint16_t attr_handle, struct
|
||||||
ctxt->om,
|
ctxt->om,
|
||||||
sizeof value,
|
sizeof value,
|
||||||
sizeof value,
|
sizeof value,
|
||||||
&value, &vlen
|
&value, NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "value (%d): %d", vlen, value);
|
|
||||||
|
|
||||||
switch(uuid16) {
|
switch(uuid16) {
|
||||||
case BAROS_CHAR_POUR:
|
case BAROS_CHAR_POUR:
|
||||||
if(value == 1) {
|
if(value == 1) {
|
||||||
|
|
|
@ -23,9 +23,6 @@ uint8_t mac[6];
|
||||||
nvs_handle_t config_handle = {};
|
nvs_handle_t config_handle = {};
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
// init pump IO immediately to limit run away pumps in case power is on
|
|
||||||
pumps_io_init();
|
|
||||||
|
|
||||||
esp_err_t err = nvs_flash_init();
|
esp_err_t err = nvs_flash_init();
|
||||||
|
|
||||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
@ -56,7 +53,7 @@ void app_main(void) {
|
||||||
.elements = {
|
.elements = {
|
||||||
CFGLR_ELEMENT_U8("armed", 1, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_U8("armed", 1, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_U8("monitor", 0, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_U8("monitor", 0, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_U8("pour_button", 19, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_U8("pour_button", 21, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_STR("device_name", 32, name, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_STR("device_name", 32, name, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_BIN("tank_levels", 4, tank_levels, 4, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_BIN("tank_levels", 4, tank_levels, 4, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_BIN("pump_pins", 4, pump_gpio_map, 4, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_BIN("pump_pins", 4, pump_gpio_map, 4, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
|
|
19
main/pumps.c
19
main/pumps.c
|
@ -47,7 +47,7 @@ uint8_t pumps_set_enabled(uint8_t idx, uint8_t value) {
|
||||||
|
|
||||||
value = (value ? 1 : 0);
|
value = (value ? 1 : 0);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "gpio: %d value: %d", io, value);
|
ESP_LOGD(TAG, "gpio: %d value: %d", io, value);
|
||||||
// invert IO
|
// invert IO
|
||||||
if(safety)
|
if(safety)
|
||||||
gpio_set_level(io, value);
|
gpio_set_level(io, value);
|
||||||
|
@ -89,6 +89,8 @@ void pumps_stop() {
|
||||||
if(pump_timers[i] != NULL) {
|
if(pump_timers[i] != NULL) {
|
||||||
pump_disable(i);
|
pump_disable(i);
|
||||||
xTimerStop(pump_timers[i], 0);
|
xTimerStop(pump_timers[i], 0);
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,13 +103,15 @@ void pumps_run() {
|
||||||
|
|
||||||
running++;
|
running++;
|
||||||
|
|
||||||
|
pump_timers[i] = xTimerCreate((const char *)(0x48 + i), (pumps_duration[i] * 1000 / portTICK_PERIOD_MS), pdFALSE, (void*)0, pump_timer_done);
|
||||||
|
|
||||||
xTimerStart(pump_timers[i], 0);
|
xTimerStart(pump_timers[i], 0);
|
||||||
|
|
||||||
pumps_set_enabled(i, 1);
|
pumps_set_enabled(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t pumps_io_init() {
|
uint8_t pumps_init() {
|
||||||
gpio_config_t io_conf;
|
gpio_config_t io_conf;
|
||||||
|
|
||||||
// put the output high before initializing
|
// put the output high before initializing
|
||||||
|
@ -121,21 +125,12 @@ uint8_t pumps_io_init() {
|
||||||
io_conf.pin_bit_mask = GPIO_PUMP_PIN_SEL;
|
io_conf.pin_bit_mask = GPIO_PUMP_PIN_SEL;
|
||||||
io_conf.pull_down_en = 1;
|
io_conf.pull_down_en = 1;
|
||||||
io_conf.pull_up_en = 0;
|
io_conf.pull_up_en = 0;
|
||||||
|
gpio_config(&io_conf);
|
||||||
return gpio_config(&io_conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t pumps_init() {
|
|
||||||
|
|
||||||
// zero out pump enabled, duration
|
// zero out pump enabled, duration
|
||||||
memset(&pumps_enabled, 0, sizeof(uint8_t) * PUMPS);
|
memset(&pumps_enabled, 0, sizeof(uint8_t) * PUMPS);
|
||||||
memset(&pumps_duration, 5, sizeof(uint8_t) * PUMPS);
|
memset(&pumps_duration, 5, sizeof(uint8_t) * PUMPS);
|
||||||
|
|
||||||
for(uint8_t i = 0; i < PUMPS; i++) {
|
|
||||||
gpio_set_level(pump_gpio_map[i], 0);
|
|
||||||
pump_timers[i] = xTimerCreate((const char *)(0x48 + i), (pumps_duration[i] * 1000 / portTICK_PERIOD_MS), pdFALSE, (void*)0, pump_timer_done);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = sizeof(uint8_t) * PUMPS;
|
size_t size = sizeof(uint8_t) * PUMPS;
|
||||||
if(!nvs_get_blob(config_handle, "pumps_duration", &pumps_duration, &size)) {
|
if(!nvs_get_blob(config_handle, "pumps_duration", &pumps_duration, &size)) {
|
||||||
ESP_LOGI(TAG, "Initializing pumps config");
|
ESP_LOGI(TAG, "Initializing pumps config");
|
||||||
|
|
|
@ -2,14 +2,12 @@
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "pumps.h"
|
#include "pumps.h"
|
||||||
#include "ble.h"
|
#include "ble.h"
|
||||||
|
|
||||||
#define GPIO_USER_BUTTON (19)
|
#define GPIO_USER_BUTTON (14)
|
||||||
#define TAG "user_btn"
|
|
||||||
|
|
||||||
static void IRAM_ATTR gpio_isr_handler(void* arg) {
|
static void IRAM_ATTR gpio_isr_handler(void* arg) {
|
||||||
uint32_t gpio_num = (uint32_t) arg;
|
uint32_t gpio_num = (uint32_t) arg;
|
||||||
|
@ -29,7 +27,7 @@ static void gpio_task(void* arg) {
|
||||||
if(level == last_level) continue;
|
if(level == last_level) continue;
|
||||||
last_level = level;
|
last_level = level;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "GPIO[%ld] intr, val: %d\n", io_num, level);
|
printf("GPIO[%ld] intr, val: %d\n", io_num, level);
|
||||||
|
|
||||||
if(state == 0)
|
if(state == 0)
|
||||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||||
|
@ -44,8 +42,6 @@ static void gpio_task(void* arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void user_button_init() {
|
void user_button_init() {
|
||||||
ESP_LOGI(TAG, "user_button_init");
|
|
||||||
|
|
||||||
gpio_config_t io_conf;
|
gpio_config_t io_conf;
|
||||||
|
|
||||||
io_conf.intr_type = GPIO_INTR_ANYEDGE;
|
io_conf.intr_type = GPIO_INTR_ANYEDGE;
|
||||||
|
|
Loading…
Add table
Reference in a new issue