]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/locomotive.h
b8d58c29b34a35174780ab661ef5b123e6bc15fc
[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
21 class Locomotive
22 {
23 private:
24         const LocoType &type;
25         Control  &control;
26         unsigned addr;
27         unsigned speed;
28         bool     reverse;
29         unsigned funcs;
30
31 public:
32         sigc::signal<void, unsigned> signal_speed_changed;
33         sigc::signal<void, unsigned, bool> signal_function_changed;
34
35         Locomotive(const LocoType &, Control &, unsigned);
36
37         const LocoType &get_type() const { return type; }
38         void     set_speed(unsigned);
39         void     set_reverse(bool);
40         void     set_function(unsigned, bool);
41         unsigned get_address() const   { return addr; }
42         unsigned get_speed() const     { return speed; }
43         bool     get_reverse() const   { return reverse; }
44         bool     get_function(unsigned f) const { return (funcs>>f)&1; }
45         void     refresh_status();
46 private:
47         void     send_command(bool);
48         void     status_reply(Error, const std::string &);
49         bool     reverse_timeout();
50 };
51
52 } // namespace Marklin
53
54 #endif