]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/locomotive.h
a127a173c3af4a395e0dad757467c7bdc393cbfb
[r2c2.git] / source / libmarklin / locomotive.h
1 #ifndef LIBMARKLIN_LOCOMOTIVE_H_
2 #define LIBMARKLIN_LOCOMOTIVE_H_
3
4 #include <list>
5 #include <string>
6 #include <sigc++/signal.h>
7 #include "constants.h"
8
9 namespace Marklin {
10
11 class Control;
12 class LocoType;
13
14 class Locomotive
15 {
16 private:
17         const LocoType &type;
18         Control  &control;
19         unsigned addr;
20         unsigned speed;
21         bool     reverse;
22         unsigned funcs;
23
24 public:
25         sigc::signal<void, unsigned> signal_speed_changed;
26         sigc::signal<void, unsigned, bool> signal_function_changed;
27
28         Locomotive(const LocoType &, Control &, unsigned);
29
30         const LocoType &get_type() const { return type; }
31         void     set_speed(unsigned);
32         void     set_reverse(bool);
33         void     set_function(unsigned, bool);
34         unsigned get_address() const   { return addr; }
35         unsigned get_speed() const     { return speed; }
36         bool     get_reverse() const   { return reverse; }
37         bool     get_function(unsigned f) const { return (funcs>>f)&1; }
38         void     refresh_status();
39 private:
40         void     send_command(bool);
41         void     status_reply(Error, const std::string &);
42         bool     reverse_timeout();
43 };
44
45 } // namespace Marklin
46
47 #endif