diff options
| author | Luke Hoersten <[email protected]> | 2021-03-12 17:35:50 -0600 |
|---|---|---|
| committer | Luke Hoersten <[email protected]> | 2021-03-12 17:35:50 -0600 |
| commit | ca72e0e90f850ff5d757be2f6dc658c5d558620c (patch) | |
| tree | 62c9b43a6647f6bcc4171854c6d8659b188601fc | |
| parent | d23be047e18ef9b97e5c72073c9236f59ac60d5f (diff) | |
Removed the event queue. Apparently esp-homekit is thread safe.
| -rw-r--r-- | esp-homekit-intercom.code-workspace | 21 | ||||
| -rw-r--r-- | main/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | main/app_main.c | 11 | ||||
| -rw-r--r-- | main/include/event_queue.h | 13 | ||||
| -rw-r--r-- | main/include/intercom.h | 1 | ||||
| -rw-r--r-- | main/src/bell.c | 6 | ||||
| -rw-r--r-- | main/src/event_queue.c | 77 | ||||
| -rw-r--r-- | main/src/led.c | 2 | ||||
| -rw-r--r-- | main/src/lock.c | 29 |
9 files changed, 21 insertions, 141 deletions
diff --git a/esp-homekit-intercom.code-workspace b/esp-homekit-intercom.code-workspace deleted file mode 100644 index 0d5d87d..0000000 --- a/esp-homekit-intercom.code-workspace +++ /dev/null @@ -1,21 +0,0 @@ -{ - "folders": [ - { - "path": "." - } - ], - "settings": { - "files.associations": { - "stdio.h": "c", - "hap.h": "c", - "freertos.h": "c", - "hap_apple_servs.h": "c", - "app_hap_setup_payload.h": "c", - "lock.h": "c", - "task.h": "c" - }, - "git.ignoreLimitWarning": true, - "idf.port": "/dev/cu.usbserial-01D11E9B", - "idf.flashType": "UART" - } -}
\ No newline at end of file diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index ea17f2b..196fe52 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,4 +1,4 @@ idf_component_register( - SRCS "src/event_queue.c" "src/lock.c" "src/bell.c" "src/led.c" "app_main.c" + SRCS "src/lock.c" "src/bell.c" "src/led.c" "app_main.c" INCLUDE_DIRS "include" ) diff --git a/main/app_main.c b/main/app_main.c index ee0a6ad..fd462b4 100644 --- a/main/app_main.c +++ b/main/app_main.c @@ -8,7 +8,7 @@ #include <led.h> #include <lock.h> #include <bell.h> -#include <event_queue.h> +#include <intercom.h> #define INTERCOM_TASK_PRIORITY 1 #define INTERCOM_TASK_STACKSIZE 4 * 1024 @@ -40,13 +40,6 @@ static void intercom_thread_entry(void *p) /* Add a dummy Product Data */ uint8_t product_data[] = {'E', 'S', 'P', '3', '2', 'H', 'A', 'P'}; hap_acc_add_product_data(intercom_accessory, product_data, sizeof(product_data)); - - if (!intercom_event_queue_init()) - { - ESP_LOGI(TAG, "Failed to initialize event queue"); - return; - } - hap_acc_add_serv(intercom_accessory, intercom_bell_init(CONFIG_HOMEKIT_INTERCOM_BELL_GPIO_PIN)); hap_acc_add_serv(intercom_accessory, intercom_lock_init(CONFIG_HOMEKIT_INTERCOM_LOCK_GPIO_PIN)); intercom_led_init(CONFIG_HOMEKIT_INTERCOM_LED_GPIO_PIN); @@ -82,7 +75,7 @@ static void intercom_thread_entry(void *p) hap_start(); /* After all the initializations are done, start the HAP core */ app_wifi_start(portMAX_DELAY); /* Start Wi-Fi */ - intercom_event_queue_run(); + vTaskDelete(NULL); /* The task ends here. The read/write callbacks will be invoked by the HAP Framework */ } void app_main() diff --git a/main/include/event_queue.h b/main/include/event_queue.h deleted file mode 100644 index 79ce6a4..0000000 --- a/main/include/event_queue.h +++ /dev/null @@ -1,13 +0,0 @@ -static const char *TAG = "HAP Intercom"; - -void intercom_event_queue_bell_ring(); - -void intercom_event_queue_lock_unsecure(); - -void intercom_event_queue_lock_secure(); - -void intercom_event_queue_lock_timeout(); - -void intercom_event_queue_run(); - -bool intercom_event_queue_init(); diff --git a/main/include/intercom.h b/main/include/intercom.h new file mode 100644 index 0000000..54926d2 --- /dev/null +++ b/main/include/intercom.h @@ -0,0 +1 @@ +static const char *TAG = "HAP Intercom";
\ No newline at end of file diff --git a/main/src/bell.c b/main/src/bell.c index 689856c..4045d90 100644 --- a/main/src/bell.c +++ b/main/src/bell.c @@ -7,7 +7,7 @@ #include <hap_apple_servs.h> #include <hap_apple_chars.h> -#include <event_queue.h> +#include <intercom.h> #include <bell.h> #define ESP_INTR_FLAG_DEFAULT 0 @@ -35,7 +35,7 @@ void IRAM_ATTR intercom_bell_isr(void *arg) if (is_bell_ringing(val)) { ESP_LOGI(TAG, "Intercom bell ring value in range [%d]", val); - intercom_event_queue_bell_ring(); + intercom_bell_ring(); is_intercom_bell_blocked = true; } else @@ -46,7 +46,7 @@ void IRAM_ATTR intercom_bell_isr(void *arg) void intercom_bell_ring() { - ESP_LOGI(TAG, "Intercom bell ring event processed"); + ESP_LOGI(TAG, "Intercom bell ring"); hap_char_update_val(intercom_bell_current_state, &HAP_PROGRAMMABLE_SWITCH_EVENT_SINGLE_PRESS); xTimerReset(intercom_bell_timer, 10); } diff --git a/main/src/event_queue.c b/main/src/event_queue.c deleted file mode 100644 index dfd0d7b..0000000 --- a/main/src/event_queue.c +++ /dev/null @@ -1,77 +0,0 @@ -#include <freertos/FreeRTOS.h> -#include <freertos/queue.h> -#include <esp_log.h> - -#include <lock.h> -#include <bell.h> -#include <event_queue.h> - -static const int INTERCOM_EVENT_QUEUE_BELL_RING = 1; -static const int INTERCOM_EVENT_QUEUE_LOCK_UNSECURE = 2; -static const int INTERCOM_EVENT_QUEUE_LOCK_SECURE = 3; -static const int INTERCOM_EVENT_QUEUE_LOCK_TIMEOUT = 4; - -static xQueueHandle intercom_event_queue = NULL; - -void intercom_event_queue_bell_ring() -{ - ESP_LOGI(TAG, "Intercom event queued BELL RING"); - xQueueSendFromISR(intercom_event_queue, (void *)&INTERCOM_EVENT_QUEUE_BELL_RING, NULL); -} - -void intercom_event_queue_lock_unsecure() -{ - ESP_LOGI(TAG, "Intercom event queued LOCK UNSECURE"); - xQueueSendToBack(intercom_event_queue, (void *)&INTERCOM_EVENT_QUEUE_LOCK_UNSECURE, 10); -} - -void intercom_event_queue_lock_secure() -{ - ESP_LOGI(TAG, "Intercom event queued LOCK SECURE"); - xQueueSendToBack(intercom_event_queue, (void *)&INTERCOM_EVENT_QUEUE_LOCK_SECURE, 10); -} - -void intercom_event_queue_lock_timeout() -{ - ESP_LOGI(TAG, "Intercom event queued LOCK TIMEOUT"); - xQueueSendToBack(intercom_event_queue, (void *)&INTERCOM_EVENT_QUEUE_LOCK_TIMEOUT, 10); -} - -void intercom_event_queue_run() -{ - uint8_t intercom_event_queue_item = INTERCOM_EVENT_QUEUE_LOCK_SECURE; - - while (1) - { - if (xQueueReceive(intercom_event_queue, &intercom_event_queue_item, portMAX_DELAY) == pdFALSE) - { - ESP_LOGI(TAG, "Intercom event queue trigger FAIL"); - } - else - { - switch (intercom_event_queue_item) - { - case INTERCOM_EVENT_QUEUE_BELL_RING: - intercom_bell_ring(); - break; - case INTERCOM_EVENT_QUEUE_LOCK_UNSECURE: - intercom_lock_unsecure(); - break; - case INTERCOM_EVENT_QUEUE_LOCK_SECURE: - intercom_lock_secure(); - break; - case INTERCOM_EVENT_QUEUE_LOCK_TIMEOUT: - intercom_lock_timeout(); - break; - } - } - } -} - -bool intercom_event_queue_init() -{ - int queue_len = 8; - int queue_item_size = sizeof(uint8_t); - intercom_event_queue = xQueueCreate(queue_len, queue_item_size); - return intercom_event_queue != NULL; -} diff --git a/main/src/led.c b/main/src/led.c index 154bcd1..394577c 100644 --- a/main/src/led.c +++ b/main/src/led.c @@ -5,7 +5,7 @@ #include <hap.h> #include <led.h> -#include <event_queue.h> +#include <intercom.h> int intercom_led_identify(hap_acc_t *ha) { diff --git a/main/src/lock.c b/main/src/lock.c index ac99864..4b98f51 100644 --- a/main/src/lock.c +++ b/main/src/lock.c @@ -7,26 +7,29 @@ #include <hap_apple_servs.h> #include <hap_apple_chars.h> -#include <event_queue.h> #include <lock.h> +#include <intercom.h> #define INTERCOM_LOCK_GPIO_LOCKED 0 #define INTERCOM_LOCK_GPIO_UNLOCKED 1 +#define HAP_LOCK_CURRENT_STATE_UNSECURED 0 +#define HAP_LOCK_CURRENT_STATE_SECURED 1 + #define HAP_LOCK_TARGET_STATE_UNSECURED 0 #define HAP_LOCK_TARGET_STATE_SECURED 1 -static hap_val_t HAP_VAL_LOCK_CURRENT_STATE_UNSECURED = {.u = 0}; -static hap_val_t HAP_VAL_LOCK_CURRENT_STATE_SECURED = {.u = 1}; +static hap_val_t HAP_VAL_LOCK_CURRENT_STATE_UNSECURED = {.u = HAP_LOCK_CURRENT_STATE_UNSECURED}; +static hap_val_t HAP_VAL_LOCK_CURRENT_STATE_SECURED = {.u = HAP_LOCK_CURRENT_STATE_SECURED}; static hap_val_t HAP_VAL_LOCK_TARGET_STATE_SECURED = {.u = HAP_LOCK_TARGET_STATE_SECURED}; -static TimerHandle_t intercom_lock_timer = NULL; // lock the door when timer triggered +static TimerHandle_t intercom_lock_timer; // lock the door when timer triggered static hap_char_t *intercom_lock_current_state; static hap_char_t *intercom_lock_target_state; void intercom_lock_unsecure() { - ESP_LOGI(TAG, "Intercom lock unsecure event processed"); + ESP_LOGI(TAG, "Intercom lock unsecure"); gpio_set_level(CONFIG_HOMEKIT_INTERCOM_LOCK_GPIO_PIN, INTERCOM_LOCK_GPIO_UNLOCKED); hap_char_update_val(intercom_lock_current_state, &HAP_VAL_LOCK_CURRENT_STATE_UNSECURED); xTimerReset(intercom_lock_timer, 10); @@ -34,18 +37,11 @@ void intercom_lock_unsecure() void intercom_lock_secure() { - ESP_LOGI(TAG, "Intercom lock secure event processed"); + ESP_LOGI(TAG, "Intercom lock secure"); gpio_set_level(CONFIG_HOMEKIT_INTERCOM_LOCK_GPIO_PIN, INTERCOM_LOCK_GPIO_LOCKED); hap_char_update_val(intercom_lock_current_state, &HAP_VAL_LOCK_CURRENT_STATE_SECURED); } -void intercom_lock_timeout() -{ - ESP_LOGI(TAG, "Intercom lock timeout event processed"); - intercom_event_queue_lock_secure(); - hap_char_update_val(intercom_lock_target_state, &HAP_VAL_LOCK_TARGET_STATE_SECURED); -} - int intercom_lock_write_cb(hap_write_data_t write_data[], int count, void *serv_priv, void *write_priv) { int i, ret = HAP_SUCCESS; @@ -60,10 +56,10 @@ int intercom_lock_write_cb(hap_write_data_t write_data[], int count, void *serv_ switch (write->val.u) { case HAP_LOCK_TARGET_STATE_UNSECURED: - intercom_event_queue_lock_unsecure(); + intercom_lock_unsecure(); break; case HAP_LOCK_TARGET_STATE_SECURED: - intercom_event_queue_lock_secure(); + intercom_lock_secure(); break; } @@ -82,7 +78,8 @@ int intercom_lock_write_cb(hap_write_data_t write_data[], int count, void *serv_ void intercom_lock_timer_cb(TimerHandle_t timer) { ESP_LOGI(TAG, "Intercom lock timer fired"); - intercom_event_queue_lock_timeout(); + intercom_lock_secure(); + hap_char_update_val(intercom_lock_target_state, &HAP_VAL_LOCK_TARGET_STATE_SECURED); } hap_serv_t *intercom_lock_init(uint32_t key_gpio_pin) |
