go BrainCenter(zmqctx, brain_listen_addr_, store_these_events_chan)
go MetaEventRoutine_Movement(ps, 10, 20, 10)
- go MetaEventRoutine_Presence(ps)
+ go MetaEventRoutine_Presence(ps, 21, 200)
// --- get update on most recent status ---
answ := ZmqsAskQuestionsAndClose(zmqctx, door_cmd_addr_, [][][]byte{[][]byte{[]byte("status")}})
import (
"time"
- //~ "./brain"
pubsub "github.com/tuxychandru/pubsub"
"container/ring"
r3events "svn.spreadspace.org/realraum/go.svn/r3events"
)
+/// Movement Meta Event Injector:
+/// threshold number of movements within gran_duration*granularity seconds -> SomethingReallyIsMoving{True}
+/// No movement within 3 hours but movement within the last 6 hours -> SomethingReallyIsMoving{False}
+///
+/// Thus SomethingReallyIsMoving{True} fires regularly, but at most every gran_duration seconds
+/// While SomethingReallyIsMoving{False} fires only once to assure us that everybody might really be gone
+
+
func MetaEventRoutine_Movement(ps *pubsub.PubSub, granularity, gran_duration int , threshold uint32) {
var last_movement int64
movement_window := ring.New(granularity+1)
r3events "svn.spreadspace.org/realraum/go.svn/r3events"
)
-func MetaEventRoutine_Presence(ps *pubsub.PubSub) {
+func MetaEventRoutine_Presence(ps *pubsub.PubSub, movement_timeout, button_timeout int64) {
//~ var last_door_cmd *r3events.DoorCommandEvent
var last_presence bool
- var last_movement, last_buttonpress int64
+ var last_movement, last_buttonpress, last_frontlock_use int64
var front_locked, front_shut, back_shut bool = true, true, true
events_chan := ps.Sub("door", "doorcmd", "buttons", "movement")
last_movement = evnt.Ts
} else {
last_movement = 0
+ if last_presence { Syslog_.Print("Presence: Mhh, SomethingReallyIsMoving{false} received but presence still true. Quite still a bunch we have here.") }
}
case r3events.BoreDoomButtonPressEvent:
last_buttonpress = evnt.Ts
//~ last_door_cmd = &evnt
case r3events.DoorLockUpdate:
front_locked = evnt.Locked
+ last_frontlock_use = evnt.Ts
case r3events.DoorAjarUpdate:
- front_shut = evnt.Shut
+ if front_shut == false && evnt.Shut && front_locked && evnt.Ts - last_frontlock_use > 2 {
+ Syslog_.Print("Presence: ignoring frontdoor ajar event, since obviously someone is fooling around with the microswitch while the door is still open")
+ } else {
+ front_shut = evnt.Shut
+ }
case r3events.BackdoorAjarUpdate:
back_shut = evnt.Shut
}
//... skip state check .. we had a definite presence event
} else if any_door_unlocked || any_door_ajar {
new_presence = true
- } else if last_movement != 0 || ts - last_buttonpress < 200 {
+ } else if ts - last_movement < movement_timeout || ts - last_buttonpress < button_timeout {
new_presence = true
} else {
new_presence = false