You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MM2 is an implementation of the Motorola 1 and 2 (MM1/2) protocol. Details on the format can be found on Dr. König's Märklin-Digital-Page or in the docs folder in case this site goes offline. This library supports MM1 and 2 as well as some additions like CV programming and follow-up addresses for supporting more than 5 functions.
Examples
Currently there is only one class for receiving MM2.
mm2::rx::CrtpBase
As the names suggest this class relies on CRTP to implement static polymorphism. The template argument of the base classes is checked with a concept called Decoder.
Here is an example for how a class which implements it might look. The friend declarations are only necessary if the methods the base(s) need to call are not public.
#include<mm2/mm2.hpp>structMm2 : mm2::rx::CrtpBase<Mm2> {
friend mm2::rx::CrtpBase<Mm2>;
private:// Set direction (1 forward, 0 backward)voiddirection(uint32_t addr, bool dir) {}
// Set speed [0, 255] (regardless of CV settings)voidspeed(uint32_t addr, int32_t speed) {}
// Reverse directionvoidreverse(uint32_t addr) {}
// Set function inputsvoidfunction(uint32_t addr, uint32_t mask, uint32_t state) {}
// Read CVuint8_treadCv(uint32_t cv_addr) {}
// Write CVuint8_twriteCv(uint32_t cv_addr, uint8_t byte) {}
// Timer interrupt calls receive with captured valuevoidinterrupt() {
uint32_tconst timer_value{/* captured timer value */};
receive(timer_value);
}
};
About
MM1/2 protocol for controlling digital model railways