diff --git a/src/playground/blocks/hardware/block_roborobo.js b/src/playground/blocks/hardware/block_roborobo.js deleted file mode 100644 index c86c6a69c7..0000000000 --- a/src/playground/blocks/hardware/block_roborobo.js +++ /dev/null @@ -1,4654 +0,0 @@ -'use strict'; - -Entry.Roborobo_Roduino = { - id: '10.1', - name: 'roborobo_roduino', - url: 'http://www.roborobo.co.kr', - imageName: 'roborobo_roduino.png', - title: { - ko: '로두이노', - en: 'Roduino', - }, - INSTRUCTION: { - INPUT: 0, - OUTPUT: 1, - ANALOG: 2, - PWM: 3, - SERVO: 4, - SONAR: 11, - }, - setZero: function() { - Entry.hw.sendQueue.colorPin = 0; - Entry.hw.sendQueue.digitalPinMode = []; - Entry.hw.sendQueue.preDigitalPinMode = []; - Entry.hw.sendQueue.stopSend = false; - - for (var port = 0; port < 14; port++) { - Entry.hw.sendQueue[port] = 0; - Entry.hw.sendQueue.preDigitalPinMode[port] = -2; - Entry.hw.sendQueue.digitalPinMode[port] = -1; - } - this.ColorPin = [0, 0, 0]; - Entry.hw.update(); - }, - ColorPin: [0, 0, 0], - - monitorTemplate: { - imgPath: 'hw/roborobo_roduino.png', - keys: ['value'], - width: 256, - height: 256, - listPorts: { - a0: { - name: 'A0', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - a1: { - name: 'A1', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - a2: { - name: 'A2', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - a3: { - name: 'A3', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - a4: { - name: 'A4', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - a5: { - name: 'A5', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 2: { - name: 'D2', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 3: { - name: 'D3', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 4: { - name: 'D4', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 5: { - name: 'D5', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 6: { - name: 'D6', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 7: { - name: 'D7', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 8: { - name: 'D8', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 9: { - name: 'D9', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - 10: { - name: 'D10', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - }, - mode: 'both', - }, -}; - -Entry.Roborobo_Roduino.setLanguage = function() { - return { - ko: { - template: { - roduino_get_analog_number: '%1 ', - roduino_get_port_number: '%1 ', - roduino_get_analog_value: '아날로그 %1 번 센서값 ', - roduino_get_digital_value: '디지털 %1 번 센서값 ', - roduino_set_digital: '디지털 %1 번 핀 %2 %3', - roduino_motor: '%1 %2 %3', - roduino_set_color_pin: '컬러센서 R : %1, G : %2, B : %3 %4', - roduino_get_color: '컬러센서 %1 감지', - roduino_on_block: ' On ', - roduino_off_block: ' Off ', - roduino_set_servo_value: '서보모터 %1 번 핀 %2˚ %3', - roduino_set_pwm_value: 'PWM %1 번 핀 %2으로 전류조절 %3', - roduino_get_sensor_analog_value: '아날로그 %1 %2 번 핀 값', - roduino_get_sensor_digital_value: '디지털 %1 %2 번 핀 값', - }, - Blocks: { - roborobo_get_temperutre: '온도센서', - roborobo_get_joystick_x: '조이스틱X', - roborobo_get_joystick_y: '조이스틱Y', - roborobo_get_light: '빛센서', - roborobo_get_dial: '다이얼', - roborobo_get_keypad_a: 'A키패트(키번호)', - roborobo_get_ultrasonic: '초음파센서[cm]', - roborobo_num_analog_value_1: '아날로그', - roborobo_num_analog_value_2: '번 센서값', - roborobo_get_digital_value_1: '디지털', - roborobo_num_pin_1: '디지털', - roborobo_num_pin_2: '번 핀', - roborobo_on: '켜기', - roborobo_off: '끄기', - roborobo_motor1: '모터1', - roborobo_motor2: '모터2', - roborobo_motor_CW: '정회전', - roborobo_motor_CCW: '역회전', - roborobo_motor_stop: '정지', - roborobo_input_mode: '입력', - roborobo_output_mode: '출력', - roborobo_pwm_mode: '전류조절(pwm)', - roborobo_servo_mode: '서보모터', - roborobo_color: '컬러센서', - roborobo_color_red: ' 빨간색 ', - roborobo_color_green: ' 녹색 ', - roborobo_color_blue: ' 파란색 ', - roborobo_color_yellow: ' 노란색 ', - roborobo_color_detected: ' 감지 ', - roborobo_degree: ' ˚', - }, - }, - en: { - template: { - roduino_get_analog_number: '%1 ', - roduino_get_port_number: '%1 ', - roduino_get_analog_value: 'Analog %1 Sensor value ', - roduino_get_digital_value: 'Digital %1 Sensor value ', - roduino_set_digital: 'Digital %1 Pin %2 %3', - roduino_motor: '%1 %2 %3', - roduino_set_color_pin: 'Color Sensor R : %1, G : %2, B : %3 %4', - roduino_get_color: 'Color Sensor %1 Detected ', - roduino_on_block: ' On ', - roduino_off_block: ' Off ', - roduino_set_servo_value: 'Servo %1 Pin %2˚ %3', - roduino_set_pwm_value: 'PWM Set pin %1 to %2', - roduino_get_sensor_analog_value: 'analog %1 Pin %2 value', - roduino_get_sensor_digital_value: 'digital %1 %2 번 핀 값', - }, - Blocks: { - roborobo_num_analog_value_1: 'Analog', - roborobo_num_analog_value_2: 'Sensor Value', - roborobo_get_digital_value_1: 'Digital', - roborobo_num_pin_1: 'Digital', - roborobo_num_pin_2: 'Pin', - roborobo_on: 'On', - roborobo_off: 'Off', - roborobo_motor1: 'motor1', - roborobo_motor2: 'motor2', - roborobo_motor_CW: 'ClockWise', - roborobo_motor_CCW: 'CounterClockWise', - roborobo_motor_stop: 'Stop', - roborobo_input_mode: 'Input', - roborobo_output_mode: 'Output', - roborobo_pwm_mode: 'PWM', - roborobo_servo_mode: 'Servo', - roborobo_color: 'Color Sensor ', - roborobo_color_red: ' Red ', - roborobo_color_green: ' Green ', - roborobo_color_blue: ' Blue ', - roborobo_color_yellow: ' Yellow ', - roborobo_color_detected: ' Detected ', - roborobo_degree: ' ˚', - roborobo_get_temperutre: 'Temperature Sensor', - roborobo_get_joystick_x: 'JoystickX', - roborobo_get_joystick_y: 'JoystickY', - roborobo_get_light: 'Light Sensor', - roborobo_get_dial: 'Dial', - roborobo_get_keypad_a: 'A Keypad(key number)', - roborobo_get_ultrasonic: 'Ultrasonic Sensor[cm]', - }, - }, - }; -}; - -Entry.Roborobo_SchoolKit = { - hasPracticalCourse: true, - id: '10.2', - name: 'roborobo_schoolkit', - url: 'http://www.roborobo.co.kr', - imageName: 'roborobo_schoolkit.png', - title: { - ko: '스쿨키트', - en: 'School Kit', - }, - pinMode: { - INPUT: 0, - OUTPUT: 1, - ANALOG: 2, - PWM: 3, - SERVO: 4, - }, - inputPort: { - ir: 7, - sound: 8, - contact: 9, - cds: 10, - }, - setZero: function() { - Entry.hw.sendQueue.digitalPinMode = []; - Entry.hw.sendQueue.previousValue = []; - - for (var port = 0; port < 14; port++) { - Entry.hw.sendQueue[port] = 0; - Entry.hw.sendQueue.digitalPinMode[port] = 0; - Entry.hw.sendQueue.previousValue[port] = -1; - } - Entry.hw.update(); - }, - monitorTemplate: { - imgPath: 'hw/roborobo_schoolkit.png', - keys: ['value'], - width: 256, - height: 256, - listPorts: { - '0': { - name: 'D1', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - '1': { - name: 'D2', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - '2': { - name: 'D3', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - '3': { - name: 'D4', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - '4': { - name: 'D5', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - '5': { - name: 'D6', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - '6': { - name: 'D7', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - }, - mode: 'both', - }, -}; - -Entry.Roborobo_RoE = { - id: '48.1', - name: 'roborobo_roe', - url: 'http://www.roborobo.co.kr', - imageName: 'roborobo_roe.png', - title: { - ko: '로이', - en: 'Ro-E', - }, - setZero: function() { - Entry.hw.sendQueue['LED'] = 0; - Entry.hw.sendQueue['Melody'] = [0, 0, 0]; //[octave, note, duration] - Entry.hw.sendQueue['LeftMotor'] = [0, 0]; //[direction, value] - Entry.hw.sendQueue['RightMotor'] = [0, 0]; //[direction, value] - Entry.hw.update(); - }, - motorDiretion: { - STOP: 0, - CW: 1, - CCW: 2 - }, - monitorTemplate: { - imgPath: 'hw/roborobo_roe.png', - keys: ['value'], - width: 256, - height: 256, - listPorts: { - lColor: { - name: 'Color Sensor(Left)', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - rColor: { - name: 'Color Sensor(Right)', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - ir: { - name: 'IR Sensor', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - switch: { - name: 'Switch Sensor', - type: 'input', - pos: { - x: 0, - y: 0, - }, - }, - }, - mode: 'both', - }, -}; - -Entry.Roborobo_Roduino.blockMenuBlocks = [ - 'roduino_on_block', - 'roduino_off_block', - 'roduino_get_sensor_analog_value', - 'roduino_get_sensor_digital_value', - 'roduino_get_analog_value', - 'roduino_get_digital_value', - 'roduino_get_color', - 'roduino_set_digital', - 'roduino_motor', - 'roduino_set_color_pin', - 'roduino_set_servo_value', - 'roduino_set_pwm_value', -]; - -Entry.Roborobo_Roduino.getBlocks = function() { - return { - //region roduino 로두이노 - roduino_on_block: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'roduino_on_block', - }, - paramsKeyMap: {}, - class: 'roduino_value', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - return '1'; - }, - syntax: { - js: [], - py: ['Roborobo_roduino.roduino_on_block()'], - }, - }, - roduino_off_block: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'roduino_off_block', - }, - paramsKeyMap: {}, - class: 'roduino_value', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - return '0'; - }, - syntax: { - js: [], - py: ['Roborobo_roduino.roduino_off_block()'], - }, - }, - roduino_get_analog_number: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - ['0', '0'], - ['1', '1'], - ['2', '2'], - ['3', '3'], - ['4', '4'], - ['5', '5'], - ], - value: '0', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - PORT: 0, - }, - func: function(sprite, script) { - return script.getStringField('PORT'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['0', '0'], - ['1', '1'], - ['2', '2'], - ['3', '3'], - ['4', '4'], - ['5', '5'], - ], - value: '0', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - keyOption: 'roduino_get_analog_number', - }, - ], - }, - }, - roduino_get_port_number: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - ['2', '2'], - ['3', '3'], - ['4', '4'], - ['5', '5'], - ['6', '6'], - ['7', '7'], - ['8', '8'], - ], - value: '2', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - PORT: 0, - }, - func: function(sprite, script) { - return script.getStringField('PORT'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['2', '2'], - ['3', '3'], - ['4', '4'], - ['5', '5'], - ['6', '6'], - ['7', '7'], - ['8', '8'], - ], - value: '2', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - keyOption: 'roduino_get_port_number', - }, - ], - }, - }, - roduino_get_analog_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [ - { - type: 'roduino_get_analog_number', - }, - ], - type: 'roduino_get_analog_value', - }, - paramsKeyMap: { - VALUE: 0, - }, - class: 'roduino_value', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var signal = script.getValue('VALUE', script); - return Entry.hw.getAnalogPortValue(signal); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.read_analog(%1)', - blockType: 'param', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - roduino_get_digital_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [ - { - type: 'roduino_get_port_number', - }, - ], - type: 'roduino_get_digital_value', - }, - paramsKeyMap: { - VALUE: 0, - }, - class: 'roduino_value', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var signal = script.getNumberValue('VALUE', script); - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = [ - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ]; - } - Entry.hw.sendQueue.digitalPinMode[signal] = - Entry.Roborobo_Roduino.INSTRUCTION.INPUT; - Entry.hw.update(); - return Entry.hw.getDigitalPortValue(signal); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.read_digital(%1)', - blockType: 'param', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - roduino_get_color: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_color_red, 'red'], - [Lang.Blocks.roborobo_color_green, 'green'], - [Lang.Blocks.roborobo_color_blue, 'blue'], - [Lang.Blocks.roborobo_color_yellow, 'yellow'], - ], - value: 'red', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - type: 'roduino_get_color', - }, - paramsKeyMap: { - VALUE: 0, - }, - class: 'roduino_value', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var flag = 0; - var signal = script.getField('VALUE', script); - var value = [ - Entry.hw.portData[Entry.Roborobo_Roduino.ColorPin[0]], - Entry.hw.portData[Entry.Roborobo_Roduino.ColorPin[1]], - Entry.hw.portData[Entry.Roborobo_Roduino.ColorPin[2]], - ]; - - switch (signal) { - case 'red': - if (value[0] == 1 && value[1] == 0 && value[2] == 0) { - flag = 1; - } - break; - case 'green': - if (value[0] == 0 && value[1] == 1 && value[2] == 0) { - flag = 1; - } - break; - case 'blue': - if (value[0] == 0 && value[1] == 0 && value[2] == 1) { - flag = 1; - } - break; - case 'yellow': - if (value[0] == 1 && value[1] == 1 && value[2] == 1) { - flag = 1; - } - break; - } - return flag; - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.read_color(%1)', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_color_red, 'red'], - [Lang.Blocks.roborobo_color_green, 'green'], - [Lang.Blocks.roborobo_color_blue, 'blue'], - [Lang.Blocks.roborobo_color_yellow, 'yellow'], - ], - value: 'red', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - }, - ], - }, - }, - roduino_get_sensor_analog_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_get_temperutre, 'temperature'], - [Lang.Blocks.roborobo_get_joystick_x, 'joystickX'], - [Lang.Blocks.roborobo_get_joystick_y, 'joystickY'], - [Lang.Blocks.roborobo_get_light, 'light'], - [Lang.Blocks.roborobo_get_dial, 'dial'], - [Lang.Blocks.roborobo_get_keypad_a, 'keypad'], - ], - value: 'temperature', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [ - null, - { - type: 'roduino_get_analog_number', - }, - ], - type: 'roduino_get_sensor_analog_value', - }, - paramsKeyMap: { - SENSOR: 0, - VALUE: 1, - }, - class: 'roduino_value', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var sensor = script.getField('SENSOR'); - var signal = script.getNumberValue('VALUE'); - var readData = Entry.hw.getAnalogPortValue(signal); - var data = 0; - switch (sensor) { - case 'temperature': - // var data = 5 / 51.0 * readData - 22; - data = readData; - break; - case 'joystickX': - readData = readData >> 6; - if (readData > 14) data = 2; - else if (readData > 9) data = 1; - else if (readData > 5) data = 0; - else if (readData > 1) data = -1; - else data = -2; - break; - case 'joystickY': - readData = readData >> 6; - if (readData > 14) data = 2; - else if (readData > 9) data = 1; - else if (readData > 5) data = 0; - else if (readData > 1) data = -1; - else data = -2; - break; - case 'light': - data = Math.round(readData / 10) * 10; - break; - case 'dial': - data = Math.round(readData / 10); - break; - case 'keypad': - if (readData >= 450) data = 1; - else if (readData >= 390) data = 2; - else if (readData >= 310) data = 3; - else if (readData >= 200) data = 4; - else if (readData >= 100) data = 5; - else data = 0; - break; - } - return data; - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.read_analog_sensor(%1, %2)', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_get_temperutre, 'temperature'], - [Lang.Blocks.roborobo_get_joystick_x, 'joystickX'], - [Lang.Blocks.roborobo_get_joystick_y, 'joystickY'], - [Lang.Blocks.roborobo_get_light, 'light'], - [Lang.Blocks.roborobo_get_dial, 'dial'], - [Lang.Blocks.roborobo_get_keypad_a, 'keypad'], - ], - value: 'temperature', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - roduino_get_sensor_digital_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [[Lang.Blocks.roborobo_get_ultrasonic, 'ultrasonic']], - value: 'ultrasonic', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [ - null, - { - type: 'roduino_get_port_number', - }, - ], - type: 'roduino_get_sensor_digital_value', - }, - paramsKeyMap: { - SENSOR: 0, - VALUE: 1, - }, - class: 'roduino_value', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var sensor = script.getField('SENSOR'); - var signal = script.getNumberValue('VALUE', script); - switch (sensor) { - case 'ultrasonic': - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = [ - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ]; - } - Entry.hw.sendQueue.digitalPinMode[signal] = - Entry.Roborobo_Roduino.INSTRUCTION.SONAR; - Entry.hw.update(); - break; - } - return Entry.hw.getDigitalPortValue(signal); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.read_digital_sensor(%1, %2)', - textParams: [ - { - type: 'Dropdown', - options: [[Lang.Blocks.roborobo_get_ultrasonic, 'ultrasonic']], - value: 'ultrasonic', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - roduino_set_digital: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_on, 'on'], - [Lang.Blocks.roborobo_off, 'off'], - ], - value: 'on', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [ - { - type: 'roduino_get_port_number', - }, - null, - null, - ], - type: 'roduino_set_digital', - }, - paramsKeyMap: { - VALUE: 0, - OPERATOR: 1, - }, - class: 'roduino_set', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var pin = script.getNumberValue('VALUE', script); - var operator = script.getField('OPERATOR'); - var value = operator == 'on' ? 1 : 0; - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = [ - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ]; - } - Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_Roduino.INSTRUCTION.OUTPUT; - - Entry.hw.setDigitalPortValue(pin, value); - return script.callReturn(); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.wirte_digital(%1, %2)', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_on, 'on'], - [Lang.Blocks.roborobo_off, 'off'], - ], - value: 'on', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - }, - ], - }, - }, - roduino_get_pwm_port_number: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - template: '%1', - params: [ - { - type: 'Dropdown', - options: [ - ['3', 3], - ['5', 5], - ['6', 6], - ], - value: 3, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - PORT: 0, - }, - func: function(sprite, script) { - return script.getNumberField('PORT'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['3', 3], - ['5', 5], - ['6', 6], - ], - value: 3, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - keyOption: 'roduino_get_pwm_port_number', - }, - ], - }, - }, - roduino_get_pwm_output_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - template: '%1', - params: [ - { - type: 'Dropdown', - options: [ - ['0', '0'], - ['1', '1'], - ['2', '2'], - ['3', '3'], - ['4', '4'], - ['5', '5'], - ['6', '6'], - ['7', '7'], - ['8', '8'], - ['9', '9'], - ['10', '10'], - ['11', '11'], - ['12', '12'], - ['13', '13'], - ['14', '14'], - ['15', '15'], - ], - value: '0', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: '0', - }, - func: function(sprite, script) { - return script.getNumberField('VALUE'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['0', '0'], - ['1', '1'], - ['2', '2'], - ['3', '3'], - ['4', '4'], - ['5', '5'], - ['6', '6'], - ['7', '7'], - ['8', '8'], - ['9', '9'], - ['10', '10'], - ['11', '11'], - ['12', '12'], - ['13', '13'], - ['14', '14'], - ['15', '15'], - ], - value: '0', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - keyOption: 'roduino_get_pwm_output_value', - }, - ], - }, - }, - roduino_set_pwm_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [ - { - type: 'roduino_get_pwm_port_number', - }, - { - type: 'roduino_get_pwm_output_value', - }, - null, - ], - type: 'roduino_set_pwm_value', - }, - paramsKeyMap: { - PIN: 0, - VALUE: 1, - }, - class: 'roduino_set', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var pin = script.getNumberValue('PIN', script); - var value = script.getNumberValue('VALUE'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = [ - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ]; - } - - Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_Roduino.INSTRUCTION.PWM; - - Entry.hw.setDigitalPortValue(pin, value); - return script.callReturn(); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.write_analog(%1, %2)', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - roduino_get_servo_port_number: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - template: '%1', - params: [ - { - type: 'Dropdown', - options: [ - ['3', 3], - ['5', 5], - ['6', 6], - ], - value: 3, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - PORT: 0, - }, - func: function(sprite, script) { - return script.getNumberField('PORT'); - }, - - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['3', 3], - ['5', 5], - ['6', 6], - ], - value: 3, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - keyOption: 'roduino_get_servo_port_number', - }, - ], - }, - }, - roduino_set_servo_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [ - { - type: 'roduino_get_servo_port_number', - }, - { - type: 'number', - params: ['90'], - }, - null, - ], - type: 'roduino_set_servo_value', - }, - paramsKeyMap: { - PIN: 0, - VALUE: 1, - }, - class: 'roduino_set', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var pin = script.getNumberValue('PIN', script); - var value = script.getNumberValue('VALUE'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = [ - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ]; - } - - Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_Roduino.INSTRUCTION.SERVO; - - if (value < 0) { - value = 0; - } else if (value > 180) { - value = 180; - } - - Entry.hw.setDigitalPortValue(pin, value); - return script.callReturn(); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.move_servo(%1, %2)', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - roduino_motor: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor1, 'motor1'], - [Lang.Blocks.roborobo_motor2, 'motor2'], - ], - value: 'motor1', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor_CW, 'cw'], - [Lang.Blocks.roborobo_motor_CCW, 'ccw'], - [Lang.Blocks.roborobo_motor_stop, 'stop'], - ], - value: 'cw', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [null, null, null], - type: 'roduino_motor', - }, - paramsKeyMap: { - MODE: 0, - OPERATOR: 1, - }, - class: 'roduino_set', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var pin1 = 0; - var pin2 = 0; - var value1 = 0; - var value2 = 0; - var mode = script.getField('MODE'); - var operator = script.getField('OPERATOR'); - - if (mode == 'motor1') { - pin1 = 9; - pin2 = 10; - } else { - pin1 = 11; - pin2 = 12; - } - - if (operator == 'cw') { - value1 = 1; - value2 = 0; - } else if (operator == 'ccw') { - value1 = 0; - value2 = 1; - } else { - value1 = 0; - value2 = 0; - } - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = [ - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ]; - } - Entry.hw.sendQueue.digitalPinMode[pin1] = Entry.Roborobo_Roduino.INSTRUCTION.OUTPUT; - Entry.hw.sendQueue.digitalPinMode[pin2] = Entry.Roborobo_Roduino.INSTRUCTION.OUTPUT; - - Entry.hw.setDigitalPortValue(pin1, value1); - Entry.hw.setDigitalPortValue(pin2, value2); - Entry.hw.update(); - return script.callReturn(); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roduino.move_motor(%1, %2)', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor1, 'motor1'], - [Lang.Blocks.roborobo_motor2, 'motor2'], - ], - value: 'motor1', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor_CW, 'cw'], - [Lang.Blocks.roborobo_motor_CCW, 'ccw'], - [Lang.Blocks.roborobo_motor_stop, 'stop'], - ], - value: 'cw', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - }, - ], - }, - }, - roduino_set_color_pin: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [ - { - type: 'number', - params: ['2'], - }, - { - type: 'number', - params: ['3'], - }, - { - type: 'number', - params: ['4'], - }, - null, - ], - type: 'roduino_set_color_pin', - }, - paramsKeyMap: { - RED: 0, - GREEN: 1, - BLUE: 2, - }, - class: 'roduino_set', - isNotFor: ['roborobo_roduino'], - func: function(sprite, script) { - var redPin = script.getNumberValue('RED', script); - var greenPin = script.getNumberValue('GREEN', script); - var bluePin = script.getNumberValue('BLUE', script); - - Entry.Roborobo_Roduino.ColorPin = [redPin, greenPin, bluePin]; - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = [ - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ]; - } - Entry.hw.sendQueue.digitalPinMode[redPin] = - Entry.Roborobo_Roduino.INSTRUCTION.INPUT; - Entry.hw.sendQueue.digitalPinMode[greenPin] = - Entry.Roborobo_Roduino.INSTRUCTION.INPUT; - Entry.hw.sendQueue.digitalPinMode[bluePin] = - Entry.Roborobo_Roduino.INSTRUCTION.INPUT; - Entry.hw.update(); - return script.callReturn(); - }, - syntax: { - js: [], - py: ['Roborobo_roduino.set_color_pin_mode(%1, %2, %3)'], - }, - }, - //endregion roduino 로두이노 - }; -}; - -Entry.Roborobo_SchoolKit.setLanguage = function() { - return { - ko: { - template: { - schoolkit_get_in_port_number: '%1 ', - schoolkit_get_out_port_number: '%1 ', - schoolkit_get_servo_port_number: '%1 ', - schoolkit_get_input_value: '디지털 %1 번 센서값 ', - schoolkit_set_output: '디지털 %1 번 핀 %2 %3', - schoolkit_motor: '%1 속도 %2(으)로 %3 %4', - schoolkit_set_servo_value: '서보모터 %1 번 핀 %2˚ %3', - schoolkit_on_block: ' On ', - schoolkit_off_block: ' Off ', - }, - }, - en: { - template: { - schoolkit_get_in_port_number: '%1 ', - schoolkit_get_out_port_number: '%1 ', - schoolkit_get_servo_port_number: '%1 ', - schoolkit_get_input_value: 'Digital %1 Sensor value ', - schoolkit_set_output: 'Digital %1 Pin %2 %3', - schoolkit_motor: '%1 Speed %2 %3 %4', - schoolkit_set_servo_value: 'Servo %1 Pin %2˚ %3', - schoolkit_on_block: ' On ', - schoolkit_off_block: ' Off ', - }, - }, - }; -}; - -Entry.Roborobo_SchoolKit.blockMenuBlocks = [ - 'schoolkit_on_block', - 'schoolkit_off_block', - 'schoolkit_get_input_value', - 'schoolkit_set_output', - 'schoolkit_motor', - 'schoolkit_set_servo_value', -]; - -Entry.Roborobo_SchoolKit.practicalBlockMenuBlocks = { - hw_motor: [ - // 'roborobo_motor_speed', - 'roborobo_move_for_secs', - 'roborobo_move_for', - 'roborobo_turn_for', - 'roborobo_stop_for', - ], - hw_melody: [ - - ], - hw_sensor: [ - 'roborobo_touch_value', - 'roborobo_touch_value_boolean', - 'roborobo_light_value', - 'roborobo_light_value_boolean', - 'roborobo_sound_value', - 'roborobo_sound_value_boolean', - 'roborobo_irs_value', - 'roborobo_irs_value_boolean', - ], - hw_led: [ - 'roborobo_diode_secs_toggle', - 'roborobo_diode_toggle', - 'roborobo_diode_inout_toggle', - 'roborobo_diode_set_output', - 'roborobo_diode_input_value', - ], -} - -Entry.Roborobo_SchoolKit.getBlocks = function() { - return { - //region schoolkit 스쿨키트 - schoolkit_on_block: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'schoolkit_on_block', - }, - paramsKeyMap: {}, - class: 'schoolkit_value', - isNotFor: ['roborobo_schoolkit'], - func: function(sprite, script) { - return '1'; - }, - syntax: { - js: [], - py: ['Roborobo_SchoolKit.schoolkit_on_block()'], - }, - }, - schoolkit_off_block: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'schoolkit_off_block', - }, - paramsKeyMap: {}, - class: 'schoolkit_value', - isNotFor: ['roborobo_schoolkit'], - func: function(sprite, script) { - return '0'; - }, - syntax: { - js: [], - py: ['Roborobo_SchoolKit.schoolkit_off_block()'], - }, - }, - schoolkit_get_out_port_number: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - ['OUT1', 2], - ['OUT2', 3], - ['OUT3', 4], - ['OUT4', 5], - ['OUT5', 6], - ], - value: 2, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - PORT: 0, - }, - func: function(sprite, script) { - return script.getNumberField('PORT'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['OUT1', 2], - ['OUT2', 3], - ['OUT3', 4], - ['OUT4', 5], - ['OUT5', 6], - ], - value: 2, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'schoolkit_get_out_port_number', - }, - ], - }, - }, - schoolkit_get_servo_port_number: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - ['OUT1', 2], - ['OUT2', 3], - ['OUT3', 4], - ], - value: 2, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - PORT: 0, - }, - func: function(sprite, script) { - return script.getNumberField('PORT'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['OUT1', 2], - ['OUT2', 3], - ['OUT3', 4], - ], - value: 2, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'schoolkit_get_servo_port_number', - }, - ], - }, - }, - schoolkit_get_in_port_number: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - ['IN1', 7], - ['IN2', 8], - ['IN3', 9], - ['IN4', 10], - ['IN5', 11], - ['IN6', 12], - ['IN7', 13], - ], - value: 7, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - PORT: 0, - }, - func: function(sprite, script) { - return script.getNumberField('PORT'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - ['IN1', 7], - ['IN2', 8], - ['IN3', 9], - ['IN4', 10], - ['IN5', 11], - ['IN6', 12], - ['IN7', 13], - ], - value: 7, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'schoolkit_get_in_port_number', - }, - ], - }, - }, - schoolkit_set_output: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_on, 'on'], - [Lang.Blocks.roborobo_off, 'off'], - ], - value: 'on', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [ - { - type: 'schoolkit_get_out_port_number', - }, - null, - null, - ], - type: 'schoolkit_set_output', - }, - paramsKeyMap: { - VALUE: 0, - OPERATOR: 1, - }, - class: 'schoolkit_set', - isNotFor: ['roborobo_schoolkit'], - func: function(sprite, script) { - var pin = script.getNumberValue('VALUE', script); - var operator = script.getField('OPERATOR'); - var value = operator == 'on' ? 1 : 0; - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_SchoolKit.pinMode.OUTPUT; - Entry.hw.sendQueue[pin] = value; - return script.callReturn(); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_schoolkit.wirte_digital(%1, %2)', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_on, 'on'], - [Lang.Blocks.roborobo_off, 'off'], - ], - value: 'on', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - }, - ], - }, - }, - schoolkit_get_input_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [ - { - type: 'schoolkit_get_in_port_number', - }, - ], - type: 'schoolkit_get_input_value', - }, - paramsKeyMap: { - VALUE: 0, - }, - class: 'schoolkit_value', - isNotFor: ['roborobo_schoolkit'], - func: function(sprite, script) { - var signal = script.getNumberValue('VALUE', script); - return Entry.hw.portData[signal - 7]; - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_schoolkit.read_digital(%1)', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - schoolkit_motor: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor1, 'motor1'], - [Lang.Blocks.roborobo_motor2, 'motor2'], - ], - value: 'motor1', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Dropdown', - options: [ - ['0', '45'], - ['1', '59'], - ['2', '73'], - ['3', '87'], - ['4', '101'], - ['5', '115'], - ['6', '129'], - ['7', '143'], - ['8', '157'], - ['9', '171'], - ['10', '185'], - ['11', '199'], - ['12', '213'], - ['13', '227'], - ['14', '241'], - ['15', '255'], - ], - value: '45', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor_CW, 'cw'], - [Lang.Blocks.roborobo_motor_CCW, 'ccw'], - [Lang.Blocks.roborobo_motor_stop, 'stop'], - ], - value: 'cw', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [null, null, null, null], - type: 'schoolkit_motor', - }, - paramsKeyMap: { - MODE: 0, - VALUE: 1, - OPERATOR: 2, - }, - class: 'schoolkit_set', - isNotFor: ['roborobo_schoolkit'], - func: function(sprite, script) { - var mode = script.getField('MODE'); - var pin = 0; - var operator = script.getField('OPERATOR'); - var value = script.getField('VALUE'); - - if (mode == 'motor1') { - pin = 0; - } else { - pin = 1; - } - - if (value > 255) { - value = 255; - } else if (value < 0) { - value = 0; - } - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[pin + 7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - if (operator == 'cw') { - Entry.hw.sendQueue[pin] = value; - } else if (operator == 'ccw') { - Entry.hw.sendQueue[pin] = -value; - } else if (operator == 'stop') { - Entry.hw.sendQueue[pin] = 0x00; - } - return script.callReturn(); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_schoolkit.move_motor_speed(%1, %2, %3)', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor1, 'motor1'], - [Lang.Blocks.roborobo_motor2, 'motor2'], - ], - value: 'motor1', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - { - type: 'Dropdown', - options: [ - ['0', '45'], - ['1', '59'], - ['2', '73'], - ['3', '87'], - ['4', '101'], - ['5', '115'], - ['6', '129'], - ['7', '143'], - ['8', '157'], - ['9', '171'], - ['10', '185'], - ['11', '199'], - ['12', '213'], - ['13', '227'], - ['14', '241'], - ['15', '255'], - ], - value: '45', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roborobo_motor_CW, 'cw'], - [Lang.Blocks.roborobo_motor_CCW, 'ccw'], - [Lang.Blocks.roborobo_motor_stop, 'stop'], - ], - value: 'cw', - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - }, - ], - }, - }, - schoolkit_set_servo_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12, - }, - ], - events: {}, - def: { - params: [ - { - type: 'schoolkit_get_servo_port_number', - }, - { - type: 'number', - params: ['0'], - }, - null, - ], - type: 'schoolkit_set_servo_value', - }, - paramsKeyMap: { - PIN: 0, - VALUE: 1, - }, - class: 'schoolkit_set', - isNotFor: ['roborobo_schoolkit'], - func: function(sprite, script) { - var pin = script.getNumberValue('PIN', script); - var value = script.getNumberValue('VALUE'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_SchoolKit.pinMode.SERVO; - - if (value < 0) { - value = 0; - } else if (value > 180) { - value = 180; - } - Entry.hw.sendQueue[pin] = value; - return script.callReturn(); - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_schoolkit.move_servo(%1, %2)', - textParams: [ - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - ], - }, - ], - }, - }, - //endregion schoolkit 스쿨키트 - }; -}; - -Entry.Roborobo_SchoolKit.getPracticalBlocks = function() { - return { - // roborobo_mini - roborobo_motor_speed: { - color: '#00B200', - outerLine: '#019101', - skeleton: 'basic_string_field', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1', - params: [ - { - type: 'Dropdown', - options: [ - ['1', '52'], - ['2', '66'], - ['3', '80'], - ['4', '94'], - ['5', '107'], - ['6', '120'], - ['7', '134'], - ['8', '148'], - ['9', '162'], - ['10', '176'], - ['11', '190'], - ['12', '204'], - ['13', '218'], - ['14', '232'], - ['15', '255'], - ], - value: '255', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func(sprite, script) { - return script.getStringField('VALUE'); - }, - }, - roborobo_move_for_secs: { - color: '#00B200', - outerLine: '#019101', - skeleton: 'basic', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1모터를 %2 %3의 속도로 %4초 동안 회전 %5', - params: [ - { - type: 'Dropdown', - options: [ - ['양쪽', '1'], - ['오른쪽', '2'], - ['왼쪽', '3'], - ], - value: '1', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Dropdown', - options: [ - ['앞으로', '1'], - ['뒤로', '2'], - ], - value: '1', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/dcmotor.png', - size: 12, - }, - ], - events: {}, - def: { - params: [ - null, - null, - { - type: 'roborobo_motor_speed', - }, - { - type: 'number', - params: ['2'], - }, - null, - ], - type: 'roborobo_move_for_secs', - }, - paramsKeyMap: { - WHEEL: 0, - DIRECTION: 1, - SPEED: 2, - DURATION: 3, - }, - class: 'roborobo_motor', - func(sprite, script) { - const motor1 = 0; - const motor2 = 1; - const wheel = script.getNumberField('WHEEL'); - const speed = script.getNumberValue('SPEED'); - const direction = script.getNumberField('DIRECTION'); - const duration = script.getNumberValue('DURATION'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - if (!script.isStart) { - if (wheel == 1) { - Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (direction == 1) { - Entry.hw.sendQueue[motor1] = speed; - Entry.hw.sendQueue[motor2] = speed; - } else if (direction == 2) { - Entry.hw.sendQueue[motor1] = -speed; - Entry.hw.sendQueue[motor2] = -speed; - } - } else if (wheel == 2) { - Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (direction == 1) { - Entry.hw.sendQueue[motor1] = 0x00; - Entry.hw.sendQueue[motor2] = speed; - } else if (direction == 2) { - Entry.hw.sendQueue[motor1] = 0x00; - Entry.hw.sendQueue[motor2] = -speed; - } - } else if (wheel == 3) { - Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (direction == 1) { - Entry.hw.sendQueue[motor1] = speed; - Entry.hw.sendQueue[motor2] = 0x00; - } else if (direction == 2) { - Entry.hw.sendQueue[motor1] = -speed; - Entry.hw.sendQueue[motor2] = 0x00; - } - } - - script.wheelMode = wheel; - script.isStart = true; - script.timeFlag = 1; - setTimeout(() => { - script.timeFlag = 0; - }, duration * 1000); - return script; - } else if (script.timeFlag == 1) { - return script; - } else { - Entry.hw.sendQueue[motor1] = 0x00; - Entry.hw.sendQueue[motor2] = 0x00; - - delete script.timeFlag; - delete script.isStart; - delete script.wheelMode; - Entry.engine.isContinue = false; - return script.callReturn(); - } - }, - }, - roborobo_move_for: { - color: '#00B200', - outerLine: '#019101', - skeleton: 'basic', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1모터를 %2 %3의 속도로 계속 회전 %4', - params: [ - { - type: 'Dropdown', - options: [ - ['양쪽', '1'], - ['오른쪽', '2'], - ['왼쪽', '3'], - ], - value: '1', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Dropdown', - options: [ - ['앞으로', '1'], - ['뒤로', '2'], - ], - value: '1', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/dcmotor.png', - size: 12, - }, - ], - events: {}, - def: { - params: [ - null, - null, - { - type: 'roborobo_motor_speed', - }, - null, - ], - type: 'roborobo_move_for', - }, - paramsKeyMap: { - WHEEL: 0, - DIRECTION: 1, - SPEED: 2, - }, - class: 'roborobo_motor', - //'isNotFor': ['mini'], - func(sprite, script) { - const motor1 = 0; - const motor2 = 1; - const wheel = script.getNumberField('WHEEL'); - const speed = script.getNumberValue('SPEED'); - const direction = script.getNumberField('DIRECTION'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - if (wheel == 1) { - Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (direction == 1) { - Entry.hw.sendQueue[motor1] = speed; - Entry.hw.sendQueue[motor2] = speed; - } else if (direction == 2) { - Entry.hw.sendQueue[motor1] = -speed; - Entry.hw.sendQueue[motor2] = -speed; - } - } else if (wheel == 2) { - Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (direction == 1) { - Entry.hw.sendQueue[motor1] = 0x00; - Entry.hw.sendQueue[motor2] = speed; - } else if (direction == 2) { - Entry.hw.sendQueue[motor1] = 0x00; - Entry.hw.sendQueue[motor2] = -speed; - } - } else if (wheel == 3) { - Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (direction == 1) { - Entry.hw.sendQueue[motor1] = speed; - Entry.hw.sendQueue[motor2] = 0x00; - } else if (direction == 2) { - Entry.hw.sendQueue[motor1] = -speed; - //Entry.hw.sendQueue[motor2] = 0x00; - } - } - - return script.callReturn(); - }, - }, - roborobo_turn_for: { - color: '#00B200', - outerLine: '#019101', - skeleton: 'basic', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '오른쪽 모터를 %1 %2, 왼쪽 모터를 %3 %4의 속도로 계속 회전 %5', - params: [ - { - type: 'Dropdown', - options: [ - ['앞으로', '1'], - ['뒤로', '2'], - ], - value: '1', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Dropdown', - options: [ - ['앞으로', '1'], - ['뒤로', '2'], - ], - value: '1', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/dcmotor.png', - size: 12, - }, - ], - events: {}, - def: { - params: [ - null, - { type: 'roborobo_motor_speed' }, - null, - { type: 'roborobo_motor_speed' }, - null, - ], - type: 'roborobo_turn_for', - }, - paramsKeyMap: { - RDIR: 0, - RSPEED: 1, - LDIR: 2, - LSPEED: 3, - }, - class: 'roborobo_motor', - //'isNotFor': ['mini'], - func(sprite, script) { - const motor1 = 0; - const motor2 = 1; - - const rightDir = script.getNumberField('RDIR'); - const rightSpeed = script.getNumberValue('RSPEED'); - const leftDir = script.getNumberField('LDIR'); - const leftSpeed = script.getNumberValue('LSPEED'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (leftDir == 1) { - Entry.hw.sendQueue[motor1] = leftSpeed; - } else { - Entry.hw.sendQueue[motor1] = -leftSpeed; - } - - if (rightDir == 1) { - Entry.hw.sendQueue[motor2] = rightSpeed; - } else { - Entry.hw.sendQueue[motor2] = -rightSpeed; - } - - return script.callReturn(); - }, - }, - roborobo_stop_for: { - color: '#00B200', - outerLine: '#019101', - skeleton: 'basic', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1모터를 정지 %2', - params: [ - { - type: 'Dropdown', - options: [ - ['양쪽', '1'], - ['오른쪽', '2'], - ['왼쪽', '3'], - ], - value: '1', - fontSize: 11, - bgColor: '#019101', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/dcmotor.png', - size: 12, - }, - ], - events: {}, - def: { - params: [null, null], - type: 'roborobo_stop_for', - }, - paramsKeyMap: { - WHEEL: 0, - }, - class: 'roborobo_motor', - func(sprite, script) { - const motor1 = 0; - const motor2 = 1; - const wheel = script.getNumberField('WHEEL'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - if (wheel == 1) { - Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - Entry.hw.sendQueue[motor1] = 0x00; - Entry.hw.sendQueue[motor2] = 0x00; - } else if (wheel == 2) { - Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - Entry.hw.sendQueue[motor2] = 0x00; - } else if (wheel == 3) { - Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - Entry.hw.sendQueue[motor1] = 0x00; - } - - return script.callReturn(); - }, - }, - roborobo_touch_value: { - color: '#2AB4D3', - outerLine: '#0e93b1', - skeleton: 'basic_string_field', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '접촉 센서 값', - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'roborobo_touch_value', - }, - paramsKeyMap: {}, - class: 'roborobo_touch', - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.contact; - Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.INPUT; - Entry.hw.update(); - return Entry.hw.portData[port - 7]; - }, - }, - roborobo_touch_value_boolean: { - color: '#2AB4D3', - outerLine: '#0e93b1', - skeleton: 'basic_boolean_field', - fontColor: '#fff', - isNotFor: ['roborobo_schoolkit'], - template: '접촉 센서가 %1', - params: [ - { - type: 'Dropdown', - options: [ - ['접촉 되면', '1'], - ['접촉 안되면', '0'], - ], - value: '1', - fontSize: 11, - bgColor: '#0e93b1', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - ], - def: { - params: [null], - type: 'roborobo_touch_value_boolean', - }, - paramsKeyMap: { - TOUCH: 0, - }, - class: 'roborobo_touch', - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.contact; - const touch = script.getNumberField('TOUCH', script); - - Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.INPUT; - Entry.hw.update(); - - const value = Entry.hw.portData[port - 7]; - const isTouch = touch == value; - - return isTouch; - }, - }, - roborobo_light_value: { - color: '#ff8d0f', - outerLine: '#e37100', - skeleton: 'basic_string_field', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: 'CDS 센서 값', - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'roborobo_light_value', - }, - paramsKeyMap: {}, - class: 'roborobo_light', - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.cds; - return Entry.hw.portData[port - 7]; - }, - }, - roborobo_light_value_boolean: { - color: '#ff8d0f', - outerLine: '#e37100', - skeleton: 'basic_boolean_field', - fontColor: '#fff', - isNotFor: ['roborobo_schoolkit'], - template: 'CDS 센서 값 %1 %2', - params: [ - { - type: 'Dropdown', - options: [ - ['=', 'EQUAL'], - ['>', 'GREATER'], - ['<', 'LESS'], - ['≥', 'GREATER_OR_EQUAL'], - ['≤', 'LESS_OR_EQUAL'], - ], - value: 'LESS', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - noaRrow: true, - }, - { - type: 'Block', - accept: 'string', - }, - ], - def: { - params: [ - null, - { - type: 'number', - params: ['512'], - }, - ], - type: 'roborobo_light_value_boolean', - }, - paramsKeyMap: { - OPERATOR: 0, - RIGHTVALUE: 1, - }, - class: 'roborobo_light', - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.cds; - const operator = script.getField('OPERATOR', script); - let rightValue = script.getNumberValue('RIGHTVALUE', script); - const leftValue = Entry.hw.portData[port - 7]; - let isCheck = false; - - if (rightValue < 0) { - rightValue = 0; - } else if (rightValue > 1023) { - rightValue = 1023; - } - switch (operator) { - case 'EQUAL': - isCheck = leftValue == rightValue; - break; - case 'GREATER': - isCheck = Number(leftValue) > Number(rightValue); - break; - case 'LESS': - isCheck = Number(leftValue) < Number(rightValue); - break; - case 'GREATER_OR_EQUAL': - isCheck = Number(leftValue) >= Number(rightValue); - break; - case 'LESS_OR_EQUAL': - isCheck = Number(leftValue) <= Number(rightValue); - break; - } - return isCheck; - }, - }, - roborobo_sound_value: { - color: '#01d67f', - outerLine: '#00b36a', - skeleton: 'basic_string_field', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '소리 센서에 감지되는 소리 값', - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'roborobo_sound_value', - }, - paramsKeyMap: {}, - class: 'roborobo_sound', - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.sound; - return Entry.hw.portData[port - 7]; - }, - }, - roborobo_sound_value_boolean: { - color: '#01d67f', - outerLine: '#00b36a', - skeleton: 'basic_boolean_field', - fontColor: '#fff', - isNotFor: ['roborobo_schoolkit'], - template: '소리 센서에 감지되는 소리 값 %1 %2', - params: [ - { - type: 'Dropdown', - options: [ - ['=', 'EQUAL'], - ['>', 'GREATER'], - ['<', 'LESS'], - ['≥', 'GREATER_OR_EQUAL'], - ['≤', 'LESS_OR_EQUAL'], - ], - value: 'LESS', - fontSize: 11, - bgColor: '#00b36a', - arrowColor: EntryStatic.colorSet.common.WHITE, - noaRrow: true, - }, - { - type: 'Block', - accept: 'string', - }, - ], - def: { - params: [ - null, - { - type: 'number', - params: ['512'], - }, - ], - type: 'roborobo_sound_value_boolean', - }, - paramsKeyMap: { - OPERATOR: 0, - RIGHTVALUE: 1, - }, - class: 'roborobo_sound', - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.sound; - const operator = script.getField('OPERATOR', script); - let rightValue = script.getNumberValue('RIGHTVALUE', script); - const leftValue = Entry.hw.portData[port - 7]; - let isCheck = false; - - if (rightValue < 0) { - rightValue = 0; - } else if (rightValue > 1023) { - rightValue = 1023; - } - - switch (operator) { - case 'EQUAL': - isCheck = leftValue == rightValue; - break; - case 'GREATER': - isCheck = Number(leftValue) > Number(rightValue); - break; - case 'LESS': - isCheck = Number(leftValue) < Number(rightValue); - break; - case 'GREATER_OR_EQUAL': - isCheck = Number(leftValue) >= Number(rightValue); - break; - case 'LESS_OR_EQUAL': - isCheck = Number(leftValue) <= Number(rightValue); - break; - } - - return isCheck; - }, - }, - roborobo_irs_value: { - color: '#C4065C', - outerLine: '#9a0045', - skeleton: 'basic_string_field', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '적외선 센서 값', - params: [ - { - type: 'Block', - accept: 'string', - }, - ], - events: {}, - def: { - params: [null], - type: 'roborobo_irs_value', - }, - paramsKeyMap: {}, - class: 'roborobo_irs', - //'isNotFor': ['mini'], - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.ir; - const value = - Entry.hw.portData[port - 7] == undefined ? 0 : Entry.hw.portData[port - 7]; - return value; - }, - }, - roborobo_irs_value_boolean: { - color: '#C4065C', - outerLine: '#9a0045', - skeleton: 'basic_boolean_field', - fontColor: '#fff', - isNotFor: ['roborobo_schoolkit'], - template: '적외선 센서가 %1', - params: [ - { - type: 'Dropdown', - options: [ - ['감지 되면', '1'], - ['감지 안되면', '0'], - ], - value: '1', - fontSize: 11, - bgColor: '#9a0045', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - ], - def: { - params: [null], - type: 'roborobo_irs_value_boolean', - }, - paramsKeyMap: { - DETECT: 0, - }, - class: 'roborobo_irs', - //'isNotFor': ['mini'], - func(sprite, script) { - const port = Entry.Roborobo_SchoolKit.inputPort.ir; - const detect = script.getNumberField('DETECT', script); - - Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.INPUT; - Entry.hw.update(); - - const value = Entry.hw.portData[port - 7]; - const isDetect = detect == value; - - return isDetect; - }, - }, - roborobo_diode_secs_toggle: { - color: '#ff8d0f', - outerLine: '#e37100', - skeleton: 'basic', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1번 포트의 발광다이오드를 %2초 동안 %3 %4', - params: [ - { - type: 'Dropdown', - options: [ - ['LED 1', '5'], - ['LED 2', '4'], - ['R - A', '3'], - ['R - B', '2'], - ], - value: '5', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Dropdown', - options: [ - ['켜기', '255'], - ['끄기', '0'], - ], - value: '255', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/diode.png', - size: 12, - }, - ], - events: {}, - def: { - params: [ - null, - { - type: 'number', - params: ['2'], - }, - null, - null, - ], - type: 'roborobo_diode_secs_toggle', - }, - paramsKeyMap: { - PORT: 0, - DURATION: 1, - VALUE: 2, - }, - class: 'roborobo_diode', - func(sprite, script) { - const port = script.getNumberField('PORT'); - const duration = script.getNumberValue('DURATION'); - const value = script.getNumberField('VALUE'); - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.PWM; - - if (!script.isStart) { - script.isStart = true; - script.timeFlag = 1; - Entry.hw.sendQueue[port] = value; - - setTimeout(() => { - script.timeFlag = 0; - }, duration * 1000); - return script; - } else if (script.timeFlag == 1) { - return script; - } else { - Entry.hw.sendQueue[port] = 0; - delete script.timeFlag; - delete script.isStart; - Entry.engine.isContinue = false; - return script.callReturn(); - } - }, - }, - roborobo_diode_toggle: { - color: '#ff8d0f', - outerLine: '#e37100', - skeleton: 'basic', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1번 포트의 발광다이오드를 %2 %3', - params: [ - { - type: 'Dropdown', - options: [ - ['LED 1', '5'], - ['LED 2', '4'], - ['R - A', '3'], - ['R - B', '2'], - ], - value: '5', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Dropdown', - options: [ - ['켜기', '255'], - ['끄기', '0'], - ], - value: '255', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/diode.png', - size: 12, - }, - ], - events: {}, - def: { - params: [null, null, null], - type: 'roborobo_diode_toggle', - }, - paramsKeyMap: { - PORT: 0, - VALUE: 1, - }, - class: 'roborobo_diode', - //'isNotFor': ['mini'], - func(sprite, script) { - const port = script.getNumberField('PORT'); - const value = script.getNumberField('VALUE'); - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue[port] = value; - - return script.callReturn(); - }, - }, - roborobo_diode_inout_toggle: { - color: '#ff8d0f', - outerLine: '#e37100', - skeleton: 'basic', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1번 포트의 발광다이오드를 %2번 포트의 %3~%4의 범위로 켜기%5', - params: [ - { - type: 'Dropdown', - options: [ - ['LED 1', '5'], - ['LED 2', '4'], - ['R - A', '3'], - ['R - B', '2'], - ], - value: '5', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Dropdown', - options: [ - ['소 리', '8'], - ['CDS', '10'], - ], - value: '8', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/diode.png', - size: 12, - }, - ], - events: {}, - def: { - params: [ - null, - null, - { type: 'number', params: ['0'] }, - { type: 'number', params: ['255'] }, - null, - ], - type: 'roborobo_diode_inout_toggle', - }, - paramsKeyMap: { - OUTPUT: 0, - INPUT: 1, - MIN: 2, - MAX: 3, - }, - class: 'roborobo_diode', - //'isNotFor': ['mini'], - func(sprite, script) { - const outputPort = script.getNumberField('OUTPUT'); - const inputPort = script.getNumberField('INPUT'); - - const oMin = script.getNumberValue('MIN'); - const oMax = script.getNumberValue('MAX'); - const nMin = 0; - const nMax = 255; - const x = Entry.hw.portData[inputPort - 7] / 4; - const percent = (x - oMin) / (oMax - oMin); - let result = percent * (nMax - nMin) + nMin; - if (result > nMax) { - result = nMax; - } - if (result < nMin) { - result = nMin; - } - - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - - Entry.hw.sendQueue.digitalPinMode[outputPort] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue[outputPort] = result; - - return script.callReturn(); - }, - }, - roborobo_diode_set_output: { - color: '#ff8d0f', - outerLine: '#e37100', - skeleton: 'basic', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1번 포트의 발광다이오드를 %2의 밝기로 켜기 %3', - params: [ - { - type: 'Dropdown', - options: [ - ['LED 1', '5'], - ['LED 2', '4'], - ['R - A', '3'], - ['R - B', '2'], - ], - value: '5', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - { - type: 'Block', - accept: 'string', - }, - { - type: 'Indicator', - img: 'block_icon/practical_course/diode.png', - size: 12, - }, - ], - events: {}, - def: { - params: [ - null, - { - type: 'number', - params: ['255'], - }, - null, - ], - type: 'roborobo_diode_set_output', - }, - paramsKeyMap: { - PORT: 0, - VALUE: 1, - }, - class: 'roborobo_diode', - //'isNotFor': ['mini'], - func(sprite, script) { - const port = script.getStringField('PORT', script); - let value = script.getNumberValue('VALUE', script); - - if (value < 0) { - value = 0; - } else if (value > 255) { - value = 255; - } - if (!Entry.hw.sendQueue.digitalPinMode) { - Entry.hw.sendQueue.digitalPinMode = {}; - } - Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.PWM; - Entry.hw.sendQueue[port] = value; - - return script.callReturn(); - }, - }, - roborobo_diode_input_value: { - color: '#ff8d0f', - outerLine: '#e37100', - skeleton: 'basic_string_field', - fontColor: '#fff', - statements: [], - isNotFor: ['roborobo_schoolkit'], - template: '%1 포트의 값', - params: [ - { - type: 'Dropdown', - options: [ - ['적외선', '7'], - ['소 리', '8'], - ['접 촉', '9'], - ['CDS', '10'], - ], - value: '8', - fontSize: 11, - bgColor: '#e37100', - arrowColor: EntryStatic.colorSet.common.WHITE, - }, - ], - events: {}, - def: { - params: [null], - type: 'roborobo_diode_input_value', - }, - paramsKeyMap: { - PORT: 0, - }, - class: 'roborobo_diode', - func(sprite, script) { - const port = script.getNumberField('PORT'); - return Entry.hw.portData[port - 7]; - }, - }, - } -} - -Entry.Roborobo_RoE.setLanguage = function() { - return { - ko: { - template: { - roe_set_led: '%1 LED 켜기 %2', - roe_set_led_off: 'LED 끄기 %1', - roe_set_motor: '로이 %1 %2', - roe_set_motor_value: '%1 모터 : %2 만큼 %3 %4', - roe_set_melody: '%1 옥타브 %2 을(를) %3 초 연주 %4', - roe_get_input_switch: '접촉센서가 %1 ?', - roe_get_input_ir: '적외선 센서가 %1 ?', - roe_get_input_color: '%1 컬러센서 값이 %2 인가?', - roe_led_color_dropdown: '%1', - roe_melody_dropdown: '%1', - roe_motor_dropdown: '%1', - roe_movement_dropdown: '%1', - roe_detect_dropdown: '%1', - roe_color_select_dropdown: '%1', - roe_color_color_dropdown: '%1', - }, - Blocks: { - roe_color_sensor_left: '왼쪽', - roe_color_sensor_right: '오른쪽', - roe_color_sensor_both: '양쪽', - roe_color_red: '빨간색', - roe_color_orange: '주황색', - roe_color_yellow: '노란색', - roe_color_yellowgreen: '연두색', - roe_color_green: '초록색', - roe_color_skyblue: '하늘색', - roe_color_blue: '파란색', - roe_color_purple: '보라색', - roe_color_pink: '분홍색', - roe_color_white: '흰색', - roe_color_black: '검정색', - roe_color_random: '무작위 색', - roe_color_none: '미감지', - roe_motor_both: '양쪽', - roe_motor_left: '왼쪽', - roe_motor_right: '오른쪽', - roe_move_forward: '전진', - roe_move_backward: '후진', - roe_move_turnleft: '좌회전', - roe_move_turnright: '우회전', - roe_move_stop: '정지', - roe_detected: '감지되었는가', - roe_undetected: '감지되지 않았는가', - roe_melody_do: '도', - roe_melody_doS: '도#', - roe_melody_re: '레', - roe_melody_miF: '미b', - roe_melody_mi: '미', - roe_melody_pa: '파', - roe_melody_paS: '파#', - roe_melody_sol: '솔', - roe_melody_solS: '솔#', - roe_melody_la: '라', - roe_melody_siF: '시b', - roe_melody_si: '시', - } - }, - en: { - template: { - roe_set_led: 'Turn on %1 LED %2', - roe_set_led_off: 'Turn off LED %1', - roe_set_motor: 'Ro-E %1 %2', - roe_set_motor_value: '%1 motor(s) : Move %3 by %2 %4', - roe_set_melody: 'Play %1 octave %2 tone for %3 second(s) %4', - roe_get_input_switch: 'Is the switch sensor %1 ?', - roe_get_input_ir: 'Is the IR sensor %1 ?', - roe_get_input_color: 'Is %1 color sensor value %2 ?', - roe_led_color_dropdown: '%1', - roe_melody_dropdown: '%1', - roe_motor_dropdown: '%1', - roe_movement_dropdown: '%1', - roe_detect_dropdown: '%1', - roe_color_select_dropdown: '%1', - roe_color_color_dropdown: '%1', - }, - Blocks: { - roe_color_sensor_left: 'left', - roe_color_sensor_right: 'right', - roe_color_sensor_both: 'both', - roe_color_red: 'Red', - roe_color_orange: 'Orange', - roe_color_yellow: 'Yellow', - roe_color_yellowgreen: 'Yellow Green', - roe_color_green: 'Green', - roe_color_skyblue: 'Sky Blue', - roe_color_blue: 'Blue', - roe_color_purple: 'Purple', - roe_color_pink: 'Pink', - roe_color_white: 'White', - roe_color_black: 'Black', - roe_color_random: 'Random', - roe_color_none: 'Undetected', - roe_motor_both: 'Both', - roe_motor_left: 'Left', - roe_motor_right: 'Right', - roe_move_forward: 'forward', - roe_move_backward: 'backward', - roe_move_turnleft: 'turn left', - roe_move_turnright: 'turn right', - roe_move_stop: 'stop', - roe_detected: 'detected', - roe_undetected: 'undetected', - roe_melody_do: 'C', - roe_melody_doS: 'C#', - roe_melody_re: 'D', - roe_melody_miF: 'Eb', - roe_melody_mi: 'E', - roe_melody_pa: 'F', - roe_melody_paS: 'F#', - roe_melody_sol: 'G', - roe_melody_solS: 'G#', - roe_melody_la: 'A', - roe_melody_siF: 'Bb', - roe_melody_si: 'B', - }, - }, - }; -}; - -Entry.Roborobo_RoE.blockMenuBlocks = [ - 'roe_set_led', - 'roe_set_led_off', - 'roe_set_motor', - 'roe_set_motor_value', - 'roe_set_melody', - 'roe_get_input_switch', - 'roe_get_input_ir', - 'roe_get_input_color', -]; - -Entry.Roborobo_RoE.getBlocks = function() { - return { - //region roe 로이 - roe_led_color_dropdown: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_color_red, 1], - [Lang.Blocks.roe_color_orange, 2], - [Lang.Blocks.roe_color_yellow, 3], - [Lang.Blocks.roe_color_yellowgreen, 4], - [Lang.Blocks.roe_color_green, 5], - [Lang.Blocks.roe_color_skyblue, 6], - [Lang.Blocks.roe_color_blue, 7], - [Lang.Blocks.roe_color_purple, 8], - [Lang.Blocks.roe_color_pink, 9], - [Lang.Blocks.roe_color_white, 10] - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func: function(sprite, script) { - return script.getNumberField('VALUE'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_color_red, 1], - [Lang.Blocks.roe_color_orange, 2], - [Lang.Blocks.roe_color_yellow, 3], - [Lang.Blocks.roe_color_yellowgreen, 4], - [Lang.Blocks.roe_color_green, 5], - [Lang.Blocks.roe_color_skyblue, 6], - [Lang.Blocks.roe_color_blue, 7], - [Lang.Blocks.roe_color_purple, 8], - [Lang.Blocks.roe_color_pink, 9], - [Lang.Blocks.roe_color_white, 10] - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'roe_led_color_dropdown', - }, - ], - }, - }, - roe_melody_dropdown: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_melody_do, 1], - [Lang.Blocks.roe_melody_re, 2], - [Lang.Blocks.roe_melody_mi, 3], - [Lang.Blocks.roe_melody_pa, 4], - [Lang.Blocks.roe_melody_sol, 5], - [Lang.Blocks.roe_melody_la, 6], - [Lang.Blocks.roe_melody_si, 7], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func: function(sprite, script) { - return script.getNumberField('VALUE', script); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_melody_do, 1], - [Lang.Blocks.roe_melody_re, 2], - [Lang.Blocks.roe_melody_mi, 3], - [Lang.Blocks.roe_melody_pa, 4], - [Lang.Blocks.roe_melody_sol, 5], - [Lang.Blocks.roe_melody_la, 6], - [Lang.Blocks.roe_melody_si, 7], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - keyOption: 'roe_melody_dropdown', - }, - ], - }, - }, - roe_motor_dropdown: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_motor_both, 1], - [Lang.Blocks.roe_motor_left, 2], - [Lang.Blocks.roe_motor_right, 3], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func: function(sprite, script) { - return script.getNumberField('VALUE'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_motor_both, 1], - [Lang.Blocks.roe_motor_left, 2], - [Lang.Blocks.roe_motor_right, 3], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'roe_motor_dropdown', - }, - ], - }, - }, - roe_movement_dropdown: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_move_forward, 1], - [Lang.Blocks.roe_move_backward, 2], - [Lang.Blocks.roe_move_turnleft, 3], - [Lang.Blocks.roe_move_turnright, 4], - [Lang.Blocks.roe_move_stop, 5], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func: function(sprite, script) { - return script.getNumberField('VALUE'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_move_forward, 1], - [Lang.Blocks.roe_move_backward, 2], - [Lang.Blocks.roe_move_turnleft, 3], - [Lang.Blocks.roe_move_turnright, 4], - [Lang.Blocks.roe_move_stop, 5], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'roe_movement_dropdown', - }, - ], - }, - }, - roe_detect_dropdown: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_detected, 1], - [Lang.Blocks.roe_undetected, 0], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func: function(sprite, script) { - return script.getNumberField('VALUE'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_detected, 1], - [Lang.Blocks.roe_undetected, 2], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'roe_detect_dropdown', - }, - ], - }, - }, - roe_color_select_dropdown: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_color_sensor_both, 1], - [Lang.Blocks.roe_color_sensor_left, 2], - [Lang.Blocks.roe_color_sensor_right, 3], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func: function(sprite, script) { - return script.getNumberField('VALUE'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_color_sensor_both, 1], - [Lang.Blocks.roe_color_sensor_left, 2], - [Lang.Blocks.roe_color_sensor_right, 3], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'roe_color_select_dropdown', - }, - ], - }, - }, - roe_color_color_dropdown: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic_string_field', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_color_red, 1], - [Lang.Blocks.roe_color_orange, 2], - [Lang.Blocks.roe_color_yellow, 3], - [Lang.Blocks.roe_color_yellowgreen, 7], - [Lang.Blocks.roe_color_green, 4], - [Lang.Blocks.roe_color_skyblue, 8], - [Lang.Blocks.roe_color_blue, 5], - [Lang.Blocks.roe_color_purple, 6], - [Lang.Blocks.roe_color_pink, 9], - [Lang.Blocks.roe_color_black, 10], - [Lang.Blocks.roe_color_white, 11], - [Lang.Blocks.roe_color_none, 127], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - ], - events: {}, - def: { - params: [null], - }, - paramsKeyMap: { - VALUE: 0, - }, - func: function(sprite, script) { - return script.getNumberField('VALUE'); - }, - syntax: { - js: [], - py: [ - { - syntax: '%1', - textParams: [ - { - type: 'Dropdown', - options: [ - [Lang.Blocks.roe_color_red, 1], - [Lang.Blocks.roe_color_orange, 2], - [Lang.Blocks.roe_color_yellow, 3], - [Lang.Blocks.roe_color_yellowgreen, 7], - [Lang.Blocks.roe_color_green, 4], - [Lang.Blocks.roe_color_skyblue, 8], - [Lang.Blocks.roe_color_blue, 5], - [Lang.Blocks.roe_color_purple, 6], - [Lang.Blocks.roe_color_pink, 9], - [Lang.Blocks.roe_color_black, 10], - [Lang.Blocks.roe_color_white, 11], - [Lang.Blocks.roe_color_none, 127], - ], - value: 1, - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - converter: Entry.block.converters.returnStringValue, - }, - ], - keyOption: 'roe_color_color_dropdown', - }, - ], - }, - }, - roe_set_led: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Block', - accept: 'string' - }, - { - type: 'Indicator', - img: 'block_icon/hardware_icon.svg', - size: 12 - } - ], - events: {}, - def: { - params: [ - { - type: 'roe_led_color_dropdown', - }, - null - ], - type: 'roe_set_led', - }, - paramsKeyMap: { - VALUE: 0, - }, - class: 'roe_set', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - var color = script.getNumberValue('VALUE', script); - Entry.hw.sendQueue['LED'] = color; - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roe.roe_set_led(%1)', - textParams: [ - { - type: "Block", - accept: "string" - }, - { - type: 'roe_led_color_dropdown' - } - ], - }, - ], - }, - }, - roe_set_led_off: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic', - statements: [], - params: [ - { - type: "Indicator", - img: "block_icon/hardware_icon.svg", - size: 12 - } - ], - events: {}, - def: { - params: [ - null - ], - type: 'roe_set_led_off' - }, - paramsKeyMap: {}, - class: 'roe_set', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - Entry.hw.sendQueue['LED'] = 0; - }, - syntax: { - js: [], - py: ['Roborobo_roe.roe_set_led_off()'], - }, - }, - roe_set_melody: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic', - statements: [], - params: [ - { - type: 'Dropdown', - options: [ - ['4', '4'], - ['5', '5'], - ['6', '6'], - ['7', '7'], - ], - fontSize: 11, - bgColor: EntryStatic.colorSet.block.darken.HARDWARE, - arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, - }, - { - type: 'Block', - accept: 'string' - }, - { - type: 'Block', - accept: 'string' - }, - { - type: "Indicator", - img: "block_icon/hardware_icon.svg", - size: 12 - } - ], - events: {}, - def: { - params: [ - '4', - { - type: 'roe_melody_dropdown', - }, - '1', - null - ], - type: 'roe_set_melody', - }, - paramsKeyMap: { - OCTAVE: 0, - NOTE: 1, - DURATION: 2 - }, - class: 'roe_set', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - if (!script.isStart) { - var octave = script.getNumberValue('OCTAVE', script); - var note = script.getNumberValue('NOTE', script); - var duration = script.getNumberValue('DURATION', script); - - if(octave < 4) { - octave = 4; - } else if (octave > 7) { - octave = 7; - } - - if(note < 1) { - note = 1; - } else if (note > 7) { - note = 7; - } - duration = duration < 0 ? 0 : duration; - duration = duration * 1000; - - script.isStart = true; - script.timeFlag = 1; - - Entry.hw.sendQueue['Melody'] = [octave, note, duration]; - - setTimeout(function() { - script.timeFlag = 0; - }, duration); - return script; - } else if (script.timeFlag == 1) { - return script; - } else { - delete script.timeFlag; - delete script.isStart; - } - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roe.roe_set_melody(%1 %2 %3)', - textParams: [ - '4', - { - type: 'roe_melody_dropdown', - }, - '1', - ], - }, - ], - }, - }, - roe_set_motor: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: "Block", - accept: "string" - }, - { - type: "Indicator", - img: "block_icon/hardware_icon.svg", - size: 12 - } - ], - events: {}, - def: { - params: [ - { - type: 'roe_movement_dropdown' - }, - null - ], - type: 'roe_set_motor' - }, - paramsKeyMap: { - OPERATOR: 0, - }, - class: 'roe_set', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - var op = script.getNumberValue('OPERATOR', script); - if(op == 1) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, 0 ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, 0 ]; - } else if (op == 2) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, 0] ; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, 0 ]; - } else if (op == 3) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, 0 ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, 0 ]; - } else if (op == 4) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, 0 ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, 0 ]; - } else if (op == 5) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.STOP, 0 ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.STOP,0 ]; - } - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roe.roe_set_motor(%1)', - textParams: [ - { - type: 'roe_movement_dropdown' - }, - ], - }, - ], - }, - }, - roe_set_motor_value: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - skeleton: 'basic', - statements: [], - params: [ - { - type: "Block", - accept: "string" - }, - { - type: "Block", - accept: "string" - }, - { - type: "Block", - accept: "string" - }, - { - type: "Indicator", - img: "block_icon/hardware_icon.svg", - size: 12 - } - ], - events: {}, - def: { - params: [ - { - type: 'roe_motor_dropdown' - }, - '100', - { - type: 'roe_movement_dropdown' - }, - null - ], - type: 'roe_set_motor_value' - }, - paramsKeyMap: { - MOTOR: 0, - VALUE: 1, - OPERATOR: 2, - }, - class: 'roe_set', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - var motor = script.getNumberValue('MOTOR', script); - var value = script.getNumberValue('VALUE', script); - var op = script.getNumberValue('OPERATOR', script); - - if(value < 0) { - value = 0; - } else if(value > 100) { - value = 100; - } - - if(motor == 1) { - if(op == 1) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ]; - } else if (op == 2) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ] ; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - } else if (op == 3) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ]; - } else if (op == 4) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - } else if (op == 5) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.STOP, value ]; - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.STOP, value ]; - } - } else if (motor == 2) { - if(op == 1) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - } else if (op == 2) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ] ; - } else if (op == 3) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ]; - } else if (op == 4) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - } else if (op == 5) { - Entry.hw.sendQueue['LeftMotor'] = [ Entry.Roborobo_RoE.motorDiretion.STOP, value ]; - } - } else if (motor == 3) { - if(op == 1) { - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ]; - } else if (op == 2) { - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - } else if (op == 3) { - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CW, value ]; - } else if (op == 4) { - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.CCW, value ]; - } else if (op == 5) { - Entry.hw.sendQueue['RightMotor'] = [ Entry.Roborobo_RoE.motorDiretion.STOP, value ]; - } - } - }, - syntax: { - js: [], - py: [ - { - syntax: 'Roborobo_roe.roe_set_motor_value(%1 %2 %3)', - textParams: [ - { - type: 'roe_motor_dropdown' - }, - '100', - { - type: 'roe_movement_dropdown' - }, - ], - }, - ], - }, - }, - roe_get_input_switch: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_boolean_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string' - }, - { - type: "Indicator", - img: "block_icon/hardware_icon.svg", - size: 12 - } - ], - events: {}, - def: { - params: [ - { - type: 'roe_detect_dropdown', - }, - null - ], - type: 'roe_get_input_switch' - }, - paramsKeyMap: { - DETECT: 0 - }, - class: 'roe_get', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - var detect = script.getNumberValue('DETECT', script); - var value = Entry.hw.portData['Switch']; - // console.log('Switch Value : ' + value); - return detect == value ? true : false; - }, - syntax: { - js: [], - py: ['Roborobo_roe.roe_get_input_switch()'], - }, - }, - roe_get_input_ir: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_boolean_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string' - }, - { - type: "Indicator", - img: "block_icon/hardware_icon.svg", - size: 12 - } - ], - events: {}, - def: { - params: [ - { - type: 'roe_detect_dropdown', - }, - null - ], - type: 'roe_get_input_ir' - }, - paramsKeyMap: { - DETECT: 0 - }, - class: 'roe_get', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - var detect = script.getNumberValue('DETECT', script); - var value = Entry.hw.portData['IR']; - // console.log('IR Value : ' + value); - return detect == value ? true : false; - }, - syntax: { - js: [], - py: ['Roborobo_roe.roe_get_input_ir()'], - }, - }, - roe_get_input_color: { - color: EntryStatic.colorSet.block.default.HARDWARE, - outerLine: EntryStatic.colorSet.block.darken.HARDWARE, - fontColor: '#fff', - skeleton: 'basic_boolean_field', - statements: [], - params: [ - { - type: 'Block', - accept: 'string' - }, - { - type: 'Block', - accept: 'string' - }, - { - type: "Indicator", - img: "block_icon/hardware_icon.svg", - size: 12 - } - ], - events: {}, - def: { - params: [ - { - type: 'roe_color_select_dropdown', - }, - { - type: 'roe_color_color_dropdown', - }, - null - ], - type: 'roe_get_input_color' - }, - paramsKeyMap: { - SENSOR: 0, - COLOR: 1 - }, - class: 'roe_get', - isNotFor: ['roborobo_roe'], - func: function(sprite, script) { - var result = false; - var sensor = script.getNumberValue('SENSOR', script); - var color = script.getNumberValue('COLOR', script); - var left = Entry.hw.portData['LeftColor']; - var right = Entry.hw.portData['RightColor']; - - if(sensor == 1) { - if(left == color && right == color) { - result = true; - } - } else if (sensor == 2) { - result = left == color ? true : false; - } else if (sensor == 3) { - result = right == color ? true : false; - } - return result; - }, - syntax: { - js: [], - py: ['Roborobo_roe.roe_get_input_color()'], - }, - }, - //endregion roe 로이 - }; -}; - -module.exports = [Entry.Roborobo_Roduino, Entry.Roborobo_SchoolKit, Entry.Roborobo_RoE]; diff --git a/src/playground/blocks/hardware/block_roborobo_base.js b/src/playground/blocks/hardware/block_roborobo_base.js new file mode 100644 index 0000000000..620d6843e2 --- /dev/null +++ b/src/playground/blocks/hardware/block_roborobo_base.js @@ -0,0 +1,422 @@ +'use strict'; + +const PinMode = { + INPUT: 0x00, + OUTPUT: 0x01, + ANALOG: 0x02, + I2C: 0x06, +} + +class ArduinoBase { + constructor () { + this.resetState(); + } + + setLanguage () {throw new Error('재정의 필요');} + getBlocks () {throw new Error('재정의 필요');} + + setZero () { + this.resetState(); + this.request('reset', null, null, true); + } + + afterReceive = function (data) { + const keys = data.state ? Object.keys(data.state) : []; + keys.forEach(key => this.state[key] = data.state[key]); + } + + afterSend = function () { + Entry.hw.sendQueue = {}; + } + + request (func, subkey, value, updateNow = false) { + if (!Entry.hw.sendQueue[func]) Entry.hw.sendQueue[func] = {}; + + if (subkey) { + Entry.hw.sendQueue[func][subkey.toString()] = value; + } else { + Entry.hw.sendQueue[func] = value; + } + + if (updateNow) Entry.hw.update(); + } + + resetState () { + this.state = { + pin: [], + rx: {} + }; + } + + pinToNumber (pin) { + if (pin === undefined || pin === null) return 0; + if (typeof pin === 'number') { + if (Number.isNaN(pin)) return 0; + return pin; + } + + const pinStr = pin.toString().toLowerCase(); + switch (pinStr) { + case 'd2': return 2; + case 'd3': return 3; + case 'd4': return 4; + case 'd5': return 5; + case 'd6': return 6; + case 'd7': return 7; + case 'd8': return 8; + case 'd9': return 9; + case 'd10': return 10; + case 'd11': return 11; + case 'd12': return 12; + case 'd13': return 13; + case 'a0': return 14; + case 'a1': return 15; + case 'a2': return 16; + case 'a3': return 17; + case 'a4': return 18; + case 'a5': return 19; + default: { + const n = Number(pin); + if (Number.isNaN(n)) return 0; + return n; + } + } + } + + isEqualsPinMode (pin, mode) { + return typeof pin === 'number' && this.state.pin[pin] && this.state.pin[pin].mode == mode; + } + + isDigitalPin (pin) { + return typeof pin === 'number' && 2 <= pin && pin <= 15; + } + + isAnalogPin (pin) { + return typeof pin === 'number' && 14 <= pin && pin <= 19; + } + + measureAnalogPin (pin) { + const analogPin = pin - 14; + return Math.min(5, Math.max(0, analogPin)); + } + + getDigitalValue (pin) { + if (!this.isDigitalPin(pin)) return 0; + + if (!this.isEqualsPinMode(pin, PinMode.INPUT)) { + this.request('enableDigitalInput', pin, {pin}, true); + } + + return this.state.rx.digital && typeof this.state.rx.digital[pin] === 'number' + ? this.state.rx.digital[pin] + : 0; + } + + getAnalogValue (pin, defValue = 0) { + if (!this.isAnalogPin(pin)) return defValue; + + if (!this.isEqualsPinMode(pin, PinMode.ANALOG)) { + this.request('enableAnalogInput', pin, {pin}, true); + } + + const analogPin = this.measureAnalogPin(pin); + return this.state.rx.analog && typeof this.state.rx.analog[analogPin] === 'number' + ? this.state.rx.analog[analogPin] + : defValue; + } + + set_digital (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const value = script.getNumberValue('VALUE'); + + this.request('setDigital', pin, {pin, value}); + return script.callReturn(); + } + + set_motor (sprite, script) { + const motor = script.getNumberValue('MOTOR'); + const speed = script.getNumberValue('SPEED'); + const state = script.getStringValue('STATE'); + + let stateNum = 0; + if (state == 'cw') stateNum = 1; + else if (state == 'ccw') stateNum = 2; + + this.request('setMotor', motor, {motor, speed, state: stateNum}); + return script.callReturn(); + } + + set_motors (sprite, script) { + const motors = script.getNumberValue('MOTORS'); + const speed1 = script.getNumberValue('SPEED1'); + const speed2 = script.getNumberValue('SPEED2'); + const state = script.getStringValue('STATE'); + + const speed = [speed1, speed2]; + let motor = [] + if (motors == 12) { + motor = [1, 2]; + } else if (motors == 34) { + motor = [3, 4]; + } + + let stateNum = [0, 0]; + switch (state) { + case 'forward': + stateNum = [2, 1]; + break; + case 'turn-left': + stateNum = [1, 1]; + break; + case 'backward': + stateNum = [1, 2]; + break; + case 'turn-right': + stateNum = [2, 2]; + break; + } + + for (let i = 0; i < 2; i++) { + this.request('setMotor', i + 1, {motor: motor[i], speed: speed[i], state: stateNum[i]}); + } + return script.callReturn(); + } + + set_servo_angle (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const angle = script.getNumberValue('ANGLE'); + + this.request('setServo', pin, {pin, angle}); + return script.callReturn(); + } + + set_rgbled_color (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + let colorString = script.getStringValue('COLOR'); + + let color; + if (typeof colorString === 'string' && colorString.substring(0, 1) === '#') { + const shorThandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; + colorString = colorString.replace(shorThandRegex, (m, r, g, b) => r + r + g + g + b + b); + const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(colorString); + color = result ? { + r: parseInt(result[1], 16), + g: parseInt(result[2], 16), + b: parseInt(result[3], 16) + } : null; + } + if (!color) color = {r: 0, g: 0, b: 0}; + + this.request('setRgbLedColor', pin, {pin, color}); + return script.callReturn(); + + } + + change_rgbled_brightness_by (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const brightness = script.getNumberValue('BRIGHTNESS'); + + this.request('changeRgbLedBrightnessBy', pin, {pin, brightness}); + return script.callReturn(); + } + + set_rgbled_brightness_to (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const brightness = script.getNumberValue('BRIGHTNESS'); + + this.request('setRgbLedBrightnessTo', pin, {pin, brightness}); + return script.callReturn(); + } + + play_piezobuzzer (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const octave = script.getNumberValue('OCTAVE'); + const duration = script.getNumberValue('DURATION'); + let note = script.getNumberValue('NOTE'); + note = (octave - 1) * 12 + note; + + this.request('setPiezoBuzzer', pin, {pin, note, duration}); + return script.callReturn(); + } + + play_piezobuzzer_until_done (sprite, script) { + const duration = script.getNumberValue('DURATION'); + this.play_piezobuzzer(sprite, script); + return new Promise(resolve => setTimeout(() => resolve(), duration * 1000)); + } + + get_digital_value (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + return this.getDigitalValue(pin); + } + + is_digital_detected (sprite, script) { + return this.get_digital_value(sprite, script) == 1; + } + + get_analog_value (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + return this.getAnalogValue(pin); + } + + compare_analog_value (sprite, script) { + const value1 = this.get_analog_value(sprite, script); + const symbol = script.getStringValue('SYMBOL'); + const value2 = script.getStringValue('VALUE'); + + return this._compare(value1, value2, symbol); + } + + _compare (v1, v2, symbol) { + switch (symbol) { + case 'greater-than': + return v1 > v2; + case 'equal': + return v1 == v2; + case 'less-than': + return v1 < v2; + default: return false; + } + } + + get_sensor_value (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const sensor = script.getStringValue('SENSOR'); + + if (sensor == 'ultrasonic') { + if (!this.isEqualsPinMode(pin, PinMode.INPUT)) { + this.request('enableSonarSensor', pin, {pin}, true); + } + return this.state.rx.digital[pin]; + } + + if (!this.isEqualsPinMode(pin, PinMode.ANALOG)) { + this.request('enableAnalogInput', pin, {pin}, true); + } + const analogPin = this.measureAnalogPin(pin); + switch (sensor) { + case "joystickx": + case "joysticky": { + const analogValue = this.getAnalogValue(pin, 512); + const value = analogValue >> 6; + + if (value > 14) return 2; + else if (value > 9) return 1; + else if (value > 5) return 0; + else if (value > 1) return -1; + else return -2; + } + case "light": { + const analogValue = this.getAnalogValue(pin); + return parseInt(Math.round(analogValue * 0.1)); + } + case "dial": { + const analogValue = this.getAnalogValue(pin); + return Math.round(analogValue * 0.1); + } + case "akeypad": { + const analogValue = this.getAnalogValue(pin); + if (analogValue >= 450) return 1; + else if (analogValue >= 390) return 2; + else if (analogValue >= 310) return 3; + else if (analogValue >= 200) return 4; + else if (analogValue >= 100) return 5; + else return 0; + } + case 'temperature': { + if (!this.state.rx.temperature[analogPin] || !this.state.rx.temperature[analogPin].enable) { + this.request('enableTemperatureSensor', pin, {pin}, true); + } + + if (this.state.rx.temperature[analogPin] && this.state.rx.temperature[analogPin].value) { + return this.state.rx.temperature[analogPin].value; + } + } break; + case 'magnetic': { + const analogValue = this.getAnalogValue(pin, 512); + + const zero = 512; + const zeroGap = 32; + const startS = zero + zeroGap; + const startN = zero - zeroGap; + const maxArea = 64; + + let value = 0; + if (analogValue > startS) { + value = (analogValue > 1024 - maxArea) ? 1024 - maxArea : analogValue; + value = Math.min(10, parseInt(Math.round((value - startS) / 32))); + } else if (analogValue < startN) { + value = (analogValue < maxArea) ? maxArea : analogValue; + value = Math.min(10, parseInt(Math.round((startN - value) / 32))) * -1; + } + return value; + } + case 'rotaryposition': { + if (!this.state.rx.rotaryPosition[analogPin] || !this.state.rx.rotaryPosition[analogPin].enable) { + this.request('enableRotaryPositionSensor', pin, {pin}, true); + } + + if (this.state.rx.rotaryPosition[analogPin] && this.state.rx.rotaryPosition[analogPin].rotation) { + return this.state.rx.rotaryPosition[analogPin].originAngle; + } + } break; + } + return 0; + } + + compare_sensor_value (sprite, script) { + const value1 = this.get_sensor_value(sprite, script); + const symbol = script.getStringValue('SYMBOL'); + const value2 = script.getStringValue('VALUE'); + + return this._compare(value1, value2, symbol); + } + + get_rotary_position_sensor_value (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const analogPin = this.measureAnalogPin(pin); + const type = script.getStringValue('PROPERTY'); + + if (!this.state.rx.rotaryPosition[analogPin] || !this.state.rx.rotaryPosition[analogPin].enable) { + this.request('enableRotaryPositionSensor', pin, {pin}, true); + } + + if (!this.state.rx.rotaryPosition[analogPin] || !this.state.rx.rotaryPosition[analogPin].rotation) return 0; + + const obj = this.state.rx.rotaryPosition[analogPin]; + let value = 0; + switch (type) { + case 'rotation': { + if (obj.isIntegerRotation) { + value = parseInt(obj.rotation); + } else { + value = obj.rotation; + } + } break; + case 'position': { + if (obj.isIntegerPosition) { + value = parseInt(Math.round(obj.position)); + } else { + value = obj.position; + } + } break; + case 'angle': { + value = obj.angle; + } break; + case 'angle-origin': { + value = obj.originAngle; + } break; + } + return value; + } + + reset_rotary_position_sensor (sprite, script) { + const pin = this.pinToNumber(script.getStringValue('PIN')); + const type = script.getStringValue('PROPERTY'); + const value = script.getNumberValue('VALUE'); + + this.request('resetRotaryPositionSensor', pin, {pin, type, value}); + } +} + +module.exports = {ArduinoBase, PinMode}; diff --git a/src/playground/blocks/hardware/block_roborobo_robokit_rs.js b/src/playground/blocks/hardware/block_roborobo_robokit_rs.js new file mode 100644 index 0000000000..5366dad99a --- /dev/null +++ b/src/playground/blocks/hardware/block_roborobo_robokit_rs.js @@ -0,0 +1,2152 @@ +'use strict'; +const {ArduinoBase, PinMode} = require('./block_roborobo_base.js'); + +class RobokitRS extends ArduinoBase { + constructor () { + super(); + + this.id = '10.3'; + this.name = 'roborobo_robokit_rs'; + this.url = 'http://www.roborobo.co.kr'; + this.imageName = 'roborobo_robokit_rs.png'; + this.title = { + ko: '로보키트 RS', + en: 'Robokit RS', + } + this.blockMenuBlocks = this.getBlockMenuBlocks(); + } + + /** + * 언어 번역 사용을 위해 함수 형태로 유지 + */ + monitorTemplate () { + return { + //imgPath: 'hw/~~.png', + //width: 256, + //height: 256, + // 모니터 화면 상단에 차례대로 나열하는 값 + listPorts: { + digital_2: {name: (Lang.Blocks.monitor_digital + ': 2'), type: 'input', pos: {x: 0, y: 0, }}, + digital_3: {name: (Lang.Blocks.monitor_digital + ': 3'), type: 'input', pos: {x: 0, y: 0, }}, + digital_4: {name: (Lang.Blocks.monitor_digital + ': 4'), type: 'input', pos: {x: 0, y: 0, }}, + digital_5: {name: (Lang.Blocks.monitor_digital + ': 5'), type: 'input', pos: {x: 0, y: 0, }}, + digital_6: {name: (Lang.Blocks.monitor_digital + ': 6'), type: 'input', pos: {x: 0, y: 0, }}, + digital_7: {name: (Lang.Blocks.monitor_digital + ': 7'), type: 'input', pos: {x: 0, y: 0, }}, + digital_8: {name: (Lang.Blocks.monitor_digital + ': 8'), type: 'input', pos: {x: 0, y: 0, }}, + digital_9: {name: (Lang.Blocks.monitor_digital + ': 9'), type: 'input', pos: {x: 0, y: 0, }}, + digital_10: {name: (Lang.Blocks.monitor_digital + ': 10'), type: 'input', pos: {x: 0, y: 0, }}, + digital_11: {name: (Lang.Blocks.monitor_digital + ': 11'), type: 'input', pos: {x: 0, y: 0, }}, + digital_12: {name: (Lang.Blocks.monitor_digital + ': 12'), type: 'input', pos: {x: 0, y: 0, }}, + digital_13: {name: (Lang.Blocks.monitor_digital + ': 13'), type: 'input', pos: {x: 0, y: 0, }}, + analog_0: {name: (Lang.Blocks.monitor_analog + ': A0'), type: 'input', pos: {x: 0, y: 0, }}, + analog_1: {name: (Lang.Blocks.monitor_analog + ': A1'), type: 'input', pos: {x: 0, y: 0, }}, + analog_2: {name: (Lang.Blocks.monitor_analog + ': A2'), type: 'input', pos: {x: 0, y: 0, }}, + analog_3: {name: (Lang.Blocks.monitor_analog + ': A3'), type: 'input', pos: {x: 0, y: 0, }}, + analog_4: {name: (Lang.Blocks.monitor_analog + ': A4'), type: 'input', pos: {x: 0, y: 0, }}, + analog_5: {name: (Lang.Blocks.monitor_analog + ': A5'), type: 'input', pos: {x: 0, y: 0, }}, + sensor_gyroscope_angle_x: {name: Lang.Blocks.monitor_gyroscope_angle_x, type: 'input', pos: {x: 0, y: 0, }}, + sensor_gyroscope_angle_y: {name: Lang.Blocks.monitor_gyroscope_angle_y, type: 'input', pos: {x: 0, y: 0, }}, + sensor_gyroscope_angle_z: {name: Lang.Blocks.monitor_gyroscope_angle_z, type: 'input', pos: {x: 0, y: 0, }}, + sensor_gyroscope_gyro_x: {name: Lang.Blocks.monitor_gyroscope_x, type: 'input', pos: {x: 0, y: 0, }}, + sensor_gyroscope_gyro_y: {name: Lang.Blocks.monitor_gyroscope_y, type: 'input', pos: {x: 0, y: 0, }}, + sensor_gyroscope_gyro_z: {name: Lang.Blocks.monitor_gyroscope_z, type: 'input', pos: {x: 0, y: 0, }}, + sensor_gyroscope_shake: {name: Lang.Blocks.monitor_gyroscope_shake, type: 'input', pos: {x: 0, y: 0, }}, + }, + // 모니터 화면 지정 위치와 선으로 연결하여 표시하는 값 + ports: {}, + mode: 'both', + } + } + + getBlockMenuBlocks () { + return [ + 'robokit_rs_menu_digital_pin', + 'robokit_rs_menu_analog_pin', + 'robokit_rs_menu_pin', + 'robokit_rs_menu_digital_value', + 'robokit_rs_menu_motor_number', + + 'robokit_rs_set_digital', + 'robokit_rs_set_motor', + 'robokit_rs_set_motors', + 'robokit_rs_set_mecanumwheels', + 'robokit_rs_set_servo_angle', + 'robokit_rs_set_rgbled_color', + 'robokit_rs_change_rgbled_brightness_by', + 'robokit_rs_set_rgbled_brightness_to', + 'robokit_rs_set_dot_state_of_dotmatrix', + 'robokit_rs_set_dotmatrix_row', + 'robokit_rs_set_dotmatrix', + 'robokit_rs_clear_dotmatrix', + 'robokit_rs_play_piezobuzzer', + 'robokit_rs_play_piezobuzzer_until_done', + 'robokit_rs_get_digital_value', + 'robokit_rs_get_analog_value', + 'robokit_rs_get_sensor_value', + 'robokit_rs_is_digital_detected', + 'robokit_rs_compare_analog_value', + 'robokit_rs_compare_sensor_value', + 'robokit_rs_get_gyro_sensor_value', + 'robokit_rs_is_shaken_gyro_sensor', + 'robokit_rs_reset_gyro_sensor', + 'robokit_rs_get_rotary_position_sensor_value', + 'robokit_rs_reset_rotary_position_sensor', + ]; + } + + setLanguage () { + return { + ko: { + template: { + robokit_rs_menu_digital_pin: '%1', + robokit_rs_menu_analog_pin: '%1', + robokit_rs_menu_pin: '%1', + robokit_rs_menu_digital_value: '%1', + robokit_rs_menu_motor_number: '%1', + + robokit_rs_set_digital: '%1 번 핀 디지털 값을 %2 (으)로 정하기 %3', + robokit_rs_set_motor: '%1 번 모터를 속도 %2 (으)로 %3 %4', + robokit_rs_set_motors: '%1 번 모터, 속도 %2, %3 (으)로 로봇을 %4 %5', + robokit_rs_set_mecanumwheels: '메카넘 휠 로봇을 속도 %1 (으)로 %2 %3', + robokit_rs_set_servo_angle: '%1 번 핀 서보 모터를 %2 도로 회전하기 %3', + robokit_rs_set_rgbled_color: '%1 번 핀 RGB LED 색상을 %2 색으로 정하기 %3', + robokit_rs_change_rgbled_brightness_by: '%1 번 핀 RGB LED 밝기를 %2 만큼 바꾸기 %3', + robokit_rs_set_rgbled_brightness_to: '%1 번 핀 RGB LED 밝기를 %2 %로 정하기 %3', + robokit_rs_set_dot_state_of_dotmatrix: '도트 매트릭스 x: %1 y: %2 좌표를 %3 (으)로 정하기 %4', + robokit_rs_set_dotmatrix_row: '도트 매트릭스 y: %1 행에 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16 그리기 %17', + robokit_rs_set_dotmatrix: '도트 매트릭스에 %1 그리기 %2', + robokit_rs_clear_dotmatrix: '도트 매트릭스 모두 지우기 %1', + robokit_rs_play_piezobuzzer: '%1 번 핀 피에조 버저로 %2 옥타브 %3 음을 %4 초 소리내기 %5', + robokit_rs_play_piezobuzzer_until_done: '%1 번 핀 피에조 버저로 %2 옥타브 %3 음을 %4 초 소리내며 기다리기 %5', + robokit_rs_get_digital_value: '%1 번 핀 디지털 값', + robokit_rs_get_analog_value: '%1 번 핀 아날로그 값', + robokit_rs_get_sensor_value: '%1 번 핀 %2 값', + robokit_rs_is_digital_detected: '%1 번 핀이 감지되었는가?', + robokit_rs_compare_analog_value: '%1 번 핀 아날로그 값 %2 %3', + robokit_rs_compare_sensor_value: '%1 번 핀 %2 값 %3 %4', + robokit_rs_get_gyro_sensor_value: '자이로 센서 %1 값', + robokit_rs_is_shaken_gyro_sensor: '자이로 센서를 흔들었는가?', + robokit_rs_reset_gyro_sensor: '자이로 센서 기본 자세의 방향을 %1 정하기 %2', + robokit_rs_get_rotary_position_sensor_value: '%1 번 핀 회전 위치 센서 %2 값', + robokit_rs_reset_rotary_position_sensor: '%1 번 핀 회전 위치 센서 %2 값을 %3 (으)로 정하기 %4' + }, + Blocks: { + monitor_digital: '디지털', + monitor_analog: '아날로그', + monitor_gyroscope_angle_x: '자이로 센서 : 기울기 x', + monitor_gyroscope_angle_y: '자이로 센서 : 기울기 y', + monitor_gyroscope_angle_z: '자이로 센서 : 기울기 z', + monitor_gyroscope_x: '자이로 센서 : 각속도 x', + monitor_gyroscope_y: '자이로 센서 : 각속도 y', + monitor_gyroscope_z: '자이로 센서 : 각속도 z', + monitor_gyroscope_shake: '자이로 센서 : 흔들림', + + robokit_rs_motor_state_cw: '시계 방향 회전', + robokit_rs_motor_state_ccw: '시계 반대 방향 회전', + robokit_rs_motor_state_stop: '정지', + + robokit_rs_motors_state_forward: '앞으로 이동', + robokit_rs_motors_state_backward: '뒤로 이동', + robokit_rs_motors_state_turn_left: '왼쪽으로 회전', + robokit_rs_motors_state_turn_right: '오른쪽으로 회전', + robokit_rs_motors_state_stop: '정지', + + robokit_rs_mecanumwheels_state_0: '앞으로 이동', + robokit_rs_mecanumwheels_state_180: '뒤로 이동', + robokit_rs_mecanumwheels_state_270: '왼쪽으로 이동', + robokit_rs_mecanumwheels_state_90: '오른쪽으로 이동', + robokit_rs_mecanumwheels_state_45: '45도 방향으로 이동', + robokit_rs_mecanumwheels_state_135: '135도 방향으로 이동', + robokit_rs_mecanumwheels_state_315: '-45도 방향으로 이동', + robokit_rs_mecanumwheels_state_225: '-135도 방향으로 이동', + robokit_rs_mecanumwheels_state_cw: '시계 방향 회전', + robokit_rs_mecanumwheels_state_ccw: '시계 반대 방향 회전', + robokit_rs_mecanumwheels_state_stop: '정지', + + robokit_rs_dotmatrix_example_eighth_note: '8분 음표', + robokit_rs_dotmatrix_example_sixteenth_note: '16분 음표', + robokit_rs_dotmatrix_example_square: '네모', + robokit_rs_dotmatrix_example_triangle: '세모', + robokit_rs_dotmatrix_example_circle: '동그라미', + robokit_rs_dotmatrix_example_heart: '하트', + robokit_rs_dotmatrix_example_ga: '가', + robokit_rs_dotmatrix_example_na: '나', + robokit_rs_dotmatrix_example_speech_bubble: '말풍선', + robokit_rs_dotmatrix_example_looking_at_top_right: '오른쪽 위 보기', + robokit_rs_dotmatrix_example_looking_at_bottom_right: '오른쪽 아래 보기', + robokit_rs_dotmatrix_example_looking_at_top_left: '왼쪽 위 보기', + robokit_rs_dotmatrix_example_looking_at_bottom_left: '왼쪽 아래 보기', + robokit_rs_dotmatrix_example_square_basic: '네모 기본', + robokit_rs_dotmatrix_example_square_basic_2: '네모 기본2', + robokit_rs_dotmatrix_example_square_square_eyes: '네모 네모 눈', + robokit_rs_dotmatrix_example_square_surprised_mouth: '네모 놀란 입', + robokit_rs_dotmatrix_example_big_round_eyes: '크고 둥근 눈', + robokit_rs_dotmatrix_example_small_round_eyes: '작고 둥근 눈', + robokit_rs_dotmatrix_example_wink_right_eye: '오른쪽 윙크', + robokit_rs_dotmatrix_example_wink_left_eye: '왼쪽 윙크', + robokit_rs_dotmatrix_example_eyebrow_eye_right: '오른쪽 눈썹 눈', + robokit_rs_dotmatrix_example_eyebrow_eye_left: '왼쪽 눈썹 눈', + robokit_rs_dotmatrix_example_expressionless: '무표정', + robokit_rs_dotmatrix_example_cutie: '귀요미', + robokit_rs_dotmatrix_example_cute: '깜찍이', + robokit_rs_dotmatrix_example_small_eyes_smile: '작은 눈 웃는 표정', + robokit_rs_dotmatrix_example_half_moon_shape_eyes: '반달 눈', + robokit_rs_dotmatrix_example_half_moon_shape_eyes_smiling: '반달 눈 웃기', + robokit_rs_dotmatrix_example_half_moon_shape_eyes_closed: '반달 눈 감기', + robokit_rs_dotmatrix_example_sad_expression: '슬픈 표정', + robokit_rs_dotmatrix_example_sullen: '시무룩', + robokit_rs_dotmatrix_example_crying_eyes: '우는 눈', + robokit_rs_dotmatrix_example_melancholy_look: '우울한 표정', + robokit_rs_dotmatrix_example_angry_eyes: '화난 눈', + robokit_rs_dotmatrix_example_o_shape_mouth: '오모양 입', + robokit_rs_dotmatrix_example_yo_shape_mouth: '요모양 입', + + robokit_rs_piezobuzzer_tone_c: '도', + robokit_rs_piezobuzzer_tone_c_sharp: '도♯(레♭)', + robokit_rs_piezobuzzer_tone_d: '레', + robokit_rs_piezobuzzer_tone_d_sharp: '레♯(미♭)', + robokit_rs_piezobuzzer_tone_e: '미', + robokit_rs_piezobuzzer_tone_f: '파', + robokit_rs_piezobuzzer_tone_f_sharp: '파♯(솔♭)', + robokit_rs_piezobuzzer_tone_g: '솔', + robokit_rs_piezobuzzer_tone_g_sharp: '솔♯(라♭)', + robokit_rs_piezobuzzer_tone_a: '라', + robokit_rs_piezobuzzer_tone_a_sharp: '라♯(시♭)', + robokit_rs_piezobuzzer_tone_b: '시', + + robokit_rs_sensor_temperutre: '온도 센서', + robokit_rs_sensor_joystick_x: '조이스틱 x', + robokit_rs_sensor_joystick_y: '조이스틱 y', + robokit_rs_sensor_light: '빛 센서', + robokit_rs_sensor_dial: '다이얼', + robokit_rs_sensor_a_keypad: 'A 키패드', + robokit_rs_sensor_rotaryposition: '회전 위치 센서', + robokit_rs_sensor_magnetic: '자기 센서', + robokit_rs_sensor_ultrasonic: '초음파 센서', + + robokit_rs_sensor_gyroscope_angle_x: '기울기 x', + robokit_rs_sensor_gyroscope_angle_y: '기울기 y', + robokit_rs_sensor_gyroscope_angle_z: '기울기 z', + robokit_rs_sensor_gyroscope_x: '각속도 x', + robokit_rs_sensor_gyroscope_y: '각속도 y', + robokit_rs_sensor_gyroscope_z: '각속도 z', + robokit_rs_sensor_gyroscope_shake: '흔들림', + + robokit_rs_sensor_gyroscope_direction_up: '위로', + robokit_rs_sensor_gyroscope_direction_forward: '앞으로', + robokit_rs_sensor_gyroscope_direction_right: '오른쪽으로', + robokit_rs_sensor_gyroscope_direction_backward: '뒤로', + robokit_rs_sensor_gyroscope_direction_left: '왼쪽으로', + + robokit_rs_sensor_rotaryposition_rotation: '회전', + robokit_rs_sensor_rotaryposition_position: '위치', + robokit_rs_sensor_rotaryposition_angle: '각도', + }, + }, + en: { + template: { + robokit_rs_menu_digital_pin: '%1', + robokit_rs_menu_analog_pin: '%1', + robokit_rs_menu_pin: '%1', + robokit_rs_menu_digital_value: '%1', + robokit_rs_menu_motor_number: '%1', + + robokit_rs_set_digital: 'set pin %1 digital value to %2 %3', + robokit_rs_set_motor: 'set motor %1 speed to %2 %3 %4', + robokit_rs_set_motors: '%4 a robot with motor %1 at speed %2 %3 %5', + robokit_rs_set_mecanumwheels: 'mecanum wheel robot %1 at speed %2 %3', + robokit_rs_set_servo_angle: 'rotate pin %1 servo motor to %2 degree %3', + robokit_rs_set_rgbled_color: 'set %1 pin RGB LED color to the %2 color %3', + robokit_rs_change_rgbled_brightness_by: 'change pin %1 RGB LED brightness by %2 %3', + robokit_rs_set_rgbled_brightness_to: 'set pin %1 RGB LED brightness to %2 % %3', + robokit_rs_set_dot_state_of_dotmatrix: 'Set dot matrix X: %1 Y: %2 to %3 %4', + robokit_rs_set_dotmatrix_row: 'Draw %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16 on dot matrix y:%1 column %17', + robokit_rs_set_dotmatrix: 'draw %1 on dotmatrix %2', + robokit_rs_clear_dotmatrix: 'Clear all dot matrix %1', + robokit_rs_play_piezobuzzer: 'Play pin %1 peizo buzzer with %2 otave %3 note for %4 sec %5', + robokit_rs_play_piezobuzzer_until_done: 'Play pin %1 peizo buzzer with %2 otave %3 note for %4 sec and wait %5', + robokit_rs_get_digital_value: 'pin %1 digital value', + robokit_rs_get_analog_value: 'pin %1 analog value', + robokit_rs_get_sensor_value: 'pin %1 %2 value', + robokit_rs_is_digital_detected: 'pin %1 detected?', + robokit_rs_compare_analog_value: 'pin %1 analog value %2 %3', + robokit_rs_compare_sensor_value: 'pin %1 %2 value %3 %4', + robokit_rs_get_gyro_sensor_value: '%1 value of gyrosensor', + robokit_rs_is_shaken_gyro_sensor: 'is gyrosensor shaken?', + robokit_rs_reset_gyro_sensor: 'set basic position of gyrosensor %1 %2', + robokit_rs_get_rotary_position_sensor_value: 'rotary position sensor of pin %1 %2 value', + robokit_rs_reset_rotary_position_sensor: 'rotary position sensor of pin %1 set %2 value to %3 %4' + }, + Blocks: { + monitor_digital: 'Digital', + monitor_analog: 'Analog', + monitor_gyroscope_angle_x: 'Gyroscope sensor : angle x', + monitor_gyroscope_angle_y: 'Gyroscope sensor : angle y', + monitor_gyroscope_angle_z: 'Gyroscope sensor : angle z', + monitor_gyroscope_x: 'Gyroscope sensor : angular velocity x', + monitor_gyroscope_y: 'Gyroscope sensor : angular velocity y', + monitor_gyroscope_z: 'Gyroscope sensor : angular velocity z', + monitor_gyroscope_shake: 'Gyroscope sensor : shake', + + robokit_rs_motor_state_cw: 'rotate clockwise', + robokit_rs_motor_state_ccw: 'rotate counterclockwise', + robokit_rs_motor_state_stop: 'stop', + + robokit_rs_motors_state_forward: 'move forward', + robokit_rs_motors_state_backward: 'move backword', + robokit_rs_motors_state_turn_left: 'turn left', + robokit_rs_motors_state_turn_right: 'turn right', + robokit_rs_motors_state_stop: 'stop', + + robokit_rs_mecanumwheels_state_0: 'move forward', + robokit_rs_mecanumwheels_state_180: 'move backward', + robokit_rs_mecanumwheels_state_270: 'move left', + robokit_rs_mecanumwheels_state_90: 'move right', + robokit_rs_mecanumwheels_state_45: 'move 45 degree', + robokit_rs_mecanumwheels_state_135: 'move 135 degree', + robokit_rs_mecanumwheels_state_315: 'move -45 degree', + robokit_rs_mecanumwheels_state_225: 'move -135 degree', + robokit_rs_mecanumwheels_state_cw: 'rotate clockwise', + robokit_rs_mecanumwheels_state_ccw: 'rotate counterclockwise', + robokit_rs_mecanumwheels_state_stop: 'stop', + + robokit_rs_dotmatrix_example_eighth_note: 'eighth note', + robokit_rs_dotmatrix_example_sixteenth_note: 'sixteenth note', + robokit_rs_dotmatrix_example_square: 'square', + robokit_rs_dotmatrix_example_triangle: 'triangle', + robokit_rs_dotmatrix_example_circle: 'circle', + robokit_rs_dotmatrix_example_heart: 'heart', + robokit_rs_dotmatrix_example_ga: 'ga', + robokit_rs_dotmatrix_example_ga: 'na', + robokit_rs_dotmatrix_example_speech_bubble: 'speech bubble', + robokit_rs_dotmatrix_example_looking_at_top_right: 'looking at top right', + robokit_rs_dotmatrix_example_looking_at_bottom_right: 'looking at bottom right', + robokit_rs_dotmatrix_example_looking_at_top_left: 'looking at top left', + robokit_rs_dotmatrix_example_looking_at_bottom_left: 'looking at bottom left', + robokit_rs_dotmatrix_example_square_basic: 'square basic', + robokit_rs_dotmatrix_example_square_basic_2: 'square basic2', + robokit_rs_dotmatrix_example_square_square_eyes: 'square square eyes', + robokit_rs_dotmatrix_example_square_surprised_mouth: 'square surprised mouth', + robokit_rs_dotmatrix_example_big_round_eyes: 'big round eyes', + robokit_rs_dotmatrix_example_small_round_eyes: 'small round eyes', + robokit_rs_dotmatrix_example_wink_right_eye: 'wink right eye', + robokit_rs_dotmatrix_example_wink_left_eye: 'wink left eye', + robokit_rs_dotmatrix_example_eyebrow_eye_right: 'eyebrow eye to the right', + robokit_rs_dotmatrix_example_eyebrow_eye_left: 'eyebrow eye to the left', + robokit_rs_dotmatrix_example_expressionless: 'expressionless', + robokit_rs_dotmatrix_example_cutie: 'cutie', + robokit_rs_dotmatrix_example_cute: 'cute', + robokit_rs_dotmatrix_example_small_eyes_smile: 'small eyes smile', + robokit_rs_dotmatrix_example_half_moon_shape_eyes: 'half moon shape eyes', + robokit_rs_dotmatrix_example_half_moon_shape_eyes_smiling: 'half moon shape eyes smiling', + robokit_rs_dotmatrix_example_half_moon_shape_eyes_closed: 'half moon shape eyes closed', + robokit_rs_dotmatrix_example_sad_expression: 'sad expression', + robokit_rs_dotmatrix_example_sullen: 'sullen', + robokit_rs_dotmatrix_example_crying_eyes: 'crying eyes', + robokit_rs_dotmatrix_example_melancholy_look: 'melancholy look', + robokit_rs_dotmatrix_example_angry_eyes: 'angry eyes', + robokit_rs_dotmatrix_example_o_shape_mouth: 'o shape mouth', + robokit_rs_dotmatrix_example_yo_shape_mouth: 'yo shape mouth', + + robokit_rs_piezobuzzer_tone_c: 'C', + robokit_rs_piezobuzzer_tone_c_sharp: 'C♯(D♭)', + robokit_rs_piezobuzzer_tone_d: 'D', + robokit_rs_piezobuzzer_tone_d_sharp: 'D♯(E♭)', + robokit_rs_piezobuzzer_tone_e: 'E', + robokit_rs_piezobuzzer_tone_f: 'F', + robokit_rs_piezobuzzer_tone_f_sharp: 'F♯(G♭)', + robokit_rs_piezobuzzer_tone_g: 'G', + robokit_rs_piezobuzzer_tone_g_sharp: 'G♯(A♭)', + robokit_rs_piezobuzzer_tone_a: 'A', + robokit_rs_piezobuzzer_tone_a_sharp: 'A♯(B♭)', + robokit_rs_piezobuzzer_tone_b: 'B', + + robokit_rs_sensor_temperutre: 'temperature sensor', + robokit_rs_sensor_joystick_x: 'joystick x', + robokit_rs_sensor_joystick_y: 'joystick y', + robokit_rs_sensor_light: 'light sensor', + robokit_rs_sensor_dial: 'dial', + robokit_rs_sensor_a_keypad: 'A keypad', + robokit_rs_sensor_rotaryposition: 'rotary position sensor', + robokit_rs_sensor_magnetic: 'magnetic sensor', + robokit_rs_sensor_ultrasonic: 'ultrasonic sensor', + + robokit_rs_sensor_gyroscope_angle_x: 'angle x', + robokit_rs_sensor_gyroscope_angle_y: 'angle y', + robokit_rs_sensor_gyroscope_angle_z: 'angle z', + robokit_rs_sensor_gyroscope_x: 'angular velocity x', + robokit_rs_sensor_gyroscope_y: 'angular velocity y', + robokit_rs_sensor_gyroscope_z: 'angular velocity z', + robokit_rs_sensor_gyroscope_shake: 'shake', + + robokit_rs_sensor_gyroscope_direction_up: 'up', + robokit_rs_sensor_gyroscope_direction_forward: 'forward', + robokit_rs_sensor_gyroscope_direction_right: 'right', + robokit_rs_sensor_gyroscope_direction_backward: 'backward', + robokit_rs_sensor_gyroscope_direction_left: 'left', + + robokit_rs_sensor_rotaryposition_rotation: 'rotation', + robokit_rs_sensor_rotaryposition_position: 'position', + robokit_rs_sensor_rotaryposition_angle: 'angle', + }, + }, + }; + }; + + getBlocks () { + return { + robokit_rs_menu_digital_pin: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ['9', '9'], + ['10', '10'], + ['11', '11'], + ['12', '12'], + ['13', '13'] + ], + value: '2', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PIN: 0, + }, + func: (sprite, script) => { + return script.getStringField('PIN'); + }, + }, + robokit_rs_menu_analog_pin: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['A0', '14'], + ['A1', '15'], + ['A2', '16'], + ['A3', '17'], + ['A4', '18'], + ['A5', '19'], + ], + value: '14', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PIN: 0, + }, + func: (sprite, script) => { + return script.getStringField('PIN'); + }, + }, + robokit_rs_menu_pin: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['A0', '14'], + ['A1', '15'], + ['A2', '16'], + ['A3', '17'], + ['A4', '18'], + ['A5', '19'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ['9', '9'], + ['10', '10'], + ['11', '11'], + ['12', '12'], + ['13', '13'], + ], + value: '14', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PIN: 0, + }, + func: (sprite, script) => { + return script.getStringField('PIN'); + }, + }, + robokit_rs_menu_digital_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['0', '0'], + ['1', '1'], + ], + value: '1', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + NUM: 0, + }, + func: (sprite, script) => { + return script.getStringField('NUM'); + }, + }, + robokit_rs_menu_motor_number: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['1', '1'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ], + value: '1', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + NUM: 0, + }, + func: (sprite, script) => { + return script.getStringField('NUM'); + }, + }, + robokit_rs_set_digital: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + } + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin', + }, + { + type: 'robokit_rs_menu_digital_value', + }, + null, + ], + type: 'robokit_rs_set_digital', + }, + paramsKeyMap: { + PIN: 0, + VALUE: 1, + }, + class: 'motion', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_digital(sprite, script), + }, + robokit_rs_set_motor: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_motor_state_cw, 'cw'], + [Lang.Blocks.robokit_rs_motor_state_ccw, 'ccw'], + [Lang.Blocks.robokit_rs_motor_state_stop, 'stop'], + ], + value: 'cw', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_motor_number' + }, + { + type: 'number', + params: ['15'], + }, + null, + null, + + ], + type: 'robokit_rs_set_motor', + }, + paramsKeyMap: { + MOTOR: 0, + SPEED: 1, + STATE: 2, + }, + class: 'motion', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_motor(sprite, script) + }, + robokit_rs_set_motors: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['1, 2', '12'], + ['3, 4', '34'] + ], + value: '12', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_motors_state_forward, 'forward'], + [Lang.Blocks.robokit_rs_motors_state_backward, 'backward'], + [Lang.Blocks.robokit_rs_motors_state_turn_left, 'turn-left'], + [Lang.Blocks.robokit_rs_motors_state_turn_right, 'turn-right'], + [Lang.Blocks.robokit_rs_motors_state_stop, 'stop'], + ], + value: 'forward', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + { + type: 'number', + params: ['15'], + }, + { + type: 'number', + params: ['15'], + }, + null, + null, + + ], + type: 'robokit_rs_set_motors', + }, + paramsKeyMap: { + MOTORS: 0, + SPEED1: 1, + SPEED2: 2, + STATE: 3, + }, + class: 'motion', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_motors(sprite, script) + }, + robokit_rs_set_mecanumwheels: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_mecanumwheels_state_0, '0'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_180, '180'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_270, '270'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_90, '90'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_45, '45'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_135, '135'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_315, '315'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_225, '225'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_cw, 'cw'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_ccw, 'ccw'], + [Lang.Blocks.robokit_rs_mecanumwheels_state_stop, 'stop'], + ], + value: '0', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'number', + params: ['15'], + }, + null, + null, + + ], + type: 'robokit_rs_set_mecanumwheels', + }, + paramsKeyMap: { + SPEED: 0, + STATE: 1, + }, + class: 'motion', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_mecanumwheels(sprite, script) + }, + robokit_rs_set_servo_angle: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin' + }, + { + type: 'number', + params: ['0'], + }, + null, + + ], + type: 'robokit_rs_set_servo_angle', + }, + paramsKeyMap: { + PIN: 0, + ANGLE: 1, + }, + class: 'motion', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_servo_angle(sprite, script) + }, + robokit_rs_set_rgbled_color: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Color', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin' + }, + null, + null, + + ], + type: 'robokit_rs_set_rgbled_color', + }, + paramsKeyMap: { + PIN: 0, + COLOR: 1, + }, + class: 'looks', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_rgbled_color(sprite, script) + }, + robokit_rs_change_rgbled_brightness_by: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin' + }, + { + type: 'number', + params: ['10'], + }, + null, + + ], + type: 'robokit_rs_change_rgbled_brightness_by', + }, + paramsKeyMap: { + PIN: 0, + BRIGHTNESS: 1, + }, + class: 'looks', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.change_rgbled_brightness_by(sprite, script) + }, + robokit_rs_set_rgbled_brightness_to: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin' + }, + { + type: 'number', + params: ['100'], + }, + null, + + ], + type: 'robokit_rs_set_rgbled_brightness_to', + }, + paramsKeyMap: { + PIN: 0, + BRIGHTNESS: 1, + }, + class: 'looks', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_rgbled_brightness_to(sprite, script) + }, + robokit_rs_set_dot_state_of_dotmatrix: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'robokit_rs_menu_digital_value', + }, + null, + ], + type: 'robokit_rs_set_dot_state_of_dotmatrix', + }, + paramsKeyMap: { + X: 0, + Y: 1, + STATE: 2, + }, + class: 'looks_dot_matrix', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_dot_state_of_dotmatrix(sprite, script) + }, + robokit_rs_set_dotmatrix_row: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['0', '0'], + ['1', '1'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ], + value: '0', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + { + type: 'number', + params: ['0'], + }, + null, + + ], + type: 'robokit_rs_set_dotmatrix_row', + }, + paramsKeyMap: { + Y: 0, + X0: 1, X1: 2, X2: 3, X3: 4, X4: 5, X5: 6, X6: 7, X7: 8, X8: 9, X9: 10, X10: 11, X11: 12, X12: 13, X13: 14, X14: 15, X15: 16, + }, + class: 'looks_dot_matrix', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_dotmatrix_row(sprite, script) + }, + robokit_rs_set_dotmatrix: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_dotmatrix_example_eighth_note, '000000000000000000000011000000000000010100000000000010100000000001110100000000011110000000000001100000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_sixteenth_note, '000000001111000000000011001000000000010001000000000010011000000001110111000000011110111000000001100000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_square, '000111111111000000111111111000000110000011000000110000011000000110000011000000111111111000000111111111000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_triangle, '000000010000000000000111000000000001101100000000011000110000000110000011000001100000001100001111111111100'], + [Lang.Blocks.robokit_rs_dotmatrix_example_circle, '000001111100000000011000110000000110000011000000100000001000000110000011000000011000110000000001111100000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_heart, '000011000110000000111101111000001111111111100001111111111100000111111111000000001111100000000000010000000'], + ['X', '000110000011000000011000110000000001111100000000000111000000000001111100000000011000110000000110000011000'], + ['A', '000000111000000000001000100000000001000100000000001111100000000001000100000000001000100000000001000100000'], + ['B', '000001111000000000001000100000000001000100000000001111100000000001000100000000001000100000000001111000000'], + ['C', '000000111000000000001000100000000001000000000000001000000000000001000000000000001000100000000000111000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_ga, '000000000000000000011101000000000000101000000000000101100000000001001000000000000001000000000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_na, '000000000000000000010001000000000010001000000000010001100000000011101000000000000001000000000000000000000'], + ['!', '000000010000000000000010000000000000010000000000000010000000000000010000000000000000000000000000010000000'], + ['?', '000000111000000000001000100000000000000100000000000001000000000000010000000000000000000000000000010000000'], + ['0', '000001111100000000001000100000000001000100000000001000100000000001000100000000001000100000000001111100000'], + ['1', '000000010000000000000110000000000001010000000000000010000000000000010000000000000010000000000001111100000'], + ['2', '000001111100000000000000100000000000000100000000001111100000000001000000000000001000000000000001111100000'], + ['3', '000001111100000000000000100000000000000100000000001111100000000000000100000000000000100000000001111100000'], + ['4', '000001000100000000001000100000000001000100000000001000100000000001111110000000000000100000000000000100000'], + ['5', '000001111100000000001000000000000001000000000000001111100000000000000100000000000000100000000001111100000'], + ['6', '000001111100000000001000000000000001000000000000001111100000000001000100000000001000100000000001111100000'], + ['7', '000001111100000000001000100000000001000100000000000000100000000000000100000000000000100000000000000100000'], + ['8', '000001111100000000001000100000000001000100000000001111100000000001000100000000001000100000000001111100000'], + ['9', '000001111100000000001000100000000001000100000000001111100000000000000100000000000000100000000001111100000'], + ['10', '000010001111100000110001000100001010001000100000010001000100000010001000100000010001000100001111101111100'], + [Lang.Blocks.robokit_rs_dotmatrix_example_speech_bubble, '111111111111111100000000000001100111111111001100000000000001111110011111111000010100000000000011000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_looking_at_top_right, '011111000111110111100101111001111100101111001111111101111111111111101111111111111101111111011111000111110'], + [Lang.Blocks.robokit_rs_dotmatrix_example_looking_at_bottom_right, '011111000111110111111101111111111111101111111111111101111111111100101111001111100101111001011111000111110'], + [Lang.Blocks.robokit_rs_dotmatrix_example_looking_at_top_left, '011111000111110100111101001111100111101001111111111101111111111111101111111111111101111111011111000111110'], + [Lang.Blocks.robokit_rs_dotmatrix_example_looking_at_bottom_left, '011111000111110111111101111111111111101111111111111101111111100111101001111100111101001111011111000111110'], + [Lang.Blocks.robokit_rs_dotmatrix_example_square_basic, '111111111111111100000000000001100100000001001100000000000001100111111111001100000000000001111111111111111'], + [Lang.Blocks.robokit_rs_dotmatrix_example_square_basic_2, '111111111111111100000000000001101111000111101100110000011001100110010011001100000000000001111111111111111'], + [Lang.Blocks.robokit_rs_dotmatrix_example_square_square_eyes, '111111111111111100000000000001101111000111101101001000100101101111010111101100000000000001111111111111111'], + [Lang.Blocks.robokit_rs_dotmatrix_example_square_surprised_mouth, '111111111111111100000000000001100100111001001100000101000001100000101000001100000111000001111111111111111'], + [Lang.Blocks.robokit_rs_dotmatrix_example_big_round_eyes, '001111000111100011111101111110011111101111110011111101111110011111101111110011111101111110001111000111100'], + [Lang.Blocks.robokit_rs_dotmatrix_example_small_round_eyes, '000000000000000001111000111100011111101111110011111101111110011111101111110001111000111100000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_wink_right_eye, '000000000000000001111000000000011111100000000011111100111100011111101111110001111000111100000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_wink_left_eye, '000000000000000000000000111100000000001111110001111001111110011111101111110001111000111100000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_eyebrow_eye_right, '111111000111111000000000000000111111000111111011101000111010011111000111110011110000011110000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_eyebrow_eye_left, '111111000111111000000000000000111111000111111010111000101110011111000111110011110000011110000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_expressionless, '000000000000000011111000111110000000000000000000111000111000000111000111000000111000111000000111000111000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_cutie, '000000000000000001110000011100001110000011100001010010010100001110010011100000000101000000000011000110000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_cute, '001000000000100000100000001000000010000010000000100000001000001000010000100000000000000000000111111111000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_small_eyes_smile, '000000000000000000100000001000000100000001000000000000000000001111111111100001111111111100000111111111000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_half_moon_shape_eyes, '000000000000000001111000111100011111101111110010000101000010000000000000000000000000000000000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_half_moon_shape_eyes_smiling, '001111000111100011111101111110010000101000010000000000000000001100000001100000110000011000000011111110000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_half_moon_shape_eyes_closed, '000000000000000000000000000000000000000000000010000101000010011111101111110001111000111100000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_sad_expression, '000000000000000000010000010000000100000001000001000000000100010110000011010000110000011000000110000011000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_sullen, '000000000000000001100000001100011110000011110011110000011110001100111001100000001111100000000011000110000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_crying_eyes, '000000000000000000000000000000011111000111110001010000010100001010000010100001010000010100000000000000000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_melancholy_look, '011111000111110001100000001100001100000001100000001111100000000011000110000000110000011000000100000001000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_angry_eyes, '100000000000001010000000000010001000000000100000100000001000011010000010110011001000100110011000000000110'], + [Lang.Blocks.robokit_rs_dotmatrix_example_o_shape_mouth, '000000000000000001100000001100011010000011010011110000011110001100010001100000000010000000000001111100000'], + [Lang.Blocks.robokit_rs_dotmatrix_example_yo_shape_mouth, '000000000000000010001000100010010001000100010001110000011100000000000000000000000101000000000000111000000'], + ['↑', '000000010000000000000111000000000001010100000000000010000000000000010000000000000010000000000000010000000'], + ['↗', '000000011110000000000000110000000000001010000000000010010000000000100000000000001000000000000010000000000'], + ['→', '000000000000000000000001000000000000000100000000011111110000000000000100000000000001000000000000000000000'], + ['↘', '000010000000000000001000000000000000100000000000000010010000000000001010000000000000110000000000011110000'], + ['↓', '000000010000000000000010000000000000010000000000000010000000000001010100000000000111000000000000010000000'], + ['↙', '000000000010000000000000100000000000001000000000010010000000000010100000000000011000000000000011110000000'], + ['←', '000000000000000000000100000000000001000000000000011111110000000001000000000000000100000000000000000000000'], + ['↖', '000011110000000000011000000000000010100000000000010010000000000000001000000000000000100000000000000010000'], + ], + value: '000000000000000000000011000000000000010100000000000010100000000001110100000000011110000000000001100000000', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + null, + ], + type: 'robokit_rs_set_dotmatrix', + }, + paramsKeyMap: { + MATRIX: 0 + }, + class: 'looks_dot_matrix', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.set_dotmatrix(sprite, script) + }, + robokit_rs_clear_dotmatrix: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + ], + type: 'robokit_rs_clear_dotmatrix', + }, + paramsKeyMap: {}, + class: 'looks_dot_matrix', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.clear_dotmatrix(sprite, script) + }, + robokit_rs_play_piezobuzzer: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['1', '1'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ], + value: '4', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_piezobuzzer_tone_c, '0'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_c_sharp, '1'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_d, '2'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_d_sharp, '3'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_e, '4'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_f, '5'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_f_sharp, '6'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_g, '7'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_g_sharp, '8'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_a, '9'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_a_sharp, '10'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_b, '11'], + ], + value: '0', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin' + }, + null, + null, + { + type: 'number', + params: ['0.5'], + }, + null, + + ], + type: 'robokit_rs_play_piezobuzzer', + }, + paramsKeyMap: { + PIN: 0, + OCTAVE: 1, + NOTE: 2, + DURATION: 3, + }, + class: 'sound', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.play_piezobuzzer(sprite, script) + }, + robokit_rs_play_piezobuzzer_until_done: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['1', '1'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ], + value: '4', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_piezobuzzer_tone_c, '0'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_c_sharp, '1'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_d, '2'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_d_sharp, '3'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_e, '4'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_f, '5'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_f_sharp, '6'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_g, '7'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_g_sharp, '8'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_a, '9'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_a_sharp, '10'], + [Lang.Blocks.robokit_rs_piezobuzzer_tone_b, '11'], + ], + value: '0', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin' + }, + null, + null, + { + type: 'number', + params: ['0.5'], + }, + null, + + ], + type: 'robokit_rs_play_piezobuzzer_until_done', + }, + paramsKeyMap: { + PIN: 0, + OCTAVE: 1, + NOTE: 2, + DURATION: 3, + }, + class: 'sound', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.play_piezobuzzer_until_done(sprite, script) + }, + robokit_rs_get_digital_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin', + }, + ], + type: 'robokit_rs_get_digital_value', + }, + paramsKeyMap: { + PIN: 0, + }, + class: 'sensing', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.get_digital_value(sprite, script), + }, + robokit_rs_get_analog_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_analog_pin', + }, + ], + type: 'robokit_rs_get_analog_value', + }, + paramsKeyMap: { + PIN: 0, + }, + class: 'sensing', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.get_analog_value(sprite, script), + }, + robokit_rs_get_sensor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_sensor_temperutre, 'temperature'], + [Lang.Blocks.robokit_rs_sensor_joystick_x, 'joystickx'], + [Lang.Blocks.robokit_rs_sensor_joystick_y, 'joysticky'], + [Lang.Blocks.robokit_rs_sensor_light, 'light'], + [Lang.Blocks.robokit_rs_sensor_dial, 'dial'], + [Lang.Blocks.robokit_rs_sensor_a_keypad, 'akeypad'], + [Lang.Blocks.robokit_rs_sensor_rotaryposition, 'rotaryposition'], + [Lang.Blocks.robokit_rs_sensor_magnetic, 'magnetic'], + [Lang.Blocks.robokit_rs_sensor_ultrasonic, 'ultrasonic'], + ], + value: 'temperature', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_pin', + }, + null, + ], + type: 'robokit_rs_get_sensor_value', + }, + paramsKeyMap: { + PIN: 0, + SENSOR: 1, + }, + class: 'sensing', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.get_sensor_value(sprite, script) + }, + robokit_rs_is_digital_detected: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_digital_pin', + }, + ], + type: 'robokit_rs_is_digital_detected', + }, + paramsKeyMap: { + PIN: 0, + }, + class: 'sensing', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.is_digital_detected(sprite, script), + }, + robokit_rs_compare_analog_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['>', 'greater-than'], + ['=', 'equal'], + ['<', 'less-than'], + ], + value: 'greater-than', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_analog_pin', + }, + null, + { + type: 'number', + params: ['512'], + }, + ], + type: 'robokit_rs_compare_analog_value', + }, + paramsKeyMap: { + PIN: 0, + SYMBOL: 1, + VALUE: 2, + }, + class: 'sensing', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.compare_analog_value(sprite, script), + }, + robokit_rs_compare_sensor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_sensor_temperutre, 'temperature'], + [Lang.Blocks.robokit_rs_sensor_joystick_x, 'joystickx'], + [Lang.Blocks.robokit_rs_sensor_joystick_y, 'joysticky'], + [Lang.Blocks.robokit_rs_sensor_light, 'light'], + [Lang.Blocks.robokit_rs_sensor_dial, 'dial'], + [Lang.Blocks.robokit_rs_sensor_a_keypad, 'akeypad'], + [Lang.Blocks.robokit_rs_sensor_rotaryposition, 'rotaryposition'], + [Lang.Blocks.robokit_rs_sensor_magnetic, 'magnetic'], + [Lang.Blocks.robokit_rs_sensor_ultrasonic, 'ultrasonic'], + ], + value: 'temperature', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + ['>', 'greater-than'], + ['=', 'equal'], + ['<', 'less-than'], + ], + value: 'greater-than', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_pin', + }, + null, + null, + { + type: 'number', + params: ['0'], + }, + ], + type: 'robokit_rs_compare_sensor_value', + }, + paramsKeyMap: { + PIN: 0, + SENSOR: 1, + SYMBOL: 2, + VALUE: 3, + }, + class: 'sensing', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.compare_sensor_value(sprite, script), + }, + robokit_rs_get_gyro_sensor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_sensor_gyroscope_angle_x, "anglex"], + [Lang.Blocks.robokit_rs_sensor_gyroscope_angle_y, "angley"], + [Lang.Blocks.robokit_rs_sensor_gyroscope_angle_z, "anglez"], + [Lang.Blocks.robokit_rs_sensor_gyroscope_x, "gyrox"], + [Lang.Blocks.robokit_rs_sensor_gyroscope_y, "gyroy"], + [Lang.Blocks.robokit_rs_sensor_gyroscope_z, "gyroz"], + [Lang.Blocks.robokit_rs_sensor_gyroscope_shake, "shake"] + ], + value: 'anglex', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [ + null, + null, + ], + type: 'robokit_rs_get_gyro_sensor_value', + }, + paramsKeyMap: { + PROPERTY: 0, + }, + class: 'sensing_gyro_sensor', + isNotFor: ['roborobo_robokit_rs'], + + func: (sprite, script) => this.get_gyro_sensor_value(sprite, script), + }, + robokit_rs_is_shaken_gyro_sensor: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [], + events: {}, + def: { + params: [], + type: 'robokit_rs_is_shaken_gyro_sensor', + }, + paramsKeyMap: {}, + class: 'sensing_gyro_sensor', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.is_shaken_gyro_sensor(sprite, script) + }, + robokit_rs_reset_gyro_sensor: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_sensor_gyroscope_direction_up, 'up'], + [Lang.Blocks.robokit_rs_sensor_gyroscope_direction_forward, 'forward'], + [Lang.Blocks.robokit_rs_sensor_gyroscope_direction_right, 'right'], + [Lang.Blocks.robokit_rs_sensor_gyroscope_direction_backward, 'backward'], + [Lang.Blocks.robokit_rs_sensor_gyroscope_direction_left, 'left'] + ], + value: 'up', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + null, + ], + type: 'robokit_rs_reset_gyro_sensor', + }, + paramsKeyMap: { + DIRECTION: 0, + }, + class: 'sensing_gyro_sensor', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.reset_gyro_sensor(sprite, script) + }, + + robokit_rs_get_rotary_position_sensor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_sensor_rotaryposition_rotation, 'rotation'], + [Lang.Blocks.robokit_rs_sensor_rotaryposition_position, 'position'], + [Lang.Blocks.robokit_rs_sensor_rotaryposition_angle, 'angle'] + ], + value: 'rotation', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_analog_pin', + }, + null, + ], + type: 'robokit_rs_get_rotary_position_sensor_value', + }, + paramsKeyMap: { + PIN: 0, + PROPERTY: 1, + }, + class: 'sensing_rotary_position_sensor', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.get_rotary_position_sensor_value(sprite, script) + }, + + robokit_rs_reset_rotary_position_sensor: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.robokit_rs_sensor_rotaryposition_rotation, 'rotation'], + [Lang.Blocks.robokit_rs_sensor_rotaryposition_position, 'position'], + [Lang.Blocks.robokit_rs_sensor_rotaryposition_angle, 'angle'] + ], + value: 'rotation', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'robokit_rs_menu_analog_pin', + }, + null, + { + type: 'number', + params: ['0'], + }, + null, + ], + type: 'robokit_rs_reset_rotary_position_sensor', + }, + paramsKeyMap: { + PIN: 0, + PROPERTY: 1, + VALUE: 2, + }, + class: 'sensing_rotary_position_sensor', + isNotFor: ['roborobo_robokit_rs'], + func: (sprite, script) => this.reset_rotary_position_sensor(sprite, script) + }, + }; + }; + + setZero () { + super.setZero(); + } + + afterReceive (data) { + super.afterReceive(data); + } + + afterSend () { + super.afterSend(); + } + + request (func, subkey, value, updateNow = false) { + super.request(func, subkey, value, updateNow); + } + + /** + * -----------------------------------block execute----------------------------------- + * 공통 사용 함수를 제외한 나머지 블록 동작을 작성 + * ----------------------------------------------------------------------------------- + */ + + set_mecanumwheels (sprite, script) { + const speed = script.getNumberValue('SPEED'); + const state = script.getStringValue('STATE'); + + let data = [] + for (let i = 0; i < 4; i++) { + data[i] = {motor: i + 1, speed: speed, state: 0} + } + + switch (state) { + case '0': { + data[0].state = 2; + data[1].state = 1; + data[2].state = 2; + data[3].state = 1; + } + break; + case '45': { + data[0].state = 2; + data[3].state = 1; + } + break; + case '90': { + data[0].state = 2; + data[1].state = 2; + data[2].state = 1; + data[3].state = 1; + } + break; + case '135': { + data[1].state = 2; + data[2].state = 1; + } + break; + case '180': { + data[0].state = 1; + data[1].state = 2; + data[2].state = 1; + data[3].state = 2; + } + break; + case '225': { + data[0].state = 1; + data[3].state = 2; + } + break; + case '270': { + data[0].state = 1; + data[1].state = 1; + data[2].state = 2; + data[3].state = 2; + } + break; + case '315': { + data[1].state = 1; + data[2].state = 2; + } + break; + case 'cw': { + data[0].state = 2; + data[1].state = 2; + data[2].state = 2; + data[3].state = 2; + } + break; + case 'ccw': { + data[0].state = 1; + data[1].state = 1; + data[2].state = 1; + data[3].state = 1; + } + break; + case 'stop': + break; + } + + for (let i = 0; i < 4; i++) { + this.request('setMotor', i + 1, data[i]); + } + return script.callReturn(); + } + + set_dot_state_of_dotmatrix (sprite, script) { + const x = script.getNumberValue('X'); + const y = script.getNumberValue('Y'); + const state = script.getNumberValue('STATE'); + if (x < 0 || x > 14 || y < 0 || y > 6) return script.callReturn(); + + this.request('setDotMatrix', null, {type: 'dot', x, y, dot: Math.min(1, Math.max(0, state)).toString()}, true); + return script.callReturn(); + } + + set_dotmatrix_row (sprite, script) { + const y = script.getNumberValue('Y'); + let dots = ''; + for (let i = 0; i < 16; i++) { + const value = script.getNumberValue('X' + i); + dots += Math.max(0, Math.min(1, value)).toString(); + } + + this.request('setDotMatrix', null, {type: 'row', y, dots}, true); + return script.callReturn(); + } + + set_dotmatrix (sprite, script) { + const example = script.getStringValue('MATRIX') + this.request('setDotMatrix', null, {type: 'all', dots: example}, true); + return script.callReturn(); + } + + clear_dotmatrix (sprite, script) { + const length = 15 * 7; + let dots = ''; + for (let i = 0; i < length; i++) {dots += 0;} + + this.request('setDotMatrix', null, {type: 'all', dots}); + return script.callReturn(); + } + + get_gyro_sensor_value (sprite, script) { + const type = script.getStringValue('PROPERTY'); + + const obj = this.state.rx.gyro; + if (!this.isEqualsPinMode(18, PinMode.I2C) || !this.isEqualsPinMode(19, PinMode.I2C) || !obj || !obj.enable) { + this.request('enableGyroSensor', null, null, true); + } + + if (!obj) return 0; + switch (type) { + case 'anglex': return obj.angle.x; + case 'angley': return obj.angle.y; + case 'anglez': return obj.angle.z; + case 'gyrox': return obj.gyro.x; + case 'gyroy': return obj.gyro.y; + case 'gyroz': return obj.gyro.z; + case 'shake': return obj.shake; + default: return 0; + } + } + + is_shaken_gyro_sensor (sprite, script) { + const obj = this.state.rx.gyro; + + if (!this.isEqualsPinMode(18, PinMode.I2C) || !this.isEqualsPinMode(19, PinMode.I2C) || !obj || !obj.enable) { + this.request('enableGyroSensor', null, null, true); + } + + return obj ? obj.shake == 1 : false; + } + + reset_gyro_sensor (sprite, script) { + const dir = script.getStringValue('DIRECTION'); + let dirNum = 0; + switch (dir) { + case 'up': + dirNum = 0; + break; + case 'forward': + dirNum = 1; + break; + case 'right': + dirNum = 2; + break; + case 'backward': + dirNum = 3; + break; + case 'left': + dirNum = 4; + break; + } + this.request('resetGyroSensor', null, {direction: dirNum}, true); + return new Promise(resolve => setTimeout(() => resolve(), 500)); + } +} + +module.exports = new RobokitRS(); \ No newline at end of file diff --git a/src/playground/blocks/hardware/block_roborobo_roduino.js b/src/playground/blocks/hardware/block_roborobo_roduino.js new file mode 100644 index 0000000000..034c6e2bad --- /dev/null +++ b/src/playground/blocks/hardware/block_roborobo_roduino.js @@ -0,0 +1,1340 @@ +'use strict'; +const {ArduinoBase} = require('./block_roborobo_base.js'); + +class Roduino extends ArduinoBase { + constructor () { + super(); + + this.id = '10.1'; + this.name = 'roborobo_roduino'; + this.url = 'http://www.roborobo.co.kr'; + this.imageName = 'roborobo_roduino.png'; + this.title = { + ko: '로두이노', + en: 'Roduino', + } + this.blockMenuBlocks = this.getBlockMenuBlocks(); + } + + /** + * 언어 번역 사용을 위해 함수 형태로 유지 + */ + monitorTemplate () { + return { + //imgPath: 'hw/~~.png', + //width: 256, + //height: 256, + // 모니터 화면 상단에 차례대로 나열하는 값 + listPorts: { + digital_2: {name: (Lang.Blocks.monitor_digital + ': 2'), type: 'input', pos: {x: 0, y: 0, }}, + digital_3: {name: (Lang.Blocks.monitor_digital + ': 3'), type: 'input', pos: {x: 0, y: 0, }}, + digital_4: {name: (Lang.Blocks.monitor_digital + ': 4'), type: 'input', pos: {x: 0, y: 0, }}, + digital_5: {name: (Lang.Blocks.monitor_digital + ': 5'), type: 'input', pos: {x: 0, y: 0, }}, + digital_6: {name: (Lang.Blocks.monitor_digital + ': 6'), type: 'input', pos: {x: 0, y: 0, }}, + digital_7: {name: (Lang.Blocks.monitor_digital + ': 7'), type: 'input', pos: {x: 0, y: 0, }}, + digital_8: {name: (Lang.Blocks.monitor_digital + ': 8'), type: 'input', pos: {x: 0, y: 0, }}, + analog_0: {name: (Lang.Blocks.monitor_analog + ': A0'), type: 'input', pos: {x: 0, y: 0, }}, + analog_1: {name: (Lang.Blocks.monitor_analog + ': A1'), type: 'input', pos: {x: 0, y: 0, }}, + analog_2: {name: (Lang.Blocks.monitor_analog + ': A2'), type: 'input', pos: {x: 0, y: 0, }}, + analog_3: {name: (Lang.Blocks.monitor_analog + ': A3'), type: 'input', pos: {x: 0, y: 0, }}, + analog_4: {name: (Lang.Blocks.monitor_analog + ': A4'), type: 'input', pos: {x: 0, y: 0, }}, + analog_5: {name: (Lang.Blocks.monitor_analog + ': A5'), type: 'input', pos: {x: 0, y: 0, }}, + }, + // 모니터 화면 지정 위치와 선으로 연결하여 표시하는 값 + ports: {}, + mode: 'both', + } + } + + getBlockMenuBlocks () { + return [ + 'roduino_menu_digital_pin', + 'roduino_menu_analog_pin', + 'roduino_menu_pin', + 'roduino_menu_digital_value', + 'roduino_menu_motor_number', + + 'roduino_set_digital', + 'roduino_set_motor_rotation', + 'roduino_set_rgbled_color', + 'roduino_change_rgbled_brightness_by', + 'roduino_set_rgbled_brightness_to', + 'roduino_play_piezobuzzer', + 'roduino_play_piezobuzzer_until_done', + 'roduino_get_digital_value', + 'roduino_get_analog_value', + 'roduino_get_sensor_value', + 'roduino_is_digital_detected', + 'roduino_compare_analog_value', + 'roduino_compare_sensor_value', + 'roduino_get_rotary_position_sensor_value', + 'roduino_reset_rotary_position_sensor', + 'roduino_get_color_sensor_detected_value', + 'roduino_is_color_sensor_detected', + 'roduino_set_color_sensor_pins', + ]; + } + + setLanguage () { + return { + ko: { + template: { + roduino_menu_digital_pin: '%1', + roduino_menu_analog_pin: '%1', + roduino_menu_pin: '%1', + roduino_menu_digital_value: '%1', + roduino_menu_motor_number: '%1', + + roduino_set_digital: '%1 번 핀 디지털 값을 %2 (으)로 정하기 %3', + roduino_set_motor_rotation: '%1 번 모터를 %2 하기 %3', + roduino_set_rgbled_color: '%1 번 핀 RGB LED 색상을 %2 색으로 정하기 %3', + roduino_change_rgbled_brightness_by: '%1 번 핀 RGB LED 밝기를 %2 만큼 바꾸기 %3', + roduino_set_rgbled_brightness_to: '%1 번 핀 RGB LED 밝기를 %2 %로 정하기 %3', + roduino_play_piezobuzzer: '%1 번 핀 피에조 버저로 %2 옥타브 %3 음을 %4 초 소리내기 %5', + roduino_play_piezobuzzer_until_done: '%1 번 핀 피에조 버저로 %2 옥타브 %3 음을 %4 초 소리내며 기다리기 %5', + roduino_get_digital_value: '%1 번 핀 디지털 값', + roduino_get_analog_value: '%1 번 핀 아날로그 값', + roduino_get_sensor_value: '%1 번 핀 %2 값', + roduino_is_digital_detected: '%1 번 핀이 감지되었는가?', + roduino_compare_analog_value: '%1 번 핀 아날로그 값 %2 %3', + roduino_compare_sensor_value: '%1 번 핀 %2 값 %3 %4', + roduino_get_rotary_position_sensor_value: '%1 번 핀 회전 위치 센서 %2 값', + roduino_reset_rotary_position_sensor: '%1 번 핀 회전 위치 센서 %2 값을 %3 (으)로 정하기 %4', + roduino_get_color_sensor_detected_value: '%1 감지 값', + roduino_is_color_sensor_detected: '%1 이 감지되었는가?', + roduino_set_color_sensor_pins: '컬러 센서 핀을 R: %1 G: %2 B: %3 번으로 정하기 %4', + }, + Blocks: { + monitor_digital: '디지털', + monitor_analog: '아날로그', + + roduino_motor_state_cw: '시계 방향 회전', + roduino_motor_state_ccw: '시계 반대 방향 회전', + roduino_motor_state_stop: '정지', + + roduino_piezobuzzer_tone_c: '도', + roduino_piezobuzzer_tone_c_sharp: '도♯(레♭)', + roduino_piezobuzzer_tone_d: '레', + roduino_piezobuzzer_tone_d_sharp: '레♯(미♭)', + roduino_piezobuzzer_tone_e: '미', + roduino_piezobuzzer_tone_f: '파', + roduino_piezobuzzer_tone_f_sharp: '파♯(솔♭)', + roduino_piezobuzzer_tone_g: '솔', + roduino_piezobuzzer_tone_g_sharp: '솔♯(라♭)', + roduino_piezobuzzer_tone_a: '라', + roduino_piezobuzzer_tone_a_sharp: '라♯(시♭)', + roduino_piezobuzzer_tone_b: '시', + + roduino_sensor_temperutre: '온도 센서', + roduino_sensor_joystick_x: '조이스틱 x', + roduino_sensor_joystick_y: '조이스틱 y', + roduino_sensor_light: '빛 센서', + roduino_sensor_dial: '다이얼', + roduino_sensor_a_keypad: 'A 키패드', + roduino_sensor_rotaryposition: '회전 위치 센서', + roduino_sensor_magnetic: '자기 센서', + roduino_sensor_ultrasonic: '초음파 센서', + + roduino_sensor_rotaryposition_rotation: '회전', + roduino_sensor_rotaryposition_position: '위치', + roduino_sensor_rotaryposition_angle: '각도', + + roduino_sensor_color_red: '빨간색', + roduino_sensor_color_yellow: '노란색', + roduino_sensor_color_green: '초록색', + roduino_sensor_color_blue: '파란색', + }, + }, + en: { + template: { + roduino_menu_digital_pin: '%1', + roduino_menu_analog_pin: '%1', + roduino_menu_pin: '%1', + roduino_menu_digital_value: '%1', + roduino_menu_motor_number: '%1', + + roduino_set_digital: 'set pin %1 digital value to %2 %3', + roduino_set_motor_rotation: 'set %1 the %2 motor %3', + roduino_set_rgbled_color: 'set %1 pin RGB LED color to the %2 color %3', + roduino_change_rgbled_brightness_by: 'change pin %1 RGB LED brightness by %2 %3', + roduino_set_rgbled_brightness_to: 'set pin %1 RGB LED brightness to %2 % %3', + roduino_play_piezobuzzer: 'Play pin %1 peizo buzzer with %2 otave %3 note for %4 sec %5', + roduino_play_piezobuzzer_until_done: 'Play pin %1 peizo buzzer with %2 otave %3 note for %4 sec and wait %5', + roduino_get_digital_value: 'pin %1 digital value', + roduino_get_analog_value: 'pin %1 analog value', + roduino_get_sensor_value: 'pin %1 %2 value', + roduino_is_digital_detected: 'pin %1 detected?', + roduino_compare_analog_value: 'pin %1 analog value %2 %3', + roduino_compare_sensor_value: 'pin %1 %2 value %3 %4', + roduino_get_rotary_position_sensor_value: 'rotary position sensor of pin %1 %2 value', + roduino_reset_rotary_position_sensor: 'rotary position sensor of pin %1 set %2 value to %3 %4', + roduino_get_color_sensor_detected_value: '%1 detection value', + roduino_is_color_sensor_detected: 'is %1 detected?', + roduino_set_color_sensor_pins: 'set color sensor pins to R: %1 G: %2 B: %3 %4', + }, + Blocks: { + monitor_digital: 'Digital', + monitor_analog: 'Analog', + + roduino_motor_state_cw: 'rotate clockwise', + roduino_motor_state_ccw: 'rotate counterclockwise', + roduino_motor_state_stop: 'stop', + + roduino_piezobuzzer_tone_c: 'C', + roduino_piezobuzzer_tone_c_sharp: 'C♯(D♭)', + roduino_piezobuzzer_tone_d: 'D', + roduino_piezobuzzer_tone_d_sharp: 'D♯(E♭)', + roduino_piezobuzzer_tone_e: 'E', + roduino_piezobuzzer_tone_f: 'F', + roduino_piezobuzzer_tone_f_sharp: 'F♯(G♭)', + roduino_piezobuzzer_tone_g: 'G', + roduino_piezobuzzer_tone_g_sharp: 'G♯(A♭)', + roduino_piezobuzzer_tone_a: 'A', + roduino_piezobuzzer_tone_a_sharp: 'A♯(B♭)', + roduino_piezobuzzer_tone_b: 'B', + + roduino_sensor_temperutre: 'temperature sensor', + roduino_sensor_joystick_x: 'joystick x', + roduino_sensor_joystick_y: 'joystick y', + roduino_sensor_light: 'light sensor', + roduino_sensor_dial: 'dial', + roduino_sensor_a_keypad: 'A keypad', + roduino_sensor_rotaryposition: 'rotary position sensor', + roduino_sensor_magnetic: 'magnetic sensor', + roduino_sensor_ultrasonic: 'ultrasonic sensor', + + roduino_sensor_rotaryposition_rotation: 'rotation', + roduino_sensor_rotaryposition_position: 'position', + roduino_sensor_rotaryposition_angle: 'angle', + + roduino_sensor_color_red: 'red', + roduino_sensor_color_yellow: 'yellow', + roduino_sensor_color_green: 'green', + roduino_sensor_color_blue: 'blue', + }, + }, + }; + }; + + getBlocks () { + return { + roduino_menu_digital_pin: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ], + value: '2', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PIN: 0, + }, + func: (sprite, script) => { + return script.getStringField('PIN'); + }, + }, + roduino_menu_analog_pin: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['A0', '14'], + ['A1', '15'], + ['A2', '16'], + ['A3', '17'], + ['A4', '18'], + ['A5', '19'], + ], + value: '14', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PIN: 0, + }, + func: (sprite, script) => { + return script.getStringField('PIN'); + }, + }, + roduino_menu_pin: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['A0', '14'], + ['A1', '15'], + ['A2', '16'], + ['A3', '17'], + ['A4', '18'], + ['A5', '19'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ], + value: '14', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PIN: 0, + }, + func: (sprite, script) => { + return script.getStringField('PIN'); + }, + }, + roduino_menu_digital_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['0', '0'], + ['1', '1'], + ], + value: '1', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + NUM: 0, + }, + func: (sprite, script) => { + return script.getStringField('NUM'); + }, + }, + roduino_menu_motor_number: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['1', '1'], + ['2', '2'] + ], + value: '1', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + NUM: 0, + }, + func: (sprite, script) => { + return script.getStringField('NUM'); + }, + }, + roduino_set_digital: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + } + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin', + }, + { + type: 'roduino_menu_digital_value', + }, + null, + ], + type: 'roduino_set_digital', + }, + paramsKeyMap: { + PIN: 0, + VALUE: 1, + }, + class: 'motion', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.set_digital(sprite, script), + }, + roduino_set_motor_rotation: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_motor_state_cw, 'cw'], + [Lang.Blocks.roduino_motor_state_ccw, 'ccw'], + [Lang.Blocks.roduino_motor_state_stop, 'stop'], + ], + value: 'cw', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_motor_number' + }, + null, + null, + + ], + type: 'roduino_set_motor_rotation', + }, + paramsKeyMap: { + MOTOR: 0, + STATE: 1, + }, + class: 'motion', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.set_motor_rotation(sprite, script) + }, + roduino_set_rgbled_color: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Color', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin' + }, + null, + null, + + ], + type: 'roduino_set_rgbled_color', + }, + paramsKeyMap: { + PIN: 0, + COLOR: 1, + }, + class: 'looks', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.set_rgbled_color(sprite, script) + }, + roduino_change_rgbled_brightness_by: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin' + }, + { + type: 'number', + params: ['10'], + }, + null, + + ], + type: 'roduino_change_rgbled_brightness_by', + }, + paramsKeyMap: { + PIN: 0, + BRIGHTNESS: 1, + }, + class: 'looks', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.change_rgbled_brightness_by(sprite, script) + }, + roduino_set_rgbled_brightness_to: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin' + }, + { + type: 'number', + params: ['100'], + }, + null, + + ], + type: 'roduino_set_rgbled_brightness_to', + }, + paramsKeyMap: { + PIN: 0, + BRIGHTNESS: 1, + }, + class: 'looks', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.set_rgbled_brightness_to(sprite, script) + }, + roduino_play_piezobuzzer: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['1', '1'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ], + value: '4', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_piezobuzzer_tone_c, '0'], + [Lang.Blocks.roduino_piezobuzzer_tone_c_sharp, '1'], + [Lang.Blocks.roduino_piezobuzzer_tone_d, '2'], + [Lang.Blocks.roduino_piezobuzzer_tone_d_sharp, '3'], + [Lang.Blocks.roduino_piezobuzzer_tone_e, '4'], + [Lang.Blocks.roduino_piezobuzzer_tone_f, '5'], + [Lang.Blocks.roduino_piezobuzzer_tone_f_sharp, '6'], + [Lang.Blocks.roduino_piezobuzzer_tone_g, '7'], + [Lang.Blocks.roduino_piezobuzzer_tone_g_sharp, '8'], + [Lang.Blocks.roduino_piezobuzzer_tone_a, '9'], + [Lang.Blocks.roduino_piezobuzzer_tone_a_sharp, '10'], + [Lang.Blocks.roduino_piezobuzzer_tone_b, '11'], + ], + value: '0', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin' + }, + null, + null, + { + type: 'number', + params: ['0.5'], + }, + null, + + ], + type: 'roduino_play_piezobuzzer', + }, + paramsKeyMap: { + PIN: 0, + OCTAVE: 1, + NOTE: 2, + DURATION: 3, + }, + class: 'sound', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.play_piezobuzzer(sprite, script) + }, + roduino_play_piezobuzzer_until_done: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['1', '1'], + ['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ], + value: '4', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_piezobuzzer_tone_c, '0'], + [Lang.Blocks.roduino_piezobuzzer_tone_c_sharp, '1'], + [Lang.Blocks.roduino_piezobuzzer_tone_d, '2'], + [Lang.Blocks.roduino_piezobuzzer_tone_d_sharp, '3'], + [Lang.Blocks.roduino_piezobuzzer_tone_e, '4'], + [Lang.Blocks.roduino_piezobuzzer_tone_f, '5'], + [Lang.Blocks.roduino_piezobuzzer_tone_f_sharp, '6'], + [Lang.Blocks.roduino_piezobuzzer_tone_g, '7'], + [Lang.Blocks.roduino_piezobuzzer_tone_g_sharp, '8'], + [Lang.Blocks.roduino_piezobuzzer_tone_a, '9'], + [Lang.Blocks.roduino_piezobuzzer_tone_a_sharp, '10'], + [Lang.Blocks.roduino_piezobuzzer_tone_b, '11'], + ], + value: '0', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin' + }, + null, + null, + { + type: 'number', + params: ['0.5'], + }, + null, + + ], + type: 'roduino_play_piezobuzzer_until_done', + }, + paramsKeyMap: { + PIN: 0, + OCTAVE: 1, + NOTE: 2, + DURATION: 3, + }, + class: 'sound', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.play_piezobuzzer_until_done(sprite, script) + }, + roduino_get_digital_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin', + }, + ], + type: 'roduino_get_digital_value', + }, + paramsKeyMap: { + PIN: 0, + }, + class: 'sensing', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.get_digital_value(sprite, script), + }, + roduino_get_analog_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_analog_pin', + }, + ], + type: 'roduino_get_analog_value', + }, + paramsKeyMap: { + PIN: 0, + }, + class: 'sensing', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.get_analog_value(sprite, script), + }, + roduino_get_sensor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_sensor_temperutre, 'temperature'], + [Lang.Blocks.roduino_sensor_joystick_x, 'joystickx'], + [Lang.Blocks.roduino_sensor_joystick_y, 'joysticky'], + [Lang.Blocks.roduino_sensor_light, 'light'], + [Lang.Blocks.roduino_sensor_dial, 'dial'], + [Lang.Blocks.roduino_sensor_a_keypad, 'akeypad'], + [Lang.Blocks.roduino_sensor_rotaryposition, 'rotaryposition'], + [Lang.Blocks.roduino_sensor_magnetic, 'magnetic'], + [Lang.Blocks.roduino_sensor_ultrasonic, 'ultrasonic'], + ], + value: 'temperature', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_pin', + }, + null, + ], + type: 'roduino_get_sensor_value', + }, + paramsKeyMap: { + PIN: 0, + SENSOR: 1, + }, + class: 'sensing', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.get_sensor_value(sprite, script) + }, + roduino_is_digital_detected: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin', + }, + ], + type: 'roduino_is_digital_detected', + }, + paramsKeyMap: { + PIN: 0, + }, + class: 'sensing', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.is_digital_detected(sprite, script), + }, + roduino_compare_analog_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['>', 'greater-than'], + ['=', 'equal'], + ['<', 'less-than'], + ], + value: 'greater-than', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_analog_pin', + }, + null, + { + type: 'number', + params: ['512'], + }, + ], + type: 'roduino_compare_analog_value', + }, + paramsKeyMap: { + PIN: 0, + SYMBOL: 1, + VALUE: 2, + }, + class: 'sensing', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.compare_analog_value(sprite, script), + }, + roduino_compare_sensor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_sensor_temperutre, 'temperature'], + [Lang.Blocks.roduino_sensor_joystick_x, 'joystickx'], + [Lang.Blocks.roduino_sensor_joystick_y, 'joysticky'], + [Lang.Blocks.roduino_sensor_light, 'light'], + [Lang.Blocks.roduino_sensor_dial, 'dial'], + [Lang.Blocks.roduino_sensor_a_keypad, 'akeypad'], + [Lang.Blocks.roduino_sensor_rotaryposition, 'rotaryposition'], + [Lang.Blocks.roduino_sensor_magnetic, 'magnetic'], + [Lang.Blocks.roduino_sensor_ultrasonic, 'ultrasonic'], + ], + value: 'temperature', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + ['>', 'greater-than'], + ['=', 'equal'], + ['<', 'less-than'], + ], + value: 'greater-than', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_pin', + }, + null, + null, + { + type: 'number', + params: ['0'], + }, + ], + type: 'roduino_compare_sensor_value', + }, + paramsKeyMap: { + PIN: 0, + SENSOR: 1, + SYMBOL: 2, + VALUE: 3, + }, + class: 'sensing', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.compare_sensor_value(sprite, script), + }, + + roduino_get_rotary_position_sensor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_sensor_rotaryposition_rotation, 'rotation'], + [Lang.Blocks.roduino_sensor_rotaryposition_position, 'position'], + [Lang.Blocks.roduino_sensor_rotaryposition_angle, 'angle'] + ], + value: 'rotation', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_analog_pin', + }, + null, + ], + type: 'roduino_get_rotary_position_sensor_value', + }, + paramsKeyMap: { + PIN: 0, + PROPERTY: 1, + }, + class: 'sensing_rotary_position_sensor', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.get_rotary_position_sensor_value(sprite, script) + }, + + roduino_reset_rotary_position_sensor: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_sensor_rotaryposition_rotation, 'rotation'], + [Lang.Blocks.roduino_sensor_rotaryposition_position, 'position'], + [Lang.Blocks.roduino_sensor_rotaryposition_angle, 'angle'] + ], + value: 'rotation', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string', + defualtType: 'number', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_analog_pin', + }, + null, + { + type: 'number', + params: ['0'], + }, + null, + ], + type: 'roduino_reset_rotary_position_sensor', + }, + paramsKeyMap: { + PIN: 0, + PROPERTY: 1, + VALUE: 2, + }, + class: 'sensing_rotary_position_sensor', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.reset_rotary_position_sensor(sprite, script) + }, + roduino_get_color_sensor_detected_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_sensor_color_red, '#FF0000'], + [Lang.Blocks.roduino_sensor_color_yellow, '#FFEE00'], + [Lang.Blocks.roduino_sensor_color_green, '#00AA00'], + [Lang.Blocks.roduino_sensor_color_blue, '#0055FF'], + ], + value: '#FF0000', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [ + null, + ], + type: 'roduino_get_color_sensor_detected_value', + }, + paramsKeyMap: { + COLOR: 0, + }, + class: 'sensing_color_sensor', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.get_color_sensor_detected_value(sprite, script) + }, + roduino_is_color_sensor_detected: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roduino_sensor_color_red, '#FF0000'], + [Lang.Blocks.roduino_sensor_color_yellow, '#FFEE00'], + [Lang.Blocks.roduino_sensor_color_green, '#00AA00'], + [Lang.Blocks.roduino_sensor_color_blue, '#0055FF'], + ], + value: '#FF0000', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [ + null, + ], + type: 'roduino_is_color_sensor_detected', + }, + paramsKeyMap: { + COLOR: 0, + }, + class: 'sensing_color_sensor', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.is_color_sensor_detected(sprite, script) + }, + roduino_set_color_sensor_pins: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'roduino_menu_digital_pin', + params: ['6'], + }, + { + type: 'roduino_menu_digital_pin', + params: ['7'], + }, + { + type: 'roduino_menu_digital_pin', + params: ['8'], + }, + null, + ], + type: 'roduino_set_color_sensor_pins', + }, + paramsKeyMap: { + RED: 0, + GREEN: 1, + BLUE: 2, + }, + class: 'sensing_color_sensor', + isNotFor: ['roborobo_roduino'], + func: (sprite, script) => this.set_color_sensor_pins(sprite, script) + }, + }; + }; + + setZero () { + super.setZero(); + } + + afterReceive (data) { + super.afterReceive(data); + } + + afterSend () { + super.afterSend(); + } + + request (func, subkey, value, updateNow = false) { + super.request(func, subkey, value, updateNow); + } + + resetState () { + super.resetState(); + this.state.tx = {color: {pins: {r: -1, g: -1, b: -1}}}; + } + + /** + * -----------------------------------block execute----------------------------------- + * 공통 사용 함수를 제외한 나머지 블록 동작을 작성 + * ----------------------------------------------------------------------------------- + */ + + set_motor_rotation (sprite, script) { + const motor = script.getNumberValue('MOTOR'); + const state = script.getStringValue('STATE'); + + let stateNum = 0; + if (state == 'cw') stateNum = 1; + else if (state == 'ccw') stateNum = 2; + + this.request('setMotor', motor, {motor, speed: 0, state: stateNum}); + return script.callReturn(); + } + + get_color_sensor_detected_value (sprite, script) { + const color = script.getStringValue('COLOR'); + return this._isColorSensorDetected(color) ? 1 : 0; + } + + is_color_sensor_detected (sprite, script) { + const color = script.getStringValue('COLOR'); + return this._isColorSensorDetected(color); + } + + _isColorSensorDetected (color) { + const pins = this.state.tx.color.pins; + if (!pins || !this.isDigitalPin(pins.r) || !this.isDigitalPin(pins.g) || !this.isDigitalPin(pins.b)) return false; + + const r = this.getDigitalValue(pins.r); + const g = this.getDigitalValue(pins.g); + const b = this.getDigitalValue(pins.b); + + switch (color) { + case '#FF0000': + return r == 1 && g == 0 && b == 0; + case '#00AA00': + return r == 0 && g == 1 && b == 0; + case '#0055FF': + return r == 0 && g == 0 && b == 1; + case '#FFEE00': + return r == 1 && g == 1 && b == 1; + } + return false; + } + + set_color_sensor_pins (sprite, script) { + const r = this.pinToNumber(script.getStringValue('RED')); + const g = this.pinToNumber(script.getStringValue('GREEN')); + const b = this.pinToNumber(script.getStringValue('BLUE')); + + const colorPins = this.state.tx.color.pins; + if (!colorPins) return; + + if (colorPins.r != r) { + this.request('enableDigitalInput', r, {pin: r}); + colorPins.r = r; + } + if (colorPins.g != g) { + this.request('enableDigitalInput', g, {pin: g}); + colorPins.g = g; + } + if (colorPins.b != b) { + this.request('enableDigitalInput', b, {pin: b}, true); + colorPins.b = b; + } + } +} + +module.exports = new Roduino(); \ No newline at end of file diff --git a/src/playground/blocks/hardware/block_roborobo_roe.js b/src/playground/blocks/hardware/block_roborobo_roe.js new file mode 100644 index 0000000000..4ec189e542 --- /dev/null +++ b/src/playground/blocks/hardware/block_roborobo_roe.js @@ -0,0 +1,1146 @@ +'use strict'; + +Entry.Roborobo_RoE = { + id: '48.1', + name: 'roborobo_roe', + url: 'http://www.roborobo.co.kr', + imageName: 'roborobo_roe.png', + title: { + ko: '로이', + en: 'Ro-E', + }, + setZero: function () { + Entry.hw.sendQueue['LED'] = 0; + Entry.hw.sendQueue['Melody'] = [0, 0, 0]; //[octave, note, duration] + Entry.hw.sendQueue['LeftMotor'] = [0, 0]; //[direction, value] + Entry.hw.sendQueue['RightMotor'] = [0, 0]; //[direction, value] + Entry.hw.update(); + }, + motorDiretion: { + STOP: 0, + CW: 1, + CCW: 2 + }, + monitorTemplate: { + imgPath: 'hw/roborobo_roe.png', + keys: ['value'], + width: 256, + height: 256, + listPorts: { + lColor: { + name: 'Color Sensor(Left)', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + rColor: { + name: 'Color Sensor(Right)', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + ir: { + name: 'IR Sensor', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + switch: { + name: 'Switch Sensor', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + }, + mode: 'both', + }, +}; + +Entry.Roborobo_RoE.setLanguage = function () { + return { + ko: { + template: { + roe_set_led: '%1 LED 켜기 %2', + roe_set_led_off: 'LED 끄기 %1', + roe_set_motor: '로이 %1 %2', + roe_set_motor_value: '%1 모터 : %2 만큼 %3 %4', + roe_set_melody: '%1 옥타브 %2 을(를) %3 초 연주 %4', + roe_get_input_switch: '접촉센서가 %1 ?', + roe_get_input_ir: '적외선 센서가 %1 ?', + roe_get_input_color: '%1 컬러센서 값이 %2 인가?', + roe_led_color_dropdown: '%1', + roe_melody_dropdown: '%1', + roe_motor_dropdown: '%1', + roe_movement_dropdown: '%1', + roe_detect_dropdown: '%1', + roe_color_select_dropdown: '%1', + roe_color_color_dropdown: '%1', + }, + Blocks: { + roe_color_sensor_left: '왼쪽', + roe_color_sensor_right: '오른쪽', + roe_color_sensor_both: '양쪽', + roe_color_red: '빨간색', + roe_color_orange: '주황색', + roe_color_yellow: '노란색', + roe_color_yellowgreen: '연두색', + roe_color_green: '초록색', + roe_color_skyblue: '하늘색', + roe_color_blue: '파란색', + roe_color_purple: '보라색', + roe_color_pink: '분홍색', + roe_color_white: '흰색', + roe_color_black: '검정색', + roe_color_random: '무작위 색', + roe_color_none: '미감지', + roe_motor_both: '양쪽', + roe_motor_left: '왼쪽', + roe_motor_right: '오른쪽', + roe_move_forward: '전진', + roe_move_backward: '후진', + roe_move_turnleft: '좌회전', + roe_move_turnright: '우회전', + roe_move_stop: '정지', + roe_detected: '감지되었는가', + roe_undetected: '감지되지 않았는가', + roe_melody_do: '도', + roe_melody_doS: '도#', + roe_melody_re: '레', + roe_melody_miF: '미b', + roe_melody_mi: '미', + roe_melody_pa: '파', + roe_melody_paS: '파#', + roe_melody_sol: '솔', + roe_melody_solS: '솔#', + roe_melody_la: '라', + roe_melody_siF: '시b', + roe_melody_si: '시', + } + }, + en: { + template: { + roe_set_led: 'Turn on %1 LED %2', + roe_set_led_off: 'Turn off LED %1', + roe_set_motor: 'Ro-E %1 %2', + roe_set_motor_value: '%1 motor(s) : Move %3 by %2 %4', + roe_set_melody: 'Play %1 octave %2 tone for %3 second(s) %4', + roe_get_input_switch: 'Is the switch sensor %1 ?', + roe_get_input_ir: 'Is the IR sensor %1 ?', + roe_get_input_color: 'Is %1 color sensor value %2 ?', + roe_led_color_dropdown: '%1', + roe_melody_dropdown: '%1', + roe_motor_dropdown: '%1', + roe_movement_dropdown: '%1', + roe_detect_dropdown: '%1', + roe_color_select_dropdown: '%1', + roe_color_color_dropdown: '%1', + }, + Blocks: { + roe_color_sensor_left: 'left', + roe_color_sensor_right: 'right', + roe_color_sensor_both: 'both', + roe_color_red: 'Red', + roe_color_orange: 'Orange', + roe_color_yellow: 'Yellow', + roe_color_yellowgreen: 'Yellow Green', + roe_color_green: 'Green', + roe_color_skyblue: 'Sky Blue', + roe_color_blue: 'Blue', + roe_color_purple: 'Purple', + roe_color_pink: 'Pink', + roe_color_white: 'White', + roe_color_black: 'Black', + roe_color_random: 'Random', + roe_color_none: 'Undetected', + roe_motor_both: 'Both', + roe_motor_left: 'Left', + roe_motor_right: 'Right', + roe_move_forward: 'forward', + roe_move_backward: 'backward', + roe_move_turnleft: 'turn left', + roe_move_turnright: 'turn right', + roe_move_stop: 'stop', + roe_detected: 'detected', + roe_undetected: 'undetected', + roe_melody_do: 'C', + roe_melody_doS: 'C#', + roe_melody_re: 'D', + roe_melody_miF: 'Eb', + roe_melody_mi: 'E', + roe_melody_pa: 'F', + roe_melody_paS: 'F#', + roe_melody_sol: 'G', + roe_melody_solS: 'G#', + roe_melody_la: 'A', + roe_melody_siF: 'Bb', + roe_melody_si: 'B', + }, + }, + }; +}; + +Entry.Roborobo_RoE.blockMenuBlocks = [ + 'roe_set_led', + 'roe_set_led_off', + 'roe_set_motor', + 'roe_set_motor_value', + 'roe_set_melody', + 'roe_get_input_switch', + 'roe_get_input_ir', + 'roe_get_input_color', +]; + +Entry.Roborobo_RoE.getBlocks = function () { + return { + //region roe 로이 + roe_led_color_dropdown: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_color_red, 1], + [Lang.Blocks.roe_color_orange, 2], + [Lang.Blocks.roe_color_yellow, 3], + [Lang.Blocks.roe_color_yellowgreen, 4], + [Lang.Blocks.roe_color_green, 5], + [Lang.Blocks.roe_color_skyblue, 6], + [Lang.Blocks.roe_color_blue, 7], + [Lang.Blocks.roe_color_purple, 8], + [Lang.Blocks.roe_color_pink, 9], + [Lang.Blocks.roe_color_white, 10] + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func: function (sprite, script) { + return script.getNumberField('VALUE'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_color_red, 1], + [Lang.Blocks.roe_color_orange, 2], + [Lang.Blocks.roe_color_yellow, 3], + [Lang.Blocks.roe_color_yellowgreen, 4], + [Lang.Blocks.roe_color_green, 5], + [Lang.Blocks.roe_color_skyblue, 6], + [Lang.Blocks.roe_color_blue, 7], + [Lang.Blocks.roe_color_purple, 8], + [Lang.Blocks.roe_color_pink, 9], + [Lang.Blocks.roe_color_white, 10] + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'roe_led_color_dropdown', + }, + ], + }, + }, + roe_melody_dropdown: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_melody_do, 1], + [Lang.Blocks.roe_melody_re, 2], + [Lang.Blocks.roe_melody_mi, 3], + [Lang.Blocks.roe_melody_pa, 4], + [Lang.Blocks.roe_melody_sol, 5], + [Lang.Blocks.roe_melody_la, 6], + [Lang.Blocks.roe_melody_si, 7], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func: function (sprite, script) { + return script.getNumberField('VALUE', script); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_melody_do, 1], + [Lang.Blocks.roe_melody_re, 2], + [Lang.Blocks.roe_melody_mi, 3], + [Lang.Blocks.roe_melody_pa, 4], + [Lang.Blocks.roe_melody_sol, 5], + [Lang.Blocks.roe_melody_la, 6], + [Lang.Blocks.roe_melody_si, 7], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + keyOption: 'roe_melody_dropdown', + }, + ], + }, + }, + roe_motor_dropdown: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_motor_both, 1], + [Lang.Blocks.roe_motor_left, 2], + [Lang.Blocks.roe_motor_right, 3], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func: function (sprite, script) { + return script.getNumberField('VALUE'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_motor_both, 1], + [Lang.Blocks.roe_motor_left, 2], + [Lang.Blocks.roe_motor_right, 3], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'roe_motor_dropdown', + }, + ], + }, + }, + roe_movement_dropdown: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_move_forward, 1], + [Lang.Blocks.roe_move_backward, 2], + [Lang.Blocks.roe_move_turnleft, 3], + [Lang.Blocks.roe_move_turnright, 4], + [Lang.Blocks.roe_move_stop, 5], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func: function (sprite, script) { + return script.getNumberField('VALUE'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_move_forward, 1], + [Lang.Blocks.roe_move_backward, 2], + [Lang.Blocks.roe_move_turnleft, 3], + [Lang.Blocks.roe_move_turnright, 4], + [Lang.Blocks.roe_move_stop, 5], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'roe_movement_dropdown', + }, + ], + }, + }, + roe_detect_dropdown: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_detected, 1], + [Lang.Blocks.roe_undetected, 0], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func: function (sprite, script) { + return script.getNumberField('VALUE'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_detected, 1], + [Lang.Blocks.roe_undetected, 2], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'roe_detect_dropdown', + }, + ], + }, + }, + roe_color_select_dropdown: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_color_sensor_both, 1], + [Lang.Blocks.roe_color_sensor_left, 2], + [Lang.Blocks.roe_color_sensor_right, 3], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func: function (sprite, script) { + return script.getNumberField('VALUE'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_color_sensor_both, 1], + [Lang.Blocks.roe_color_sensor_left, 2], + [Lang.Blocks.roe_color_sensor_right, 3], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'roe_color_select_dropdown', + }, + ], + }, + }, + roe_color_color_dropdown: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_color_red, 1], + [Lang.Blocks.roe_color_orange, 2], + [Lang.Blocks.roe_color_yellow, 3], + [Lang.Blocks.roe_color_yellowgreen, 7], + [Lang.Blocks.roe_color_green, 4], + [Lang.Blocks.roe_color_skyblue, 8], + [Lang.Blocks.roe_color_blue, 5], + [Lang.Blocks.roe_color_purple, 6], + [Lang.Blocks.roe_color_pink, 9], + [Lang.Blocks.roe_color_black, 10], + [Lang.Blocks.roe_color_white, 11], + [Lang.Blocks.roe_color_none, 127], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func: function (sprite, script) { + return script.getNumberField('VALUE'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roe_color_red, 1], + [Lang.Blocks.roe_color_orange, 2], + [Lang.Blocks.roe_color_yellow, 3], + [Lang.Blocks.roe_color_yellowgreen, 7], + [Lang.Blocks.roe_color_green, 4], + [Lang.Blocks.roe_color_skyblue, 8], + [Lang.Blocks.roe_color_blue, 5], + [Lang.Blocks.roe_color_purple, 6], + [Lang.Blocks.roe_color_pink, 9], + [Lang.Blocks.roe_color_black, 10], + [Lang.Blocks.roe_color_white, 11], + [Lang.Blocks.roe_color_none, 127], + ], + value: 1, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'roe_color_color_dropdown', + }, + ], + }, + }, + roe_set_led: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string' + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12 + } + ], + events: {}, + def: { + params: [ + { + type: 'roe_led_color_dropdown', + }, + null + ], + type: 'roe_set_led', + }, + paramsKeyMap: { + VALUE: 0, + }, + class: 'roe_set', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + var color = script.getNumberValue('VALUE', script); + Entry.hw.sendQueue['LED'] = color; + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_roe.roe_set_led(%1)', + textParams: [ + { + type: "Block", + accept: "string" + }, + { + type: 'roe_led_color_dropdown' + } + ], + }, + ], + }, + }, + roe_set_led_off: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic', + statements: [], + params: [ + { + type: "Indicator", + img: "block_icon/hardware_icon.svg", + size: 12 + } + ], + events: {}, + def: { + params: [ + null + ], + type: 'roe_set_led_off' + }, + paramsKeyMap: {}, + class: 'roe_set', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + Entry.hw.sendQueue['LED'] = 0; + }, + syntax: { + js: [], + py: ['Roborobo_roe.roe_set_led_off()'], + }, + }, + roe_set_melody: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ], + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Block', + accept: 'string' + }, + { + type: 'Block', + accept: 'string' + }, + { + type: "Indicator", + img: "block_icon/hardware_icon.svg", + size: 12 + } + ], + events: {}, + def: { + params: [ + '4', + { + type: 'roe_melody_dropdown', + }, + '1', + null + ], + type: 'roe_set_melody', + }, + paramsKeyMap: { + OCTAVE: 0, + NOTE: 1, + DURATION: 2 + }, + class: 'roe_set', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + if (!script.isStart) { + var octave = script.getNumberValue('OCTAVE', script); + var note = script.getNumberValue('NOTE', script); + var duration = script.getNumberValue('DURATION', script); + + if (octave < 4) { + octave = 4; + } else if (octave > 7) { + octave = 7; + } + + if (note < 1) { + note = 1; + } else if (note > 7) { + note = 7; + } + duration = duration < 0 ? 0 : duration; + duration = duration * 1000; + + script.isStart = true; + script.timeFlag = 1; + + Entry.hw.sendQueue['Melody'] = [octave, note, duration]; + + setTimeout(function () { + script.timeFlag = 0; + }, duration); + return script; + } else if (script.timeFlag == 1) { + return script; + } else { + delete script.timeFlag; + delete script.isStart; + } + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_roe.roe_set_melody(%1 %2 %3)', + textParams: [ + '4', + { + type: 'roe_melody_dropdown', + }, + '1', + ], + }, + ], + }, + }, + roe_set_motor: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: "Block", + accept: "string" + }, + { + type: "Indicator", + img: "block_icon/hardware_icon.svg", + size: 12 + } + ], + events: {}, + def: { + params: [ + { + type: 'roe_movement_dropdown' + }, + null + ], + type: 'roe_set_motor' + }, + paramsKeyMap: { + OPERATOR: 0, + }, + class: 'roe_set', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + var op = script.getNumberValue('OPERATOR', script); + if (op == 1) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, 0]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, 0]; + } else if (op == 2) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, 0]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, 0]; + } else if (op == 3) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, 0]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, 0]; + } else if (op == 4) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, 0]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, 0]; + } else if (op == 5) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.STOP, 0]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.STOP, 0]; + } + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_roe.roe_set_motor(%1)', + textParams: [ + { + type: 'roe_movement_dropdown' + }, + ], + }, + ], + }, + }, + roe_set_motor_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: "Block", + accept: "string" + }, + { + type: "Block", + accept: "string" + }, + { + type: "Block", + accept: "string" + }, + { + type: "Indicator", + img: "block_icon/hardware_icon.svg", + size: 12 + } + ], + events: {}, + def: { + params: [ + { + type: 'roe_motor_dropdown' + }, + '100', + { + type: 'roe_movement_dropdown' + }, + null + ], + type: 'roe_set_motor_value' + }, + paramsKeyMap: { + MOTOR: 0, + VALUE: 1, + OPERATOR: 2, + }, + class: 'roe_set', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + var motor = script.getNumberValue('MOTOR', script); + var value = script.getNumberValue('VALUE', script); + var op = script.getNumberValue('OPERATOR', script); + + if (value < 0) { + value = 0; + } else if (value > 100) { + value = 100; + } + + if (motor == 1) { + if (op == 1) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + } else if (op == 2) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + } else if (op == 3) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + } else if (op == 4) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + } else if (op == 5) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.STOP, value]; + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.STOP, value]; + } + } else if (motor == 2) { + if (op == 1) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + } else if (op == 2) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + } else if (op == 3) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + } else if (op == 4) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + } else if (op == 5) { + Entry.hw.sendQueue['LeftMotor'] = [Entry.Roborobo_RoE.motorDiretion.STOP, value]; + } + } else if (motor == 3) { + if (op == 1) { + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + } else if (op == 2) { + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + } else if (op == 3) { + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CW, value]; + } else if (op == 4) { + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.CCW, value]; + } else if (op == 5) { + Entry.hw.sendQueue['RightMotor'] = [Entry.Roborobo_RoE.motorDiretion.STOP, value]; + } + } + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_roe.roe_set_motor_value(%1 %2 %3)', + textParams: [ + { + type: 'roe_motor_dropdown' + }, + '100', + { + type: 'roe_movement_dropdown' + }, + ], + }, + ], + }, + }, + roe_get_input_switch: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string' + }, + { + type: "Indicator", + img: "block_icon/hardware_icon.svg", + size: 12 + } + ], + events: {}, + def: { + params: [ + { + type: 'roe_detect_dropdown', + }, + null + ], + type: 'roe_get_input_switch' + }, + paramsKeyMap: { + DETECT: 0 + }, + class: 'roe_get', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + var detect = script.getNumberValue('DETECT', script); + var value = Entry.hw.portData['Switch']; + // console.log('Switch Value : ' + value); + return detect == value ? true : false; + }, + syntax: { + js: [], + py: ['Roborobo_roe.roe_get_input_switch()'], + }, + }, + roe_get_input_ir: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string' + }, + { + type: "Indicator", + img: "block_icon/hardware_icon.svg", + size: 12 + } + ], + events: {}, + def: { + params: [ + { + type: 'roe_detect_dropdown', + }, + null + ], + type: 'roe_get_input_ir' + }, + paramsKeyMap: { + DETECT: 0 + }, + class: 'roe_get', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + var detect = script.getNumberValue('DETECT', script); + var value = Entry.hw.portData['IR']; + // console.log('IR Value : ' + value); + return detect == value ? true : false; + }, + syntax: { + js: [], + py: ['Roborobo_roe.roe_get_input_ir()'], + }, + }, + roe_get_input_color: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic_boolean_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string' + }, + { + type: 'Block', + accept: 'string' + }, + { + type: "Indicator", + img: "block_icon/hardware_icon.svg", + size: 12 + } + ], + events: {}, + def: { + params: [ + { + type: 'roe_color_select_dropdown', + }, + { + type: 'roe_color_color_dropdown', + }, + null + ], + type: 'roe_get_input_color' + }, + paramsKeyMap: { + SENSOR: 0, + COLOR: 1 + }, + class: 'roe_get', + isNotFor: ['roborobo_roe'], + func: function (sprite, script) { + var result = false; + var sensor = script.getNumberValue('SENSOR', script); + var color = script.getNumberValue('COLOR', script); + var left = Entry.hw.portData['LeftColor']; + var right = Entry.hw.portData['RightColor']; + + if (sensor == 1) { + if (left == color && right == color) { + result = true; + } + } else if (sensor == 2) { + result = left == color ? true : false; + } else if (sensor == 3) { + result = right == color ? true : false; + } + return result; + }, + syntax: { + js: [], + py: ['Roborobo_roe.roe_get_input_color()'], + }, + }, + //endregion roe 로이 + }; +}; + +module.exports = Entry.Roborobo_RoE; diff --git a/src/playground/blocks/hardware/block_roborobo_schoolkit.js b/src/playground/blocks/hardware/block_roborobo_schoolkit.js new file mode 100644 index 0000000000..fd91dadfda --- /dev/null +++ b/src/playground/blocks/hardware/block_roborobo_schoolkit.js @@ -0,0 +1,1946 @@ +'use strict'; + +Entry.Roborobo_SchoolKit = { + hasPracticalCourse: true, + id: '10.2', + name: 'roborobo_schoolkit', + url: 'http://www.roborobo.co.kr', + imageName: 'roborobo_schoolkit.png', + title: { + ko: '스쿨키트', + en: 'School Kit', + }, + pinMode: { + INPUT: 0, + OUTPUT: 1, + ANALOG: 2, + PWM: 3, + SERVO: 4, + }, + inputPort: { + ir: 7, + sound: 8, + contact: 9, + cds: 10, + }, + setZero: function () { + Entry.hw.sendQueue.digitalPinMode = []; + Entry.hw.sendQueue.previousValue = []; + + for (var port = 0; port < 14; port++) { + Entry.hw.sendQueue[port] = 0; + Entry.hw.sendQueue.digitalPinMode[port] = 0; + Entry.hw.sendQueue.previousValue[port] = -1; + } + Entry.hw.update(); + }, + monitorTemplate: { + imgPath: 'hw/roborobo_schoolkit.png', + keys: ['value'], + width: 256, + height: 256, + listPorts: { + '0': { + name: 'D1', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + '1': { + name: 'D2', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + '2': { + name: 'D3', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + '3': { + name: 'D4', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + '4': { + name: 'D5', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + '5': { + name: 'D6', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + '6': { + name: 'D7', + type: 'input', + pos: { + x: 0, + y: 0, + }, + }, + }, + mode: 'both', + }, +}; + +Entry.Roborobo_SchoolKit.setLanguage = function () { + return { + ko: { + template: { + schoolkit_get_in_port_number: '%1 ', + schoolkit_get_out_port_number: '%1 ', + schoolkit_get_servo_port_number: '%1 ', + schoolkit_get_input_value: '디지털 %1 번 센서값 ', + schoolkit_set_output: '디지털 %1 번 핀 %2 %3', + schoolkit_motor: '%1 속도 %2(으)로 %3 %4', + schoolkit_set_servo_value: '서보모터 %1 번 핀 %2˚ %3', + schoolkit_on_block: ' On ', + schoolkit_off_block: ' Off ', + }, + }, + en: { + template: { + schoolkit_get_in_port_number: '%1 ', + schoolkit_get_out_port_number: '%1 ', + schoolkit_get_servo_port_number: '%1 ', + schoolkit_get_input_value: 'Digital %1 Sensor value ', + schoolkit_set_output: 'Digital %1 Pin %2 %3', + schoolkit_motor: '%1 Speed %2 %3 %4', + schoolkit_set_servo_value: 'Servo %1 Pin %2˚ %3', + schoolkit_on_block: ' On ', + schoolkit_off_block: ' Off ', + }, + }, + }; +}; + +Entry.Roborobo_SchoolKit.blockMenuBlocks = [ + 'schoolkit_on_block', + 'schoolkit_off_block', + 'schoolkit_get_input_value', + 'schoolkit_set_output', + 'schoolkit_motor', + 'schoolkit_set_servo_value', +]; + +Entry.Roborobo_SchoolKit.practicalBlockMenuBlocks = { + hw_motor: [ + // 'roborobo_motor_speed', + 'roborobo_move_for_secs', + 'roborobo_move_for', + 'roborobo_turn_for', + 'roborobo_stop_for', + ], + hw_melody: [ + + ], + hw_sensor: [ + 'roborobo_touch_value', + 'roborobo_touch_value_boolean', + 'roborobo_light_value', + 'roborobo_light_value_boolean', + 'roborobo_sound_value', + 'roborobo_sound_value_boolean', + 'roborobo_irs_value', + 'roborobo_irs_value_boolean', + ], + hw_led: [ + 'roborobo_diode_secs_toggle', + 'roborobo_diode_toggle', + 'roborobo_diode_inout_toggle', + 'roborobo_diode_set_output', + 'roborobo_diode_input_value', + ], +} + +Entry.Roborobo_SchoolKit.getBlocks = function () { + return { + //region schoolkit 스쿨키트 + schoolkit_on_block: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [null], + type: 'schoolkit_on_block', + }, + paramsKeyMap: {}, + class: 'schoolkit_value', + isNotFor: ['roborobo_schoolkit'], + func: function (sprite, script) { + return '1'; + }, + syntax: { + js: [], + py: ['Roborobo_SchoolKit.schoolkit_on_block()'], + }, + }, + schoolkit_off_block: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [null], + type: 'schoolkit_off_block', + }, + paramsKeyMap: {}, + class: 'schoolkit_value', + isNotFor: ['roborobo_schoolkit'], + func: function (sprite, script) { + return '0'; + }, + syntax: { + js: [], + py: ['Roborobo_SchoolKit.schoolkit_off_block()'], + }, + }, + schoolkit_get_out_port_number: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['OUT1', 2], + ['OUT2', 3], + ['OUT3', 4], + ['OUT4', 5], + ['OUT5', 6], + ], + value: 2, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PORT: 0, + }, + func: function (sprite, script) { + return script.getNumberField('PORT'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + ['OUT1', 2], + ['OUT2', 3], + ['OUT3', 4], + ['OUT4', 5], + ['OUT5', 6], + ], + value: 2, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'schoolkit_get_out_port_number', + }, + ], + }, + }, + schoolkit_get_servo_port_number: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['OUT1', 2], + ['OUT2', 3], + ['OUT3', 4], + ], + value: 2, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PORT: 0, + }, + func: function (sprite, script) { + return script.getNumberField('PORT'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + ['OUT1', 2], + ['OUT2', 3], + ['OUT3', 4], + ], + value: 2, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'schoolkit_get_servo_port_number', + }, + ], + }, + }, + schoolkit_get_in_port_number: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + ['IN1', 7], + ['IN2', 8], + ['IN3', 9], + ['IN4', 10], + ['IN5', 11], + ['IN6', 12], + ['IN7', 13], + ], + value: 7, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + PORT: 0, + }, + func: function (sprite, script) { + return script.getNumberField('PORT'); + }, + syntax: { + js: [], + py: [ + { + syntax: '%1', + textParams: [ + { + type: 'Dropdown', + options: [ + ['IN1', 7], + ['IN2', 8], + ['IN3', 9], + ['IN4', 10], + ['IN5', 11], + ['IN6', 12], + ['IN7', 13], + ], + value: 7, + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + keyOption: 'schoolkit_get_in_port_number', + }, + ], + }, + }, + schoolkit_set_output: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roborobo_on, 'on'], + [Lang.Blocks.roborobo_off, 'off'], + ], + value: 'on', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'schoolkit_get_out_port_number', + }, + null, + null, + ], + type: 'schoolkit_set_output', + }, + paramsKeyMap: { + VALUE: 0, + OPERATOR: 1, + }, + class: 'schoolkit_set', + isNotFor: ['roborobo_schoolkit'], + func: function (sprite, script) { + var pin = script.getNumberValue('VALUE', script); + var operator = script.getField('OPERATOR'); + var value = operator == 'on' ? 1 : 0; + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_SchoolKit.pinMode.OUTPUT; + Entry.hw.sendQueue[pin] = value; + return script.callReturn(); + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_schoolkit.wirte_digital(%1, %2)', + textParams: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roborobo_on, 'on'], + [Lang.Blocks.roborobo_off, 'off'], + ], + value: 'on', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + }, + ], + }, + }, + schoolkit_get_input_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + fontColor: '#fff', + skeleton: 'basic_string_field', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [ + { + type: 'schoolkit_get_in_port_number', + }, + ], + type: 'schoolkit_get_input_value', + }, + paramsKeyMap: { + VALUE: 0, + }, + class: 'schoolkit_value', + isNotFor: ['roborobo_schoolkit'], + func: function (sprite, script) { + var signal = script.getNumberValue('VALUE', script); + return Entry.hw.portData[signal - 7]; + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_schoolkit.read_digital(%1)', + textParams: [ + { + type: 'Block', + accept: 'string', + }, + ], + }, + ], + }, + }, + schoolkit_motor: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roborobo_motor1, 'motor1'], + [Lang.Blocks.roborobo_motor2, 'motor2'], + ], + value: 'motor1', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + ['0', '45'], + ['1', '59'], + ['2', '73'], + ['3', '87'], + ['4', '101'], + ['5', '115'], + ['6', '129'], + ['7', '143'], + ['8', '157'], + ['9', '171'], + ['10', '185'], + ['11', '199'], + ['12', '213'], + ['13', '227'], + ['14', '241'], + ['15', '255'], + ], + value: '45', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roborobo_motor_CW, 'cw'], + [Lang.Blocks.roborobo_motor_CCW, 'ccw'], + [Lang.Blocks.roborobo_motor_stop, 'stop'], + ], + value: 'cw', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [null, null, null, null], + type: 'schoolkit_motor', + }, + paramsKeyMap: { + MODE: 0, + VALUE: 1, + OPERATOR: 2, + }, + class: 'schoolkit_set', + isNotFor: ['roborobo_schoolkit'], + func: function (sprite, script) { + var mode = script.getField('MODE'); + var pin = 0; + var operator = script.getField('OPERATOR'); + var value = script.getField('VALUE'); + + if (mode == 'motor1') { + pin = 0; + } else { + pin = 1; + } + + if (value > 255) { + value = 255; + } else if (value < 0) { + value = 0; + } + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[pin + 7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + if (operator == 'cw') { + Entry.hw.sendQueue[pin] = value; + } else if (operator == 'ccw') { + Entry.hw.sendQueue[pin] = -value; + } else if (operator == 'stop') { + Entry.hw.sendQueue[pin] = 0x00; + } + return script.callReturn(); + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_schoolkit.move_motor_speed(%1, %2, %3)', + textParams: [ + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roborobo_motor1, 'motor1'], + [Lang.Blocks.roborobo_motor2, 'motor2'], + ], + value: 'motor1', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + { + type: 'Dropdown', + options: [ + ['0', '45'], + ['1', '59'], + ['2', '73'], + ['3', '87'], + ['4', '101'], + ['5', '115'], + ['6', '129'], + ['7', '143'], + ['8', '157'], + ['9', '171'], + ['10', '185'], + ['11', '199'], + ['12', '213'], + ['13', '227'], + ['14', '241'], + ['15', '255'], + ], + value: '45', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + }, + { + type: 'Dropdown', + options: [ + [Lang.Blocks.roborobo_motor_CW, 'cw'], + [Lang.Blocks.roborobo_motor_CCW, 'ccw'], + [Lang.Blocks.roborobo_motor_stop, 'stop'], + ], + value: 'cw', + fontSize: 11, + bgColor: EntryStatic.colorSet.block.darken.HARDWARE, + arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, + converter: Entry.block.converters.returnStringValue, + }, + ], + }, + ], + }, + }, + schoolkit_set_servo_value: { + color: EntryStatic.colorSet.block.default.HARDWARE, + outerLine: EntryStatic.colorSet.block.darken.HARDWARE, + skeleton: 'basic', + statements: [], + params: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/hardware_icon.svg', + size: 12, + }, + ], + events: {}, + def: { + params: [ + { + type: 'schoolkit_get_servo_port_number', + }, + { + type: 'number', + params: ['0'], + }, + null, + ], + type: 'schoolkit_set_servo_value', + }, + paramsKeyMap: { + PIN: 0, + VALUE: 1, + }, + class: 'schoolkit_set', + isNotFor: ['roborobo_schoolkit'], + func: function (sprite, script) { + var pin = script.getNumberValue('PIN', script); + var value = script.getNumberValue('VALUE'); + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + Entry.hw.sendQueue.digitalPinMode[pin] = Entry.Roborobo_SchoolKit.pinMode.SERVO; + + if (value < 0) { + value = 0; + } else if (value > 180) { + value = 180; + } + Entry.hw.sendQueue[pin] = value; + return script.callReturn(); + }, + syntax: { + js: [], + py: [ + { + syntax: 'Roborobo_schoolkit.move_servo(%1, %2)', + textParams: [ + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + ], + }, + ], + }, + }, + //endregion schoolkit 스쿨키트 + }; +}; + +Entry.Roborobo_SchoolKit.getPracticalBlocks = function () { + return { + // roborobo_mini + roborobo_motor_speed: { + color: '#00B200', + outerLine: '#019101', + skeleton: 'basic_string_field', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1', + params: [ + { + type: 'Dropdown', + options: [ + ['1', '52'], + ['2', '66'], + ['3', '80'], + ['4', '94'], + ['5', '107'], + ['6', '120'], + ['7', '134'], + ['8', '148'], + ['9', '162'], + ['10', '176'], + ['11', '190'], + ['12', '204'], + ['13', '218'], + ['14', '232'], + ['15', '255'], + ], + value: '255', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + ], + events: {}, + def: { + params: [null], + }, + paramsKeyMap: { + VALUE: 0, + }, + func (sprite, script) { + return script.getStringField('VALUE'); + }, + }, + roborobo_move_for_secs: { + color: '#00B200', + outerLine: '#019101', + skeleton: 'basic', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1모터를 %2 %3의 속도로 %4초 동안 회전 %5', + params: [ + { + type: 'Dropdown', + options: [ + ['양쪽', '1'], + ['오른쪽', '2'], + ['왼쪽', '3'], + ], + value: '1', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Dropdown', + options: [ + ['앞으로', '1'], + ['뒤로', '2'], + ], + value: '1', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/dcmotor.png', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + null, + { + type: 'roborobo_motor_speed', + }, + { + type: 'number', + params: ['2'], + }, + null, + ], + type: 'roborobo_move_for_secs', + }, + paramsKeyMap: { + WHEEL: 0, + DIRECTION: 1, + SPEED: 2, + DURATION: 3, + }, + class: 'roborobo_motor', + func (sprite, script) { + const motor1 = 0; + const motor2 = 1; + const wheel = script.getNumberField('WHEEL'); + const speed = script.getNumberValue('SPEED'); + const direction = script.getNumberField('DIRECTION'); + const duration = script.getNumberValue('DURATION'); + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + if (!script.isStart) { + if (wheel == 1) { + Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (direction == 1) { + Entry.hw.sendQueue[motor1] = speed; + Entry.hw.sendQueue[motor2] = speed; + } else if (direction == 2) { + Entry.hw.sendQueue[motor1] = -speed; + Entry.hw.sendQueue[motor2] = -speed; + } + } else if (wheel == 2) { + Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (direction == 1) { + Entry.hw.sendQueue[motor1] = 0x00; + Entry.hw.sendQueue[motor2] = speed; + } else if (direction == 2) { + Entry.hw.sendQueue[motor1] = 0x00; + Entry.hw.sendQueue[motor2] = -speed; + } + } else if (wheel == 3) { + Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (direction == 1) { + Entry.hw.sendQueue[motor1] = speed; + Entry.hw.sendQueue[motor2] = 0x00; + } else if (direction == 2) { + Entry.hw.sendQueue[motor1] = -speed; + Entry.hw.sendQueue[motor2] = 0x00; + } + } + + script.wheelMode = wheel; + script.isStart = true; + script.timeFlag = 1; + setTimeout(() => { + script.timeFlag = 0; + }, duration * 1000); + return script; + } else if (script.timeFlag == 1) { + return script; + } else { + Entry.hw.sendQueue[motor1] = 0x00; + Entry.hw.sendQueue[motor2] = 0x00; + + delete script.timeFlag; + delete script.isStart; + delete script.wheelMode; + Entry.engine.isContinue = false; + return script.callReturn(); + } + }, + }, + roborobo_move_for: { + color: '#00B200', + outerLine: '#019101', + skeleton: 'basic', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1모터를 %2 %3의 속도로 계속 회전 %4', + params: [ + { + type: 'Dropdown', + options: [ + ['양쪽', '1'], + ['오른쪽', '2'], + ['왼쪽', '3'], + ], + value: '1', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Dropdown', + options: [ + ['앞으로', '1'], + ['뒤로', '2'], + ], + value: '1', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/dcmotor.png', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + null, + { + type: 'roborobo_motor_speed', + }, + null, + ], + type: 'roborobo_move_for', + }, + paramsKeyMap: { + WHEEL: 0, + DIRECTION: 1, + SPEED: 2, + }, + class: 'roborobo_motor', + //'isNotFor': ['mini'], + func (sprite, script) { + const motor1 = 0; + const motor2 = 1; + const wheel = script.getNumberField('WHEEL'); + const speed = script.getNumberValue('SPEED'); + const direction = script.getNumberField('DIRECTION'); + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + if (wheel == 1) { + Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (direction == 1) { + Entry.hw.sendQueue[motor1] = speed; + Entry.hw.sendQueue[motor2] = speed; + } else if (direction == 2) { + Entry.hw.sendQueue[motor1] = -speed; + Entry.hw.sendQueue[motor2] = -speed; + } + } else if (wheel == 2) { + Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (direction == 1) { + Entry.hw.sendQueue[motor1] = 0x00; + Entry.hw.sendQueue[motor2] = speed; + } else if (direction == 2) { + Entry.hw.sendQueue[motor1] = 0x00; + Entry.hw.sendQueue[motor2] = -speed; + } + } else if (wheel == 3) { + Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (direction == 1) { + Entry.hw.sendQueue[motor1] = speed; + Entry.hw.sendQueue[motor2] = 0x00; + } else if (direction == 2) { + Entry.hw.sendQueue[motor1] = -speed; + //Entry.hw.sendQueue[motor2] = 0x00; + } + } + + return script.callReturn(); + }, + }, + roborobo_turn_for: { + color: '#00B200', + outerLine: '#019101', + skeleton: 'basic', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '오른쪽 모터를 %1 %2, 왼쪽 모터를 %3 %4의 속도로 계속 회전 %5', + params: [ + { + type: 'Dropdown', + options: [ + ['앞으로', '1'], + ['뒤로', '2'], + ], + value: '1', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['앞으로', '1'], + ['뒤로', '2'], + ], + value: '1', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/dcmotor.png', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + {type: 'roborobo_motor_speed'}, + null, + {type: 'roborobo_motor_speed'}, + null, + ], + type: 'roborobo_turn_for', + }, + paramsKeyMap: { + RDIR: 0, + RSPEED: 1, + LDIR: 2, + LSPEED: 3, + }, + class: 'roborobo_motor', + //'isNotFor': ['mini'], + func (sprite, script) { + const motor1 = 0; + const motor2 = 1; + + const rightDir = script.getNumberField('RDIR'); + const rightSpeed = script.getNumberValue('RSPEED'); + const leftDir = script.getNumberField('LDIR'); + const leftSpeed = script.getNumberValue('LSPEED'); + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (leftDir == 1) { + Entry.hw.sendQueue[motor1] = leftSpeed; + } else { + Entry.hw.sendQueue[motor1] = -leftSpeed; + } + + if (rightDir == 1) { + Entry.hw.sendQueue[motor2] = rightSpeed; + } else { + Entry.hw.sendQueue[motor2] = -rightSpeed; + } + + return script.callReturn(); + }, + }, + roborobo_stop_for: { + color: '#00B200', + outerLine: '#019101', + skeleton: 'basic', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1모터를 정지 %2', + params: [ + { + type: 'Dropdown', + options: [ + ['양쪽', '1'], + ['오른쪽', '2'], + ['왼쪽', '3'], + ], + value: '1', + fontSize: 11, + bgColor: '#019101', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/dcmotor.png', + size: 12, + }, + ], + events: {}, + def: { + params: [null, null], + type: 'roborobo_stop_for', + }, + paramsKeyMap: { + WHEEL: 0, + }, + class: 'roborobo_motor', + func (sprite, script) { + const motor1 = 0; + const motor2 = 1; + const wheel = script.getNumberField('WHEEL'); + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + if (wheel == 1) { + Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + Entry.hw.sendQueue[motor1] = 0x00; + Entry.hw.sendQueue[motor2] = 0x00; + } else if (wheel == 2) { + Entry.hw.sendQueue.digitalPinMode[8] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[1] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + Entry.hw.sendQueue[motor2] = 0x00; + } else if (wheel == 3) { + Entry.hw.sendQueue.digitalPinMode[7] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue.digitalPinMode[0] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + Entry.hw.sendQueue[motor1] = 0x00; + } + + return script.callReturn(); + }, + }, + roborobo_touch_value: { + color: '#2AB4D3', + outerLine: '#0e93b1', + skeleton: 'basic_string_field', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '접촉 센서 값', + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [null], + type: 'roborobo_touch_value', + }, + paramsKeyMap: {}, + class: 'roborobo_touch', + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.contact; + Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.INPUT; + Entry.hw.update(); + return Entry.hw.portData[port - 7]; + }, + }, + roborobo_touch_value_boolean: { + color: '#2AB4D3', + outerLine: '#0e93b1', + skeleton: 'basic_boolean_field', + fontColor: '#fff', + isNotFor: ['roborobo_schoolkit'], + template: '접촉 센서가 %1', + params: [ + { + type: 'Dropdown', + options: [ + ['접촉 되면', '1'], + ['접촉 안되면', '0'], + ], + value: '1', + fontSize: 11, + bgColor: '#0e93b1', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + ], + def: { + params: [null], + type: 'roborobo_touch_value_boolean', + }, + paramsKeyMap: { + TOUCH: 0, + }, + class: 'roborobo_touch', + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.contact; + const touch = script.getNumberField('TOUCH', script); + + Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.INPUT; + Entry.hw.update(); + + const value = Entry.hw.portData[port - 7]; + const isTouch = touch == value; + + return isTouch; + }, + }, + roborobo_light_value: { + color: '#ff8d0f', + outerLine: '#e37100', + skeleton: 'basic_string_field', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: 'CDS 센서 값', + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [null], + type: 'roborobo_light_value', + }, + paramsKeyMap: {}, + class: 'roborobo_light', + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.cds; + return Entry.hw.portData[port - 7]; + }, + }, + roborobo_light_value_boolean: { + color: '#ff8d0f', + outerLine: '#e37100', + skeleton: 'basic_boolean_field', + fontColor: '#fff', + isNotFor: ['roborobo_schoolkit'], + template: 'CDS 센서 값 %1 %2', + params: [ + { + type: 'Dropdown', + options: [ + ['=', 'EQUAL'], + ['>', 'GREATER'], + ['<', 'LESS'], + ['≥', 'GREATER_OR_EQUAL'], + ['≤', 'LESS_OR_EQUAL'], + ], + value: 'LESS', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + noaRrow: true, + }, + { + type: 'Block', + accept: 'string', + }, + ], + def: { + params: [ + null, + { + type: 'number', + params: ['512'], + }, + ], + type: 'roborobo_light_value_boolean', + }, + paramsKeyMap: { + OPERATOR: 0, + RIGHTVALUE: 1, + }, + class: 'roborobo_light', + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.cds; + const operator = script.getField('OPERATOR', script); + let rightValue = script.getNumberValue('RIGHTVALUE', script); + const leftValue = Entry.hw.portData[port - 7]; + let isCheck = false; + + if (rightValue < 0) { + rightValue = 0; + } else if (rightValue > 1023) { + rightValue = 1023; + } + switch (operator) { + case 'EQUAL': + isCheck = leftValue == rightValue; + break; + case 'GREATER': + isCheck = Number(leftValue) > Number(rightValue); + break; + case 'LESS': + isCheck = Number(leftValue) < Number(rightValue); + break; + case 'GREATER_OR_EQUAL': + isCheck = Number(leftValue) >= Number(rightValue); + break; + case 'LESS_OR_EQUAL': + isCheck = Number(leftValue) <= Number(rightValue); + break; + } + return isCheck; + }, + }, + roborobo_sound_value: { + color: '#01d67f', + outerLine: '#00b36a', + skeleton: 'basic_string_field', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '소리 센서에 감지되는 소리 값', + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [null], + type: 'roborobo_sound_value', + }, + paramsKeyMap: {}, + class: 'roborobo_sound', + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.sound; + return Entry.hw.portData[port - 7]; + }, + }, + roborobo_sound_value_boolean: { + color: '#01d67f', + outerLine: '#00b36a', + skeleton: 'basic_boolean_field', + fontColor: '#fff', + isNotFor: ['roborobo_schoolkit'], + template: '소리 센서에 감지되는 소리 값 %1 %2', + params: [ + { + type: 'Dropdown', + options: [ + ['=', 'EQUAL'], + ['>', 'GREATER'], + ['<', 'LESS'], + ['≥', 'GREATER_OR_EQUAL'], + ['≤', 'LESS_OR_EQUAL'], + ], + value: 'LESS', + fontSize: 11, + bgColor: '#00b36a', + arrowColor: EntryStatic.colorSet.common.WHITE, + noaRrow: true, + }, + { + type: 'Block', + accept: 'string', + }, + ], + def: { + params: [ + null, + { + type: 'number', + params: ['512'], + }, + ], + type: 'roborobo_sound_value_boolean', + }, + paramsKeyMap: { + OPERATOR: 0, + RIGHTVALUE: 1, + }, + class: 'roborobo_sound', + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.sound; + const operator = script.getField('OPERATOR', script); + let rightValue = script.getNumberValue('RIGHTVALUE', script); + const leftValue = Entry.hw.portData[port - 7]; + let isCheck = false; + + if (rightValue < 0) { + rightValue = 0; + } else if (rightValue > 1023) { + rightValue = 1023; + } + + switch (operator) { + case 'EQUAL': + isCheck = leftValue == rightValue; + break; + case 'GREATER': + isCheck = Number(leftValue) > Number(rightValue); + break; + case 'LESS': + isCheck = Number(leftValue) < Number(rightValue); + break; + case 'GREATER_OR_EQUAL': + isCheck = Number(leftValue) >= Number(rightValue); + break; + case 'LESS_OR_EQUAL': + isCheck = Number(leftValue) <= Number(rightValue); + break; + } + + return isCheck; + }, + }, + roborobo_irs_value: { + color: '#C4065C', + outerLine: '#9a0045', + skeleton: 'basic_string_field', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '적외선 센서 값', + params: [ + { + type: 'Block', + accept: 'string', + }, + ], + events: {}, + def: { + params: [null], + type: 'roborobo_irs_value', + }, + paramsKeyMap: {}, + class: 'roborobo_irs', + //'isNotFor': ['mini'], + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.ir; + const value = + Entry.hw.portData[port - 7] == undefined ? 0 : Entry.hw.portData[port - 7]; + return value; + }, + }, + roborobo_irs_value_boolean: { + color: '#C4065C', + outerLine: '#9a0045', + skeleton: 'basic_boolean_field', + fontColor: '#fff', + isNotFor: ['roborobo_schoolkit'], + template: '적외선 센서가 %1', + params: [ + { + type: 'Dropdown', + options: [ + ['감지 되면', '1'], + ['감지 안되면', '0'], + ], + value: '1', + fontSize: 11, + bgColor: '#9a0045', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + ], + def: { + params: [null], + type: 'roborobo_irs_value_boolean', + }, + paramsKeyMap: { + DETECT: 0, + }, + class: 'roborobo_irs', + //'isNotFor': ['mini'], + func (sprite, script) { + const port = Entry.Roborobo_SchoolKit.inputPort.ir; + const detect = script.getNumberField('DETECT', script); + + Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.INPUT; + Entry.hw.update(); + + const value = Entry.hw.portData[port - 7]; + const isDetect = detect == value; + + return isDetect; + }, + }, + roborobo_diode_secs_toggle: { + color: '#ff8d0f', + outerLine: '#e37100', + skeleton: 'basic', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1번 포트의 발광다이오드를 %2초 동안 %3 %4', + params: [ + { + type: 'Dropdown', + options: [ + ['LED 1', '5'], + ['LED 2', '4'], + ['R - A', '3'], + ['R - B', '2'], + ], + value: '5', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Dropdown', + options: [ + ['켜기', '255'], + ['끄기', '0'], + ], + value: '255', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/diode.png', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + { + type: 'number', + params: ['2'], + }, + null, + null, + ], + type: 'roborobo_diode_secs_toggle', + }, + paramsKeyMap: { + PORT: 0, + DURATION: 1, + VALUE: 2, + }, + class: 'roborobo_diode', + func (sprite, script) { + const port = script.getNumberField('PORT'); + const duration = script.getNumberValue('DURATION'); + const value = script.getNumberField('VALUE'); + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.PWM; + + if (!script.isStart) { + script.isStart = true; + script.timeFlag = 1; + Entry.hw.sendQueue[port] = value; + + setTimeout(() => { + script.timeFlag = 0; + }, duration * 1000); + return script; + } else if (script.timeFlag == 1) { + return script; + } else { + Entry.hw.sendQueue[port] = 0; + delete script.timeFlag; + delete script.isStart; + Entry.engine.isContinue = false; + return script.callReturn(); + } + }, + }, + roborobo_diode_toggle: { + color: '#ff8d0f', + outerLine: '#e37100', + skeleton: 'basic', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1번 포트의 발광다이오드를 %2 %3', + params: [ + { + type: 'Dropdown', + options: [ + ['LED 1', '5'], + ['LED 2', '4'], + ['R - A', '3'], + ['R - B', '2'], + ], + value: '5', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Dropdown', + options: [ + ['켜기', '255'], + ['끄기', '0'], + ], + value: '255', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/diode.png', + size: 12, + }, + ], + events: {}, + def: { + params: [null, null, null], + type: 'roborobo_diode_toggle', + }, + paramsKeyMap: { + PORT: 0, + VALUE: 1, + }, + class: 'roborobo_diode', + //'isNotFor': ['mini'], + func (sprite, script) { + const port = script.getNumberField('PORT'); + const value = script.getNumberField('VALUE'); + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue[port] = value; + + return script.callReturn(); + }, + }, + roborobo_diode_inout_toggle: { + color: '#ff8d0f', + outerLine: '#e37100', + skeleton: 'basic', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1번 포트의 발광다이오드를 %2번 포트의 %3~%4의 범위로 켜기%5', + params: [ + { + type: 'Dropdown', + options: [ + ['LED 1', '5'], + ['LED 2', '4'], + ['R - A', '3'], + ['R - B', '2'], + ], + value: '5', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Dropdown', + options: [ + ['소 리', '8'], + ['CDS', '10'], + ], + value: '8', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/diode.png', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + null, + {type: 'number', params: ['0']}, + {type: 'number', params: ['255']}, + null, + ], + type: 'roborobo_diode_inout_toggle', + }, + paramsKeyMap: { + OUTPUT: 0, + INPUT: 1, + MIN: 2, + MAX: 3, + }, + class: 'roborobo_diode', + //'isNotFor': ['mini'], + func (sprite, script) { + const outputPort = script.getNumberField('OUTPUT'); + const inputPort = script.getNumberField('INPUT'); + + const oMin = script.getNumberValue('MIN'); + const oMax = script.getNumberValue('MAX'); + const nMin = 0; + const nMax = 255; + const x = Entry.hw.portData[inputPort - 7] / 4; + const percent = (x - oMin) / (oMax - oMin); + let result = percent * (nMax - nMin) + nMin; + if (result > nMax) { + result = nMax; + } + if (result < nMin) { + result = nMin; + } + + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + + Entry.hw.sendQueue.digitalPinMode[outputPort] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue[outputPort] = result; + + return script.callReturn(); + }, + }, + roborobo_diode_set_output: { + color: '#ff8d0f', + outerLine: '#e37100', + skeleton: 'basic', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1번 포트의 발광다이오드를 %2의 밝기로 켜기 %3', + params: [ + { + type: 'Dropdown', + options: [ + ['LED 1', '5'], + ['LED 2', '4'], + ['R - A', '3'], + ['R - B', '2'], + ], + value: '5', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + { + type: 'Block', + accept: 'string', + }, + { + type: 'Indicator', + img: 'block_icon/practical_course/diode.png', + size: 12, + }, + ], + events: {}, + def: { + params: [ + null, + { + type: 'number', + params: ['255'], + }, + null, + ], + type: 'roborobo_diode_set_output', + }, + paramsKeyMap: { + PORT: 0, + VALUE: 1, + }, + class: 'roborobo_diode', + //'isNotFor': ['mini'], + func (sprite, script) { + const port = script.getStringField('PORT', script); + let value = script.getNumberValue('VALUE', script); + + if (value < 0) { + value = 0; + } else if (value > 255) { + value = 255; + } + if (!Entry.hw.sendQueue.digitalPinMode) { + Entry.hw.sendQueue.digitalPinMode = {}; + } + Entry.hw.sendQueue.digitalPinMode[port] = Entry.Roborobo_SchoolKit.pinMode.PWM; + Entry.hw.sendQueue[port] = value; + + return script.callReturn(); + }, + }, + roborobo_diode_input_value: { + color: '#ff8d0f', + outerLine: '#e37100', + skeleton: 'basic_string_field', + fontColor: '#fff', + statements: [], + isNotFor: ['roborobo_schoolkit'], + template: '%1 포트의 값', + params: [ + { + type: 'Dropdown', + options: [ + ['적외선', '7'], + ['소 리', '8'], + ['접 촉', '9'], + ['CDS', '10'], + ], + value: '8', + fontSize: 11, + bgColor: '#e37100', + arrowColor: EntryStatic.colorSet.common.WHITE, + }, + ], + events: {}, + def: { + params: [null], + type: 'roborobo_diode_input_value', + }, + paramsKeyMap: { + PORT: 0, + }, + class: 'roborobo_diode', + func (sprite, script) { + const port = script.getNumberField('PORT'); + return Entry.hw.portData[port - 7]; + }, + }, + } +} + +module.exports = Entry.Roborobo_SchoolKit;