]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/locomotive.h
Rewrite command/reply system
[r2c2.git] / source / libmarklin / locomotive.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_LOCOMOTIVE_H_
9 #define LIBMARKLIN_LOCOMOTIVE_H_
10
11 #include <list>
12 #include <string>
13 #include <sigc++/signal.h>
14 #include "constants.h"
15
16 namespace Marklin {
17
18 class Control;
19 class LocoType;
20 class Reply;
21
22 class Locomotive
23 {
24 private:
25         const LocoType &type;
26         Control  &control;
27         unsigned addr;
28         unsigned speed;
29         bool     reverse;
30         unsigned funcs;
31
32 public:
33         sigc::signal<void, unsigned> signal_speed_changed;
34         sigc::signal<void, unsigned, bool> signal_function_changed;
35
36         Locomotive(const LocoType &, Control &, unsigned);
37
38         const LocoType &get_type() const { return type; }
39         void     set_speed(unsigned);
40         void     set_reverse(bool);
41         void     set_function(unsigned, bool);
42         unsigned get_address() const   { return addr; }
43         unsigned get_speed() const     { return speed; }
44         bool     get_reverse() const   { return reverse; }
45         bool     get_function(unsigned f) const { return (funcs>>f)&1; }
46         void     refresh_status();
47 private:
48         void     send_command(bool);
49         void     status_reply(const Reply &);
50         bool     reverse_timeout();
51 };
52
53 } // namespace Marklin
54
55 #endif