]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/arducontrol.cpp
Keep track of the active accessory bit index
[r2c2.git] / source / libr2c2 / arducontrol.cpp
index dd4e0574eb7d52c4714e8740db3e99c20be40ed8..3d2d39b1a0b2aca8c13e8018a21f189ecbd975cd 100644 (file)
@@ -18,9 +18,9 @@ ArduControl::ProtocolInfo ArduControl::protocol_info[2] =
        { 0x3FFF, 126, 15 }  // MFX
 };
 
-ArduControl::ArduControl(const string &dev):
-       serial(dev),
-       debug(1),
+ArduControl::ArduControl(const Options &opts):
+       serial(opts.get<string>(string(), "ttyUSB0")),
+       debug(opts.get<unsigned>("debug")),
        state_file("arducontrol.state"),
        power(false),
        active_accessory(0),
@@ -357,9 +357,7 @@ void ArduControl::tick()
 
                        Accessory &acc = i->second;
                        if(tag.command==Accessory::ACTIVATE)
-                       {
                                off_timeout = Time::now()+acc.active_time;
-                       }
                        else if(tag.command==Accessory::DEACTIVATE)
                        {
                                if(acc.state.commit(tag.serial))
@@ -403,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);
@@ -417,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);
                }
        }
@@ -969,6 +968,8 @@ void ArduControl::ControlThread::init_baud_rate()
 
        if(!rate)
        {
+               if(control.debug>=1)
+                       IO::print("ArduControl detection failed\n");
                done = true;
                return;
        }