// blocks_richshield1.js

const RSV1_COLOR = 20;

Blockly.defineBlocksWithJsonArray([
  // --- TASTER ---
  {
    "type": "rsv1_button_event",
    "message0": "Falls Taster %1 %2",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "BUTTON",
        "options": [ ["K1 (D9)", "btnK1"], ["K2 (D8)", "btnK2"] ]
      },
      {
        "type": "field_dropdown",
        "name": "EVENT",
        "options": [
          ["wurde gedrückt", "KK_SINGLE_CLICK"],
          ["wurde doppelt gedrückt", "KK_DOUBLE_CLICK"],
          ["wurde lange gedrückt", "KK_LONG_PRESS"]
        ]
      }
    ],
    "output": "Boolean",
    "colour": RSV1_COLOR,
    "tooltip": "Prüft das Klick-Ereignis von Taster K1 oder K2."
  },
  {
    "type": "rsv1_button_counter",
    "message0": "Zählerwert von Taster %1",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "BUTTON",
        "options": [ ["K1", "btnK1"], ["K2", "btnK2"] ]
      }
    ],
    "output": "Number",
    "colour": RSV1_COLOR,
    "tooltip": "Gibt zurück, wie oft der Taster gedrückt wurde."
  },
  {
    "type": "rsv1_button_reset",
    "message0": "Setze Zähler von Taster %1 zurück",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "BUTTON",
        "options": [ ["K1", "btnK1"], ["K2", "btnK2"] ]
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV1_COLOR
  },

  // --- LEDs ---
  {
    "type": "rsv1_led_digital",
    "message0": "Schalte %1 auf %2",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "LED",
        "options": [ ["LED1 (Gelb)", "1"], ["LED2 (Blau)", "2"], ["LED3 (Grün)", "3"], ["LED4 (Rot)", "4"] ]
      },
      {
        "type": "field_dropdown",
        "name": "STATE",
        "options": [ ["AN", "true"], ["AUS", "false"] ]
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV1_COLOR
  },
  {
    "type": "rsv1_led_pwm",
    "message0": "Setze Helligkeit von %1 auf %2 %",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "LED",
        "options": [ ["LED2 (Blau)", "2"], ["LED3 (Grün)", "3"] ]
      },
      {
        "type": "input_value",
        "name": "VALUE",
        "check": "Number"
      }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV1_COLOR,
    "tooltip": "Regelt die Helligkeit über PWM (0-100%)."
  },

  // --- SUMMER ---
  {
    "type": "rsv1_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": RSV1_COLOR
  },

  // --- SENSOREN & ANALOGE HELFER ---
  {
    "type": "rsv1_read_analog",
    "message0": "Lese %1",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "SENSOR",
        "options": [ ["Potentiometer (0-1023)", "POTI"], ["Lichtsensor LDR (0-100%)", "LDR"], ["Temperatursensor NTC (°C)", "NTC"] ]
      }
    ],
    "output": "Number",
    "colour": RSV1_COLOR
  },
  {
    "type": "rsv1_read_dht",
    "message0": "Lese %1 von DHT11",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "TYPE",
        "options": [ ["Temperatur (°C)", "TEMP"], ["Luftfeuchtigkeit (%)", "HUM"] ]
      }
    ],
    "output": "Number",
    "colour": RSV1_COLOR
  },
  {
    "type": "rsv1_read_voltage",
    "message0": "Gemessene Spannung an Klemmen (Volt)",
    "output": "Number",
    "colour": RSV1_COLOR
  },

  // --- DISPLAY ---
  {
    "type": "rsv1_display_number",
    "message0": "Zeige Zahl auf Display: %1",
    "args0": [
      { "type": "input_value", "name": "VALUE", "check": "Number" }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV1_COLOR
  },
  {
    "type": "rsv1_display_word",
    "message0": "Zeige Text auf Display: %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": RSV1_COLOR
  },
  {
    "type": "rsv1_display_clear",
    "message0": "Display löschen",
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV1_COLOR
  },

  // --- INFRAROT ---
  {
    "type": "rsv1_ir_print",
    "message0": "Sende empfangene IR-Signale an seriellen Monitor",
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV1_COLOR,
    "tooltip": "Gibt den Code (z.B. 0xFF30CF) aus, wenn eine Taste auf der Fernbedienung gedrückt wird."
  },
  {
    "type": "rsv1_ir_check",
    "message0": "Falls IR-Signal gleich %1",
    "args0": [
      {
        "type": "field_input",
        "name": "HEXCODE",
        "text": "0xFF30CF"
      }
    ],
    "output": "Boolean",
    "colour": RSV1_COLOR,
    "tooltip": "Prüft, ob der eingegebene Code von der Fernbedienung gesendet wurde."
  }
]);