+static uint8_t get_speed(uint8_t command)
+{
+ uint8_t b1, b2, b3, b4, b5, b6, b7, b8;
+ b1 = ((command & 0x80) != 0);
+ b2 = ((command & 0x40) != 0);
+ b3 = ((command & 0x20) != 0);
+ b4 = ((command & 0x10) != 0);
+ b5 = ((command & 0x8) != 0);
+ b6 = ((command & 0x4) != 0);
+ b7 = ((command & 0x2) != 0);
+ b8 = ((command & 0x1) != 0);
+
+ //if ((b1 != b2) || (b2 != b3) || (b3 != b4) || (b5 != b6) || (b7 != b8))
+ // return 0xff;
+
+ return (b1 + b3*2 + b5*4 +b7*8);
+}
+
+void mm_switch_drive(uint8_t decoder, uint8_t function, uint8_t command)
+{
+ static uint8_t seen_before = 0;
+ uint8_t speed;
+
+
+ if (!seen_before) {
+ // if (decoder == 100)
+ //
+
+ if ((decoder == 100) && (function == 0) && (command == 0xc0)) {
+ config.magic = 0;
+ save_config();
+ }
+ }
+ seen_before = 1;
+ speed = get_speed(command);
+ static uint8_t itsme = 0;
+ if (decoder == 10) {
+ trigger();
+
+ if (speed == 1) {
+ itsme = 1;
+ drive_on = 1;
+ }else {
+ if (itsme) {
+ drive_on = 0;
+ itsme = 0;
+ }
+ }
+ }
+ if (decoder == 33) {
+ // trigger();
+
+ speed = get_speed(command);
+ if (speed != 0xff) {
+ if (speed >= 1) speed -= 1;
+ if (speed <= 14)
+ config.on_duty_cycle = speed;
+ else
+ config.on_duty_cycle = 14;
+ }
+ }
+}
+