Compare commits
No commits in common. "development" and "vienna_wtf" have entirely different histories.
developmen
...
vienna_wtf
16 changed files with 129 additions and 350 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
steps:
|
steps:
|
||||||
build:
|
build:
|
||||||
image: espressif/idf:v5.5.5
|
image: espressif/idf:v5.2.2
|
||||||
when:
|
when:
|
||||||
- event: [ tag, push, manual ]
|
- event: [ tag, push, manual ]
|
||||||
commands:
|
commands:
|
||||||
|
|
@ -13,6 +13,7 @@ steps:
|
||||||
- idf.py build
|
- idf.py build
|
||||||
release:
|
release:
|
||||||
image: woodpeckerci/plugin-release
|
image: woodpeckerci/plugin-release
|
||||||
|
secrets: [ ACCESS_TOKEN ]
|
||||||
when:
|
when:
|
||||||
- event: tag
|
- event: tag
|
||||||
settings:
|
settings:
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6467f21fcaf29cc8eb11d9e899a53f73acb13651
|
Subproject commit 54c7a2d2d65dc9159dad27d6388d8a5409b59dd0
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2e690a786443773b4bfddd9e631e04293c947c17
|
Subproject commit af52863f024eeed3c4730e2a7b945a18e9bfb9fb
|
||||||
|
|
@ -1,118 +0,0 @@
|
||||||
dependencies:
|
|
||||||
espressif/ble_conn_mgr:
|
|
||||||
component_hash: 4edfb961659fb1eec522acca3fa8826e04a7090f29021a354b92f33a86141cc9
|
|
||||||
dependencies:
|
|
||||||
- name: espressif/cmake_utilities
|
|
||||||
registry_url: https://components.espressif.com
|
|
||||||
require: private
|
|
||||||
version: 0.*
|
|
||||||
- name: idf
|
|
||||||
require: private
|
|
||||||
version: '>=4.3'
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com/
|
|
||||||
type: service
|
|
||||||
version: 1.2.0
|
|
||||||
espressif/ble_ota:
|
|
||||||
component_hash: 1415ffdf0ff3169d52b668f5da8c3dd60932938f07a28c54ffbc0e8901dbf7ba
|
|
||||||
dependencies:
|
|
||||||
- name: espressif/cmake_utilities
|
|
||||||
registry_url: https://components.espressif.com
|
|
||||||
require: private
|
|
||||||
version: 0.*
|
|
||||||
- name: espressif/esp_encrypted_img
|
|
||||||
registry_url: https://components.espressif.com
|
|
||||||
require: private
|
|
||||||
version: ^2.0.1
|
|
||||||
- name: idf
|
|
||||||
require: private
|
|
||||||
version: '>=4.4'
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com/
|
|
||||||
type: service
|
|
||||||
targets:
|
|
||||||
- esp32
|
|
||||||
- esp32c3
|
|
||||||
- esp32h2
|
|
||||||
- esp32s3
|
|
||||||
- esp32c2
|
|
||||||
- esp32c6
|
|
||||||
version: 0.1.16
|
|
||||||
espressif/ble_services:
|
|
||||||
component_hash: 1ec69e3bbb886d29ad2bec6c9db63c52784117a15d1a74ac07097f546b1822f3
|
|
||||||
dependencies: []
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com/
|
|
||||||
type: service
|
|
||||||
version: 1.4.0~1
|
|
||||||
espressif/cmake_utilities:
|
|
||||||
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
|
|
||||||
dependencies:
|
|
||||||
- name: idf
|
|
||||||
require: private
|
|
||||||
version: '>=4.1'
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com
|
|
||||||
type: service
|
|
||||||
version: 0.5.3
|
|
||||||
espressif/esp_delta_ota:
|
|
||||||
component_hash: 147161b602ef51e9f6649eb6d90c4d4ac3c94228cb264fa0e68be7877180462d
|
|
||||||
dependencies:
|
|
||||||
- name: idf
|
|
||||||
require: private
|
|
||||||
version: '>=4.3'
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com/
|
|
||||||
type: service
|
|
||||||
version: 1.1.4
|
|
||||||
espressif/esp_encrypted_img:
|
|
||||||
component_hash: c04b8f14c45a836b4f9f8dc6e7767a5adc034f00492354423053e042c5aeb342
|
|
||||||
dependencies:
|
|
||||||
- name: espressif/esp_secure_cert_mgr
|
|
||||||
registry_url: https://components.espressif.com
|
|
||||||
require: private
|
|
||||||
rules:
|
|
||||||
- if: idf_version >= 5.3
|
|
||||||
version: '>=2.5.1'
|
|
||||||
- name: idf
|
|
||||||
require: private
|
|
||||||
version: '>=5.0'
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com/
|
|
||||||
type: service
|
|
||||||
version: 2.7.1
|
|
||||||
espressif/esp_secure_cert_mgr:
|
|
||||||
component_hash: 0b83e150f48d6839f0a0a8753850be55a51cc298cfca7658f21d355d5f41dd67
|
|
||||||
dependencies:
|
|
||||||
- name: idf
|
|
||||||
require: private
|
|
||||||
version: '>=4.3'
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com
|
|
||||||
type: service
|
|
||||||
version: 2.9.3
|
|
||||||
espressif/led_strip:
|
|
||||||
component_hash: 28621486f77229aaf81c71f5e15d6fbf36c2949cf11094e07090593e659e7639
|
|
||||||
dependencies:
|
|
||||||
- name: idf
|
|
||||||
require: private
|
|
||||||
version: '>=5.0'
|
|
||||||
source:
|
|
||||||
registry_url: https://components.espressif.com/
|
|
||||||
type: service
|
|
||||||
version: 3.0.3
|
|
||||||
idf:
|
|
||||||
source:
|
|
||||||
type: idf
|
|
||||||
version: 5.5.5
|
|
||||||
direct_dependencies:
|
|
||||||
- espressif/ble_conn_mgr
|
|
||||||
- espressif/ble_ota
|
|
||||||
- espressif/ble_services
|
|
||||||
- espressif/esp_delta_ota
|
|
||||||
- espressif/esp_encrypted_img
|
|
||||||
- espressif/led_strip
|
|
||||||
- idf
|
|
||||||
manifest_hash: 1cb97a3caa49761f939cab42584ada31292591aa3d07b9c39eaf5674fabe7ad1
|
|
||||||
target: esp32
|
|
||||||
version: 2.0.0
|
|
||||||
2
esp-idf
2
esp-idf
|
|
@ -1 +1 @@
|
||||||
Subproject commit b774170ff46c393eeb5e495ea37936038d3f4f4f
|
Subproject commit 3b8741b172dc951e18509698dee938304bcf1523
|
||||||
|
|
@ -1,13 +1,9 @@
|
||||||
#ifndef __BARBACK_H__
|
#ifndef __BARBACK_H__
|
||||||
#define __BARBACK_H__
|
#define __BARBACK_H__
|
||||||
|
|
||||||
#include "configulator.h"
|
|
||||||
|
|
||||||
typedef uint8_t (*barback_ble_access_read_t)(uint8_t idx);
|
typedef uint8_t (*barback_ble_access_read_t)(uint8_t idx);
|
||||||
typedef uint8_t (*barback_ble_access_write_t)(uint8_t idx, uint8_t value);
|
typedef uint8_t (*barback_ble_access_write_t)(uint8_t idx, uint8_t value);
|
||||||
|
|
||||||
extern cfglr_handle_t *configulator;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t base_uuid;
|
uint16_t base_uuid;
|
||||||
|
|
||||||
|
|
|
||||||
5
include/console.h
Normal file
5
include/console.h
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#ifndef __CONSOLE_H__
|
||||||
|
#define __CONSOLE_H__
|
||||||
|
void console_task(void *args);
|
||||||
|
void console_init();
|
||||||
|
#endif
|
||||||
|
|
@ -12,7 +12,6 @@ extern uint8_t running;
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
set(COMPONENT_SRCS "\
|
set(COMPONENT_SRCS "\
|
||||||
main.c\
|
main.c\
|
||||||
|
ble.c\
|
||||||
|
console.c\
|
||||||
pumps.c\
|
pumps.c\
|
||||||
user_button.c\
|
user_button.c\
|
||||||
")
|
")
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
80
main/console.c
Normal file
80
main/console.c
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_console.h"
|
||||||
|
#include "esp_vfs_dev.h"
|
||||||
|
#include "driver/uart.h"
|
||||||
|
#include "linenoise/linenoise.h"
|
||||||
|
#include "argtable3/argtable3.h"
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
// main console setup and task, assume mostly copied from example
|
||||||
|
void console_task(void *args) {
|
||||||
|
// disable buffering
|
||||||
|
setvbuf(stdin, NULL, _IONBF, 0);
|
||||||
|
|
||||||
|
// setup line endings
|
||||||
|
esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
|
||||||
|
esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
|
||||||
|
|
||||||
|
const uart_config_t uart_config = {
|
||||||
|
.baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE,
|
||||||
|
.data_bits = UART_DATA_8_BITS,
|
||||||
|
.parity = UART_PARITY_DISABLE,
|
||||||
|
.stop_bits = UART_STOP_BITS_1,
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
|
||||||
|
|
||||||
|
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
|
||||||
|
|
||||||
|
esp_console_config_t console_config = {
|
||||||
|
.max_cmdline_args = 8,
|
||||||
|
.max_cmdline_length = 256,
|
||||||
|
.hint_color = atoi(LOG_COLOR_CYAN)
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_console_init(&console_config));
|
||||||
|
|
||||||
|
linenoiseSetMultiLine(1);
|
||||||
|
linenoiseSetCompletionCallback(&esp_console_get_completion);
|
||||||
|
linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint);
|
||||||
|
linenoiseHistorySetMaxLen(100);
|
||||||
|
|
||||||
|
esp_console_register_help_command();
|
||||||
|
|
||||||
|
char *prompt;
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
asprintf(&prompt, LOG_COLOR_I "> " LOG_RESET_COLOR);
|
||||||
|
|
||||||
|
char* line = linenoise(prompt);
|
||||||
|
|
||||||
|
free(prompt);
|
||||||
|
|
||||||
|
if (line == NULL) { /* Ignore empty lines */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
linenoiseHistoryAdd(line);
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
esp_err_t err = esp_console_run(line, &ret);
|
||||||
|
|
||||||
|
if (err == ESP_ERR_NOT_FOUND) {
|
||||||
|
printf("Unrecognized command\n");
|
||||||
|
} else if (err == ESP_ERR_INVALID_ARG) {
|
||||||
|
} else if (err == ESP_OK && ret != ESP_OK) {
|
||||||
|
printf("Command returned non-zero error code: 0x%x (%s)\n", ret, esp_err_to_name(err));
|
||||||
|
} else if (err != ESP_OK) {
|
||||||
|
printf("Internal error: %s\n", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
linenoiseFree(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
## IDF Component Manager Manifest File
|
|
||||||
dependencies:
|
|
||||||
## Required IDF version
|
|
||||||
idf:
|
|
||||||
version: '>=4.1.0'
|
|
||||||
# # Put list of dependencies here
|
|
||||||
# # For components maintained by Espressif:
|
|
||||||
# component: "~1.0.0"
|
|
||||||
# # For 3rd party components:
|
|
||||||
# username/component: ">=1.0.0,<2.0.0"
|
|
||||||
# username2/component2:
|
|
||||||
# version: "~1.0.0"
|
|
||||||
# # For transient dependencies `public` flag can be set.
|
|
||||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
|
||||||
# # All dependencies of `main` are public by default.
|
|
||||||
# public: true
|
|
||||||
espressif/led_strip: ^3.0.1~1
|
|
||||||
espressif/ble_ota: '>0.1.8'
|
|
||||||
espressif/esp_delta_ota: ^1.1.2
|
|
||||||
espressif/ble_conn_mgr: ^1.1.0
|
|
||||||
espressif/ble_services: =*
|
|
||||||
51
main/main.c
51
main/main.c
|
|
@ -12,11 +12,10 @@
|
||||||
|
|
||||||
#include "led_strip.h"
|
#include "led_strip.h"
|
||||||
|
|
||||||
#include "baros.h"
|
|
||||||
#include "configulator.h"
|
#include "configulator.h"
|
||||||
#include "barback.h"
|
|
||||||
// TODO main should be merged into barback
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "console.h"
|
||||||
|
#include "ble.h"
|
||||||
#include "user_button.h"
|
#include "user_button.h"
|
||||||
#include "pumps.h"
|
#include "pumps.h"
|
||||||
|
|
||||||
|
|
@ -54,14 +53,7 @@ void led_init() {
|
||||||
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
|
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_callback(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig) {
|
|
||||||
CFGLR_LOGI(TAG, "callback %s = '%s'", element->key, element->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
|
|
@ -81,54 +73,39 @@ void app_main(void) {
|
||||||
|
|
||||||
ESP_LOGI(TAG, "MAC: [%02X:%02X:%02X:%02X:%02X:%02X]", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
ESP_LOGI(TAG, "MAC: [%02X:%02X:%02X:%02X:%02X:%02X]", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
|
||||||
char *name = malloc(BAROS_NAME_MAX_LEN);
|
char *name = malloc(strlen(TAG) + 4);
|
||||||
sprintf(name, "%s-%02X", TAG, mac[5]);
|
sprintf(name, "%s-%02X", TAG, mac[5]);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "name: %p", name);
|
|
||||||
|
|
||||||
uint8_t tank_levels[] = { 100, 100, 100, 100 };
|
uint8_t tank_levels[] = { 100, 100, 100, 100 };
|
||||||
|
|
||||||
cfglr_handle_t cfglr_handle = {
|
cfglr_handle_t cfglr_handle = {
|
||||||
.namespace = "configulator",
|
.namespace = "configulator",
|
||||||
.backend = CFGLR_BACKEND_NVS(),
|
.backend = CFGLR_BACKEND_NVS(),
|
||||||
.elements = {
|
.elements = {
|
||||||
CFGLR_ELEMENT_U8("armed", NULL, 1, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_U8("armed", 1, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_U8("monitor", NULL, 0, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_U8("monitor", 0, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_U8("pour_button", NULL, 19, CFGLR_SIGNALER_IDF_EVENT()),
|
CFGLR_ELEMENT_U8("pour_button", 21, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
CFGLR_ELEMENT_STR(
|
CFGLR_ELEMENT_STR("device_name", 32, name, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
"device_name",
|
CFGLR_ELEMENT_BIN("tank_levels", 4, tank_levels, 4, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
name,
|
CFGLR_ELEMENT_BIN("pump_pins", 4, pump_gpio_map, 4, CFGLR_SIGNALER_IDF_EVENT()),
|
||||||
BAROS_NAME_MAX_LEN,
|
|
||||||
name,
|
|
||||||
CFGLR_SIGNALER_IDF_EVENT(),
|
|
||||||
CFGLR_SIGNALER_CALLBACK(test_callback)
|
|
||||||
),
|
|
||||||
CFGLR_ELEMENT_BIN("tank_levels", NULL, 4, tank_levels, 4, CFGLR_SIGNALER_IDF_EVENT()),
|
|
||||||
{ NULL },
|
{ NULL },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// setup configulator global handler
|
uint8_t ret = cfglr_init(&cfglr_handle);
|
||||||
configulator = &cfglr_handle;
|
|
||||||
|
|
||||||
uint8_t ret = cfglr_init(configulator);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
baros_cfg_t cfg = {
|
|
||||||
.name = name,
|
|
||||||
.role = BAROS_ROLE_BACK
|
|
||||||
};
|
|
||||||
|
|
||||||
baros_init(&cfg);
|
|
||||||
|
|
||||||
user_button_init();
|
user_button_init();
|
||||||
pumps_init();
|
pumps_init();
|
||||||
|
ble_init(name);
|
||||||
|
|
||||||
|
xTaskCreate(console_task, "console", 4048, NULL, tskIDLE_PRIORITY + 3, NULL);
|
||||||
|
|
||||||
led_init();
|
led_init();
|
||||||
|
|
||||||
uint16_t tick = 0;
|
uint16_t tick = 0;
|
||||||
|
|
||||||
printf(BARBACK_BANNER);
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
uint16_t delay = running > 0 ? 500 / running : 500;
|
uint16_t delay = running > 0 ? 500 / running : 500;
|
||||||
vTaskDelay(delay / portTICK_PERIOD_MS);
|
vTaskDelay(delay / portTICK_PERIOD_MS);
|
||||||
|
|
|
||||||
173
main/pumps.c
173
main/pumps.c
|
|
@ -1,10 +1,8 @@
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/timers.h"
|
#include "freertos/timers.h"
|
||||||
#include "freertos/queue.h"
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/ledc.h"
|
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
@ -14,42 +12,12 @@
|
||||||
|
|
||||||
uint8_t running = 0;
|
uint8_t running = 0;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
PUMP_STATE_IDLE = 0,
|
|
||||||
PUMP_STATE_RAMPING_UP,
|
|
||||||
PUMP_STATE_RUNNING,
|
|
||||||
PUMP_STATE_RAMPING_DOWN,
|
|
||||||
} pump_states_e;
|
|
||||||
|
|
||||||
TimerHandle_t pump_timers[PUMPS];
|
TimerHandle_t pump_timers[PUMPS];
|
||||||
QueueHandle_t pump_step_queue;
|
|
||||||
|
|
||||||
static pump_states_e pump_states[PUMPS] = { PUMP_STATE_IDLE };
|
|
||||||
static uint8_t pumps_duration[PUMPS] = {0};
|
static uint8_t pumps_duration[PUMPS] = {0};
|
||||||
static uint8_t pumps_enabled[PUMPS] = {0};
|
static uint8_t pumps_enabled[PUMPS] = {0};
|
||||||
static uint8_t pumps_running[PUMPS] = {0};
|
static uint8_t pumps_running[PUMPS] = {0};
|
||||||
static uint8_t safety = 1;
|
static uint8_t safety = 1;
|
||||||
|
|
||||||
#define RAMP_UP_TIME (500)
|
|
||||||
#define RAMP_DOWN_TIME (250)
|
|
||||||
|
|
||||||
#define LEDC_HS_TIMER LEDC_TIMER_0
|
|
||||||
#define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE
|
|
||||||
#define LEDC_LS_TIMER LEDC_TIMER_1
|
|
||||||
#define LEDC_LS_MODE LEDC_LOW_SPEED_MODE
|
|
||||||
|
|
||||||
#define LEDC_CONFIG(CHANNEL_NO, GPIO) (ledc_channel_config_t){\
|
|
||||||
.channel = CHANNEL_NO,\
|
|
||||||
.duty = 0,\
|
|
||||||
.gpio_num = GPIO,\
|
|
||||||
.speed_mode = LEDC_LOW_SPEED_MODE,\
|
|
||||||
.hpoint = 0,\
|
|
||||||
.timer_sel = LEDC_TIMER_1,\
|
|
||||||
.flags.output_invert = 0,\
|
|
||||||
}
|
|
||||||
|
|
||||||
ledc_channel_config_t ledc_motor_channels[4] = {};
|
|
||||||
|
|
||||||
void pumps_update_config() {
|
void pumps_update_config() {
|
||||||
ESP_LOGI(TAG, "writing config");
|
ESP_LOGI(TAG, "writing config");
|
||||||
|
|
||||||
|
|
@ -79,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);
|
||||||
|
|
@ -108,10 +76,12 @@ uint8_t pump_disable(int8_t i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void pump_timer_done(TimerHandle_t timer) {
|
void pump_timer_done(TimerHandle_t timer) {
|
||||||
uint8_t idx = (uint8_t)(pcTimerGetName(timer) - 0x48);
|
uint8_t idx = (pcTimerGetName(timer) - 0x48);
|
||||||
ESP_LOGD(TAG, "pump done: %d", idx);
|
ESP_LOGD(TAG, "pump done: %d", idx);
|
||||||
|
|
||||||
xQueueSend(pump_step_queue, &idx, portMAX_DELAY);
|
running--;
|
||||||
|
|
||||||
|
pumps_set_enabled(idx, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pumps_stop() {
|
void pumps_stop() {
|
||||||
|
|
@ -119,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++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,84 +98,25 @@ void pumps_stop() {
|
||||||
void pumps_run() {
|
void pumps_run() {
|
||||||
if(running > 0) return;
|
if(running > 0) return;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Running pumps");
|
|
||||||
|
|
||||||
for(uint8_t i = 0; i < PUMPS; i++) {
|
for(uint8_t i = 0; i < PUMPS; i++) {
|
||||||
//if(pumps_duration[i] == 0 || pumps_enabled[i] != 1) continue;
|
if(pumps_duration[i] == 0) continue;
|
||||||
|
|
||||||
if(pump_states[i] != PUMP_STATE_IDLE) {
|
|
||||||
ESP_LOGW(TAG, "Attempting to start pump in non-IDLE state. idx: %d state: %d", i, pump_states[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
ledc_set_fade_with_time(ledc_motor_channels[i].speed_mode, ledc_motor_channels[i].channel, 8192, RAMP_UP_TIME);
|
|
||||||
ledc_fade_start(ledc_motor_channels[i].speed_mode, ledc_motor_channels[i].channel, LEDC_FADE_NO_WAIT);
|
|
||||||
|
|
||||||
pump_states[i] = PUMP_STATE_RAMPING_UP;
|
|
||||||
|
|
||||||
running++;
|
running++;
|
||||||
ESP_LOGI(TAG, "Pump %d started", i);
|
|
||||||
|
pump_timers[i] = xTimerCreate((const char *)(0x48 + i), (pumps_duration[i] * 250 / portTICK_PERIOD_MS), pdFALSE, (void*)0, pump_timer_done);
|
||||||
|
|
||||||
|
xTimerStart(pump_timers[i], 0);
|
||||||
|
|
||||||
|
pumps_set_enabled(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pump_step_task() {
|
uint8_t pumps_init() {
|
||||||
uint8_t idx;
|
|
||||||
TickType_t awoke = pdFALSE;
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Starting pump stepping task");
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
while(xQueueReceive(pump_step_queue, &idx, awoke)) {
|
|
||||||
ESP_LOGI(TAG, "step %d complete for %d", pump_states[idx], idx);
|
|
||||||
|
|
||||||
if(pump_states[idx] == PUMP_STATE_RAMPING_UP) {
|
|
||||||
uint16_t pump_time = pumps_duration[idx] * 250 - (RAMP_UP_TIME + RAMP_DOWN_TIME) / 2;
|
|
||||||
|
|
||||||
if(RAMP_UP_TIME + RAMP_DOWN_TIME / 2 > pumps_duration[idx] * 250) {
|
|
||||||
ESP_LOGW(TAG, "Pump %d total ramp time great that duration, running for 1 Tick", idx);
|
|
||||||
|
|
||||||
pump_time = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Running pump %d for %dms", idx, pump_time);
|
|
||||||
|
|
||||||
xTimerChangePeriod(pump_timers[idx], pump_time / portTICK_PERIOD_MS, portMAX_DELAY);
|
|
||||||
xTimerStart(pump_timers[idx], portMAX_DELAY);
|
|
||||||
|
|
||||||
pump_states[idx] = PUMP_STATE_RUNNING;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
} else if(pump_states[idx] == PUMP_STATE_RUNNING) {
|
|
||||||
ledc_set_fade_with_time(ledc_motor_channels[idx].speed_mode, ledc_motor_channels[idx].channel, 0, RAMP_UP_TIME);
|
|
||||||
ledc_fade_start(ledc_motor_channels[idx].speed_mode, ledc_motor_channels[idx].channel, LEDC_FADE_NO_WAIT);
|
|
||||||
|
|
||||||
pump_states[idx] = PUMP_STATE_RAMPING_DOWN;
|
|
||||||
continue;
|
|
||||||
} else if(pump_states[idx] == PUMP_STATE_RAMPING_DOWN) {
|
|
||||||
ESP_LOGI(TAG, "Pump cycles complete: %d", idx);
|
|
||||||
pump_states[idx] = PUMP_STATE_IDLE;
|
|
||||||
|
|
||||||
running--;
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Pump step fired with unknown state: %d", pump_states[idx]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vTaskDelay(portTICK_PERIOD_MS / 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static IRAM_ATTR bool ledc_fade_end_event(const ledc_cb_param_t *param, void *parg) {
|
|
||||||
BaseType_t awoke = pdFALSE;
|
|
||||||
|
|
||||||
xQueueSendFromISR(pump_step_queue, parg, &awoke);
|
|
||||||
|
|
||||||
return (awoke == pdTRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t pumps_io_init() {
|
|
||||||
gpio_config_t io_conf;
|
gpio_config_t io_conf;
|
||||||
|
|
||||||
for(uint8_t i = 0 ; i < PUMPS; i++) {
|
// put the output high before initializing
|
||||||
|
// to prevent relays from clacking
|
||||||
|
for(uint8_t i = 0 ; i < 4; i++) {
|
||||||
gpio_set_level(pump_gpio_map[i], 0);
|
gpio_set_level(pump_gpio_map[i], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,18 +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);
|
||||||
|
|
||||||
// this should neve go above 4, but just in case?
|
|
||||||
pump_step_queue = xQueueCreate(PUMPS * 4, sizeof(uint8_t));
|
|
||||||
|
|
||||||
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");
|
||||||
|
|
@ -231,50 +138,8 @@ uint8_t pumps_init() {
|
||||||
nvs_set_blob(config_handle, "pumps_duration", &pumps_duration, size);
|
nvs_set_blob(config_handle, "pumps_duration", &pumps_duration, size);
|
||||||
};
|
};
|
||||||
|
|
||||||
ledc_timer_config_t ledc_timer = {
|
|
||||||
.duty_resolution = LEDC_TIMER_13_BIT, // resolution of PWM duty
|
|
||||||
.freq_hz = 4000, // frequency of PWM signal
|
|
||||||
.speed_mode = LEDC_LS_MODE, // timer mode
|
|
||||||
.timer_num = LEDC_LS_TIMER, // timer index
|
|
||||||
.clk_cfg = LEDC_AUTO_CLK, // Auto select the source clock
|
|
||||||
};
|
|
||||||
|
|
||||||
ledc_timer_config(&ledc_timer);
|
|
||||||
|
|
||||||
ledc_timer.speed_mode = LEDC_HS_MODE;
|
|
||||||
ledc_timer.timer_num = LEDC_HS_TIMER;
|
|
||||||
|
|
||||||
ledc_timer_config(&ledc_timer);
|
|
||||||
|
|
||||||
for(uint8_t i = 0; i < PUMPS; i++) {
|
|
||||||
gpio_set_level(pump_gpio_map[i], 0);
|
|
||||||
|
|
||||||
pump_timers[i] = xTimerCreate((const char *)(0x48 + i), 1, pdFALSE, (void*)0, pump_timer_done);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(uint8_t i = 0; i < PUMPS; i++) {
|
|
||||||
ledc_motor_channels[i] = LEDC_CONFIG(i, pump_gpio_map[i]);
|
|
||||||
ledc_channel_config(&ledc_motor_channels[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
ledc_cbs_t callbacks = {
|
|
||||||
.fade_cb = ledc_fade_end_event
|
|
||||||
};
|
|
||||||
|
|
||||||
ledc_fade_func_install(0);
|
|
||||||
|
|
||||||
uint8_t *idx;
|
|
||||||
|
|
||||||
for(uint8_t i = 0; i < PUMPS; i++) {
|
|
||||||
idx = malloc(1);
|
|
||||||
memcpy(idx, &i, 1);
|
|
||||||
ledc_cb_register(ledc_motor_channels[i].speed_mode, ledc_motor_channels[i].channel, &callbacks, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "pumps_enabled: %d %d %d %d", pumps_enabled[0], pumps_enabled[1], pumps_enabled[2], pumps_enabled[3]);
|
ESP_LOGI(TAG, "pumps_enabled: %d %d %d %d", pumps_enabled[0], pumps_enabled[1], pumps_enabled[2], pumps_enabled[3]);
|
||||||
ESP_LOGI(TAG, "pumps_duration: %d %d %d %d", pumps_duration[0], pumps_duration[1], pumps_duration[2], pumps_duration[3]);
|
ESP_LOGI(TAG, "pumps_duration: %d %d %d %d", pumps_duration[0], pumps_duration[1], pumps_duration[2], pumps_duration[3]);
|
||||||
|
|
||||||
xTaskCreate(pump_step_task, "ramp", 4024, NULL, tskIDLE_PRIORITY + 4, NULL);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 (19)
|
||||||
#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;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
CONFIG_BARBACK_ID="Barback"
|
CONFIG_BARBACK_ID="Barback"
|
||||||
CONFIG_BT_ENABLED=y
|
CONFIG_BT_ENABLED=y
|
||||||
CONFIG_BT_NIMBLE_ENABLED=y
|
CONFIG_BT_NIMBLE_ENABLED=y
|
||||||
CONFIG_BT_NIMBLE_DYNAMIC_SERVICE=y
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue