summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Beattie <mike@ethernal.org>2012-03-23 08:37:53 +1300
committerMike Beattie <mike@ethernal.org>2012-03-23 08:37:53 +1300
commitf08f36c6e0714a32ea450a20de3f9805d1222c51 (patch)
tree48668730b9dd8a298dc76d93da43ee1b44cdf756
parenta3745a68b27404410648dac316841479b7e5ffcd (diff)
Large door code changes
* Move detoggle to function * Create night time check function * Add night time grace config variable * Add front door hold time config variable * Add separate "openTime" member to struct - record time door opened, not controlled. Deals with manual opens at night. * Move all door code together inside loop() (move NTP/time stuff to the top) Signed-off-by: Mike Beattie <mike@ethernal.org>
-rw-r--r--HouseControl.ino56
1 files changed, 34 insertions, 22 deletions
diff --git a/HouseControl.ino b/HouseControl.ino
index b0e78b4..cac3645 100644
--- a/HouseControl.ino
+++ b/HouseControl.ino
@@ -50,6 +50,9 @@ struct st_config {
byte notifyHost[4];
unsigned int notifyPort;
+ byte frontdoor_holdtime;
+
+ byte garagedoor_nightgracetime;
byte dawn;
byte dusk;
};
@@ -66,6 +69,7 @@ struct st_door {
boolean controlActive;
time_t controlTime;
+ time_t openTime;
};
/*********************************************************************************/
@@ -93,8 +97,11 @@ struct st_config config = {
10, 113, 1, 255, // Host to send UDP status packets to
8888, // Port to send UDP status packets to
- 7, // "Dawn"
- 21 // "Dusk" - used to shut garage doors at night.
+ 10, // Seconds to leave front door unlocked
+
+ 1, // Minutes to leave garage doors open at night
+ 7, // "Dawn" Hour - auto close before this.
+ 21 // "Dusk" Hour - auto close after this.
};
@@ -432,6 +439,9 @@ boolean readDoorState (struct st_door *door) {
door->open = !door->closed;
}
+ if (!door->last_open && door->open)
+ door->openTime = time;
+
if ((door->last_open != door->open) || (door->last_closed != door->closed))
return true;
@@ -448,6 +458,20 @@ void toggleDoorControl(struct st_door *door) {
door->controlActive = !door->controlActive;
}
+void deToggleDoorCheck(struct st_door *door, byte controlHoldTime) {
+ if (door->controlActive && ((time - door->controlTime) >= controlHoldTime) )
+ toggleDoorControl(door);
+}
+
+void garageDoorNightCheck(struct st_door *door) {
+ if ( lastNTPtime > 0
+ && !door->controlActive && door->open
+ && ((hour(time) >= config.dusk) || (hour(time) < config.dawn))
+ && ((time - door->openTime) >= (config.garagedoor_nightgracetime * 60))
+ )
+ toggleDoorControl(door);
+}
+
/*********************************************************************************/
/* Setup function */
@@ -499,34 +523,22 @@ void loop() {
time = now();
- readDoorState(&frontDoor);
- readDoorState(&garageDoor1);
- readDoorState(&garageDoor2);
-
if ((time - lastNTPtime) >= 600)
sendNTPpacket();
if (NTPSocket.parsePacket() >= 46)
parseNTPresponse();
- if (frontDoor.controlActive && ((time - frontDoor.controlTime) >= 10) ) {
- toggleDoorControl(&frontDoor);
- }
-
+ readDoorState(&frontDoor);
+ readDoorState(&garageDoor1);
+ readDoorState(&garageDoor2);
- if ( (garageDoor1.controlActive && ((time - garageDoor1.controlTime) >= 1) )
- || ( lastNTPtime > 0
- && ((hour() > config.dusk) || (hour() < config.dawn))
- && !garageDoor1.controlActive && garageDoor1.open
- && ((time - garageDoor1.controlTime) >= (2 * 60))
- )
- ) {
- toggleDoorControl(&garageDoor1);
- }
+ deToggleDoorCheck(&frontDoor, config.frontdoor_holdtime);
+ deToggleDoorCheck(&garageDoor1, 1);
+ deToggleDoorCheck(&garageDoor2, 1);
-// if (garageDoor2.controlActive && ((time - garageDoor2.controlTime) >= 1) ) {
-// toggleDoorControl(&garageDoor2);
-// }
+ garageDoorNightCheck(&garageDoor1);
+ garageDoorNightCheck(&garageDoor2);
httpServer.processConnection();