Compare commits

...

3 commits

Author SHA1 Message Date
Morgan 'ARR\!' Allen
732834ce24 add user/pour_button to config 2025-07-28 21:53:32 -07:00
Morgan 'ARR\!' Allen
bcb877887e more debugging around ble 2025-07-28 21:53:07 -07:00
Morgan 'ARR\!' Allen
8275050dee Reworked pumps and change button IO 2025-07-28 21:52:08 -07:00
5 changed files with 30 additions and 14 deletions

View file

@ -7,10 +7,12 @@
#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]));
static uint8_t pump_gpio_map[] = { 27, 26, 25, 33 };
// Pins with Weak Pull-Downs 2, 4, 12, 13
static uint8_t pump_gpio_map[] = { 12, 13, 2, 4 };
void pumps_run();
void pumps_stop();
uint8_t pumps_io_init();
uint8_t pumps_init();
uint8_t pumps_set_duration(uint8_t idx, uint8_t time);

View file

@ -138,8 +138,7 @@ static const struct ble_gatt_svc_def service_defs[] = {
{ 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;
int rc;
@ -159,6 +158,7 @@ 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) {
uint16_t uuid16 = ble_uuid_u16(ctxt->chr->uuid);
uint8_t value = 0;
uint16_t vlen = 0;
ESP_LOGI(TAG, "0x%02X access: %d", uuid16, ctxt->op);
@ -168,9 +168,11 @@ static int svc_access_system(uint16_t conn_handle, uint16_t attr_handle, struct
ctxt->om,
sizeof value,
sizeof value,
&value, NULL
&value, &vlen
);
ESP_LOGI(TAG, "value (%d): %d", vlen, value);
switch(uuid16) {
case BAROS_CHAR_POUR:
if(value == 1) {

View file

@ -23,6 +23,9 @@ uint8_t mac[6];
nvs_handle_t config_handle = {};
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();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
@ -53,7 +56,7 @@ void app_main(void) {
.elements = {
CFGLR_ELEMENT_U8("armed", 1, CFGLR_SIGNALER_IDF_EVENT()),
CFGLR_ELEMENT_U8("monitor", 0, CFGLR_SIGNALER_IDF_EVENT()),
CFGLR_ELEMENT_U8("pour_button", 21, CFGLR_SIGNALER_IDF_EVENT()),
CFGLR_ELEMENT_U8("pour_button", 19, 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("pump_pins", 4, pump_gpio_map, 4, CFGLR_SIGNALER_IDF_EVENT()),

View file

@ -47,7 +47,7 @@ uint8_t pumps_set_enabled(uint8_t idx, uint8_t value) {
value = (value ? 1 : 0);
ESP_LOGD(TAG, "gpio: %d value: %d", io, value);
ESP_LOGI(TAG, "gpio: %d value: %d", io, value);
// invert IO
if(safety)
gpio_set_level(io, value);
@ -89,8 +89,6 @@ void pumps_stop() {
if(pump_timers[i] != NULL) {
pump_disable(i);
xTimerStop(pump_timers[i], 0);
i++;
}
}
}
@ -103,15 +101,13 @@ void pumps_run() {
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);
pumps_set_enabled(i, 1);
}
}
uint8_t pumps_init() {
uint8_t pumps_io_init() {
gpio_config_t io_conf;
// put the output high before initializing
@ -125,12 +121,21 @@ uint8_t pumps_init() {
io_conf.pin_bit_mask = GPIO_PUMP_PIN_SEL;
io_conf.pull_down_en = 1;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
return gpio_config(&io_conf);
}
uint8_t pumps_init() {
// zero out pump enabled, duration
memset(&pumps_enabled, 0, 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;
if(!nvs_get_blob(config_handle, "pumps_duration", &pumps_duration, &size)) {
ESP_LOGI(TAG, "Initializing pumps config");

View file

@ -2,12 +2,14 @@
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "main.h"
#include "pumps.h"
#include "ble.h"
#define GPIO_USER_BUTTON (14)
#define GPIO_USER_BUTTON (19)
#define TAG "user_btn"
static void IRAM_ATTR gpio_isr_handler(void* arg) {
uint32_t gpio_num = (uint32_t) arg;
@ -27,7 +29,7 @@ static void gpio_task(void* arg) {
if(level == last_level) continue;
last_level = level;
printf("GPIO[%ld] intr, val: %d\n", io_num, level);
ESP_LOGI(TAG, "GPIO[%ld] intr, val: %d\n", io_num, level);
if(state == 0)
vTaskDelay(10 / portTICK_PERIOD_MS);
@ -42,6 +44,8 @@ static void gpio_task(void* arg) {
}
void user_button_init() {
ESP_LOGI(TAG, "user_button_init");
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_ANYEDGE;