-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGarageDoor.h
154 lines (124 loc) · 4.06 KB
/
GarageDoor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#pragma region Prolog
/*******************************************************************
$CRT 01 Okt 2024 : hb
$AUT Holger Burkarth
$DAT >>GarageDoor.h<< 01 Okt 2024 09:00:26 - (c) proDAD
*******************************************************************/
#pragma endregion
#pragma region Spelling
// Ignore Spelling:
#pragma endregion
#pragma region Description
/*
--EN--
This example shows a garage door opener that can be controlled by
Apple HomeKit. The device uses the same function as a traditional
button to open the door. An ultrasonic distance sensor monitors
the position of the door to tell Apple HomeKit whether the door
is closed, open, or half open.
New or different functions can be configured via CHost, derived
from CUnitBase, so that only a small amount of programming is
required, e.g. to detect the door position via limit switches or
to start the door motor other than by a pulse.
--DE--
Dieses Beispiel zeigt einen Garagentoröffner, der über Apple HomeKit
gesteuert werden kann. Das Gerät verwendet die gleiche Funktion wie
ein herkömmlicher Taster, um das Tor zu öffnen. Ein
Ultraschall-Abstandssensor überwacht die Position des Tores, um
Apple HomeKit mitzuteilen, ob das Tor geschlossen, geöffnet oder
in einer halb geöffneten Position ist.
Neue oder abweichende Funktionen können, abgeleitet aus CUnitBase,
über CHost konfiguriert werden, so dass nur ein geringer
Programmieraufwand erforderlich ist, um z.B. die Torposition über
Endschalter zu ermitteln oder den Tormotor abweichend von einem
Impuls zu starten.
*/
#pragma endregion
#pragma region Includes
#include <HomeKit_GarageDoorOpener.h>
using namespace HBHomeKit;
using namespace HBHomeKit::GarageDoorOpener;
#pragma endregion
#pragma region PIN Config
/*
* @brief This pin is used to start the door motor by pulling the trigger pin HIGH for 100 ms.
* @note Make sure that this pin is set to LOW during booting so that
* no trigger pulse is sent when restarting.
* For example: D2 would be possible, but not D3.
*/
#define DOOR_PIN D2
/* @brief The unit reads the door position from an ultrasonic sensor.
* The sensor is mounted at the top of the door and measures the distance to the door.
* @note Sensor: HC-SR04 Ultrasonic Sensor
* @node The EchoPin must be connected to an interrupt pin. (e.g.: D8)
*/
#define TRIGGER_PIN D7
#define ECHO_PIN D8 // must be interrupt capable
#pragma endregion
#pragma region HomeKit Config
/*
* @brief A HomeKit device service contains the basic information of the device
* @note The device name is also used to create the Bonjour service name.
*/
const CDeviceService Device
{
{
.DeviceName{"Garage"}, // available as http://Garage.local
/*
* ... more optional device information: You can read more about the CDeviceService in hb_homekit.h
*/
}
};
/*
* @brief Define functions by adding specialized units.
*/
CHost Host
(
MakeControlUnit()
, MakeSR04UltrasonicSensorPositionUnit({ TRIGGER_PIN, ECHO_PIN })
, MakeTriggerDoorMotorUnit(DOOR_PIN)
, MakeContinuousEventRecorderUnit()
);
/*
* @brief Garage door opener as a service for HomeKit
*/
CGarageDoorOpenerService Door(&Host);
/*
* @brief HomeKit provides everything you need to interact with Apple HomeKit and host a homepage.
*/
CHomeKit HomeKit
(
Device,
homekit_accessory_category_garage,
&Door
);
#pragma endregion
#pragma region setup
void setup()
{
Serial.begin(115200);
delay(500); // Important for ESP32: Wait until the serial interface is ready
Serial.println("\n\n\nEnter Setup");
// Installs and configures everything for CGarageDoorOpenerService.
InstallAndSetupGarageDoorOpener(HomeKit, Door, Host);
// Adds a menu (WiFi) that allows the user to connect to a WiFi network.
AddWiFiLoginMenu(HomeKit);
// Adds standard menu items to the controller.
AddStandardMenus(HomeKit);
// Installs the action UI, required for garage/WiFi web-pages.
InstallActionUI(HomeKit);
// Starts HomeKit
if(!HomeKit.Setup())
{
ERROR("HomeKit setup failed");
return;
}
INFO("Setup finished");
}
#pragma endregion
#pragma region loop
void loop()
{
HomeKit.Loop();
}
#pragma endregion