Compare commits

...

71 commits

Author SHA1 Message Date
f2c4454689 update deps
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-08-05 17:06:59 -07:00
11f767e336 move to new BAROS init
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-08-04 17:20:36 -07:00
8f05f1ac64 cleanup
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2026-08-04 12:28:40 -07:00
83efaa172d init ble earlier so dynamic services can be utilized 2026-08-04 08:07:52 -07:00
9b2cb3a712 ble dynamic services
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-08-03 22:18:16 -07:00
0a42bafaed add elements now with (NULL) pointers
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 21:48:51 -07:00
0d1edad782 update deps 2026-08-03 21:46:08 -07:00
70441061f1 use BAROS_NAME_MAX_LEN and updated deps 2026-08-03 20:54:34 -07:00
368dd37e67 update deps
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-08-03 14:48:26 -07:00
880437392f go away
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 14:40:40 -07:00
54728a31bc move Barback ble > BAROS.ble
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 14:37:20 -07:00
89f03eb82b remove console
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 14:28:16 -07:00
de5ba2558b use string pointer
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 14:17:25 -07:00
efb61e8d28 use espidf v5.5.5
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
2026-08-03 14:11:00 -07:00
776d940b33 newest configlator
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 11:28:07 -07:00
8ae42a93f8 idf_component.yml 2026-08-03 11:26:28 -07:00
6e6231d3e2 update deps and IDF to v5.5.5
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 10:25:14 -07:00
f69a28e8b8 dep those deps
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-03 10:21:00 -07:00
1a40783915 latest configulator 2026-08-02 15:03:06 -07:00
275e51dc5c latest configulator 2026-08-02 15:01:27 -07:00
d511176cd4 latest BAROS 2026-08-02 12:41:41 -07:00
e7abcc0f07 latest BAROS
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2026-08-02 12:36:10 -07:00
ef137a9e7e put pump queue in outer loop (this all needs a real rewrite...) 2026-08-02 09:37:24 -07:00
3900d87fe9 use latest configulator 2026-08-02 09:36:26 -07:00
ec6298e01e reformatate and added callback sig stub 2026-08-02 09:35:30 -07:00
52d3d70206 provide global configulator handle for main config 2026-08-02 09:34:04 -07:00
Morgan 'ARR\!' Allen
c57f25af03 rampering! fixed ramp times but works
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-07-31 19:12:20 -07:00
Morgan 'ARR\!' Allen
1bdfc64972 Merge remote-tracking branch 'origin/vienna_wtf' into development
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-07-31 12:22:53 -07:00
Morgan 'ARR\!' Allen
e180ce2416 all the vienna updates, LEDs, 1/4sec time units, move button 2025-07-31 12:20:12 -07:00
Morgan 'ARR\!' Allen
e43c72e925 updated woodpecker
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-07-29 23:04:50 -07:00
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
Morgan 'ARR\!' Allen
53a9f358fa latest configulator
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-12-05 19:58:43 -08:00
Morgan 'ARR\!' Allen
e9d61524a6 drop hardware labels until actually physical testing is available
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-12-05 19:57:35 -08:00
Morgan 'ARR\!' Allen
1e8e545713 Merge branch 'development' of git.oit.cloud:Barback/barback32 into development
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2024-12-05 19:54:18 -08:00
Morgan 'ARR\!' Allen
f81cb38f5a baseline CONFIGULATOR 2024-12-05 19:49:54 -08:00
Morgan 'ARR\!' Allen
30ae25fa04 migrating to BAROS32 based BLE definitions
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
2024-11-15 15:39:49 -08:00
Morgan 'ARR\!' Allen
aba57662ee include BAROS32 2024-11-15 15:36:50 -08:00
Morgan 'ARR\!' Allen
96dafc4941 tie esp-idf directly to project via submodule
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-11-13 15:30:59 -08:00
Morgan 'ARR\!' Allen
d00d06efb2 Merge branch 'config' into development
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
ci/woodpecker/release/woodpecker Pipeline was successful
2024-11-13 09:59:53 -08:00
Morgan 'ARR\!' Allen
9c580af534 release file is barback, not barhead
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-11-13 08:37:48 -08:00
Morgan 'ARR\!' Allen
39d4ea0b2b include esp_mac 2024-11-12 22:44:11 -08:00
Morgan 'ARR\!' Allen
cb5fd10fa9 various updates mostly related to upgrading IDF 2024-11-12 22:43:56 -08:00
Morgan 'ARR\!' Allen
7f8dec89da remove dfplayer until its actually ready 2024-11-12 22:39:09 -08:00
Morgan 'ARR\!' Allen
3d3e595dfc fix nvs_handle declaration 2024-11-12 22:38:31 -08:00
Morgan 'ARR\!' Allen
5ba2058b7c update ci to use idf and attempt release
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
2024-11-12 20:52:07 -08:00
Morgan 'ARR\!' Allen
8911bcecb2 convert ci to steps
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
2024-11-12 20:22:15 -08:00
Morgan 'ARR\!' Allen
e7695847dc limit CI to systems that have esp32 available 2024-11-12 19:50:34 -08:00
Morgan 'ARR\!' Allen
a49b0fc54e more woodpecker debug
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
2024-05-13 09:35:51 -07:00
Morgan 'ARR\!' Allen
5e309d9114 woodpecker debug
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
2024-05-13 09:34:29 -07:00
Morgan 'ARR\!' Allen
133dcffe7c using local build agent
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
2024-05-10 14:56:53 -07:00
Morgan 'ARR\!' Allen
674594d32e adding woodpecker CI
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/manual/woodpecker Pipeline was successful
2022-04-14 23:15:34 -07:00
Morgan 'ARR\!' Allen
548d4eeaa0 use https instead of git for submodule
All checks were successful
continuous-integration/drone/push Build is passing
2021-10-19 20:18:57 -07:00
Morgan 'ARR\!' Allen
fdd9166e8e hrmph
Some checks failed
continuous-integration/drone/push Build is failing
2021-10-14 23:18:07 -07:00
Morgan 'ARR\!' Allen
c82f162115 weres teh trust
Some checks failed
continuous-integration/drone/push Build is failing
2021-10-14 23:17:26 -07:00
Morgan 'ARR\!' Allen
5c5033898d update submodules before testing
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is failing
2021-10-14 23:10:30 -07:00
Morgan 'ARR\!' Allen
049de947fd include idf-dfplaymini component and add basic audio functionality
Some checks failed
continuous-integration/drone/push Build is failing
2021-10-14 22:24:39 -07:00
Morgan 'ARR\!' Allen
b56ad43a59 fix name change in pumps start > running 2021-10-08 16:21:44 -07:00
Morgan 'ARR\!' Allen
54d7eb9277 small rename/rearrange 2021-09-28 18:43:44 -07:00
Morgan 'ARR\!' Allen
e9eb537eee robustify and genericify BLE access
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone Build was killed
2021-09-23 23:00:03 -07:00
Morgan 'ARR\!' Allen
88f4c96247 pumps now write values to nvs 2021-09-23 22:59:02 -07:00
Morgan 'ARR\!' Allen
afd99d2586 lots of compiler complaining over these... 2021-09-23 22:58:35 -07:00
Morgan 'ARR\!' Allen
41da70278f fixed typo precenting reads from read/write handler 2021-09-22 20:15:06 -07:00
Morgan 'ARR\!' Allen
e3f35e4389 give basic on/off BLE signaling
debouncing could be better
2021-09-22 20:14:19 -07:00
Morgan 'ARR\!' Allen
e2f7b6a391 even more logging around pump actions 2021-09-22 18:55:49 -07:00
Morgan 'ARR\!' Allen
7be60e623a WIP handling BB<>BB notifications 2021-09-22 18:55:26 -07:00
Morgan 'ARR\!' Allen
3d9a9c530c more logging around pump actions 2021-09-22 18:54:49 -07:00
Morgan 'ARR\!' Allen
b113a70577 invoke idf export first
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-21 22:02:25 -07:00
Morgan 'ARR\!' Allen
d2a0ec8e4e debuggering
Some checks failed
continuous-integration/drone/push Build is failing
2021-09-21 21:57:51 -07:00
Morgan 'ARR\!' Allen
2ed479753f first step with drone ci
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is failing
2021-09-21 21:17:09 -07:00
20 changed files with 566 additions and 178 deletions

21
.drone.yml Normal file
View file

@ -0,0 +1,21 @@
kind: pipeline
type: docker
name: default
steps:
- name: build
image: espressif/idf:release-v4.1
commands:
- mkdir ~/.ssh
- ssh-keyscan -t rsa git.oit.cloud >> ~/.ssh/known_hosts
- git submodule update --init
- if [ -f sdkconfig ]; then
- rm sdkconfig
- fi
- ls
- . /opt/esp/idf/export.sh
- idf.py reconfigure
- echo "BB-CI-$((1 + RANDOM % 999))" > bbid
- sed -i -e s/BARBACK_ID=\"Barback\"/BARBACK_ID=\"`cat bbid`\"/ sdkconfig
- idf.py reconfigure
- idf.py build

12
.gitmodules vendored
View file

@ -1,3 +1,9 @@
[submodule "components/esp32-lora"] [submodule "components/configulator"]
path = components/esp32-lora path = components/configulator
url = https://gitlab.com/morganrallen/esp32-lora.git url = https://git.oit.cloud/morgan/configulator
[submodule "esp-idf"]
path = esp-idf
url = https://github.com/espressif/esp-idf
[submodule "components/BAROS32"]
path = components/BAROS32
url = https://git.oit.cloud/Barback/BAROS32.git

27
.woodpecker.yml Normal file
View file

@ -0,0 +1,27 @@
steps:
build:
image: espressif/idf:v5.5.5
when:
- event: [ tag, push, manual ]
commands:
- git submodule update --init
- if [ -f sdkconfig ]; then
- rm sdkconfig
- fi
- . /opt/esp/idf/export.sh
- idf.py reconfigure
- idf.py build
release:
image: woodpeckerci/plugin-release
when:
- event: tag
settings:
log_level: debug
title: 'Release ${CI_COMMIT_TAG}'
files:
- 'build/barback.bin'
api_key:
from_secret: ACCESS_TOKEN
generate_release_notes: true
overwrite: true
upload-url: https://git.oit.cloud/repos/${CI_REPO}/releases

View file

@ -3,4 +3,5 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(barback) project(barback)

1
components/BAROS32 Submodule

@ -0,0 +1 @@
Subproject commit 6467f21fcaf29cc8eb11d9e899a53f73acb13651

@ -0,0 +1 @@
Subproject commit 2e690a786443773b4bfddd9e631e04293c947c17

118
dependencies.lock Normal file
View file

@ -0,0 +1,118 @@
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

1
esp-idf Submodule

@ -0,0 +1 @@
Subproject commit b774170ff46c393eeb5e495ea37936038d3f4f4f

View file

@ -1,9 +1,13 @@
#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;

View file

@ -1,5 +0,0 @@
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
void console_task(void *args);
void console_init();
#endif

View file

@ -1,12 +1,14 @@
#ifndef __MAIN_H_ #ifndef __MAIN_H_
#define __MAIN_H_ #define __MAIN_H_
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#define PUMP_COUNT (4) #define PUMP_COUNT (4)
static xQueueHandle gpio_evt_queue = NULL; static QueueHandle_t gpio_evt_queue = NULL;
nvs_handle_t config_handle; extern nvs_handle_t config_handle;
extern uint8_t mac[6]; extern uint8_t mac[6];

View file

@ -7,10 +7,12 @@
#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]));
static uint8_t pump_gpio_map[] = { 27, 26, 25, 33 }; static uint8_t pump_gpio_map[] = { 12, 13, 2, 4 };
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);
@ -19,6 +21,6 @@ uint8_t pumps_get_duration(uint8_t idx);
uint8_t pumps_set_enabled(uint8_t idx, uint8_t value); uint8_t pumps_set_enabled(uint8_t idx, uint8_t value);
uint8_t pumps_get_enabled(uint8_t idx); uint8_t pumps_get_enabled(uint8_t idx);
uint8_t pumps_get_state(uint8_t idx); uint8_t pumps_get_running(uint8_t idx);
#endif #endif

View file

@ -1,10 +1,9 @@
set(COMPONENT_SRCS "\ set(COMPONENT_SRCS "\
main.c\ main.c\
ble.c\
console.c\
pumps.c\ pumps.c\
user_button.c\ user_button.c\
") ")
set(COMPONENT_ADD_INCLUDEDIRS ". ../include") set(COMPONENT_ADD_INCLUDEDIRS ". ../include")
set(REQUIRES configulato BAROS32)
register_component() register_component()

View file

@ -16,6 +16,7 @@
#include "driver/gpio.h" #include "driver/gpio.h"
#include "barback.h" #include "barback.h"
#include "baros.h"
#include "main.h" #include "main.h"
#include "ble.h" #include "ble.h"
#include "pumps.h" #include "pumps.h"
@ -46,21 +47,13 @@ static int svc_access_system(uint16_t conn_handle, uint16_t attr_handle, struct
static int barback_ble_char_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); static int barback_ble_char_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg);
#define BLE_SERVICE_PUMP_ENABLED (0x4200)
#define BLE_SERVICE_PUMP_STATE (0x4300)
#define BLE_SERVICE_PUMP_DURATION (0x4350)
#define BLE_SERVICE_BARBACK (0x4400)
#define CHAR_POUR (BLE_SERVICE_BARBACK + 1)
#define CHAR_BUTTON (BLE_SERVICE_BARBACK + 2)
static barback_ble_access_t barback_ble_pump_access_enabled = { static barback_ble_access_t barback_ble_pump_access_enabled = {
.read = pumps_get_enabled, .read = pumps_get_enabled,
.write = pumps_set_enabled .write = pumps_set_enabled
}; };
#define BLE_CHAR_PUMP_ENABLED(idx) {\ #define BLE_CHAR_PUMP_ENABLED(idx) {\
.uuid = BLE_UUID16_DECLARE(BLE_SERVICE_PUMP_ENABLED + idx),\ .uuid = BLE_UUID16_DECLARE(BAROS_BLE_SERVICE_PUMP_ENABLED + idx),\
.access_cb = barback_ble_char_access,\ .access_cb = barback_ble_char_access,\
.arg = &barback_ble_pump_access_enabled,\ .arg = &barback_ble_pump_access_enabled,\
.val_handle = &ble_svc_handle,\ .val_handle = &ble_svc_handle,\
@ -68,11 +61,11 @@ static barback_ble_access_t barback_ble_pump_access_enabled = {
} }
static barback_ble_access_t barback_ble_pump_access_state = { static barback_ble_access_t barback_ble_pump_access_state = {
.read = pumps_get_state, .read = pumps_get_running,
}; };
#define BLE_CHAR_PUMP_STATE(idx) {\ #define BLE_CHAR_PUMP_STATE(idx) {\
.uuid = BLE_UUID16_DECLARE(BLE_SERVICE_PUMP_STATE + idx),\ .uuid = BLE_UUID16_DECLARE(BAROS_BLE_SERVICE_PUMP_STATE + idx),\
.access_cb = barback_ble_char_access,\ .access_cb = barback_ble_char_access,\
.arg = &barback_ble_pump_access_state,\ .arg = &barback_ble_pump_access_state,\
.val_handle = &ble_svc_handle,\ .val_handle = &ble_svc_handle,\
@ -85,7 +78,7 @@ static barback_ble_access_t barback_ble_pump_access_duration = {
}; };
#define BLE_CHAR_PUMP_DURATION(idx) {\ #define BLE_CHAR_PUMP_DURATION(idx) {\
.uuid = BLE_UUID16_DECLARE(BLE_SERVICE_PUMP_DURATION + idx),\ .uuid = BLE_UUID16_DECLARE(BAROS_BLE_SERVICE_PUMP_DURATION + idx),\
.access_cb = barback_ble_char_access,\ .access_cb = barback_ble_char_access,\
.arg = &barback_ble_pump_access_duration,\ .arg = &barback_ble_pump_access_duration,\
.val_handle = &pump_duration_svc_val_handles[idx - 1],\ .val_handle = &pump_duration_svc_val_handles[idx - 1],\
@ -95,7 +88,7 @@ static barback_ble_access_t barback_ble_pump_access_duration = {
static const struct ble_gatt_svc_def service_defs[] = { static const struct ble_gatt_svc_def service_defs[] = {
{ {
.type = BLE_GATT_SVC_TYPE_PRIMARY, .type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BLE_SERVICE_PUMP_ENABLED), .uuid = BLE_UUID16_DECLARE(BAROS_BLE_SERVICE_PUMP_ENABLED),
.characteristics = (struct ble_gatt_chr_def[]) { .characteristics = (struct ble_gatt_chr_def[]) {
BLE_CHAR_PUMP_ENABLED(1), BLE_CHAR_PUMP_ENABLED(1),
@ -106,7 +99,7 @@ static const struct ble_gatt_svc_def service_defs[] = {
}, },
}, { }, {
.type = BLE_GATT_SVC_TYPE_PRIMARY, .type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BLE_SERVICE_PUMP_STATE), .uuid = BLE_UUID16_DECLARE(BAROS_BLE_SERVICE_PUMP_STATE),
.characteristics = (struct ble_gatt_chr_def[]) { .characteristics = (struct ble_gatt_chr_def[]) {
BLE_CHAR_PUMP_STATE(1), BLE_CHAR_PUMP_STATE(1),
BLE_CHAR_PUMP_STATE(2), BLE_CHAR_PUMP_STATE(2),
@ -116,7 +109,7 @@ static const struct ble_gatt_svc_def service_defs[] = {
}, },
}, { }, {
.type = BLE_GATT_SVC_TYPE_PRIMARY, .type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BLE_SERVICE_PUMP_DURATION), .uuid = BLE_UUID16_DECLARE(BAROS_BLE_SERVICE_PUMP_DURATION),
.characteristics = (struct ble_gatt_chr_def[]) { .characteristics = (struct ble_gatt_chr_def[]) {
BLE_CHAR_PUMP_DURATION(1), BLE_CHAR_PUMP_DURATION(1),
BLE_CHAR_PUMP_DURATION(2), BLE_CHAR_PUMP_DURATION(2),
@ -126,27 +119,26 @@ static const struct ble_gatt_svc_def service_defs[] = {
}, },
}, { }, {
.type = BLE_GATT_SVC_TYPE_PRIMARY, .type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(BLE_SERVICE_BARBACK), .uuid = BLE_UUID16_DECLARE(BAROS_BLE_SERVICE_BARBACK),
.characteristics = (struct ble_gatt_chr_def[]) { .characteristics = (struct ble_gatt_chr_def[]) {
{ {
.uuid = BLE_UUID16_DECLARE(CHAR_POUR), .uuid = BLE_UUID16_DECLARE(BAROS_CHAR_POUR),
.access_cb = svc_access_system, .access_cb = svc_access_system,
.val_handle = &ble_svc_handle, .val_handle = &ble_svc_handle,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ
}, { }, {
.uuid = BLE_UUID16_DECLARE(CHAR_BUTTON), .uuid = BLE_UUID16_DECLARE(BAROS_CHAR_BUTTON),
.access_cb = svc_access_system, .access_cb = svc_access_system,
.val_handle = &svc_handle_button, .val_handle = &svc_handle_button,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY
}, },
{ 0 } { 0 }
} }
}, },
{ 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, static int gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, void *dst, uint16_t *len) {
void *dst, uint16_t *len) {
uint16_t om_len; uint16_t om_len;
int rc; int rc;
@ -166,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) { 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);
@ -175,20 +168,23 @@ 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, NULL &value, &vlen
); );
ESP_LOGI(TAG, "value (%d): %d", vlen, value);
switch(uuid16) { switch(uuid16) {
case CHAR_POUR: case BAROS_CHAR_POUR:
if(value == 1) { if(value == 1) {
ESP_LOGI(TAG, "starting pump"); ESP_LOGI(TAG, "starting pumps");
pumps_run(); pumps_run();
} else { } else {
ESP_LOGI(TAG, "stoping pumps");
pumps_stop(); pumps_stop();
} }
break; break;
case CHAR_BUTTON: case BAROS_CHAR_BUTTON:
break; break;
} }
} }
@ -197,13 +193,15 @@ static int svc_access_system(uint16_t conn_handle, uint16_t attr_handle, struct
} }
static int barback_ble_char_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { static int barback_ble_char_access(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 chr_uuid = ble_uuid_u16(ctxt->chr->uuid);
uint8_t idx = uuid16 - (BLE_SERVICE_PUMP_ENABLED + 1);
// match the UUID against 0b111
uint8_t idx = (chr_uuid & 0x07) - 1;
uint8_t value = 0; uint8_t value = 0;
barback_ble_access_t *access = (barback_ble_access_t *)arg; barback_ble_access_t *access = (barback_ble_access_t *)arg;
ESP_LOGI(TAG, "conn_handle: %d attr_handle: %d char: 0x%02X op: %s", conn_handle, attr_handle, uuid16, (ctxt->op == 0 ? "read" : ctxt->op == 1 ? "write" : "unknown")); ESP_LOGI(TAG, "conn_handle: %d attr_handle: %d char: 0x%02X op: %s", conn_handle, attr_handle, chr_uuid, (ctxt->op == 0 ? "read" : ctxt->op == 1 ? "write" : "unknown"));
if(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { if(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
gatt_svr_chr_write( gatt_svr_chr_write(
@ -215,24 +213,35 @@ static int barback_ble_char_access(uint16_t conn_handle, uint16_t attr_handle, s
struct ble_gap_conn_desc notifiee; struct ble_gap_conn_desc notifiee;
// TODO
// this could needs to be verified, it might actually be needed
// NiBLE could be passing notifications itself on chr_handler changes
for (uint16_t i = 0; i < CONFIG_NIMBLE_MAX_CONNECTIONS; i++) { for (uint16_t i = 0; i < CONFIG_NIMBLE_MAX_CONNECTIONS; i++) {
if(ble_gap_conn_find(i, &notifiee) == ESP_OK) { if(ble_gap_conn_find(i, &notifiee) == ESP_OK) {
ble_gattc_notify_custom(i, attr_handle, ctxt->om); ble_gattc_notify_custom(i, attr_handle, ctxt->om);
} }
} }
if(access->write != NULL) if(access == NULL) {
ESP_LOGI(TAG, "no read/write functions defined");
return 0;
}
if(access->write != NULL) {
ESP_LOGI(TAG, "calling BLE write function: %d %d", idx, value);
access->write(idx, value); access->write(idx, value);
} else if(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) { }
if(access->read != NULL) { } else if(access != NULL && ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
if(access->read == NULL) {
ESP_LOGW(TAG, "Attempted read without defining access.read"); ESP_LOGW(TAG, "Attempted read without defining access.read");
return 1; return 1;
} }
uint8_t enabled = access->read(idx); uint8_t value = access->read(idx);
ESP_LOGI(TAG, "pumps_enabled[%d] = %d", idx, enabled); ESP_LOGI(TAG, "returning read idx: %d value: %d", idx, value);
os_mbuf_append(ctxt->om, &enabled, sizeof enabled); os_mbuf_append(ctxt->om, &value, sizeof value);
} }
return 0; return 0;
@ -376,6 +385,14 @@ static int ble_gap_event(struct ble_gap_event *event, void *arg) {
event->mtu.value); event->mtu.value);
break; break;
case BLE_GAP_EVENT_NOTIFY_RX:
ESP_LOGI(TAG, "BLE_GAP_EVENT_NOTIFY_RX; conn_handle=%d mtu=%d attr_handle=%d\n",
event->mtu.conn_handle,
event->mtu.value,
event->notify_rx.attr_handle);
break;
case BLE_GAP_EVENT_NOTIFY_TX: case BLE_GAP_EVENT_NOTIFY_TX:
ESP_LOGI(TAG, "BLE_GAP_EVENT_NOTIFY_TX; conn_handle=%d mtu=%d\n", ESP_LOGI(TAG, "BLE_GAP_EVENT_NOTIFY_TX; conn_handle=%d mtu=%d\n",
event->mtu.conn_handle, event->mtu.conn_handle,
@ -444,7 +461,7 @@ void ble_init(char *name) {
memset(&callback_handlers, 0, sizeof(event_callback_handle_t) * CONFIG_CACO_MAX_SERVICES); memset(&callback_handlers, 0, sizeof(event_callback_handle_t) * CONFIG_CACO_MAX_SERVICES);
ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init()); //ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
nimble_port_init(); nimble_port_init();

View file

@ -1,81 +0,0 @@
#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,
.use_ref_tick = true
};
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);
}
}

21
main/idf_component.yml Normal file
View file

@ -0,0 +1,21 @@
## 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: =*

View file

@ -5,21 +5,63 @@
#include "freertos/queue.h" #include "freertos/queue.h"
#include "driver/uart.h" #include "driver/uart.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_mac.h"
#include "esp_debug_helpers.h" #include "esp_debug_helpers.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "esp_vfs_dev.h" #include "esp_vfs_dev.h"
#include "led_strip.h"
#include "baros.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"
#define LED_GPIO 14
#define LED_COUNT 5
static const char *TAG = "BARBACK"; static const char *TAG = "BARBACK";
uint8_t mac[6]; uint8_t mac[6];
nvs_handle_t config_handle = {};
led_strip_handle_t led_strip;
void led_init() {
led_strip_config_t strip_config = {
.strip_gpio_num = LED_GPIO, // The GPIO that connected to the LED strip's data line
.max_leds = LED_COUNT, // The number of LEDs in the strip,
.led_model = LED_MODEL_WS2812, // LED strip model, it determines the bit timing
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, // The color component format is G-R-B
.flags = {
.invert_out = false, // don't invert the output signal
}
};
/// RMT backend specific configuration
led_strip_rmt_config_t rmt_config = {
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
.resolution_hz = 10 * 1000 * 1000, // RMT counter clock frequency: 10MHz
.mem_block_symbols = 64, // the memory size of each RMT channel, in words (4 bytes)
.flags = {
.with_dma = false, // DMA feature is available on chips like ESP32-S3/P4
}
};
/// Create the LED strip object
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) {
@ -32,23 +74,69 @@ void app_main(void) {
if (err != ESP_OK) { if (err != ESP_OK) {
printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err)); printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
} else { } else {
ESP_LOGI(TAG, "config_handle: %d", config_handle); ESP_LOGI(TAG, "config_handle: %d", (int)config_handle);
} }
esp_efuse_mac_get_default((uint8_t*)&mac); esp_efuse_mac_get_default((uint8_t*)&mac);
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(strlen(TAG) + 4); char *name = malloc(BAROS_NAME_MAX_LEN);
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 };
cfglr_handle_t cfglr_handle = {
.namespace = "configulator",
.backend = CFGLR_BACKEND_NVS(),
.elements = {
CFGLR_ELEMENT_U8("armed", NULL, 1, CFGLR_SIGNALER_IDF_EVENT()),
CFGLR_ELEMENT_U8("monitor", NULL, 0, CFGLR_SIGNALER_IDF_EVENT()),
CFGLR_ELEMENT_U8("pour_button", NULL, 19, CFGLR_SIGNALER_IDF_EVENT()),
CFGLR_ELEMENT_STR(
"device_name",
name,
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 },
},
};
// setup configulator global handler
configulator = &cfglr_handle;
uint8_t ret = cfglr_init(configulator);
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();
uint16_t tick = 0;
printf(BARBACK_BANNER);
while(1) { while(1) {
vTaskDelay(1000 / portTICK_PERIOD_MS); uint16_t delay = running > 0 ? 500 / running : 500;
vTaskDelay(delay / portTICK_PERIOD_MS);
uint8_t color = tick % (LED_COUNT * 2) > LED_COUNT ? 0 : 100;
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, tick % LED_COUNT, 5, 5, color));
ESP_ERROR_CHECK(led_strip_refresh(led_strip));
tick++;
} }
} }

View file

@ -1,22 +1,63 @@
#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 "pumps.h" #include "pumps.h"
#define TAG "PUMP!" #define TAG "PUMP!"
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_state[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() {
ESP_LOGI(TAG, "writing config");
size_t size = sizeof(uint8_t) * PUMPS;
nvs_set_blob(config_handle, "pumps_duration", &pumps_duration, size);
nvs_commit(config_handle);
}
uint8_t pumps_set_duration(uint8_t idx, uint8_t time) { uint8_t pumps_set_duration(uint8_t idx, uint8_t time) {
if(idx > PUMPS) return PUMPS_ERR_OUT_IDX; if(idx > PUMPS) return PUMPS_ERR_OUT_IDX;
@ -24,15 +65,21 @@ uint8_t pumps_set_duration(uint8_t idx, uint8_t time) {
pumps_duration[idx] = time; pumps_duration[idx] = time;
pumps_update_config();
return 0; return 0;
} }
uint8_t pumps_get_duration(uint8_t idx) {
return pumps_duration[idx];
}
uint8_t pumps_set_enabled(uint8_t idx, uint8_t value) { uint8_t pumps_set_enabled(uint8_t idx, uint8_t value) {
uint8_t io = pump_gpio_map[idx]; uint8_t io = pump_gpio_map[idx];
value = (value ? 1 : 0); value = (value ? 1 : 0);
ESP_LOGD(TAG, "gpio: %d value: %d", io, value); ESP_LOGI(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);
@ -44,79 +91,190 @@ uint8_t pumps_get_enabled(uint8_t idx) {
return pumps_enabled[idx] ? 1 : 0; return pumps_enabled[idx] ? 1 : 0;
} }
uint8_t pumps_get_duration(uint8_t idx) { uint8_t pumps_get_running(uint8_t idx) {
return pumps_duration[idx]; return pumps_running[idx];
}
uint8_t pumps_get_state(uint8_t idx) {
return pumps_state[idx];
} }
uint8_t pump_enable(int8_t i) { uint8_t pump_enable(int8_t i) {
ESP_LOGI(TAG, "pump: %d enabled", i);
return gpio_set_level(pump_gpio_map[i], 0); return gpio_set_level(pump_gpio_map[i], 0);
} }
uint8_t pump_disable(int8_t i) { uint8_t pump_disable(int8_t i) {
ESP_LOGI(TAG, "pump: %d disabled", i);
return gpio_set_level(pump_gpio_map[i], 0); return gpio_set_level(pump_gpio_map[i], 0);
} }
void pump_timer_done(TimerHandle_t timer) { void pump_timer_done(TimerHandle_t timer) {
uint8_t idx = (pcTimerGetTimerName(timer) - 0x48); uint8_t idx = (uint8_t)(pcTimerGetName(timer) - 0x48);
ESP_LOGD(TAG, "pump done: %d", idx); ESP_LOGD(TAG, "pump done: %d", idx);
running--; xQueueSend(pump_step_queue, &idx, portMAX_DELAY);
pumps_set_enabled(idx, 0);
} }
void pumps_stop() { void pumps_stop() {
for(uint8_t i = 0; i < PUMPS; i++) { for(uint8_t i = 0; i < PUMPS; i++) {
if(pump_timers[i] != NULL) if(pump_timers[i] != NULL) {
pump_disable(i);
xTimerStop(pump_timers[i], 0); xTimerStop(pump_timers[i], 0);
}
} }
} }
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) continue; //if(pumps_duration[i] == 0 || pumps_enabled[i] != 1) 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] * 1000 / portTICK_PERIOD_MS), pdFALSE, (void*)0, pump_timer_done);
xTimerStart(pump_timers[i], 0);
pumps_set_enabled(i, 1);
} }
} }
uint8_t pumps_init() { void pump_step_task() {
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;
// put the output high before initializing for(uint8_t i = 0 ; i < PUMPS; i++) {
// 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);
} }
io_conf.intr_type = GPIO_PIN_INTR_DISABLE; io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT; io_conf.mode = GPIO_MODE_OUTPUT;
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, 10, sizeof(uint8_t) * PUMPS); memset(&pumps_duration, 5, sizeof(uint8_t) * PUMPS);
//uint32_t durations; // this should neve go above 4, but just in case?
//esp_err_t err = nvs_get_i32(config_handle, "durations", &durations); pump_step_queue = xQueueCreate(PUMPS * 4, sizeof(uint8_t));
size_t size = sizeof(uint8_t) * PUMPS;
if(!nvs_get_blob(config_handle, "pumps_duration", &pumps_duration, &size)) {
ESP_LOGI(TAG, "Initializing pumps config");
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;
} }

View file

@ -2,12 +2,14 @@
#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;
@ -17,32 +19,36 @@ static void IRAM_ATTR gpio_isr_handler(void* arg) {
static void gpio_task(void* arg) { static void gpio_task(void* arg) {
uint32_t io_num; uint32_t io_num;
uint8_t on = 1; uint8_t state = 0;
uint8_t off = 0; int8_t last_level = -1;
for(;;) { for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) { if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
uint8_t level = gpio_get_level(io_num); uint8_t level = gpio_get_level(io_num);
printf("GPIO[%d] intr, val: %d\n", io_num, level);
if(level == last_level) continue;
last_level = level;
ESP_LOGI(TAG, "GPIO[%ld] intr, val: %d\n", io_num, level);
if(state == 0)
vTaskDelay(10 / portTICK_PERIOD_MS);
pumps_run(); pumps_run();
ble_send_notification((void*)&on, 1); state = !state;
// just a wee debounce ble_send_notification((void*)&state, 1);
vTaskDelay(500 / portTICK_PERIOD_MS);
ble_send_notification((void*)&off, 1);
xQueueReset(gpio_evt_queue);
} }
} }
} }
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_PIN_INTR_NEGEDGE; io_conf.intr_type = GPIO_INTR_ANYEDGE;
io_conf.mode = GPIO_MODE_INPUT; io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = (1ULL << GPIO_USER_BUTTON); io_conf.pin_bit_mask = (1ULL << GPIO_USER_BUTTON);
io_conf.pull_down_en = 0; io_conf.pull_down_en = 0;
@ -54,5 +60,5 @@ void user_button_init() {
xTaskCreate(gpio_task, "gpio_task", 4096, NULL, 10, NULL); xTaskCreate(gpio_task, "gpio_task", 4096, NULL, 10, NULL);
gpio_install_isr_service(0); gpio_install_isr_service(0);
gpio_isr_handler_add(GPIO_USER_BUTTON, gpio_isr_handler, (void*) 0); gpio_isr_handler_add(GPIO_USER_BUTTON, gpio_isr_handler, (void*)GPIO_USER_BUTTON);
} }

View file

@ -1,3 +1,4 @@
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