From: Mikko Rasa Date: Thu, 7 Nov 2013 22:38:20 +0000 (+0200) Subject: Read power state from arducontrol device on startup X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=daecd71f20c275fb6df128a3aaa4cfdda24b6886;p=r2c2.git Read power state from arducontrol device on startup --- diff --git a/source/libr2c2/arducontrol.cpp b/source/libr2c2/arducontrol.cpp index e940a2a..e5d94ef 100644 --- a/source/libr2c2/arducontrol.cpp +++ b/source/libr2c2/arducontrol.cpp @@ -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(reply[1]); diff --git a/source/libr2c2/arducontrol.h b/source/libr2c2/arducontrol.h index fb0cb68..4e9ef63 100644 --- a/source/libr2c2/arducontrol.h +++ b/source/libr2c2/arducontrol.h @@ -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 };