From: Mikko Rasa Date: Tue, 1 Apr 2014 18:14:35 +0000 (+0300) Subject: Keep track of the active accessory bit index X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b746099bd0ed4aac2484b5125135d2c21c3c4082;p=r2c2.git Keep track of the active accessory bit index 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. --- diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index 6d74f37..3d2d39b 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -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); } } diff --git a/source/libr2c2/arducontrol.h b/source/libr2c2/arducontrol.h index c1e7256..75b9dc8 100644 --- a/source/libr2c2/arducontrol.h +++ b/source/libr2c2/arducontrol.h @@ -353,6 +353,7 @@ private: AccessoryMap accessories; AccessoryPtrList accessory_queue; Accessory *active_accessory; + unsigned char active_index; Msp::Time::TimeStamp off_timeout; SensorMap sensors;