]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/locomotive.h
Major code refactoring:
[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
13 class Locomotive
14 {
15 public:
16         sigc::signal<void, unsigned> signal_speed_changed;
17
18         Locomotive(Control &, unsigned);
19         void     set_speed(unsigned);
20         void     set_reverse(bool);
21         void     set_function(unsigned, bool);
22         unsigned get_address() const   { return addr; }
23         unsigned get_speed() const     { return speed; }
24         bool     get_reverse() const   { return reverse; }
25         bool     get_function(unsigned f) const { return (funcs>>f)&1; }
26         void     refresh_status();
27 private:
28         Control  &control;
29         unsigned addr;
30         unsigned speed;
31         bool     reverse;
32         unsigned funcs;
33
34         void     send_command(bool);
35         void     status_reply(Error, const std::string &);
36         bool     reverse_timeout();
37 };
38
39 } // namespace Marklin
40
41 #endif