'use strict';

goog.provide('Blockly.Python.hci');
goog.require('Blockly.Python');

/* HID 
 * setup
 */
Blockly.Python['HID_setup'] = function(block) {
    Blockly.Python.addInclude('keyboard', '#include \"Keyboard.h\"');
    Blockly.Python.addInclude('Mouse', '#include \"Mouse.h\"');
    Blockly.Python.addSetup("HID", "Mouse.begin();\n" +
        "Keyboard.begin();\n");
    return "";
}

/* HID 
 * mouse move
 */
Blockly.Python['HID_mouse_move'] = function(block) {
    var code = "";
    var mouse_moveTowards = block.getFieldValue("mouse_towards");
    var mouse_moveDistance = block.getFieldValue("mouse_distance");
    switch (mouse_moveTowards) {
        case "KEYPAD_UP":
            code = "Mouse.move(0, -" + mouse_moveDistance + ");\n";
            break;
        case "KEYPAD_DOWN":
            code = "Mouse.move(0, " + mouse_moveDistance + ");\n";
            break;
        case "KEYPAD_LEFT":
            code = "Mouse.move(-" + mouse_moveDistance + ", 0);\n";
            break;
        case "KEYPAD_RIGHT":
            code = "Mouse.move(" + mouse_moveDistance + ", 0);\n";
            break;
    }
    return code;
}

/* HID 
 * mouse click
 */
Blockly.Python['HID_mouse_click'] = function(block) {
    var click = block.getFieldValue("CLICK");
    var code = "Mouse.click(" + click + ");\n";
    return code;
}

/* HID 
 * mouse press
 */
Blockly.Python['HID_mouse_press'] = function(block) {
    var click = block.getFieldValue("CLICK");
    var code = "Mouse.press(" + click + ");\n";
    return code;
}

/* HID 
 * mouse release
 */
Blockly.Python['HID_mouse_release'] = function(block) {
    var click = block.getFieldValue("CLICK");
    var code = "Mouse.release(" + click + ");\n";
    return code;
}


/* HID 
 * keyboard press
 */
Blockly.Python['HID_keyboard_press'] = function(block) {
    var key = block.getFieldValue("keyboard_press");
    var code = "Keyboard.press(" + key + ");\n";
    return code;
}

/* HID 
 * keyboard release
 */
Blockly.Python['HID_keyboard_release'] = function(block) {
    var key = block.getFieldValue("keyboard_press");
    var code = "Keyboard.release(" + key + ");\n";
    return code;
}

/* HID 
 * keyboard release all
 */
Blockly.Python['HID_keyboard_releaseAll'] = function(block) {
    var code = "Keyboard.releaseAll();\n";
    return code;
}