Skip to content

Commit

Permalink
added led codes and sysparams
Browse files Browse the repository at this point in the history
  • Loading branch information
maccoylton committed Feb 7, 2019
1 parent 5bd65ff commit d74b06e
Show file tree
Hide file tree
Showing 21 changed files with 651 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/esp-homekit
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions libs/button/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Component makefile for button

INC_DIRS += $(button_ROOT)

button_INC_DIR = $(button_ROOT)
button_SRC_DIR = $(button_ROOT)

$(eval $(call component_compile_rules,button))
43 changes: 43 additions & 0 deletions libs/check_wifi/check_wifi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#include <espressif/esp_wifi.h>
#include <espressif/esp_sta.h>
#include <espressif/esp_common.h>
#include <esp8266.h>
#include <FreeRTOS.h>
#include <task.h>
#include <led_codes.h>

#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);
}
}
3 changes: 3 additions & 0 deletions libs/check_wifi/check_wifi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define CHECK_INTERVAL 36000000

void checkWifiTask(void *pvParameters);
8 changes: 8 additions & 0 deletions libs/check_wifi/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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))
10 changes: 10 additions & 0 deletions libs/custom_characteristics/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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))
140 changes: 140 additions & 0 deletions libs/custom_characteristics/custom_characteristics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#include <sysparam.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <homekit/homekit.h>
#include <homekit/characteristics.h>
#include <custom_characteristics.h>

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);
}



}
60 changes: 60 additions & 0 deletions libs/custom_characteristics/custom_characteristics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 <homekit/homekit.h>
#include <homekit/characteristics.h>

#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);
8 changes: 8 additions & 0 deletions libs/http_post/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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))
Loading

0 comments on commit d74b06e

Please sign in to comment.