src.nth.io/

summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2021-03-12 12:05:39 -0600
committerLuke Hoersten <[email protected]>2021-03-12 12:05:39 -0600
commitf24b74e0881818c8b7ddf7bb786363fa9b142f67 (patch)
tree29b5e82f597c5ca7f7409206d0f471ad2037c3d9 /main
parentc6d3d96ed6a659f7a3c1f616caebe325a3d139bd (diff)
Broke out LED identify service.
Diffstat (limited to 'main')
-rw-r--r--main/CMakeLists.txt2
-rw-r--r--main/app_main.c33
-rw-r--r--main/include/led.h21
-rw-r--r--main/src/led.c48
4 files changed, 73 insertions, 31 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 1237afe..ea17f2b 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" "app_main.c"
+ SRCS "src/event_queue.c" "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 22e511f..e39f652 100644
--- a/main/app_main.c
+++ b/main/app_main.c
@@ -18,6 +18,7 @@
#include <app_wifi.h>
#include <app_hap_setup_payload.h>
+#include <led.h>
#include <lock.h>
#include <bell.h>
#include <event_queue.h>
@@ -31,34 +32,6 @@
/* static uint8_t tlv8buff[128];
static hap_data_val_t null_tlv8 = {.buf = &tlv8buff, .buflen = 127}; */
-static void led_init(uint32_t key_gpio_pin)
-{
- gpio_config_t io_conf;
-
- io_conf.intr_type = GPIO_INTR_DISABLE; /* Interrupt for falling edge */
- io_conf.pin_bit_mask = 1 << key_gpio_pin; /* Bit mask of the pins */
- io_conf.mode = GPIO_MODE_OUTPUT; /* Set as input mode */
- io_conf.pull_up_en = GPIO_PULLUP_DISABLE; /* Disable internal pull-up */
- io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE; /* Enable internal pull-down */
-
- gpio_config(&io_conf); /* Set the GPIO configuration */
-}
-
-static int intercom_identify(hap_acc_t *ha)
-{
- ESP_LOGI(TAG, "Accessory identified");
-
- for (int i = 0; i < 3; i++)
- {
- gpio_set_level(CONFIG_HOMEKIT_INTERCOM_LED_GPIO_PIN, 1);
- vTaskDelay(pdMS_TO_TICKS(500));
- gpio_set_level(CONFIG_HOMEKIT_INTERCOM_LED_GPIO_PIN, 0);
- vTaskDelay(pdMS_TO_TICKS(500));
- }
-
- return HAP_SUCCESS;
-}
-
static void intercom_thread_entry(void *p)
{
hap_init(HAP_TRANSPORT_WIFI); /* Initialize the HAP core */
@@ -74,7 +47,7 @@ static void intercom_thread_entry(void *p)
.fw_rev = "0.1.0",
.hw_rev = NULL,
.pv = "1.1.0",
- .identify_routine = intercom_identify,
+ .identify_routine = intercom_led_identify,
.cid = HAP_CID_DOOR,
};
@@ -92,7 +65,7 @@ static void intercom_thread_entry(void *p)
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));
- led_init(CONFIG_HOMEKIT_INTERCOM_LED_GPIO_PIN);
+ intercom_led_init(CONFIG_HOMEKIT_INTERCOM_LED_GPIO_PIN);
hap_add_accessory(intercom_accessory); /* Add the Accessory to the HomeKit Database */
diff --git a/main/include/led.h b/main/include/led.h
new file mode 100644
index 0000000..eb07569
--- /dev/null
+++ b/main/include/led.h
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <string.h>
+#include <freertos/FreeRTOS.h>
+#include <freertos/task.h>
+#include <freertos/timers.h>
+#include <freertos/queue.h>
+#include <esp_log.h>
+#include <driver/gpio.h>
+#include <driver/adc.h>
+
+#include <hap.h>
+
+#include <hap_apple_servs.h>
+#include <hap_apple_chars.h>
+
+#include <app_wifi.h>
+#include <app_hap_setup_payload.h>
+
+int intercom_led_identify(hap_acc_t *ha);
+
+void intercom_led_init(uint32_t key_gpio_pin); \ No newline at end of file
diff --git a/main/src/led.c b/main/src/led.c
new file mode 100644
index 0000000..37f225a
--- /dev/null
+++ b/main/src/led.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <string.h>
+#include <freertos/FreeRTOS.h>
+#include <freertos/task.h>
+#include <freertos/timers.h>
+#include <freertos/queue.h>
+#include <esp_log.h>
+#include <driver/gpio.h>
+#include <driver/adc.h>
+
+#include <hap.h>
+
+#include <hap_apple_servs.h>
+#include <hap_apple_chars.h>
+
+#include <app_wifi.h>
+#include <app_hap_setup_payload.h>
+
+#include <led.h>
+#include <event_queue.h>
+
+int intercom_led_identify(hap_acc_t *ha)
+{
+ ESP_LOGI(TAG, "Accessory identified");
+
+ for (int i = 0; i < 3; i++)
+ {
+ gpio_set_level(CONFIG_HOMEKIT_INTERCOM_LED_GPIO_PIN, 1);
+ vTaskDelay(pdMS_TO_TICKS(500));
+ gpio_set_level(CONFIG_HOMEKIT_INTERCOM_LED_GPIO_PIN, 0);
+ vTaskDelay(pdMS_TO_TICKS(500));
+ }
+
+ return HAP_SUCCESS;
+}
+
+void intercom_led_init(uint32_t key_gpio_pin)
+{
+ gpio_config_t io_conf;
+
+ io_conf.intr_type = GPIO_INTR_DISABLE; /* Interrupt for falling edge */
+ io_conf.pin_bit_mask = 1 << key_gpio_pin; /* Bit mask of the pins */
+ io_conf.mode = GPIO_MODE_OUTPUT; /* Set as input mode */
+ io_conf.pull_up_en = GPIO_PULLUP_DISABLE; /* Disable internal pull-up */
+ io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE; /* Enable internal pull-down */
+
+ gpio_config(&io_conf); /* Set the GPIO configuration */
+} \ No newline at end of file