X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Flocomotive.cpp;h=87effa04e8e35175152bc5de2e88950532a5d55c;hb=3e9c210ddc036cd015228504cc0803c909e27f84;hp=ecacea19a833af43f918823523951740d9a0e69c;hpb=6c61179fe09af2f5366d50f10aadbf5f83438087;p=r2c2.git diff --git a/source/libmarklin/locomotive.cpp b/source/libmarklin/locomotive.cpp index ecacea1..87effa0 100644 --- a/source/libmarklin/locomotive.cpp +++ b/source/libmarklin/locomotive.cpp @@ -1,3 +1,10 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #include #include #include "command.h" @@ -10,14 +17,15 @@ using namespace Msp; namespace Marklin { -Locomotive::Locomotive(Control &c, unsigned a): +Locomotive::Locomotive(const LocoType &t, Control &c, unsigned a): + type(t), control(c), addr(a), speed(0), reverse(false), funcs(0) { - control.add_locomotive(this); + control.add_locomotive(*this); refresh_status(); } @@ -27,6 +35,8 @@ void Locomotive::set_speed(unsigned spd) speed=min(spd, 14U); send_command(false); + + signal_speed_changed.emit(speed); } void Locomotive::set_reverse(bool rev) @@ -36,7 +46,7 @@ void Locomotive::set_reverse(bool rev) if(speed) { - (new Time::Timer((500+speed*150)*Time::msec))->signal_timeout.connect(sigc::mem_fun(this, &Locomotive::reverse_timeout)); + control.set_timer((500+speed*150)*Time::msec).signal_timeout.connect(sigc::mem_fun(this, &Locomotive::reverse_timeout)); set_speed(0); } else @@ -54,6 +64,8 @@ void Locomotive::set_function(unsigned func, bool state) funcs&=~(1<>8)&0xFF; - control.command(string(cmd,3)).signal_done.connect(sigc::mem_fun(this,&Locomotive::status_reply)); + control.command(string(cmd, 3)).signal_done.connect(sigc::mem_fun(this, &Locomotive::status_reply)); } void Locomotive::send_command(bool setf) @@ -88,21 +100,24 @@ void Locomotive::send_command(bool setf) if((funcs>>i)&2) cmd[4]|=(1<(reply[0])<=1) speed=0; else - speed=(unsigned char)reply[0]*2/19+1; + speed=static_cast(reply[0])*2/19+1; reverse=(reply[1]&0x20)?false:true; funcs=(reply[1]&0xF)<<1; if(reply[1]&0x10) funcs|=1; + + for(unsigned i=0; i<5; ++i) + signal_function_changed.emit(i, (funcs>>i)&1); } }