Compare commits
5 commits
c57f25af03
...
e7abcc0f07
| Author | SHA1 | Date | |
|---|---|---|---|
| e7abcc0f07 | |||
| ef137a9e7e | |||
| 3900d87fe9 | |||
| ec6298e01e | |||
| 52d3d70206 |
5 changed files with 60 additions and 35 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 54c7a2d2d65dc9159dad27d6388d8a5409b59dd0
|
||||
Subproject commit 093ce60a9f70e98bafbadad568c145de4f3c323e
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit af52863f024eeed3c4730e2a7b945a18e9bfb9fb
|
||||
Subproject commit 5aeff5d0ce651a98a9a80f0e281fe55a5863e688
|
||||
|
|
@ -1,9 +1,13 @@
|
|||
#ifndef __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_write_t)(uint8_t idx, uint8_t value);
|
||||
|
||||
extern cfglr_handle_t *configulator;
|
||||
|
||||
typedef struct {
|
||||
uint16_t base_uuid;
|
||||
|
||||
|
|
|
|||
21
main/main.c
21
main/main.c
|
|
@ -13,6 +13,8 @@
|
|||
#include "led_strip.h"
|
||||
|
||||
#include "configulator.h"
|
||||
#include "barback.h"
|
||||
// TODO main should be merged into barback
|
||||
#include "main.h"
|
||||
#include "console.h"
|
||||
#include "ble.h"
|
||||
|
|
@ -28,6 +30,8 @@ uint8_t mac[6];
|
|||
nvs_handle_t config_handle = {};
|
||||
led_strip_handle_t led_strip;
|
||||
|
||||
cfglr_handle_t *configulator;
|
||||
|
||||
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
|
||||
|
|
@ -53,6 +57,10 @@ void led_init() {
|
|||
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) {
|
||||
// init pump IO immediately to limit run away pumps in case power is on
|
||||
pumps_io_init();
|
||||
|
|
@ -89,7 +97,13 @@ void app_main(void) {
|
|||
CFGLR_ELEMENT_U8("armed", 1, 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_STR("device_name", 32, name, CFGLR_SIGNALER_IDF_EVENT()),
|
||||
CFGLR_ELEMENT_STR(
|
||||
"device_name",
|
||||
32,
|
||||
"",
|
||||
CFGLR_SIGNALER_IDF_EVENT(),
|
||||
CFGLR_SIGNALER_CALLBACK(test_callback)
|
||||
),
|
||||
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_ramp_ms", sizeof(uint16_t) * 4, pump_ramp_ms, sizeof(uint16_t) * 4, CFGLR_SIGNALER_IDF_EVENT()),
|
||||
|
|
@ -97,7 +111,10 @@ void app_main(void) {
|
|||
},
|
||||
};
|
||||
|
||||
uint8_t ret = cfglr_init(&cfglr_handle);
|
||||
// setup configulator global handler
|
||||
configulator = &cfglr_handle;
|
||||
|
||||
uint8_t ret = cfglr_init(configulator);
|
||||
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
|
|
|
|||
66
main/pumps.c
66
main/pumps.c
|
|
@ -108,7 +108,7 @@ uint8_t pump_disable(int8_t i) {
|
|||
}
|
||||
|
||||
void pump_timer_done(TimerHandle_t timer) {
|
||||
uint8_t idx = (pcTimerGetName(timer) - 0x48);
|
||||
uint8_t idx = (uint8_t)(pcTimerGetName(timer) - 0x48);
|
||||
ESP_LOGD(TAG, "pump done: %d", idx);
|
||||
|
||||
xQueueSend(pump_step_queue, &idx, portMAX_DELAY);
|
||||
|
|
@ -147,44 +147,48 @@ void pumps_run() {
|
|||
|
||||
void pump_step_task() {
|
||||
uint8_t idx;
|
||||
BaseType_t awoke = pdFALSE;
|
||||
TickType_t awoke = pdFALSE;
|
||||
|
||||
ESP_LOGI(TAG, "Starting pump stepping task");
|
||||
|
||||
while(xQueueReceive(pump_step_queue, &idx, &awoke)) {
|
||||
ESP_LOGI(TAG, "step %d complete for %d", pump_states[idx], idx);
|
||||
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(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);
|
||||
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;
|
||||
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]);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue