]> git.tdb.fi Git - r2c2.git/commitdiff
Keep track of the active accessory bit index
authorMikko Rasa <tdb@tdb.fi>
Tue, 1 Apr 2014 18:14:35 +0000 (21:14 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 1 Apr 2014 18:14:35 +0000 (21:14 +0300)
Failing to do this may theoretically cause trouble if a multi-bit
accessory spans a k83 module boundary.  Sending a deactivation command
for the first bit would only turn off the first module but not the
second.

source/libr2c2/arducontrol.cpp
source/libr2c2/arducontrol.h

index 6d74f3719587e45a4a9ec2549cff1ab3b34e7a54..3d2d39b1a0b2aca8c13e8018a21f189ecbd975cd 100644 (file)
@@ -401,6 +401,7 @@ void ArduControl::tick()
                        unsigned lowest_bit = changes&~(changes-1);
                        unsigned i;
                        for(i=0; (lowest_bit>>i)>1; ++i) ;
+                       active_index = i;
                        acc.state.set(acc.state^lowest_bit);
                        PendingCommand cmd(acc, Accessory::ACTIVATE, i);
                        command_queue.push(cmd);
@@ -415,7 +416,7 @@ void ArduControl::tick()
                if(t>off_timeout)
                {
                        off_timeout = Time::TimeStamp();
-                       PendingCommand cmd(*active_accessory, Accessory::DEACTIVATE);
+                       PendingCommand cmd(*active_accessory, Accessory::DEACTIVATE, active_index);
                        command_queue.push(cmd);
                }
        }
index c1e7256ee3f00674b113c4b4e429a77f0700ec79..75b9dc8cb8f4d283e4b0e0aa3b775192fa1357d4 100644 (file)
@@ -353,6 +353,7 @@ private:
        AccessoryMap accessories;
        AccessoryPtrList accessory_queue;
        Accessory *active_accessory;
+       unsigned char active_index;
        Msp::Time::TimeStamp off_timeout;
 
        SensorMap sensors;