Bug 5501 - Motion sensor should have some hysteresis
: Motion sensor should have some hysteresis
Status: CLOSED FIXED
Product: SB Controller
Classification: Unclassified
Component: UI
: unspecified
: Macintosh Other
: P2 normal (vote)
: 7.1
Assigned To: Richard Titmuss
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-09-16 11:24 UTC by Blackketter Dean
Modified: 2008-12-15 12:37 UTC (History)
1 user (show)

See Also:
Category: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Blackketter Dean 2007-09-16 11:24:49 UTC
I've noticed that the motion sensor tends to wake up the device with a little motion (like when I put something down on the table where the device is in its stand), but sometimes will sleep when I'm holding it. Waking up should require a bit more motion, but to stay awake should require less motion.
Comment 1 KDF 2007-09-23 00:42:07 UTC
for recording purposes, I've created a patch locally that restarts the screensaver timer on any motion, but only breaks out if there are 4 events each within 100ms of each other.  This needs more thought overall as the events can be sporadic.  One clue is that a pick up usually triggers multiple axis events, while a bump is very heavily weighted to just ONE acis.  It might also make sense to handle this deeper into the code such that events are reported only when there is a real movement, while also allowing raw access for things that need it.  It also might only be needed for clocks, as opposed to all screensavers.  Clearly a need for a meeting for sort this out.  anyway, I'll leave my working patch here for the record (in case I lose it at home).

Index: ScreenSaversApplet.lua
===================================================================
--- ScreenSaversApplet.lua      (revision 534)
+++ ScreenSaversApplet.lua      (working copy)
@@ -22,6 +22,7 @@
 local ipairs, pairs, tostring = ipairs, pairs, tostring
 
 local oo               = require("loop.simple")
+local math             = require("math")
 
 local Applet           = require("jive.Applet")
 local AppletManager    = require("jive.AppletManager")
@@ -70,8 +71,47 @@
        Framework:addListener(
                EVENT_KEY_PRESS | EVENT_SCROLL | EVENT_MOTION,
                function(event)
-                       self.timer:restart(self.timeout)
+
+                       -- accumulate and check motion events when screensaver active
+                       -- one event above min thresholds will reset screensvaer timer
+                       if event:getType() == EVENT_MOTION then
+                               local x, y, z = event:getMotion()
 
+                               -- threshold values for motion sensing
+                               local minx, miny, minz = 30, 30, 30
+
+                               x,y,z = math.abs(x),math.abs(y),math.abs(z)
+
+                               -- short circuit for low motion events
+                               if (x < minx and y < miny and z < minz) then
+                                       log:debug('Motion event below thresholds')
+                                       return EVENT_UNUSED
+                               end
+
+                               self.timer:restart(self.timeout)
+
+                               local time    = Framework:getTicks()
+                               local interval= time - (self.lasttime or time)
+
+                               -- count up events within 100ms of each other
+                               if interval < 100 and self.motioncount != nil then
+                                       self.motioncount = self.motioncount + 1
+                               else
+                                       self.motioncount = 0
+                               end
+
+                               self.lasttime = time;
+
+                               -- only pass if we have 4 events within 100ms of each other
+                               if (self.motioncount < 4) then
+                                       log:warn('Tracking motion events ',self.motioncount,' interval=',interval);
+                                       return EVENT_UNUSED
+                               end
+
+                       else 
+                               self.timer:restart(self.timeout)
+                       end
+
                        -- allow active screensaver to process events if
                        -- it is on top of the window stack
                        if self.active == Framework.windowStack[1] then
Comment 2 KDF 2007-09-23 23:45:32 UTC
side effect of a patch like that above is that the screensaver becomes re-entrant.  Some other routine (wakeup maybe?) is watching MOTION events and causing the screensaver to be able to activate multiple times.  thus, when you do really exit, you end up having to exit several layers of screensavers.  Definite hint that this should be controlled at a lower level as part of the motion event itself.
Comment 3 Chris Owens 2007-10-30 10:11:17 UTC
Richard may update the status of this later today
Comment 4 Richard Titmuss 2007-10-30 14:42:24 UTC
I have changed the configuration of the motion sensor, so the gravity is removed with a high-pass filter before the threshold for the irq. These seems to work much better (along with the application changes from kdf in jive_bsp.c). I'll mark this as fixed for now, but if after trying the latest binary you still think this is a problem please reopen the bug.
Comment 5 Chris Owens 2008-07-30 15:32:26 UTC
This bug has now been fixed in the 7.1 release version of SqueezeCenter!  Please download the new version from http://www.slimdevices.com if you haven't already.  

If you are still experiencing this problem, feel free to reopen the bug with your new comments and we'll have another look.
Comment 6 James Richardson 2008-12-15 12:37:43 UTC
This bug has been fixed in the 7.3.0 release version of SqueezeCenter!

Please download the new version from http://www.slimdevices.com/su_downloads.html if you haven't already.  

If you are still experiencing this problem, feel free to reopen the bug with your new comments and we'll have another look.