]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/controller.h
Make LCD output selectable at runtime through an extra I/O pin
[r2c2.git] / source / libmarklin / controller.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_CONTROLLER_H_
9 #define LIBMARKLIN_CONTROLLER_H_
10
11 #include <string>
12 #include <sigc++/signal.h>
13 #include <msp/time/timedelta.h>
14
15 namespace Marklin {
16
17 /**
18 Interface class for train controllers.  Takes input through a uniform named
19 control interface.  Provides information about train movement on output.
20 */
21 class Controller
22 {
23 public:
24         struct Control
25         {
26                 enum Type
27                 {
28                         BINARY,
29                         DISCRETE,
30                         CONTINUOUS
31                 };
32
33                 std::string name;
34                 Type type;
35                 float min_value;
36                 float max_value;
37                 float step;
38                 float value;
39
40         private:
41                 Control() { }
42
43         public:
44                 void set(float);
45
46                 static Control binary(const std::string &);
47                 static Control discrete(const std::string &, float, float, float);
48                 static Control continuous(const std::string &, float, float);
49         };
50
51         sigc::signal<void, const Control &> signal_control_changed;
52
53 protected:
54         Controller() { }
55 public:
56         virtual ~Controller() { }
57
58         virtual void set_control(const std::string &, float) = 0;
59         virtual const Control &get_control(const std::string &) const = 0;
60
61         /** Returns the current speed.  Always non-negative. */
62         virtual float get_speed() const = 0;
63
64         /** Returns true if traveling in reverse. */
65         virtual bool get_reverse() const = 0;
66
67         /** Determines the distance required to come to a full stop. */
68         virtual float get_braking_distance() const = 0;
69
70         virtual void tick(const Msp::Time::TimeDelta &) = 0;
71 };
72
73 } // namespace Marklin
74
75 #endif