Skip to content

Commit

Permalink
moved to common functions
Browse files Browse the repository at this point in the history
  • Loading branch information
maccoylton committed Feb 10, 2019
1 parent e306b3b commit f4e1a2e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 261 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
esp-homekit-sonoff-s20.xcodeproj
build/
firmware/
src/.DS_Store
.DS_Store
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "components/esp-cjson"]
path = components/esp-cjson
url = https://github.com/maximkulkin/esp-cjson
[submodule "components/esp-homekit-common-functions"]
path = components/esp-homekit-common-functions
url = https://github.com/maccoylton/esp-homekit-common-functions.git
5 changes: 4 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ EXTRA_COMPONENTS = \
extras/rboot-ota \
$(abspath ../components/esp-wolfssl) \
$(abspath ../components/esp-cjson) \
$(abspath ../components/esp-homekit)
$(abspath ../components/esp-homekit)\
$(abspath ../components/esp-homekit-common-functions/button)\
$(abspath ../components/esp-homekit-common-functions/led_codes)\
$(abspath ../components/esp-homekit-common-functions/ota)

FLASH_SIZE ?= 8
HOMEKIT_SPI_FLASH_BASE_ADDR ?= 0x8c000
Expand Down
109 changes: 0 additions & 109 deletions src/button.c

This file was deleted.

26 changes: 0 additions & 26 deletions src/button.h

This file was deleted.

31 changes: 8 additions & 23 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
#include <homekit/characteristics.h>
//#include <wifi_config.h>

#include "button.h"
#include <button.h>
#include <led_codes.h>

// add this section to make your device OTA capable
// create the extra characteristic &ota_trigger, at the end of the primary service (before the NULL)
// it can be used in Eve, which will show it, where Home does not
// and apply the four other parameters in the accessories_information section

#include "ota-api.h"
#include <ota-api.h>
homekit_characteristic_t ota_trigger = API_OTA_TRIGGER;
homekit_characteristic_t name = HOMEKIT_CHARACTERISTIC_(NAME, DEVICE_NAME);
homekit_characteristic_t manufacturer = HOMEKIT_CHARACTERISTIC_(MANUFACTURER, DEVICE_MANUFACTURER);
Expand All @@ -57,7 +58,7 @@ homekit_characteristic_t revision = HOMEKIT_CHARACTERISTIC_(FIRMWARE_REVISIO
// The GPIO pin that is connected to the relay and th blue LED on the Sonoff S20.
const int relay_gpio = 12;
// The GPIO pin that is connected to the green LED on the Sonoff S20.
const int led_gpio = 13;
const int LED_GPIO = 13;
// The GPIO pin that is oconnected to the button on the Sonoff S20.
const int button_gpio = 0;

Expand All @@ -69,17 +70,12 @@ void relay_write(bool on) {
}

void led_write(bool on) {
gpio_write(led_gpio, on ? 0 : 1);
gpio_write(LED_GPIO, on ? 0 : 1);
}

void reset_configuration_task() {
//Flash the LED first before we start the reset
for (int i=0; i<3; i++) {
led_write(true);
vTaskDelay(100 / portTICK_PERIOD_MS);
led_write(false);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
led_code (LED_GPIO, WIFI_CONFIG_RESET);

printf("Resetting Wifi Config\n");

Expand Down Expand Up @@ -110,7 +106,7 @@ homekit_characteristic_t switch_on = HOMEKIT_CHARACTERISTIC_(
);

void gpio_init() {
gpio_enable(led_gpio, GPIO_OUTPUT);
gpio_enable(LED_GPIO, GPIO_OUTPUT);
led_write(false);
gpio_enable(relay_gpio, GPIO_OUTPUT);
relay_write(switch_on.value.bool_value);
Expand Down Expand Up @@ -138,19 +134,8 @@ void button_callback(uint8_t gpio, button_event_t event) {

void switch_identify_task(void *_args) {
// We identify the Sonoff by Flashing it's LED.
for (int i=0; i<3; i++) {
for (int j=0; j<2; j++) {
led_write(true);
vTaskDelay(100 / portTICK_PERIOD_MS);
led_write(false);
vTaskDelay(100 / portTICK_PERIOD_MS);
}

vTaskDelay(250 / portTICK_PERIOD_MS);
}

led_write(false);

led_code( LED_GPIO, IDENTIFY_ACCESSORY);
vTaskDelete(NULL);
}

Expand Down
75 changes: 0 additions & 75 deletions src/ota-api.c

This file was deleted.

27 changes: 0 additions & 27 deletions src/ota-api.h

This file was deleted.

0 comments on commit f4e1a2e

Please sign in to comment.