]> git.tdb.fi Git - r2c2.git/commitdiff
Read power state from arducontrol device on startup
authorMikko Rasa <tdb@tdb.fi>
Thu, 7 Nov 2013 22:38:20 +0000 (00:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 7 Nov 2013 22:38:20 +0000 (00:38 +0200)
source/libr2c2/arducontrol.cpp
source/libr2c2/arducontrol.h

index e940a2aed14527ed676a6cbb4af1786762411420..e5d94ef9d5d180e0bf3f7f5a5cfdcd847f48ae77 100644 (file)
@@ -24,6 +24,10 @@ ArduControl::ArduControl(const string &dev):
        n_s88_octets(0),
        thread(*this)
 {
+       QueuedCommand cmd;
+       cmd.command[0] = READ_POWER_STATE;
+       cmd.length = 1;
+       push_command(cmd);
 }
 
 ArduControl::~ArduControl()
@@ -33,17 +37,14 @@ ArduControl::~ArduControl()
 
 void ArduControl::set_power(bool p)
 {
-       if(p==power.pending)
-               return;
-
-       power.pending = p;
-       ++power.serial;
-
-       QueuedCommand cmd(POWER);
-       cmd.tag.serial = power.serial;
-       cmd.command[0] = (p ? POWER_ON : POWER_OFF);
-       cmd.length = 1;
-       push_command(cmd);
+       if(power.set(p))
+       {
+               QueuedCommand cmd(POWER);
+               cmd.tag.serial = power.serial;
+               cmd.command[0] = (p ? POWER_ON : POWER_OFF);
+               cmd.length = 1;
+               push_command(cmd);
+       }
 }
 
 void ArduControl::halt(bool)
@@ -662,6 +663,16 @@ void ArduControl::ControlThread::main()
                                        else if(tag && !repeat_count)
                                                control.push_completed_tag(tag);
                                }
+                               else if(type==POWER_STATE && rlength==2)
+                               {
+                                       control.power.set(reply[1]);
+
+                                       Tag ptag;
+                                       ptag.type = Tag::GENERAL;
+                                       ptag.command = POWER;
+                                       ptag.serial = control.power.serial;
+                                       control.push_completed_tag(ptag);
+                               }
                                else if(type==S88_DATA && rlength>2)
                                {
                                        unsigned offset = static_cast<unsigned char>(reply[1]);
index fb0cb68c6ca03930a571a72dcd248ae00cc8b581..4e9ef63b248c631821055aecf2ad0bc53ce5fbeb 100644 (file)
@@ -17,6 +17,7 @@ private:
        {
                POWER_ON = 0x01,
                POWER_OFF = 0x02,
+               READ_POWER_STATE = 0x03,
                READ_TRACK_CURRENT = 0x08,
                SET_OVERCURRENT_LIMIT = 0x09,
                READ_INPUT_VOLTAGE = 0x0A,
@@ -35,6 +36,7 @@ private:
                OVERCURRENT = 0xA0,
                TRACK_CURRENT = 0xC0,
                INPUT_VOLTAGE = 0xC1,
+               POWER_STATE = 0xC2,
                S88_DATA = 0xD0
        };