]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/locomotive.h
9ebccdae5e3bff30814ecba38324e7f607e58914
[r2c2.git] / source / libmarklin / locomotive.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009  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 public:
25         sigc::signal<void, unsigned> signal_speed_changing;
26         sigc::signal<void, unsigned> signal_speed_changed;
27         sigc::signal<void, unsigned, bool> signal_function_changed;
28
29 private:
30         const LocoType &type;
31         Control &control;
32         unsigned addr;
33         unsigned speed;
34         bool reverse;
35         unsigned funcs;
36
37 public:
38         Locomotive(const LocoType &, Control &, unsigned);
39
40         const LocoType &get_type() const { return type; }
41         unsigned get_address() const { return addr; }
42         void set_speed(unsigned);
43         void set_reverse(bool);
44         void set_function(unsigned, bool);
45         unsigned get_speed() const { return speed; }
46         bool get_reverse() const { return reverse; }
47         bool get_function(unsigned f) const { return (funcs>>f)&1; }
48         void refresh_status();
49 private:
50         void send_command(bool);
51         void status_reply(const Reply &);
52         bool reverse_timeout();
53 };
54
55 } // namespace Marklin
56
57 #endif