X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Flocomotive.cpp;h=c7d6227cddb938e5d3acfbbb6cc2c8f564ca771f;hb=38fb8d56efde037a71c46a58bda314655e68ab6c;hp=32f2ecc1a185f2fa1ac387cb4659ad61e1926f01;hpb=449fb5de95ddb2ac9da4bd72a1c12150505d5549;p=r2c2.git diff --git a/source/libmarklin/locomotive.cpp b/source/libmarklin/locomotive.cpp index 32f2ecc..c7d6227 100644 --- a/source/libmarklin/locomotive.cpp +++ b/source/libmarklin/locomotive.cpp @@ -33,10 +33,10 @@ Locomotive::Locomotive(const LocoType &t, Control &c, unsigned a): void Locomotive::set_speed(unsigned spd) { - spd=min(spd, 14U); + spd = min(spd, 14U); signal_speed_changing.emit(spd); - speed=spd; + speed = spd; send_command(false); signal_speed_changed.emit(speed); @@ -54,7 +54,7 @@ void Locomotive::set_reverse(bool rev) } else { - reverse=rev; + reverse = rev; send_command(false); } } @@ -62,9 +62,9 @@ void Locomotive::set_reverse(bool rev) void Locomotive::set_function(unsigned func, bool state) { if(state) - funcs|=1<>8)&0xFF; + data[0] = addr&0xFF; + data[1] = (addr>>8)&0xFF; control.command(CMD_LOK_STATUS, data, 2).signal_done.connect(sigc::mem_fun(this, &Locomotive::status_reply)); } void Locomotive::send_command(bool setf) { unsigned char data[4]; - data[0]=addr&0xFF; - data[1]=(addr>>8)&0xFF; + data[0] = addr&0xFF; + data[1] = (addr>>8)&0xFF; if(speed==0) - data[2]=0; + data[2] = 0; else if(speed==1) - data[2]=2; + data[2] = 2; else - data[2]=(speed*19-18)/2; + data[2] = (speed*19-18)/2; - data[3]=(reverse ? 0 : 0x20) | ((funcs&1) ? 0x10 : 0); + data[3] = (reverse ? 0 : 0x20) | ((funcs&1) ? 0x10 : 0); if(setf) { - data[3]|=0x80; + data[3] |= 0x80; for(unsigned i=0; i<4; ++i) if((funcs>>i)&2) - data[3]|=(1<>i)&1); @@ -127,7 +127,7 @@ void Locomotive::status_reply(const Reply &reply) bool Locomotive::reverse_timeout() { - reverse=!reverse; + reverse = !reverse; send_command(true); return false; }