diff --git a/libs/button/button.c b/libs/button/button.c deleted file mode 100644 index b57074c..0000000 --- a/libs/button/button.c +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include "button.h" - -typedef struct _button { - uint8_t gpio_num; - button_callback_fn callback; - - uint16_t debounce_time; - uint16_t long_press_time; - - bool pressed_value; - - uint32_t last_press_time; - uint32_t last_event_time; - - struct _button *next; -} button_t; - - -button_t *buttons = NULL; - - -static button_t *button_find_by_gpio(const uint8_t gpio_num) { - button_t *button = buttons; - while (button && button->gpio_num != gpio_num) - button = button->next; - - return button; -} - - -void button_intr_callback(uint8_t gpio) { - button_t *button = button_find_by_gpio(gpio); - if (!button) - return; - - uint32_t now = xTaskGetTickCountFromISR(); - if ((now - button->last_event_time)*portTICK_PERIOD_MS < button->debounce_time) { - // debounce time, ignore events - return; - } - button->last_event_time = now; - if (gpio_read(button->gpio_num) == button->pressed_value) { - // Record when the button is pressed down. - button->last_press_time = now; - } else { - // The button is released. Handle the use cases. - if ((now - button->last_press_time) * portTICK_PERIOD_MS > button->long_press_time) { - button->callback(button->gpio_num, button_event_long_press); - } else { - button->callback(button->gpio_num, button_event_single_press); - } - } -} - -int button_create(const uint8_t gpio_num, bool pressed_value, uint16_t long_press_time, button_callback_fn callback) { - button_t *button = button_find_by_gpio(gpio_num); - if (button) - return -1; - - button = malloc(sizeof(button_t)); - memset(button, 0, sizeof(*button)); - button->gpio_num = gpio_num; - button->callback = callback; - button->pressed_value = pressed_value; - - // times in milliseconds - button->debounce_time = 50; - button->long_press_time = long_press_time; - - uint32_t now = xTaskGetTickCountFromISR(); - button->last_event_time = now; - button->last_press_time = now; - - button->next = buttons; - buttons = button; - - gpio_set_pullup(button->gpio_num, true, true); - gpio_set_interrupt(button->gpio_num, GPIO_INTTYPE_EDGE_ANY, button_intr_callback); - - return 0; -} - - -void button_delete(const uint8_t gpio_num) { - if (!buttons) - return; - - button_t *button = NULL; - if (buttons->gpio_num == gpio_num) { - button = buttons; - buttons = buttons->next; - } else { - button_t *b = buttons; - while (b->next) { - if (b->next->gpio_num == gpio_num) { - button = b->next; - b->next = b->next->next; - break; - } - } - } - - if (button) { - gpio_set_interrupt(gpio_num, GPIO_INTTYPE_EDGE_ANY, NULL); - } -} - diff --git a/libs/button/button.h b/libs/button/button.h deleted file mode 100644 index 990678b..0000000 --- a/libs/button/button.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -typedef enum { - button_event_single_press, - button_event_long_press, -} button_event_t; - -typedef void (*button_callback_fn)(uint8_t gpio_num, button_event_t event); - -/** - Starts monitoring the given GPIO pin for the pressed value. Events are recieved through the callback. - - @param gpio_num The GPIO pin that should be monitored - @param pressed_value The expected value when the button is pressed. For buttons connected to ground this is 0/false, for other buttons this might be 1/true. - @param long_press_time The duration that should be recognized as a long press, in miliseconds. - @param callback The callback that is called when an "button" event occurs. - @return A negative integer if this method fails. -*/ -int button_create(uint8_t gpio_num, bool pressed_value, uint16_t long_press_time, button_callback_fn callback); - -/** - Removes the given GPIO pin from monitoring. - - @param gpio_num The GPIO pin that should be removed from monitoring -*/ -void button_destroy(uint8_t gpio_num); diff --git a/libs/button/component.mk b/libs/button/component.mk deleted file mode 100644 index c2daabc..0000000 --- a/libs/button/component.mk +++ /dev/null @@ -1,8 +0,0 @@ -# Component makefile for button - -INC_DIRS += $(button_ROOT) - -button_INC_DIR = $(button_ROOT) -button_SRC_DIR = $(button_ROOT) - -$(eval $(call component_compile_rules,button)) diff --git a/libs/check_wifi/check_wifi.c b/libs/check_wifi/check_wifi.c deleted file mode 100644 index 920cd5b..0000000 --- a/libs/check_wifi/check_wifi.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "check_wifi.h" - -bool wifi_connected; - -void checkWifiTask(void *pvParameters) -{ - uint8_t status ; - - wifi_connected = false; - - while (1) - { - status = sdk_wifi_station_get_connect_status(); - switch (status) - { - case STATION_WRONG_PASSWORD: - printf("WiFi: wrong password\n\r"); - break; - case STATION_NO_AP_FOUND: - printf("WiFi: AP not found\n\r"); - break; - case STATION_CONNECT_FAIL: - printf("WiFi: connection failed\r\n"); - break; - case STATION_GOT_IP: - wifi_connected = true; - break; - default: - printf("%s: status = %d\n\r", __func__, status); - break; - } - vTaskDelay(CHECK_INTERVAL / portTICK_PERIOD_MS); - } -} diff --git a/libs/check_wifi/check_wifi.h b/libs/check_wifi/check_wifi.h deleted file mode 100644 index 18c4164..0000000 --- a/libs/check_wifi/check_wifi.h +++ /dev/null @@ -1,3 +0,0 @@ -#define CHECK_INTERVAL 36000000 - -void checkWifiTask(void *pvParameters); diff --git a/libs/check_wifi/component.mk b/libs/check_wifi/component.mk deleted file mode 100644 index 6c2303e..0000000 --- a/libs/check_wifi/component.mk +++ /dev/null @@ -1,8 +0,0 @@ -# Component makefile for check_wifi - -INC_DIRS += $(check_wifi_ROOT) - -check_wifi_INC_DIR = $(check_wifi_ROOT) -check_wifi_SRC_DIR = $(check_wifi_ROOT) - -$(eval $(call component_compile_rules,check_wifi)) diff --git a/libs/custom_characteristics/component.mk b/libs/custom_characteristics/component.mk deleted file mode 100644 index 6f5cd62..0000000 --- a/libs/custom_characteristics/component.mk +++ /dev/null @@ -1,10 +0,0 @@ -# Component makefile for custom_characteristics - - -INC_DIRS += $(custom_characteristics_ROOT) - - -custom_characteristics_INC_DIR = $(custom_characteristics_ROOT) -custom_characteristics_SRC_DIR = $(custom_characteristics_ROOT) - -$(eval $(call component_compile_rules,custom_characteristics)) diff --git a/libs/custom_characteristics/custom_characteristics.c b/libs/custom_characteristics/custom_characteristics.c deleted file mode 100644 index ccf063d..0000000 --- a/libs/custom_characteristics/custom_characteristics.c +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -void save_characteristic_to_flash(homekit_characteristic_t *ch, homekit_value_t value){ - - sysparam_status_t status = SYSPARAM_OK; - bool bool_value; - int8_t int8_value; - int32_t int32_value; - float float_value; - char *string_value=NULL; - - printf ("Save characteristic to flash\n"); - switch (ch->format) { - case homekit_format_bool: - printf ("writing bool value to flash\n"); - status = sysparam_get_bool(ch->description, &bool_value); - if (status == SYSPARAM_OK && bool_value != ch->value.bool_value) { - status = sysparam_set_bool(ch->description, ch->value.bool_value); - } else if (status == SYSPARAM_NOTFOUND) { - status = sysparam_set_bool(ch->description, ch->value.bool_value); - } - break; - case homekit_format_uint8: - printf ("writing int8 value to flash\n"); - status = sysparam_get_int8(ch->description, &int8_value); - if (status == SYSPARAM_OK && int8_value != ch->value.int_value) { - status = sysparam_set_int8(ch->description, ch->value.int_value); - } else if (status == SYSPARAM_NOTFOUND) { - status = sysparam_set_int8(ch->description, ch->value.int_value); - } - break; - case homekit_format_uint16: - case homekit_format_uint32: - printf ("writing int32 value to flash\n"); - status = sysparam_get_int32(ch->description, &int32_value); - if (status == SYSPARAM_OK && int32_value != ch->value.int_value) { - status = sysparam_set_int32(ch->description, ch->value.int_value); - } else if (status == SYSPARAM_NOTFOUND) { - status = sysparam_set_int32(ch->description, ch->value.int_value); - } - break; - case homekit_format_string: - printf ("writing string value to flash\n"); - status = sysparam_get_string(ch->description, &string_value); - if (status == SYSPARAM_OK && !strcmp (string_value, ch->value.string_value)) { - status = sysparam_set_string(ch->description, ch->value.string_value); - } else if (status == SYSPARAM_NOTFOUND) { - status = sysparam_set_string(ch->description, ch->value.string_value); - } - free(string_value); - break; - case homekit_format_float: - printf ("writing float value to flash\n"); - status = sysparam_get_int32(ch->description, &int32_value); - float_value = int32_value * 1.00f / 100; - if (status == SYSPARAM_OK && float_value != ch->value.float_value) { - int32_value = (int)ch->value.float_value*100; - status = sysparam_set_int32(ch->description, int32_value); - } else if (status == SYSPARAM_NOTFOUND) { - int32_value = (int)ch->value.float_value*100; - status = sysparam_set_int32(ch->description, int32_value); - } - break; - case homekit_format_uint64: - case homekit_format_int: - case homekit_format_tlv: - default: - printf ("Unknown characteristic format in save_charactersitics_to_flash\n"); - } - if (status != SYSPARAM_OK){ - printf ("Error in sysparams error:%i writing characteristic\n", status); - } - -} - -void load_characteristic_from_flash (homekit_characteristic_t *ch){ - - - sysparam_status_t status = SYSPARAM_OK; - bool bool_value; - int8_t int8_value; - int32_t int32_value; - char *string_value = NULL; - printf ("Loading sysparam %s\n",ch->description); - switch (ch->format){ - case homekit_format_bool: - printf("Loading bool\n"); - status = sysparam_get_bool(ch->description, &bool_value); - if (status == SYSPARAM_OK ) { - ch->value.bool_value = bool_value; - } - break; - case homekit_format_uint8: - printf("Loading int8\n"); - status = sysparam_get_int8(ch->description, &int8_value); - if (status == SYSPARAM_OK) { - ch->value.int_value = int8_value; - } - break; - case homekit_format_uint16: - case homekit_format_uint32: - printf("Loading in32\n"); - status = sysparam_get_int32(ch->description, &int32_value); - if (status == SYSPARAM_OK ) { - ch->value.int_value = int32_value; - } - break; - case homekit_format_string: - printf("Loading string\n"); - status = sysparam_get_string(ch->description, &string_value); - if (status == SYSPARAM_OK) { - ch->value = HOMEKIT_STRING(string_value); - } - break; - case homekit_format_float: - printf("Loading float\n"); - status = sysparam_get_int32(ch->description, &int32_value); - if (status == SYSPARAM_OK ) { - ch->value.float_value = int32_value * 1.0f /100; - } - break; - case homekit_format_uint64: - case homekit_format_int: - case homekit_format_tlv: - default: - printf ("Unknown characteristic format in save_charactersitics_to_flash\n"); - } - if (status != SYSPARAM_OK){ - printf ("Error in sysparams error:%i loading characteristic\n", status); - } - - - -} diff --git a/libs/custom_characteristics/custom_characteristics.h b/libs/custom_characteristics/custom_characteristics.h deleted file mode 100644 index f129cc9..0000000 --- a/libs/custom_characteristics/custom_characteristics.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * HomeKit Custom Characteristics - * - * Copyright 2018 David B Brown (@maccoylton) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#ifndef __HOMEKIT_DBB_CUSTOM_CHARACTERISTICS__ -#define __HOMEKIT_DBB_CUSTOM_CHARACTERISTICS__ - -#define HOMEKIT_CUSTOM_UUID_DBB(value) (value"-4772-4466-80fd-a6ea3d5bcd55") - - -#define HOMEKIT_CHARACTERISTIC_CUSTOM_POLL_PERIOD HOMEKIT_CUSTOM_UUID_DBB("F0000001") -#define HOMEKIT_DECLARE_CHARACTERISTIC_CUSTOM_POLL_PERIOD(_value, ...) .type = HOMEKIT_CHARACTERISTIC_CUSTOM_POLL_PERIOD, \ -.description = "Poll Period", \ -.format = homekit_format_uint8, \ -.unit = homekit_unit_seconds, \ -.permissions = homekit_permissions_paired_read \ -| homekit_permissions_paired_write \ -| homekit_permissions_notify, \ -.min_value = (float[]) {1000}, \ -.max_value = (float[]) {10000}, \ -.min_step = (float[]) {1}, \ -.value = HOMEKIT_UINT8_(_value), \ -##__VA_ARGS__ - - -#define HOMEKIT_CHARACTERISTIC_CUSTOM_SQL_LOG HOMEKIT_CUSTOM_UUID_DBB("F0000002") -#define HOMEKIT_DECLARE_CHARACTERISTIC_CUSTOM_SQL_LOG(_value, ...) \ -.type = HOMEKIT_CHARACTERISTIC_CUSTOM_SQL_LOG, \ -.description = "SQL LOG", \ -.format = homekit_format_bool, \ -.permissions = homekit_permissions_paired_read \ -| homekit_permissions_paired_write \ -| homekit_permissions_notify, \ -.value = HOMEKIT_BOOL_(_value), \ -##__VA_ARGS__ - -#endif - - - -void save_characteristic_to_flash (homekit_characteristic_t *ch, homekit_value_t value); - -void load_characteristic_from_flash (homekit_characteristic_t *ch); diff --git a/libs/http_post/component.mk b/libs/http_post/component.mk deleted file mode 100644 index d73d86d..0000000 --- a/libs/http_post/component.mk +++ /dev/null @@ -1,8 +0,0 @@ -# Component makefile for http_post - -INC_DIRS += $(http_post_ROOT) - -http_post_INC_DIR = $(http_post_ROOT) -http_post_SRC_DIR = $(http_post_ROOT) - -$(eval $(call component_compile_rules,http_post)) diff --git a/libs/http_post/http_post.c b/libs/http_post/http_post.c deleted file mode 100644 index 8555ffb..0000000 --- a/libs/http_post/http_post.c +++ /dev/null @@ -1,130 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include - -#include -#include -#include -#include -#include -#include - - -#define WEB_SERVER "192.168.1.2" -#define WEB_PORT "80" -#define WEB_URL "/esplogger/postsql.php" -char request[450]; -char details[150]; -float temperature; -float humidity; -float moisture; - -void http_post_task(void * pvParameters) -{ - int successes = 0, failures = 0; - printf("HTTP get task starting...\r\n"); - - while(1) { -// sdk_wifi_set_sleep_type(WIFI_SLEEP_NONE); - - printf ("Suspending http_post_task\n"); - vTaskSuspend( NULL ); - - printf ("Resumed http_post_task\n"); - - const struct addrinfo hints = { - .ai_family = AF_INET, - .ai_socktype = SOCK_STREAM, - }; - struct addrinfo *res; - - printf("Running DNS lookup for %s...\r\n", WEB_SERVER); - int err = getaddrinfo(WEB_SERVER, WEB_PORT, &hints, &res); - - if(err != 0 || res == NULL) { - printf("DNS lookup failed err=%d res=%p\r\n", err, res); - if(res) - freeaddrinfo(res); - vTaskDelay(1000 / portTICK_PERIOD_MS); - failures++; - continue; - } - /* Note: inet_ntoa is non-reentrant, look at ipaddr_ntoa_r for "real" code */ - struct in_addr *addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; - printf("DNS lookup succeeded. IP=%s\r\n", inet_ntoa(*addr)); - - int s = lwip_socket(res->ai_family, res->ai_socktype, 0); - if(s < 0) { - printf("... Failed to allocate socket\r\n"); - freeaddrinfo(res); - vTaskDelay(1000 / portTICK_PERIOD_MS); - failures++; - continue; - } - - printf("... allocated socket: %d \r\n", s); - - if(lwip_connect(s, res->ai_addr, res->ai_addrlen) != 0) { - lwip_close(s); - freeaddrinfo(res); - printf("... socket connect failed.\r\n"); - vTaskDelay(4000 / portTICK_PERIOD_MS); - failures++; - continue; - } - - printf("... connected\r\n"); - freeaddrinfo(res); - request[0] = "\0"; -// snprintf(details, 80, "{\"temp\": %.3f, \"hum\": %.3f, \"mois\": %.3f}\r\n", temperature, humidity, moisture); - - snprintf(details, 150, post_string); - snprintf(request, 450, "POST %s HTTP/1.0\r\n" - "Host: %s\r\n" -// "User-Agent: esp-open-rtos/0.1 esp8266\r\n" - "Content-type: application/x-www-form-urlencoded\r\n" - "Content-Length: %d\r\n\r\n" - "%s", WEB_URL, WEB_SERVER, strlen(details), details); - printf(request); - if (lwip_write(s, request, strlen(request)) < 0) { - printf("... socket send failed\r\n"); - lwip_close(s); - vTaskDelay(4000 / portTICK_PERIOD_MS); - failures++; - continue; - } - printf("... socket send success\r\n"); - - static char recv_buf[200]; - int r; - do { - printf("receiving..."); - bzero(recv_buf, 200); - r = lwip_read(s, recv_buf, 199); - if(r > 0) { - printf("%s", recv_buf); - } - } while(r > 0); - - printf("... done reading from socket. Last read return=%d errno=%d\r\n", r, errno); - if(r != 0) - failures++; - else - successes++; - lwip_close(s); - printf("successes = %d failures = %d\r\n", successes, failures); -// sdk_wifi_set_sleep_type(WIFI_SLEEP_LIGHT); - vTaskDelay(10000 / portTICK_PERIOD_MS); - printf("\r\nStarting again!\r\n"); - } -} - diff --git a/libs/http_post/http_post.h b/libs/http_post/http_post.h deleted file mode 100644 index 5a5d9df..0000000 --- a/libs/http_post/http_post.h +++ /dev/null @@ -1,4 +0,0 @@ -void http_post_task (void * pvParameters ); - - -char post_string[150]; diff --git a/libs/led_codes/component.mk b/libs/led_codes/component.mk deleted file mode 100644 index b39adc9..0000000 --- a/libs/led_codes/component.mk +++ /dev/null @@ -1,8 +0,0 @@ -# Component makefile for led_codes - -INC_DIRS += $(led_codes_ROOT) - -led_codes_INC_DIR = $(led_codes_ROOT) -led_codes_SRC_DIR = $(led_codes_ROOT) - -$(eval $(call component_compile_rules,led_codes)) diff --git a/libs/led_codes/led_codes.c b/libs/led_codes/led_codes.c deleted file mode 100644 index da3b6a8..0000000 --- a/libs/led_codes/led_codes.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * LED Codes - * - * Copyright 2018 José A. Jiménez (@RavenSystem) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "led_codes.h" - -#define DURATION_OFF 150 - -typedef struct led_params_t { - blinking_params_t blinking_params; - uint8_t gpio; - bool status; - ETSTimer timer; - uint8_t count; - uint32_t delay; -} led_params_t; - -led_params_t led_params; - -void led_code_run() { - led_params.status = !led_params.status; - - gpio_write(led_params.gpio, led_params.status); - - if (led_params.status == 0) { - led_params.delay = (led_params.blinking_params.duration * 1000) + 90; - } else { - led_params.delay = DURATION_OFF; - led_params.count++; - } - - sdk_os_timer_disarm(&led_params.timer); - - if (led_params.count < led_params.blinking_params.times) { - sdk_os_timer_arm(&led_params.timer, led_params.delay, 0); - } -} - -void led_code(uint8_t gpio, blinking_params_t blinking_params) { - led_params.gpio = gpio; - led_params.blinking_params = blinking_params; - - sdk_os_timer_disarm(&led_params.timer); - sdk_os_timer_setfn(&led_params.timer, led_code_run, NULL); - - led_params.status = 1; - led_params.count = 0; - - led_code_run(); -} diff --git a/libs/led_codes/led_codes.h b/libs/led_codes/led_codes.h deleted file mode 100644 index b054e13..0000000 --- a/libs/led_codes/led_codes.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * LED Codes - * - * Copyright 2018 José A. Jiménez (@RavenSystem) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -typedef struct blinking_params_t { - uint8_t times; - uint8_t duration; -} blinking_params_t; - -#define GENERIC_ERROR (blinking_params_t){6,0} -#define SENSOR_ERROR (blinking_params_t){5,0} -#define WIFI_CONNECTED (blinking_params_t){1,2} -#define IDENTIFY_ACCESSORY (blinking_params_t){1,3} -#define RESTART_DEVICE (blinking_params_t){2,2} -#define WIFI_CONFIG_RESET (blinking_params_t){2,0} -#define EXTRA_CONFIG_RESET (blinking_params_t){2,1} -#define FUNCTION_A (blinking_params_t){1,0} -#define FUNCTION_B (blinking_params_t){2,0} -#define FUNCTION_C (blinking_params_t){3,0} -#define FUNCTION_D (blinking_params_t){4,0} - -void led_code(uint8_t gpio, blinking_params_t blinking_params); diff --git a/libs/ota/component.mk b/libs/ota/component.mk deleted file mode 100644 index 861596a..0000000 --- a/libs/ota/component.mk +++ /dev/null @@ -1,8 +0,0 @@ -# Component makefile for ota - -INC_DIRS += $(ota_ROOT) - -ota_INC_DIR = $(ota_ROOT) -ota_SRC_DIR = $(ota_ROOT) - -$(eval $(call component_compile_rules,ota)) diff --git a/libs/ota/ota-api.c b/libs/ota/ota-api.c deleted file mode 100644 index 5126078..0000000 --- a/libs/ota/ota-api.c +++ /dev/null @@ -1,75 +0,0 @@ -#include //for printf -#include -#include - -#include -#include -#include -#include - -// the first function is the ONLY thing needed for a repo to support ota after having started with ota-boot -// in ota-boot the user gets to set the wifi and the repository details and it then installs the ota-main binary - -void ota_update(void *arg) { //arg not used - rboot_set_temp_rom(1); //select the OTA main routine - sdk_system_restart(); //#include - // there is a bug in the esp SDK such that if you do not power cycle the chip after serial flashing, restart is unreliable -} - -// this function is optional to couple Homekit parameters to the sysparam variables and github parameters -unsigned int ota_read_sysparam(char **manufacturer,char **serial,char **model,char **revision) { - sysparam_status_t status; - char *value; - - status = sysparam_get_string("ota_repo", &value); - if (status == SYSPARAM_OK) { - strchr(value,'/')[0]=0; - *manufacturer=value; - *model=value+strlen(value)+1; - } else { - *manufacturer="manuf_unknown"; - *model="model_unknown"; - } - status = sysparam_get_string("ota_version", &value); - if (status == SYSPARAM_OK) { - *revision=value; - } else *revision="0.0.0"; - - uint8_t macaddr[6]; - sdk_wifi_get_macaddr(STATION_IF, macaddr); - *serial=malloc(18); - sprintf(*serial,"%02X:%02X:%02X:%02X:%02X:%02X",macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]); - - unsigned int c_hash=0; - char version[16]; - char* rev=version; - char* dot; - strncpy(rev,*revision,16); - if ((dot=strchr(rev,'.'))) {dot[0]=0; c_hash= atoi(rev); rev=dot+1;} - if ((dot=strchr(rev,'.'))) {dot[0]=0; c_hash=c_hash*1000+atoi(rev); rev=dot+1;} - c_hash=c_hash*1000+atoi(rev); - //c_hash=c_hash*10 +configuration_variant; //possible future extension - printf("manuf=\'%s\' serial=\'%s\' model=\'%s\' revision=\'%s\' c#=%d\n",*manufacturer,*serial,*model,*revision,c_hash); - return c_hash; -} - - - - -#include -#include -#include - -static ETSTimer update_timer; - -void ota_set(homekit_value_t value) { - if (value.format != homekit_format_bool) { - printf("Invalid ota-value format: %d\n", value.format); - return; - } - if (value.bool_value) { - //make a distinct light pattern or other feedback to the user = call identify routine - sdk_os_timer_setfn(&update_timer, ota_update, NULL); - sdk_os_timer_arm(&update_timer, 500, 0); //wait 0.5 seconds to trigger the reboot so gui can update and events sent - } -} diff --git a/libs/ota/ota-api.h b/libs/ota/ota-api.h deleted file mode 100644 index fd4d2e0..0000000 --- a/libs/ota/ota-api.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __HOMEKIT_CUSTOM_CHARACTERISTICS__ -#define __HOMEKIT_CUSTOM_CHARACTERISTICS__ - -#define HOMEKIT_CUSTOM_UUID(value) (value "-0e36-4a42-ad11-745a73b84f2b") - -#define HOMEKIT_SERVICE_CUSTOM_SETUP HOMEKIT_CUSTOM_UUID("000000FF") - -#define HOMEKIT_CHARACTERISTIC_CUSTOM_OTA_TRIGGER HOMEKIT_CUSTOM_UUID("F0000001") -#define HOMEKIT_DECLARE_CHARACTERISTIC_CUSTOM_OTA_TRIGGER(_value, ...) \ - .type = HOMEKIT_CHARACTERISTIC_CUSTOM_OTA_TRIGGER, \ - .description = "FirmwareUpdate", \ - .format = homekit_format_bool, \ - .permissions = homekit_permissions_paired_read \ - | homekit_permissions_paired_write \ - | homekit_permissions_notify, \ - .value = HOMEKIT_BOOL_(_value), \ - ##__VA_ARGS__ - -unsigned int ota_read_sysparam(char **manufacturer,char **serial,char **model,char **revision); - -void ota_update(void *arg); - -void ota_set(homekit_value_t value); - -#define API_OTA_TRIGGER HOMEKIT_CHARACTERISTIC_(CUSTOM_OTA_TRIGGER, false, .setter=ota_set) - -#endif diff --git a/src/Makefile b/src/Makefile index 86f0ad1..aa85203 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,10 +10,10 @@ EXTRA_COMPONENTS = \ $(abspath ../components/esp-wolfssl) \ $(abspath ../components/esp-cjson) \ $(abspath ../components/esp-homekit)\ - $(abspath ../libs/button)\ - $(abspath ../libs/led_codes)\ - $(abspath ../libs/ota)\ - $(abspath ../libs/custom_characteristics) + $(abspath ../components/eps-common_fucntions/button)\ + $(abspath ../components/eps-common_fucntions/led_codes)\ + $(abspath ../components/eps-common_fucntions/ota)\ + $(abspath ../components/eps-common_fucntions/custom_characteristics) FONTS_TERMINUS_BOLD_8X14_ISO8859_1 = 1 FONTS_TERMINUS_BOLD_14X28_ISO8859_1 = 1