// blocks_multifunction.js

const MFS_COLOR = 210; // Blau für das Multi-Function Shield

Blockly.defineBlocksWithJsonArray([
  // --- TASTER ---
  {
    "type": "mfs_button_event",
    "message0": "Falls %1 %2",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "BUTTON",
        "options": [ ["Taste 1 (A1)", "btn1"], ["Taste 2 (A2)", "btn2"], ["Taste 3 (A3)", "btn3"] ]
      },
      {
        "type": "field_dropdown",
        "name": "EVENT",
        "options": [
          ["wurde gedrückt", "KK_SINGLE_CLICK"],
          ["wurde doppelt geklickt", "KK_DOUBLE_CLICK"],
          ["wird lange gehalten", "KK_LONG_PRESS"]
        ]
      }
    ],
    "output": "Boolean",
    "colour": MFS_COLOR,
    "tooltip": "Prüft, ob eine Taste gedrückt, doppelt geklickt oder lange gehalten wurde."
  },
  {
    "type": "mfs_button_counter",
    "message0": "Klicks von %1",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "BUTTON",
        "options": [ ["Taste 1", "btn1"], ["Taste 2", "btn2"], ["Taste 3", "btn3"] ]
      }
    ],
    "output": "Number",
    "colour": MFS_COLOR,
    "tooltip": "Gibt zurück, wie oft die Taste gedrückt wurde."
  },
  {
    "type": "mfs_button_reset",
    "message0": "Setze Klicks von %1 auf 0",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "BUTTON",
        "options": [ ["Taste 1", "btn1"], ["Taste 2", "btn2"], ["Taste 3", "btn3"] ]
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },

  // --- LEDs ---
  {
    "type": "mfs_led_digital",
    "message0": "Schalte LED %1 %2",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "LED",
        "options": [ ["D1", "1"], ["D2", "2"], ["D3", "3"], ["D4", "4"] ]
      },
      {
        "type": "field_dropdown",
        "name": "STATE",
        "options": [ ["EIN", "true"], ["AUS", "false"] ]
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },
  {
    "type": "mfs_led_pwm",
    "message0": "Setze Helligkeit von LED %1 auf Wert (0-255) %2",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "LED",
        "options": [ ["D3 (PWM)", "3"], ["D4 (PWM)", "4"] ]
      },
      {
        "type": "input_value",
        "name": "VALUE",
        "check": "Number"
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },

  // --- SUMMER ---
  {
    "type": "mfs_buzzer_digital",
    "message0": "Schalte Summer %1",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "STATE",
        "options": [ ["EIN", "true"], ["AUS", "false"] ]
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },
  {
    "type": "mfs_buzzer_tone",
    "message0": "Spiele Ton mit Frequenz %1 Hz für %2 ms",
    "args0": [
      { "type": "input_value", "name": "FREQ", "check": "Number" },
      { "type": "input_value", "name": "DURATION", "check": "Number" }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },

  // --- DISPLAY ---
  {
    "type": "mfs_display_number",
    "message0": "Zeige Zahl %1",
    "args0": [
      { "type": "input_value", "name": "VALUE", "check": "Number" }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },
  {
    "type": "mfs_display_word",
    "message0": "Zeige Wort: %1 %2 %3 %4",
    "args0": [
      {"type": "field_dropdown", "name": "C1", "options": [["H", "'H'"], ["A", "'A'"], ["b", "'b'"], ["C", "'C'"], ["d", "'d'"], ["E", "'E'"], ["F", "'F'"], ["I", "'I'"], ["L", "'L'"], ["O", "'O'"], ["P", "'P'"], ["S", "'S'"], ["U", "'U'"], ["-", "'-'"], ["Leer", "' '"]]},
      {"type": "field_dropdown", "name": "C2", "options": [["A", "'A'"], ["b", "'b'"], ["C", "'C'"], ["d", "'d'"], ["E", "'E'"], ["F", "'F'"], ["H", "'H'"], ["I", "'I'"], ["L", "'L'"], ["O", "'O'"], ["P", "'P'"], ["S", "'S'"], ["U", "'U'"], ["-", "'-'"], ["Leer", "' '"]]},
      {"type": "field_dropdown", "name": "C3", "options": [["L", "'L'"], ["A", "'A'"], ["b", "'b'"], ["C", "'C'"], ["d", "'d'"], ["E", "'E'"], ["F", "'F'"], ["H", "'H'"], ["I", "'I'"], ["O", "'O'"], ["P", "'P'"], ["S", "'S'"], ["U", "'U'"], ["-", "'-'"], ["Leer", "' '"]]},
      {"type": "field_dropdown", "name": "C4", "options": [["O", "'O'"], ["A", "'A'"], ["b", "'b'"], ["C", "'C'"], ["d", "'d'"], ["E", "'E'"], ["F", "'F'"], ["H", "'H'"], ["I", "'I'"], ["L", "'L'"], ["P", "'P'"], ["S", "'S'"], ["U", "'U'"], ["-", "'-'"], ["Leer", "' '"]]}
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },
  {
    "type": "mfs_display_clear",
    "message0": "Display löschen",
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },

  // --- POTI & MATHE ---
  {
    "type": "mfs_read_poti",
    "message0": "Lese Drehregler (A0)",
    "output": "Number",
    "colour": MFS_COLOR
  },
  {
    "type": "mfs_map_simple",
    "message0": "Ordne Wert %1 von (0 - 1023) auf (0 - 255) zu",
    "args0": [
      { "type": "input_value", "name": "VALUE", "check": "Number" }
    ],
    "output": "Number",
    "colour": MFS_COLOR
  },

  // --- ERWEITERUNGEN (Pin 5, 9, A5) ---
  {
    "type": "mfs_ext_digital",
    "message0": "Schreibe digitalen Wert %1 an Pin %2",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "STATE",
        "options": [ ["HIGH (EIN)", "HIGH"], ["LOW (AUS)", "LOW"] ]
      },
      {
        "type": "field_dropdown",
        "name": "PIN",
        "options": [ ["Pin 5", "5"], ["Pin 9", "9"], ["Pin A5", "A5"] ]
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  },
  {
    "type": "mfs_ext_servo",
    "message0": "Setze Servo an %1 auf Winkel (0-180°) %2",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "PIN",
        "options": [ ["Pin 9", "9"], ["Pin 5", "5"] ]
      },
      {
        "type": "input_value",
        "name": "ANGLE",
        "check": "Number"
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": MFS_COLOR
  }
]);