]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/intellibox.h
Make LCD output selectable at runtime through an extra I/O pin
[r2c2.git] / source / libmarklin / intellibox.h
index c5c7e7af031e4761bd9fbc2fd1dbaef8853167e4..6d061a6076bb6a07b04cc843c257a1df95680ada 100644 (file)
@@ -14,6 +14,16 @@ Distributed under the GPL
 
 namespace Marklin {
 
+/**
+Driver for Uhlenbrock Intellibox.  Uses the P50X binary protocol over RS232.
+
+Motorola decoders with 27 speed steps are supported by manually generating the
+commands necessary to reach the "half-steps".  However, sending a rapid stream
+of speed changes to the same locomotive seems to cause excessive lag, so we
+cheat a bit; instead of sending the half-step command immediately, we send it
+with a 500ms delay, but only if no new set_loco_speed calls have occurred.  As
+a downside from this accelerations and decelerations are still jerky.
+*/
 class Intellibox: public Driver
 {
 private:
@@ -61,11 +71,20 @@ private:
                ERR_LOK_POWER_OFF,
        };
 
+       enum Protocol
+       {
+               MM,
+               MM_27
+       };
+
        struct Locomotive
        {
+               Protocol protocol;
                unsigned speed;
                bool reverse;
                unsigned funcs;
+               int pending_half_step;
+               Msp::Time::TimeStamp half_step_delay;
 
                Locomotive();
        };
@@ -115,7 +134,9 @@ public:
        virtual void halt(bool);
        virtual bool is_halted() const { return halted; }
 
-       virtual void add_loco(unsigned);
+       virtual const char *enumerate_protocols(unsigned) const;
+       virtual unsigned get_protocol_speed_steps(const std::string &) const;
+       virtual void add_loco(unsigned, const std::string &);
        virtual void set_loco_speed(unsigned, unsigned);
        virtual void set_loco_reverse(unsigned, bool);
        virtual void set_loco_function(unsigned, unsigned, bool);
@@ -132,6 +153,7 @@ public:
        virtual void flush();
 
 private:
+       Protocol map_protocol(const std::string &) const;
        void command(Command);
        void command(Command, const unsigned char *, unsigned);
        void command(Command, unsigned, const unsigned char *, unsigned);