const RSV2_COLOR = 290; // Schönes Violett zur Unterscheidung

Blockly.defineBlocksWithJsonArray([
  // --- SENSOREN ---
  {
    "type": "rsv2_read_sensor",
    "message0": "Lese %1",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "SENSOR",
        "options": [ 
          ["Temperatur (°C)", "TEMP"], 
          ["Ultraschall Abstand (cm)", "US"], 
          ["Mikrofon (0-1023)", "MIC_RAW"],
          ["Mikrofon Pegel (0-100%)", "MIC_PCT"],
          ["Joystick X-Achse", "JOY_X"],
          ["Joystick Y-Achse", "JOY_Y"]
        ]
      }
    ],
    "output": "Number",
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_pir_motion",
    "message0": "Bewegung erkannt (PIR)",
    "output": "Boolean",
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_joy_dir",
    "message0": "Joystick Richtung ist %1",
    "args0": [
      {
        "type": "field_dropdown",
        "name": "DIR",
        "options": [ ["OBEN", "OBEN"], ["UNTEN", "UNTEN"], ["LINKS", "LINKS"], ["RECHTS", "RECHTS"], ["MITTE", "MITTE"] ]
      }
    ],
    "output": "Boolean",
    "colour": RSV2_COLOR
  },
  
  // --- ENCODER ---
  {
    "type": "rsv2_encoder_pos",
    "message0": "Zählerwert Drehgeber",
    "output": "Number",
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_encoder_reset",
    "message0": "Setze Drehgeber auf 0",
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_button_event",
    "message0": "Falls Drehgeber-Taster %1",
    "args0": [
      {
        "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": RSV2_COLOR
  },

  // --- AUSGABEN ---
  {
    "type": "rsv2_battery_level",
    "message0": "Setze Batterieanzeige auf Stufe %1 (0-7)",
    "args0": [{ "type": "input_value", "name": "LVL", "check": "Number" }],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_battery_pct",
    "message0": "Setze Batterieanzeige auf %1 Prozent",
    "args0": [{ "type": "input_value", "name": "PCT", "check": "Number" }],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_rgb_led",
    "message0": "Setze RGB LED %1 auf R:%2 G:%3 B:%4",
    "args0": [
      { "type": "field_dropdown", "name": "LED_NUM", "options": [["1", "0"], ["2", "1"], ["3", "2"], ["4", "3"]] },
      { "type": "input_value", "name": "R", "check": "Number" },
      { "type": "input_value", "name": "G", "check": "Number" },
      { "type": "input_value", "name": "B", "check": "Number" }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  },
  
  // --- MATRIX ---
  {
    "type": "rsv2_matrix_text",
    "message0": "Matrix Text: %1 %2 Laufschrift: %3 Tempo: %4",
    "args0": [
      { "type": "field_input", "name": "TXT", "text": "Hallo" },
      { "type": "input_dummy" },
      { "type": "field_checkbox", "name": "SCROLL", "checked": false },
      { "type": "input_value", "name": "SPEED", "check": "Number" }
    ],
    "inputsInline": true,
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_matrix_num",
    "message0": "Zeige Zahl auf Matrix: %1",
    "args0": [{ "type": "input_value", "name": "NUM", "check": "Number" }],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_matrix_pixel",
    "message0": "Setze Matrix Pixel X:%1 Y:%2 auf %3",
    "args0": [
      { "type": "input_value", "name": "X", "check": "Number" },
      { "type": "input_value", "name": "Y", "check": "Number" },
      { "type": "field_dropdown", "name": "STATE", "options": [["AN", "true"], ["AUS", "false"]] }
    ],
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  },
  {
    "type": "rsv2_matrix_clear",
    "message0": "Matrix löschen",
    "previousStatement": null,
    "nextStatement": null,
    "colour": RSV2_COLOR
  }
]);