+ /*
+ * Protocol differences:
+ * =====================
+ *
+ * I have an old "central control" 6022 and a "control unit" 6021
+ * for measurements and test. It is assumed that the 6022 outputs
+ * old MM1 format while the 6021 definitively outputs MM2 telegrams.
+ *
+ * In MM1, switch commands are different from MM2 with respect what
+ * happens if you release a button.
+ *
+ * When you press a button, both protocols send
+ *
+ * <aaaaaaaa><00><aabbcc11>
+ *
+ * where a = 1, b = 2, c = 4 and the keys are numerated from 0 to 7
+ * in the order 1 red, 1 green, 2 red, 2 green and so on.
+ *
+ * The last two bits correspond to "on" state of the button/coil.
+ *
+ * When a key is released under MM1 protocol, the sequence sent is
+ * analogue to the button down sequence:
+ *
+ * <aaaaaaaa><00><aabbcc00> where abc again represents the button's
+ * address and the last bits now signal "off".
+ *
+ * MM2 handles this differently:
+ * Whenever any key from the addressed decoder is released, the sequence
+ * <aaaaaaaa>00<00000000> is sent - not only for key 0, but for all
+ * keys!
+ *
+ * While MM1 presents the theoretical possibility to press several keys
+ * independently and simultaneously (which my keyboard does NOT
+ * support), MM2 supports only one key at a time (besides strange
+ * sequences like "one down, another down, all up"...
+ *
+ * A decoder that strictly adheres to the MM1 standard would not work
+ * properly with MM2 control units. As far as I know all K83/K84
+ * decoders always worked with MM2 control units. That means that
+ * they reduce the commands to the possibilities of MM2 from the
+ * beginning.
+ *
+ * Possible use cases for the old protocol button release commands:
+ * - Determine if the protocol is MM1 or MM2
+ * - Implement hidden evil features into the controller which can
+ * only be summoned by old MM1 gear or selfmade control telegram
+ * generators.
+ *
+ * What this code now actually does:
+ * =================================
+ *
+ * When key pressed (aabbcc11), it will send out the key number in the
+ * range 1-8 and 0 if it gets any key up command and therefore ignore
+ * the key number if it is transmitted with the key up command.
+ *
+ */
+ if (!(mm_command & 0x01))
+ res = 0;
+ else
+ res = (mm_command & 0x80) * 1 + (mm_command & 0x20) * 0x02
+ + (mm_command & 0x08) * 0x04 + 1;
+ return res;