-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitch.h
134 lines (106 loc) · 2.56 KB
/
Switch.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
#pragma region Prolog
/*******************************************************************
$CRT 03 Okt 2024 : hb
$AUT Holger Burkarth
$DAT >>Switch.h<< 11 Dez 2024 15:39:39 - (c) proDAD
*******************************************************************/
#pragma endregion
#pragma region Spelling
// Ignore Spelling:
#pragma endregion
#pragma region Description
/*
--EN--
--DE--
*/
#pragma endregion
#pragma region Includes
#include <HomeKit_Switch.h>
using namespace HBHomeKit;
using namespace HBHomeKit::Switch;
#pragma endregion
#pragma region PIN Config
/*
* @brief
*/
#define SWITCHER_PIN D2
#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{"Switch"}, // available as http://Switch.local
/*
* ... more optional device information: You can read more about the CDeviceService in hb_homekit.h
*/
}
};
/*
* @brief Switcher as a service for HomeKit
*/
CSwitchService Switcher
({
.Name = "Switch",
#if 1
.Setter = [](homekit_characteristic_t* pC, homekit_value_t value)
{
VERBOSE("Switch::Setter");
if(modify_value(pC, value))
{
bool Stat = static_value_cast<bool>(value);
digitalWrite(SWITCHER_PIN, Stat ? HIGH : LOW);
}
},
#else
.Getter = [](const homekit_characteristic_t* pC) -> homekit_value_t
{
VERBOSE("Switch::Getter");
return static_value_cast<bool>(digitalRead(SWITCHER_PIN) == HIGH);
}
#endif
});
/*
* @brief HomeKit provides everything you need to interact with Apple HomeKit and host a homepage.
*/
CHomeKit HomeKit
(
Device,
homekit_accessory_category_switch,
&Switcher
);
#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");
pinMode(SWITCHER_PIN, OUTPUT);
// Installs and configures everything for Switcher.
InstallVarsAndCmds(HomeKit);
AddMenuItems(HomeKit);
// 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