diff --git a/src/playground/blocks/hardware/block_neo.js b/src/playground/blocks/hardware/block_neo.js index 0585051572..166112d515 100644 --- a/src/playground/blocks/hardware/block_neo.js +++ b/src/playground/blocks/hardware/block_neo.js @@ -337,7 +337,7 @@ Entry.Neo = new (class Neo { // led neo_led_title: 'LED', - neo_led_on: 'LED 켜기 %1 %2 %3', + neo_led_on: 'LED 켜기 %1 %2 %3 %4', neo_led_blink: 'LED 깜빡이기 %1 %2 %3 %4', neo_led_off: 'LED 끄기 %1 %2', @@ -731,21 +731,19 @@ Entry.Neo = new (class Neo { neo_buzzer_quarter_note: '4분 음표', neo_buzzer_8th_note: '8분 음표', - neo_lcd_image_1: '1', - neo_lcd_image_2: '2', - neo_lcd_image_3: '3', - neo_lcd_image_4: '4', - neo_lcd_image_5: '5', - neo_lcd_image_6: '6', - neo_lcd_image_7: '7', - neo_lcd_image_8: '8', - neo_lcd_image_9: '9', - neo_lcd_image_10: '10', - neo_lcd_image_11: '11', - neo_lcd_image_12: '12', - neo_lcd_image_13: '13', - neo_lcd_image_14: '14', - neo_lcd_image_15: '15', + neo_lcd_image_1: '화남', + neo_lcd_image_2: '어지러움', + neo_lcd_image_3: '똑똑함', + neo_lcd_image_4: '활기참', + neo_lcd_image_5: '뽀뽀', + neo_lcd_image_6: '사랑해', + neo_lcd_image_7: '윙크', + neo_lcd_image_8: '폭풍눈물', + neo_lcd_image_9: '졸림', + neo_lcd_image_10: '미소', + neo_lcd_image_11: '깜찍함', + neo_lcd_image_12: '의심', + neo_lcd_image_13: '못마땅', }, }, en: { @@ -797,7 +795,7 @@ Entry.Neo = new (class Neo { // led neo_led_title: 'LED', - neo_led_on: 'Turn on the LED %1 %2 %3', + neo_led_on: 'Turn on the LED %1 %2 %3 %4', neo_led_blink: 'Blink the LED %1 %2 %3 %4', neo_led_off: 'Turn off the LED %1 %2', @@ -805,7 +803,8 @@ Entry.Neo = new (class Neo { neo_color_led_title: 'Color LED', neo_color_led_on: 'Turn on the color LED %1 %2 %3 %4', neo_color_led_off: 'Turn off the color LED %1 %2', - neo_color_led_on_with_sensor: 'Turn on the color LED %2 with color sensor %1 %3', + neo_color_led_on_with_sensor: + 'Turn on the color LED %2 with color sensor %1 %3', // set output neo_set_output_title: 'Set output', @@ -886,14 +885,14 @@ Entry.Neo = new (class Neo { neo_duration_c: 'constantly', neo_duration_0: '0 second', neo_duration_1: '1 second', - neo_duration_2: '2 second', - neo_duration_3: '3 second', - neo_duration_4: '4 second', - neo_duration_5: '5 second', - neo_duration_6: '6 second', - neo_duration_7: '7 second', - neo_duration_8: '8 second', - neo_duration_9: '9 second', + neo_duration_2: '2 seconds', + neo_duration_3: '3 seconds', + neo_duration_4: '4 seconds', + neo_duration_5: '5 seconds', + neo_duration_6: '6 seconds', + neo_duration_7: '7 seconds', + neo_duration_8: '8 seconds', + neo_duration_9: '9 seconds', neo_compare_gt: '≥', neo_compare_g: '>', @@ -1088,10 +1087,10 @@ Entry.Neo = new (class Neo { neo_led_brightness_100: '100%', neo_led_blink_speed_1: '1 step', - neo_led_blink_speed_2: '2 step', - neo_led_blink_speed_3: '3 step', - neo_led_blink_speed_4: '4 step', - neo_led_blink_speed_5: '5 step', + neo_led_blink_speed_2: '2 steps', + neo_led_blink_speed_3: '3 steps', + neo_led_blink_speed_4: '4 steps', + neo_led_blink_speed_5: '5 steps', neo_set_output_value_0: '0', neo_set_output_value_5: '5', @@ -1191,21 +1190,19 @@ Entry.Neo = new (class Neo { neo_buzzer_quarter_note: 'a quarter note', neo_buzzer_8th_note: 'a eighth note', - neo_lcd_image_1: '1', - neo_lcd_image_2: '2', - neo_lcd_image_3: '3', - neo_lcd_image_4: '4', - neo_lcd_image_5: '5', - neo_lcd_image_6: '6', - neo_lcd_image_7: '7', - neo_lcd_image_8: '8', - neo_lcd_image_9: '9', - neo_lcd_image_10: '10', - neo_lcd_image_11: '11', - neo_lcd_image_12: '12', - neo_lcd_image_13: '13', - neo_lcd_image_14: '14', - neo_lcd_image_15: '15', + neo_lcd_image_1: 'angry', + neo_lcd_image_2: 'dizzy', + neo_lcd_image_3: 'smart', + neo_lcd_image_4: 'lively', + neo_lcd_image_5: 'kiss', + neo_lcd_image_6: 'lovely', + neo_lcd_image_7: 'wink', + neo_lcd_image_8: 'cry', + neo_lcd_image_9: 'sleepy', + neo_lcd_image_10: 'smiley', + neo_lcd_image_11: 'cute', + neo_lcd_image_12: 'doubt', + neo_lcd_image_13: 'bad', }, }, // }; @@ -1347,7 +1344,7 @@ Entry.Neo = new (class Neo { const speed = script.getStringField('SPEED', script); const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); - if (speed === 'IN1' || speed === 'IN2' || speed === 'IN3') { + if (speed.indexOf('IN') >= 0) { this.requestExtCommand(blockId, NeoBlockType.MOTOR_MOVE, [dc, speed]); } else { this.requestCommand(blockId, NeoBlockType.MOTOR_MOVE, [dc, speed]); @@ -1426,13 +1423,16 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const speedL = script.getNumberValue('SPEED_L', script); const speedR = script.getNumberValue('SPEED_R', script); const blockId = this.generateBlockId(); script.block_id = blockId; - this.requestCommand(blockId, NeoBlockType.MOTOR_MOVE_BOTH, [speedL, speedR]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + this.requestCommand(blockId, NeoBlockType.MOTOR_MOVE_BOTH, [ + speedL, + speedR, + ]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -1532,10 +1532,16 @@ Entry.Neo = new (class Neo { const speed = script.getStringField('SPEED', script); const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); - if (speed === 'IN1' || speed === 'IN2' || speed === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.ROBOT_MOVE, [direction, speed]); + if (speed.indexOf('IN') >= 0) { + this.requestExtCommand(blockId, NeoBlockType.ROBOT_MOVE, [ + direction, + speed, + ]); } else { - this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [direction, speed]); + this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [ + direction, + speed, + ]); } if (duration === 'c' || !Entry.parseNumber(duration)) { script.block_id = blockId; @@ -1603,10 +1609,20 @@ Entry.Neo = new (class Neo { class: 'neo_motor', isNotFor: ['neo'], func: (sprite, script) => { - const dc = script.getStringValue('DC', script); - const blockId = this.generateBlockId(); - this.requestCommand(blockId, NeoBlockType.MOTOR_STOP, [dc]); - return script.callReturn(); + if (!script.exec_phase) { + const dc = script.getStringValue('DC', script); + const blockId = this.generateBlockId(); + script.block_id = blockId; + script.exec_phase = ExecPhase.PENDING_RESPONSE; + this.requestCommand(blockId, NeoBlockType.MOTOR_STOP, [dc]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { + if (!this.pendingResponseList[script.block_id]) { + delete script.block_id; + delete script.exec_phase; + return script.callReturn(); + } + } + return script; }, }, neo_robot_stop: { @@ -1632,9 +1648,19 @@ Entry.Neo = new (class Neo { class: 'neo_motor', isNotFor: ['neo'], func: (sprite, script) => { - const blockId = this.generateBlockId(); - this.requestCommand(blockId, NeoBlockType.ROBOT_STOP, []); - return script.callReturn(); + if (!script.exec_phase) { + const blockId = this.generateBlockId(); + script.block_id = blockId; + script.exec_phase = ExecPhase.PENDING_RESPONSE; + this.requestCommand(blockId, NeoBlockType.ROBOT_STOP, []); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { + if (!this.pendingResponseList[script.block_id]) { + delete script.block_id; + delete script.exec_phase; + return script.callReturn(); + } + } + return script; }, }, /** @@ -1865,22 +1891,36 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringField('OUTPUT', script); const angle = script.getStringField('ANGLE', script); const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; - if (angle === 'IN1' || angle === 'IN2' || angle === 'IN3') { - if (speed === 'IN1' || angle === 'IN2' || angle === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); + const isExt2 = angle.indexOf('IN') >= 0 && speed.indexOf('IN') >= 0; + if (isExt2) { + this.requestExt2Command(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); + } else { + const isExt1 = angle.indexOf('IN') >= 0 || speed.indexOf('IN') >= 0; + if (isExt1) { + this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); } else { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); + this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); } - } else { - this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); } - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -1971,8 +2011,12 @@ Entry.Neo = new (class Neo { const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; - this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2133,14 +2177,28 @@ Entry.Neo = new (class Neo { const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; - if (angle === 'IN1' || angle === 'IN2' || angle === 'IN3') { - if (speed === 'IN1' || angle === 'IN2' || angle === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [output, angle, speed]); + const isExt2 = angle.indexOf('IN') >= 0 && speed.indexOf('IN') >= 0; + if (isExt2) { + this.requestExt2Command(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [ + output, + angle, + speed, + ]); + } else { + const isExt1 = angle.indexOf('IN') >= 0 || speed.indexOf('IN') >= 0; + if (isExt1) { + this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [ + output, + angle, + speed, + ]); } else { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [output, angle, speed]); + this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [ + output, + angle, + speed, + ]); } - } else { - this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [output, angle, speed]); } } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { @@ -2226,18 +2284,26 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringField('OUTPUT', script); const direction = script.getStringField('DIRECTION', script); const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; if (speed.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ROTATE, [output, direction, speed]); + this.requestExtCommand(blockId, NeoBlockType.SERVO_ROTATE, [ + output, + direction, + speed, + ]); } else { - this.requestCommand(blockId, NeoBlockType.SERVO_ROTATE, [output, direction, speed]); + this.requestCommand(blockId, NeoBlockType.SERVO_ROTATE, [ + output, + direction, + speed, + ]); } - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2285,12 +2351,12 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.SERVO_STOP, [output]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2387,8 +2453,10 @@ Entry.Neo = new (class Neo { const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); const duration = script.getStringValue('DURATION', script); - if (speed === 'IN1' || speed === 'IN2' || speed === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.LINE_TRACER_START, [speed]); + if (speed.indexOf('IN') >= 0) { + this.requestExtCommand(blockId, NeoBlockType.LINE_TRACER_START, [ + speed, + ]); } else { this.requestCommand(blockId, NeoBlockType.LINE_TRACER_START, [speed]); } @@ -2621,7 +2689,9 @@ Entry.Neo = new (class Neo { const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); if (speed.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.AUTO_DRIVING_START, [speed]); + this.requestExtCommand(blockId, NeoBlockType.AUTO_DRIVING_START, [ + speed, + ]); } else { this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_START, [speed]); } @@ -2717,17 +2787,24 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const sensor = script.getNumberField('SENSOR', script); const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; if (speed.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.AUTO_DRIVING_SENSOR_START, [sensor, speed]); + this.requestExtCommand( + blockId, + NeoBlockType.AUTO_DRIVING_SENSOR_START, + [sensor, speed] + ); } else { - this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_SENSOR_START, [sensor, speed]); + this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_SENSOR_START, [ + sensor, + speed, + ]); } - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2761,11 +2838,11 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_STOP, []); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3191,7 +3268,10 @@ Entry.Neo = new (class Neo { const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); if (brightness.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.LED_ON, [output, brightness]); + this.requestExtCommand(blockId, NeoBlockType.LED_ON, [ + output, + brightness, + ]); } else { this.requestCommand(blockId, NeoBlockType.LED_ON, [output, brightness]); } @@ -3366,12 +3446,12 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.LED_OFF, [output]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3537,12 +3617,12 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.COLOR_LED_OFF, [output]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3603,13 +3683,16 @@ Entry.Neo = new (class Neo { isNotFor: ['neo'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const input = script.getStringValue('INPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; - this.requestExtCommand(blockId, NeoBlockType.COLOR_LED_ON_SENSOR, [output, input]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + this.requestExtCommand(blockId, NeoBlockType.COLOR_LED_ON_SENSOR, [ + output, + input, + ]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3767,7 +3850,10 @@ Entry.Neo = new (class Neo { const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); if (value.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.SET_OUTPUT, [output, value]); + this.requestExtCommand(blockId, NeoBlockType.SET_OUTPUT, [ + output, + value, + ]); } else { this.requestCommand(blockId, NeoBlockType.SET_OUTPUT, [output, value]); } @@ -4270,7 +4356,8 @@ Entry.Neo = new (class Neo { const sensor3 = sensorData['in3Values'][0]; let lResult = false; if (lSymbol === '=') { - lResult = lValue === sensor1 && lValue === sensor2 && lValue === sensor3; + lResult = + lValue === sensor1 && lValue === sensor2 && lValue === sensor3; } else if (lSymbol === '>') { lResult = lValue > sensor1 && lValue > sensor2 && lValue > sensor3; } else if (lSymbol === '<') { @@ -4282,7 +4369,8 @@ Entry.Neo = new (class Neo { } let rResult = false; if (rSymbol === '=') { - rResult = sensor1 === rValue && sensor2 === rValue && sensor3 === rValue; + rResult = + sensor1 === rValue && sensor2 === rValue && sensor3 === rValue; } else if (rSymbol === '>') { rResult = sensor1 > rValue && sensor2 > rValue && sensor3 > rValue; } else if (rSymbol === '<') { @@ -4386,32 +4474,68 @@ Entry.Neo = new (class Neo { const input = script.getStringField('INPUT'); const sensorData = Entry.hw.portData['sensor']; const color = script.getNumberField('COLOR'); - let sensorValue = 0; - switch (input) { - case 'in1': - sensorValue = sensorData['in1Values'][0]; - break; - case 'in2': - sensorValue = sensorData['in2Values'][0]; - break; - case 'in3': - sensorValue = sensorData['in3Values'][0]; - break; - } + if (input === 'IN12') { + const sensor1 = sensorData['in1Values'][0]; + const sensor2 = sensorData['in2Values'][0]; + if (color === 1) { + return sensor1 === 0 && sensor2 === 0; + } else if (color === 2) { + return sensor1 === 40 && sensor2 === 40; + } else if (color === 3) { + return sensor1 === 80 && sensor2 === 80; + } else if (color === 4) { + return sensor1 === 120 && sensor2 === 120; + } else if (color === 5) { + return sensor1 === 160 && sensor2 === 160; + } else if (color === 6) { + return sensor1 === 200 && sensor2 === 200; + } + } else if (input === 'IN123') { + const sensor1 = sensorData['in1Values'][0]; + const sensor2 = sensorData['in2Values'][0]; + const sensor3 = sensorData['in3Values'][0]; + if (color === 1) { + return sensor1 === 0 && sensor2 === 0 && sensor3 === 0; + } else if (color === 2) { + return sensor1 === 40 && sensor2 === 40 && sensor3 === 40; + } else if (color === 3) { + return sensor1 === 80 && sensor2 === 80 && sensor3 === 80; + } else if (color === 4) { + return sensor1 === 120 && sensor2 === 120 && sensor3 === 120; + } else if (color === 5) { + return sensor1 === 160 && sensor2 === 160 && sensor3 === 160; + } else if (color === 6) { + return sensor1 === 200 && sensor2 === 200 && sensor3 === 200; + } + } else { + let sensorValue = 0; + switch (input) { + case 'IN1': + sensorValue = sensorData['in1Values'][0]; + break; + case 'IN2': + sensorValue = sensorData['in2Values'][0]; + break; + case 'IN3': + sensorValue = sensorData['in3Values'][0]; + break; + } - if (color === 1) { - return sensorValue === 0; - } else if (color === 2) { - return sensorValue === 0; - } else if (color === 3) { - return sensorValue === 0; - } else if (color === 4) { - return sensorValue === 0; - } else if (color === 5) { - return sensorValue === 0; - } else if (color === 6) { - return sensorValue === 0; + if (color === 1) { + return sensorValue === 0; + } else if (color === 2) { + return sensorValue === 40; + } else if (color === 3) { + return sensorValue === 80; + } else if (color === 4) { + return sensorValue === 120; + } else if (color === 5) { + return sensorValue === 160; + } else if (color === 6) { + return sensorValue === 200; + } } + return false; }, }, @@ -4758,8 +4882,6 @@ Entry.Neo = new (class Neo { [Lang.Blocks.neo_lcd_image_11, '11'], [Lang.Blocks.neo_lcd_image_12, '12'], [Lang.Blocks.neo_lcd_image_13, '13'], - [Lang.Blocks.neo_lcd_image_14, '14'], - [Lang.Blocks.neo_lcd_image_15, '15'], ], value: '1', fontSize: 11, @@ -4862,7 +4984,7 @@ Entry.Neo = new (class Neo { /** * ARG Blocks */ - neo_arg_motor_speed: { + neo_arg_duration: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, skeleton: 'basic_string_field', @@ -4871,29 +4993,19 @@ Entry.Neo = new (class Neo { { type: 'Dropdown', options: [ - [Lang.Blocks.neo_motor_speed_100, '100'], - [Lang.Blocks.neo_motor_speed_90, '90'], - [Lang.Blocks.neo_motor_speed_80, '80'], - [Lang.Blocks.neo_motor_speed_70, '70'], - [Lang.Blocks.neo_motor_speed_60, '60'], - [Lang.Blocks.neo_motor_speed_50, '50'], - [Lang.Blocks.neo_motor_speed_40, '40'], - [Lang.Blocks.neo_motor_speed_30, '30'], - [Lang.Blocks.neo_motor_speed_20, '20'], - [Lang.Blocks.neo_motor_speed_10, '10'], - [Lang.Blocks.neo_motor_speed_0, '0'], - [Lang.Blocks.neo_motor_speed_n10, '-10'], - [Lang.Blocks.neo_motor_speed_n20, '-20'], - [Lang.Blocks.neo_motor_speed_n30, '-30'], - [Lang.Blocks.neo_motor_speed_n40, '-40'], - [Lang.Blocks.neo_motor_speed_n50, '-50'], - [Lang.Blocks.neo_motor_speed_n60, '-60'], - [Lang.Blocks.neo_motor_speed_n70, '-70'], - [Lang.Blocks.neo_motor_speed_n80, '-80'], - [Lang.Blocks.neo_motor_speed_n90, '-90'], - [Lang.Blocks.neo_motor_speed_n100, '-100'], + [Lang.Blocks.neo_duration_c, 'c'], + [Lang.Blocks.neo_duration_0, '0'], + [Lang.Blocks.neo_duration_1, '1'], + [Lang.Blocks.neo_duration_2, '2'], + [Lang.Blocks.neo_duration_3, '3'], + [Lang.Blocks.neo_duration_4, '4'], + [Lang.Blocks.neo_duration_5, '5'], + [Lang.Blocks.neo_duration_6, '6'], + [Lang.Blocks.neo_duration_7, '7'], + [Lang.Blocks.neo_duration_8, '8'], + [Lang.Blocks.neo_duration_9, '9'], ], - value: '100', + value: 'c', fontSize: 11, bgColor: EntryStatic.colorSet.block.darken.HARDWARE, arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, @@ -4912,7 +5024,7 @@ Entry.Neo = new (class Neo { return script.getStringField('VALUE'); }, }, - neo_arg_duration: { + neo_arg_motor_speed: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, skeleton: 'basic_string_field', @@ -4921,19 +5033,29 @@ Entry.Neo = new (class Neo { { type: 'Dropdown', options: [ - [Lang.Blocks.neo_duration_c, 'c'], - [Lang.Blocks.neo_duration_0, '0'], - [Lang.Blocks.neo_duration_1, '1'], - [Lang.Blocks.neo_duration_2, '2'], - [Lang.Blocks.neo_duration_3, '3'], - [Lang.Blocks.neo_duration_4, '4'], - [Lang.Blocks.neo_duration_5, '5'], - [Lang.Blocks.neo_duration_6, '6'], - [Lang.Blocks.neo_duration_7, '7'], - [Lang.Blocks.neo_duration_8, '8'], - [Lang.Blocks.neo_duration_9, '9'], + [Lang.Blocks.neo_motor_speed_100, '100'], + [Lang.Blocks.neo_motor_speed_90, '90'], + [Lang.Blocks.neo_motor_speed_80, '80'], + [Lang.Blocks.neo_motor_speed_70, '70'], + [Lang.Blocks.neo_motor_speed_60, '60'], + [Lang.Blocks.neo_motor_speed_50, '50'], + [Lang.Blocks.neo_motor_speed_40, '40'], + [Lang.Blocks.neo_motor_speed_30, '30'], + [Lang.Blocks.neo_motor_speed_20, '20'], + [Lang.Blocks.neo_motor_speed_10, '10'], + [Lang.Blocks.neo_motor_speed_0, '0'], + [Lang.Blocks.neo_motor_speed_n10, '-10'], + [Lang.Blocks.neo_motor_speed_n20, '-20'], + [Lang.Blocks.neo_motor_speed_n30, '-30'], + [Lang.Blocks.neo_motor_speed_n40, '-40'], + [Lang.Blocks.neo_motor_speed_n50, '-50'], + [Lang.Blocks.neo_motor_speed_n60, '-60'], + [Lang.Blocks.neo_motor_speed_n70, '-70'], + [Lang.Blocks.neo_motor_speed_n80, '-80'], + [Lang.Blocks.neo_motor_speed_n90, '-90'], + [Lang.Blocks.neo_motor_speed_n100, '-100'], ], - value: 'c', + value: '100', fontSize: 11, bgColor: EntryStatic.colorSet.block.darken.HARDWARE, arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, @@ -5389,6 +5511,23 @@ Entry.Neo = new (class Neo { Entry.hw.update(); } + requestExt2Command(blockId, type, params) { + console.log(blockId + ' requested'); + if (this.pendingResponseList[blockId]) { + delete this.pendingResponseList[blockId]; + } + this.pendingResponseList[blockId] = 'executed'; + const command = this.makeCommandExt2(blockId, type, params); + if (!command) return; + const pdu = this.makePdu(command); + this.executeList[blockId] = { + blockId, + pdu, + }; + Entry.hw.sendQueue.executeList = { ...this.executeList }; + Entry.hw.update(); + } + requestExtCommand(blockId, type, params) { console.log(blockId + ' requested'); if (this.pendingResponseList[blockId]) { @@ -5465,6 +5604,7 @@ Entry.Neo = new (class Neo { const output = params[0]; const angle = params[1]; const speed = params[2]; + body.push(this.getUnitId(output), ActorKind.SERVO, ServoCommand.ANGLE_WAIT); const data = Buffer.from([0, 0, 0, 0, 1, 0]); data.writeInt16LE(angle, 0); @@ -5622,22 +5762,35 @@ Entry.Neo = new (class Neo { if (type === NeoBlockType.MOTOR_MOVE) { const which = params[0]; const unitId = this.getUnitId(params[1]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.MOTOR); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.MOTOR + ); const data = Buffer.from([unitId, 0, which, 0, 0, 0]); body.push(...data); } else if (type === NeoBlockType.ROBOT_MOVE) { const robotCommand = params[0]; const unitId = this.getUnitId(params[1]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.ROBOT); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.ROBOT + ); const data = Buffer.from([unitId, 0, 0, 0]); data.writeInt16LE(robotCommand, 2); body.push(...data); } else if (type === NeoBlockType.SERVO_ANGLE || type === NeoBlockType.SERVO_ANGLE_WAIT) { const unitId = this.getUnitId(params[0]); - const inUnitId = this.getUnitId(params[1]); - const speed = params[2]; + let angle = params[1]; + let speed = params[2]; + if (angle.indexOf('IN') >= 0) angle = this.getUnitId(angle); body.push(PduCode.EXTEND_1, blockId, unitId, ActorKind.SERVO, ServoCommand.ANGLE); - const data = Buffer.from([inUnitId, 0, 0, 0, 1, 0]); + const data = Buffer.from([angle, 0, 0, 0, 1, 0]); data.writeInt16LE(speed, 2); body.push(...data); } else if (type === NeoBlockType.SERVO_ROTATE) { @@ -5654,13 +5807,25 @@ Entry.Neo = new (class Neo { type === NeoBlockType.AUTO_DETECT_WALL_START ) { const unitId = this.getUnitId(params[0]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.ROBOT); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.ROBOT + ); const data = Buffer.from([unitId, 0, 0x10, 0]); body.push(...data); } else if (type === NeoBlockType.AUTO_DRIVING_SENSOR_START) { const sensor = params[0]; const unitId = this.getUnitId(params[1]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.ROBOT); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.ROBOT + ); const data = Buffer.from([0, 0, 0, 0]); data.writeInt16LE(unitId, 0); data.writeInt16LE(sensor, 2); @@ -5679,7 +5844,13 @@ Entry.Neo = new (class Neo { body.push(...data); } else if (type === NeoBlockType.BUZZER_WITH_SENSOR) { const sensorUnitId = this.getUnitId(params[0]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.BUZZER); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.BUZZER + ); const data = Buffer.from([0, 0]); data.writeInt16LE(sensorUnitId, 0); body.push(...data); @@ -5693,6 +5864,18 @@ Entry.Neo = new (class Neo { return body; } + makeCommandExt2(blockId, type, params) { + const body = [FrameCode.BASIC]; + if (type === NeoBlockType.SERVO_ANGLE || type === NeoBlockType.SERVO_ANGLE_WAIT) { + const unitId = this.getUnitId(params[0]); + const angleInUnitId = this.getUnitId(params[1]); + const speedInUnitId = this.getUnitId(params[2]); + body.push(PduCode.EXTEND_2, blockId, unitId, ActorKind.SERVO, ServoCommand.ANGLE); + const data = Buffer.from([angleInUnitId, 0, speedInUnitId, 0, 1, 0]); + body.push(...data); + } + return body; + } /* 후면주차 실행 (pending response 하지 않고 바로 다음 단계로 넘어감 : phase 가 너무 많아서 간소화) 주석은 왼쪽 기준으로 오른쪽에서는 좌우만 바꿔준다. diff --git a/src/playground/blocks/hardware/block_neobot_purple.js b/src/playground/blocks/hardware/block_neobot_purple.js index 6d7a21cd5a..e9b7b16bd0 100644 --- a/src/playground/blocks/hardware/block_neobot_purple.js +++ b/src/playground/blocks/hardware/block_neobot_purple.js @@ -47,18 +47,16 @@ Entry.NeobotPurple.setLanguage = function() { ko: { template: { // sensor + neobot_purple_sensor_title: '센서', neobot_purple_sensor_value: '%1', neobot_purple_sensor_convert_scale: '%1 %2 ~ %3 를 %4 ~ %5 으로 변환', - - // decision neobot_purple_decision_sensor_is_over: '%1 %2 %3', neobot_purple_decision_equal_with_sensor: '%1 컬러가 %2', neobot_purple_decision_sensor_angle: '%1 각도 %2 %3', - - // remote neobot_purple_remote_button: '리모컨 버튼 %1 을 누름', // LED + neobot_purple_led_title: 'LED', neobot_purple_arg_led_duration: '%1', neobot_purple_led_on: 'LED 켜기 %1 %2 %3 %4', neobot_purple_output_led_off: '%1 LED 끄기 %2', @@ -66,9 +64,11 @@ Entry.NeobotPurple.setLanguage = function() { neobot_purple_color_led_on: '%1 컬러LED 켜기 R %2 G %3 B %4 %5', // output + neobot_purple_output_title: '출력', neobot_purple_set_output: '%1 에 %2 값 출력하기 %3', // motor + neobot_purple_motor_title: '회전모터', neobot_purple_robot: '로봇 %1 %2', neobot_purple_motor_start: '모터 회전하기 %1 %2 %3 %4 %5', neobot_purple_motor_stop: '%1 모터 멈추기 %2', @@ -76,11 +76,13 @@ Entry.NeobotPurple.setLanguage = function() { neobot_purple_arg_motor_duration: '%1', // melody + neobot_purple_buzzer_title: '버저', neobot_purple_play_note_for: '버저 울리기 옥타브: %2 음: %1 길이: %3 %4', neobot_purple_melody_play_with_sensor: '%1 센서로 버저 울리기 %2', neobot_purple_melody_stop: '버저 멈추기 %1', // servo + neobot_purple_servo_title: '서보모터', get_servo_degree: '%1', neobot_purple_servo_init: '%1 서보모터 리셋 %2', neobot_purple_servo_rotate: '서보모터 회전하기 %1 %2 %3 %4', @@ -220,28 +222,30 @@ Entry.NeobotPurple.setLanguage = function() { // en.js에 작성하던 내용 template: { // sensor + neobot_purple_sensor_title: 'Sensor', neobot_purple_sensor_value: '%1', - neobot_purple_sensor_convert_scale: '%1 \'s changed value range: %2 ~ %3 conversion: %4 ~ %5', - - // decision + neobot_purple_sensor_convert_scale: + "%1 's changed value range: %2 ~ %3 conversion: %4 ~ %5", neobot_purple_decision_sensor_is_over: '%1 %2 %3', - neobot_purple_decision_equal_with_sensor: '%1 \'s color is %2', + neobot_purple_decision_equal_with_sensor: "%1 's color is %2", neobot_purple_decision_sensor_angle: '%1 angle %2 %3', - - // remote neobot_purple_remote_button: 'pressing button %1 of remote controller', // LED + neobot_purple_led_title: 'LED', neobot_purple_arg_led_duration: '%1', neobot_purple_led_on: 'Turn on the LED %1 %2 %3 %4', neobot_purple_output_led_off: 'Turn off the %1 LED %2', - neobot_purple_led_brightness_with_sensor: 'Control %2 LED\'s brightness with %1 sensor %3', + neobot_purple_led_brightness_with_sensor: + "Control %2 LED's brightness with %1 sensor %3", neobot_purple_color_led_on: 'Turn on the %1 color LED R %2 G %3 B %4 %5', // output + neobot_purple_output_title: 'Set output', neobot_purple_set_output: 'Output %2 value to %1 port %3', // motor + neobot_purple_motor_title: 'Motor', neobot_purple_robot: 'Robot %1 %2', neobot_purple_motor_start: 'Motor operation %1 %2 %3 %4 %5', neobot_purple_motor_stop: 'Stop the %1 motor(s) %2', @@ -249,11 +253,13 @@ Entry.NeobotPurple.setLanguage = function() { neobot_purple_arg_motor_duration: '%1', // melody + neobot_purple_buzzer_title: 'Buzzer', neobot_purple_play_note_for: 'Buzzer octave: %1 scale: %2 note: %3 %4', neobot_purple_melody_play_with_sensor: 'Buzzer rings by %1 sensor value %2', neobot_purple_melody_stop: 'Stop the buzzer %1', // servo + neobot_purple_servo_title: 'Servo motor', neobot_purple_servo_init: 'Reset the %1 servo motor %2', neobot_purple_servo_rotate: 'Rotate the servo motor %1 %2 %3 %4', neobot_purple_servo_stop: 'Stop the %1 servo motor %2', @@ -393,41 +399,43 @@ Entry.NeobotPurple.setLanguage = function() { Entry.NeobotPurple.blockMenuBlocks = [ // sensor + 'neobot_purple_sensor_title', 'neobot_purple_sensor_value', 'neobot_purple_sensor_convert_scale', - - // decision 'neobot_purple_decision_sensor_is_over', 'neobot_purple_decision_equal_with_sensor', 'neobot_purple_decision_sensor_angle', - - // remote 'neobot_purple_remote_button', // led + 'neobot_purple_led_title', 'neobot_purple_led_on', 'neobot_purple_led_brightness_with_sensor', 'neobot_purple_color_led_on', 'neobot_purple_output_led_off', // output + 'neobot_purple_output_title', 'neobot_purple_set_output', // motor + 'neobot_purple_motor_title', 'neobot_purple_robot', 'neobot_purple_motor_start', 'neobot_purple_motor_stop', - // melody - 'neobot_purple_play_note_for', - 'neobot_purple_melody_play_with_sensor', - 'neobot_purple_melody_stop', - // servo + 'neobot_purple_servo_title', 'neobot_purple_servo_init', 'neobot_purple_servo_rotate', 'neobot_purple_servo_stop', 'neobot_purple_servo_change_degree', + + // melody + 'neobot_purple_buzzer_title', + 'neobot_purple_play_note_for', + 'neobot_purple_melody_play_with_sensor', + 'neobot_purple_melody_stop', ]; Entry.NeobotPurple.getBlocks = function() { @@ -435,6 +443,30 @@ Entry.NeobotPurple.getBlocks = function() { /************************* * class neobot_purple_sensor *************************/ + neobot_purple_sensor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_sensor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_sensor_title', + }, + class: 'neobot_purple_sensor', + isNotFor: ['neobot_purple'], + events: {}, + }, neobot_purple_sensor_value: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -571,9 +603,6 @@ Entry.NeobotPurple.getBlocks = function() { }, }, - /************************* - * class neobot_purple_decision - *************************/ neobot_purple_decision_sensor_is_over: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -623,7 +652,7 @@ Entry.NeobotPurple.getBlocks = function() { SYMBOL: 1, VALUE: 2, }, - class: 'neobot_purple_decision', + class: 'neobot_purple_sensor', isNotFor: ['neobot_purple'], func: function(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -710,7 +739,7 @@ Entry.NeobotPurple.getBlocks = function() { SENSOR: 0, COLOR: 1, }, - class: 'neobot_purple_decision', + class: 'neobot_purple_sensor', isNotFor: ['neobot_purple'], func: function(sprite, script) { var sensorTemp = script.getStringField('SENSOR'); @@ -809,7 +838,7 @@ Entry.NeobotPurple.getBlocks = function() { SYMBOL: 1, VALUE: 2, }, - class: 'neobot_purple_decision', + class: 'neobot_purple_sensor', isNotFor: ['neobot_purple'], func: function(sprite, script) { var sensorTemp = script.getStringField('SENSOR'); @@ -837,9 +866,6 @@ Entry.NeobotPurple.getBlocks = function() { }, }, - /************************* - * class neobot_purple_remote - *************************/ neobot_purple_remote_button: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -873,7 +899,7 @@ Entry.NeobotPurple.getBlocks = function() { paramsKeyMap: { KEY: 0, }, - class: 'neobot_purple_remote', + class: 'neobot_purple_sensor', isNotFor: ['neobot_purple'], func: function(sprite, script) { var key = script.getNumberField('KEY'); @@ -889,6 +915,30 @@ Entry.NeobotPurple.getBlocks = function() { /************************* * class neobot_purple_led *************************/ + neobot_purple_led_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_led_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_led_title', + }, + class: 'neobot_purple_led', + isNotFor: ['neobot_purple'], + events: {}, + }, neobot_purple_led_on: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -972,7 +1022,11 @@ Entry.NeobotPurple.getBlocks = function() { Entry.console.print('==========================', 'speak'); } - if ((duration != '계속' && duration != 'constantly') && Entry.parseNumber(duration) <= 0) { + if ( + duration != '계속' && + duration != 'constantly' && + Entry.parseNumber(duration) <= 0 + ) { return script.callReturn(); } @@ -999,7 +1053,8 @@ Entry.NeobotPurple.getBlocks = function() { } else { Entry.hw.sendQueue[port] = 0; } - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_led_on : 0', 'speak'); + if (Entry.NeobotPurple.log_to_console) + Entry.console.print('neobot_purple_led_on : 0', 'speak'); script.timeFlag = 0; }, durationValue * 1000); return script; @@ -1125,10 +1180,13 @@ Entry.NeobotPurple.getBlocks = function() { // edited 210421, IN 값 0~100 을 0~255로 변경, 센서 100 이상은 최대값으로 처리함. value = Math.max(value, 0); value = Math.min(value, 100); - value = Math.ceil(value / 100 * 255); + value = Math.ceil((value / 100) * 255); if (Entry.NeobotPurple.log_to_console) { - Entry.console.print('=== neobot_purple_led_brightness_with_sensor ===', 'speak'); + Entry.console.print( + '=== neobot_purple_led_brightness_with_sensor ===', + 'speak' + ); Entry.console.print('out port : ' + outPort, 'speak'); Entry.console.print('in port : ' + inPort, 'speak'); Entry.console.print('sensor value : ' + Entry.hw.portData[inPort], 'speak'); @@ -1259,38 +1317,67 @@ Entry.NeobotPurple.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = valRed; if (out2) Entry.hw.sendQueue['OUT2'] = valRed; if (out3) Entry.hw.sendQueue['OUT3'] = valRed; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_color_led_on : ' + valRed, 'speak'); - setTimeout(function() { // set red + if (Entry.NeobotPurple.log_to_console) + Entry.console.print('neobot_purple_color_led_on : ' + valRed, 'speak'); + setTimeout(function() { + // set red if (out1) Entry.hw.sendQueue['OUT1'] = red; if (out2) Entry.hw.sendQueue['OUT2'] = red; if (out3) Entry.hw.sendQueue['OUT3'] = red; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_color_led_on : ' + red, 'speak'); - setTimeout(function() { // choose green + if (Entry.NeobotPurple.log_to_console) + Entry.console.print('neobot_purple_color_led_on : ' + red, 'speak'); + setTimeout(function() { + // choose green if (out1) Entry.hw.sendQueue['OUT1'] = valGreen; if (out2) Entry.hw.sendQueue['OUT2'] = valGreen; if (out3) Entry.hw.sendQueue['OUT3'] = valGreen; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_color_led_on : ' + valGreen, 'speak'); - setTimeout(function() { // set green + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_color_led_on : ' + valGreen, + 'speak' + ); + setTimeout(function() { + // set green if (out1) Entry.hw.sendQueue['OUT1'] = green; if (out2) Entry.hw.sendQueue['OUT2'] = green; if (out3) Entry.hw.sendQueue['OUT3'] = green; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_color_led_on : ' + green, 'speak'); - setTimeout(function() { // choose blue + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_color_led_on : ' + green, + 'speak' + ); + setTimeout(function() { + // choose blue if (out1) Entry.hw.sendQueue['OUT1'] = valBlue; if (out2) Entry.hw.sendQueue['OUT2'] = valBlue; if (out3) Entry.hw.sendQueue['OUT3'] = valBlue; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_color_led_on : ' + valBlue, 'speak'); - setTimeout(function() { // set blue + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_color_led_on : ' + valBlue, + 'speak' + ); + setTimeout(function() { + // set blue if (out1) Entry.hw.sendQueue['OUT1'] = blue; if (out2) Entry.hw.sendQueue['OUT2'] = blue; if (out3) Entry.hw.sendQueue['OUT3'] = blue; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_color_led_on : ' + blue, 'speak'); - setTimeout(function() { // accept + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_color_led_on : ' + blue, + 'speak' + ); + setTimeout(function() { + // accept if (out1) Entry.hw.sendQueue['OUT1'] = valAccept; if (out2) Entry.hw.sendQueue['OUT2'] = valAccept; if (out3) Entry.hw.sendQueue['OUT3'] = valAccept; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_color_led_on : ' + valAccept, 'speak'); - setTimeout(function() { // final delay + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_color_led_on : ' + valAccept, + 'speak' + ); + setTimeout(function() { + // final delay script.timeFlag = 0; }, 200); }, 200); @@ -1314,6 +1401,30 @@ Entry.NeobotPurple.getBlocks = function() { /************************* * class neobot_purple_output *************************/ + neobot_purple_output_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_output_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_output_title', + }, + class: 'neobot_purple_output', + isNotFor: ['neobot_purple'], + events: {}, + }, neobot_purple_set_output: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1391,6 +1502,30 @@ Entry.NeobotPurple.getBlocks = function() { /************************* * class neobot_purple_motor *************************/ + neobot_purple_motor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_motor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_motor_title', + }, + class: 'neobot_purple_motor', + isNotFor: ['neobot_purple'], + events: {}, + }, neobot_purple_robot: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1419,10 +1554,7 @@ Entry.NeobotPurple.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_purple_robot', }, paramsKeyMap: { @@ -1550,7 +1682,11 @@ Entry.NeobotPurple.getBlocks = function() { const speed = script.getStringValue('SPEED', script); const duration = script.getStringValue('DURATION', script); - if (duration != '계속' && duration != 'constantly' && Entry.parseNumber(duration) <= 0) { + if ( + duration != '계속' && + duration != 'constantly' && + Entry.parseNumber(duration) <= 0 + ) { return script.callReturn(); } @@ -1590,7 +1726,7 @@ Entry.NeobotPurple.getBlocks = function() { } speedValue = Math.max(speedValue, 0); speedValue = Math.min(speedValue, 100); - speedValue = Math.ceil(speedValue / 100 * 15); + speedValue = Math.ceil((speedValue / 100) * 15); const leftOutValue = leftDirectionValue + speedValue; const rightOutValue = rightDirectionValue + speedValue; @@ -1601,8 +1737,14 @@ Entry.NeobotPurple.getBlocks = function() { Entry.console.print('direction : ' + direction, 'speak'); Entry.console.print('speed : ' + speed, 'speak'); Entry.console.print('duration : ' + duration, 'speak'); - Entry.console.print('left direction value : ' + leftDirectionValue, 'speak'); - Entry.console.print('right direction value : ' + rightDirectionValue, 'speak'); + Entry.console.print( + 'left direction value : ' + leftDirectionValue, + 'speak' + ); + Entry.console.print( + 'right direction value : ' + rightDirectionValue, + 'speak' + ); Entry.console.print('speed value : ' + speedValue, 'speak'); Entry.console.print('left output value : ' + leftOutValue, 'speak'); Entry.console.print('right output value : ' + rightOutValue, 'speak'); @@ -1626,7 +1768,8 @@ Entry.NeobotPurple.getBlocks = function() { setTimeout(function() { Entry.hw.sendQueue['DCL'] = 0; Entry.hw.sendQueue['DCR'] = 0; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_motor_start : 0', 'speak'); + if (Entry.NeobotPurple.log_to_console) + Entry.console.print('neobot_purple_motor_start : 0', 'speak'); script.timeFlag = 0; }, durationValue * 1000); return script; @@ -1667,9 +1810,7 @@ Entry.NeobotPurple.getBlocks = function() { ], events: {}, def: { - params: [ - null, null, - ], + params: [null, null], type: 'neobot_purple_motor_stop', }, paramsKeyMap: { @@ -1701,6 +1842,30 @@ Entry.NeobotPurple.getBlocks = function() { /************************* * class neobot_purple_melody *************************/ + neobot_purple_buzzer_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_buzzer_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_buzzer_title', + }, + class: 'neobot_purple_melody', + isNotFor: ['neobot_purple'], + events: {}, + }, neobot_purple_play_note_for: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1799,9 +1964,10 @@ Entry.NeobotPurple.getBlocks = function() { Entry.hw.sendQueue['SND'] = value; setTimeout(function() { Entry.hw.sendQueue['SND'] = 0; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_play_note_for : 0', 'speak'); + if (Entry.NeobotPurple.log_to_console) + Entry.console.print('neobot_purple_play_note_for : 0', 'speak'); script.timeFlag = 0; - }, 1 / duration * 2000); + }, (1 / duration) * 2000); return script; } else if (script.timeFlag == 1) { return script; @@ -1840,9 +2006,7 @@ Entry.NeobotPurple.getBlocks = function() { ], events: {}, def: { - params: [ - null, null, - ], + params: [null, null], type: 'neobot_purple_melody_play_with_sensor', }, paramsKeyMap: { @@ -1857,7 +2021,7 @@ Entry.NeobotPurple.getBlocks = function() { // edited 210421, 0~100 을 0~65로 변환, 100 이상은 최대값으로 처리함. value = Math.max(value, 0); value = Math.min(value, 100); - value = Math.ceil(value / 100 * 65); + value = Math.ceil((value / 100) * 65); if (Entry.NeobotPurple.log_to_console) { Entry.console.print('=== neobot_purple_melody_play_with_sensor ===', 'speak'); @@ -1885,9 +2049,7 @@ Entry.NeobotPurple.getBlocks = function() { ], events: {}, def: { - params: [ - null, - ], + params: [null], type: 'neobot_purple_melody_stop', }, paramsKeyMap: {}, @@ -1908,6 +2070,30 @@ Entry.NeobotPurple.getBlocks = function() { /************************* * class neobot_purple_servo *************************/ + neobot_purple_servo_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_servo_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_servo_title', + }, + class: 'neobot_purple_servo', + isNotFor: ['neobot_purple'], + events: {}, + }, neobot_purple_servo_init: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1935,10 +2121,7 @@ Entry.NeobotPurple.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_purple_servo_init', }, paramsKeyMap: { @@ -1973,12 +2156,14 @@ Entry.NeobotPurple.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = resetValue; if (out2) Entry.hw.sendQueue['OUT2'] = resetValue; if (out3) Entry.hw.sendQueue['OUT3'] = resetValue; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_servo_init : ' + resetValue, 'speak'); + if (Entry.NeobotPurple.log_to_console) + Entry.console.print('neobot_purple_servo_init : ' + resetValue, 'speak'); setTimeout(function() { if (out1) Entry.hw.sendQueue['OUT1'] = initValue; if (out2) Entry.hw.sendQueue['OUT2'] = initValue; if (out3) Entry.hw.sendQueue['OUT3'] = initValue; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_servo_init : ' + initValue, 'speak'); + if (Entry.NeobotPurple.log_to_console) + Entry.console.print('neobot_purple_servo_init : ' + initValue, 'speak'); setTimeout(function() { script.timeFlag = 0; }, 100); @@ -2057,12 +2242,7 @@ Entry.NeobotPurple.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - null, - null, - ], + params: [null, null, null, null], type: 'neobot_purple_servo_rotate', }, paramsKeyMap: { @@ -2148,10 +2328,7 @@ Entry.NeobotPurple.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_purple_servo_stop', }, paramsKeyMap: { @@ -2333,18 +2510,33 @@ Entry.NeobotPurple.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = directionValue; if (out2) Entry.hw.sendQueue['OUT2'] = directionValue; if (out3) Entry.hw.sendQueue['OUT3'] = directionValue; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_servo_change_degree : ' + directionValue, 'speak'); - setTimeout(function() { // speed + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_servo_change_degree : ' + directionValue, + 'speak' + ); + setTimeout(function() { + // speed if (out1) Entry.hw.sendQueue['OUT1'] = speedValue; if (out2) Entry.hw.sendQueue['OUT2'] = speedValue; if (out3) Entry.hw.sendQueue['OUT3'] = speedValue; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_servo_change_degree : ' + speedValue, 'speak'); - setTimeout(function() { // degree + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_servo_change_degree : ' + speedValue, + 'speak' + ); + setTimeout(function() { + // degree if (out1) Entry.hw.sendQueue['OUT1'] = degreeValue; if (out2) Entry.hw.sendQueue['OUT2'] = degreeValue; if (out3) Entry.hw.sendQueue['OUT3'] = degreeValue; - if (Entry.NeobotPurple.log_to_console) Entry.console.print('neobot_purple_servo_change_degree : ' + degreeValue, 'speak'); - setTimeout(function() { // final delay + if (Entry.NeobotPurple.log_to_console) + Entry.console.print( + 'neobot_purple_servo_change_degree : ' + degreeValue, + 'speak' + ); + setTimeout(function() { + // final delay script.timeFlag = 0; }, 200); }, 200); diff --git a/src/playground/blocks/hardware/block_neobot_soco.js b/src/playground/blocks/hardware/block_neobot_soco.js index 91851353f5..092cda8d1d 100644 --- a/src/playground/blocks/hardware/block_neobot_soco.js +++ b/src/playground/blocks/hardware/block_neobot_soco.js @@ -47,18 +47,16 @@ Entry.NeobotSoco.setLanguage = function() { ko: { template: { // sensor + neobot_soco_sensor_title: '센서', neobot_soco_sensor_value: '%1', neobot_soco_sensor_convert_scale: '%1 %2 ~ %3 를 %4 ~ %5 으로 변환', - - // decision neobot_soco_decision_sensor_is_over: '%1 %2 %3', neobot_soco_decision_equal_with_sensor: '%1 컬러가 %2', neobot_soco_decision_sensor_angle: '%1 각도 %2 %3', - - // remote neobot_soco_remote_button: '리모컨 버튼 %1 을 누름', // LED + neobot_soco_led_title: 'LED', neobot_soco_arg_led_duration: '%1', neobot_soco_led_on: 'LED 켜기 %1 %2 %3 %4', neobot_soco_output_led_off: '%1 LED 끄기 %2', @@ -66,9 +64,11 @@ Entry.NeobotSoco.setLanguage = function() { neobot_soco_color_led_on: '%1 컬러LED 켜기 R %2 G %3 B %4 %5', // output + neobot_soco_output_title: '출력', neobot_soco_set_output: '%1 에 %2 값 출력하기 %3', // motor + neobot_soco_motor_title: '회전모터', neobot_soco_robot: '로봇 %1 %2', neobot_soco_motor_start: '모터 회전하기 %1 %2 %3 %4 %5', neobot_soco_motor_stop: '%1 모터 멈추기 %2', @@ -76,11 +76,13 @@ Entry.NeobotSoco.setLanguage = function() { neobot_soco_arg_motor_duration: '%1', // melody + neobot_soco_buzzer_title: '버저', neobot_soco_play_note_for: '버저 울리기 옥타브: %2 음: %1 길이: %3 %4', neobot_soco_melody_play_with_sensor: '%1 센서로 버저 울리기 %2', neobot_soco_melody_stop: '버저 멈추기 %1', // servo + neobot_soco_servo_title: '서보모터', get_servo_degree: '%1', neobot_soco_servo_init: '%1 서보모터 리셋 %2', neobot_soco_servo_rotate: '서보모터 회전하기 %1 %2 %3 %4', @@ -220,28 +222,30 @@ Entry.NeobotSoco.setLanguage = function() { // en.js에 작성하던 내용 template: { // sensor + neobot_soco_sensor_title: 'Sensor', neobot_soco_sensor_value: '%1', - neobot_soco_sensor_convert_scale: '%1 \'s changed value range: %2 ~ %3 conversion: %4 ~ %5', - - // decision + neobot_soco_sensor_convert_scale: + "%1 's changed value range: %2 ~ %3 conversion: %4 ~ %5", neobot_soco_decision_sensor_is_over: '%1 %2 %3', - neobot_soco_decision_equal_with_sensor: '%1 \'s color is %2', + neobot_soco_decision_equal_with_sensor: "%1 's color is %2", neobot_soco_decision_sensor_angle: '%1 angle %2 %3', - - // remote neobot_soco_remote_button: 'pressing button %1 of remote controller', // LED + neobot_soco_led_title: 'LED', neobot_soco_arg_led_duration: '%1', neobot_soco_led_on: 'Turn on the LED %1 %2 %3 %4', neobot_soco_output_led_off: 'Turn off the %1 LED %2', - neobot_soco_led_brightness_with_sensor: 'Control %2 LED\'s brightness with %1 sensor %3', + neobot_soco_led_brightness_with_sensor: + "Control %2 LED's brightness with %1 sensor %3", neobot_soco_color_led_on: 'Turn on the %1 color LED R %2 G %3 B %4 %5', // output + neobot_soco_output_title: 'Set output', neobot_soco_set_output: 'Output %2 value to %1 port %3', // motor + neobot_soco_motor_title: 'Motor', neobot_soco_robot: 'Robot %1 %2', neobot_soco_motor_start: 'Motor operation %1 %2 %3 %4 %5', neobot_soco_motor_stop: 'Stop the %1 motor(s) %2', @@ -249,11 +253,13 @@ Entry.NeobotSoco.setLanguage = function() { neobot_soco_arg_motor_duration: '%1', // melody + neobot_soco_buzzer_title: 'Buzzer', neobot_soco_play_note_for: 'Buzzer octave: %1 scale: %2 note: %3 %4', neobot_soco_melody_play_with_sensor: 'Buzzer rings by %1 sensor value %2', neobot_soco_melody_stop: 'Stop the buzzer %1', // servo + neobot_soco_servo_title: 'Servo motor', neobot_soco_servo_init: 'Reset the %1 servo motor %2', neobot_soco_servo_rotate: 'Rotate the servo motor %1 %2 %3 %4', neobot_soco_servo_stop: 'Stop the %1 servo motor %2', @@ -393,41 +399,43 @@ Entry.NeobotSoco.setLanguage = function() { Entry.NeobotSoco.blockMenuBlocks = [ // sensor + 'neobot_soco_sensor_title', 'neobot_soco_sensor_value', 'neobot_soco_sensor_convert_scale', - - // decision 'neobot_soco_decision_sensor_is_over', 'neobot_soco_decision_equal_with_sensor', 'neobot_soco_decision_sensor_angle', - - // remote 'neobot_soco_remote_button', // led + 'neobot_soco_led_title', 'neobot_soco_led_on', 'neobot_soco_led_brightness_with_sensor', 'neobot_soco_color_led_on', 'neobot_soco_output_led_off', // output + 'neobot_soco_output_title', 'neobot_soco_set_output', // motor + 'neobot_soco_motor_title', 'neobot_soco_robot', 'neobot_soco_motor_start', 'neobot_soco_motor_stop', - // melody - 'neobot_soco_play_note_for', - 'neobot_soco_melody_play_with_sensor', - 'neobot_soco_melody_stop', - // servo + 'neobot_soco_servo_title', 'neobot_soco_servo_init', 'neobot_soco_servo_rotate', 'neobot_soco_servo_stop', 'neobot_soco_servo_change_degree', + + // melody + 'neobot_soco_buzzer_title', + 'neobot_soco_play_note_for', + 'neobot_soco_melody_play_with_sensor', + 'neobot_soco_melody_stop', ]; Entry.NeobotSoco.getBlocks = function() { @@ -435,6 +443,30 @@ Entry.NeobotSoco.getBlocks = function() { /************************* * class neobot_soco_sensor *************************/ + neobot_soco_sensor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_sensor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_sensor_title', + }, + class: 'neobot_soco_sensor', + isNotFor: ['neobot_soco'], + events: {}, + }, neobot_soco_sensor_value: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -571,9 +603,6 @@ Entry.NeobotSoco.getBlocks = function() { }, }, - /************************* - * class neobot_soco_decision - *************************/ neobot_soco_decision_sensor_is_over: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -623,7 +652,7 @@ Entry.NeobotSoco.getBlocks = function() { SYMBOL: 1, VALUE: 2, }, - class: 'neobot_soco_decision', + class: 'neobot_soco_sensor', isNotFor: ['neobot_soco'], func: function(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -710,7 +739,7 @@ Entry.NeobotSoco.getBlocks = function() { SENSOR: 0, COLOR: 1, }, - class: 'neobot_soco_decision', + class: 'neobot_soco_sensor', isNotFor: ['neobot_soco'], func: function(sprite, script) { var sensorTemp = script.getStringField('SENSOR'); @@ -809,7 +838,7 @@ Entry.NeobotSoco.getBlocks = function() { SYMBOL: 1, VALUE: 2, }, - class: 'neobot_soco_decision', + class: 'neobot_soco_sensor', isNotFor: ['neobot_soco'], func: function(sprite, script) { var sensorTemp = script.getStringField('SENSOR'); @@ -837,9 +866,6 @@ Entry.NeobotSoco.getBlocks = function() { }, }, - /************************* - * class neobot_soco_remote - *************************/ neobot_soco_remote_button: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -873,7 +899,7 @@ Entry.NeobotSoco.getBlocks = function() { paramsKeyMap: { KEY: 0, }, - class: 'neobot_soco_remote', + class: 'neobot_soco_sensor', isNotFor: ['neobot_soco'], func: function(sprite, script) { var key = script.getNumberField('KEY'); @@ -889,6 +915,30 @@ Entry.NeobotSoco.getBlocks = function() { /************************* * class neobot_soco_led *************************/ + neobot_soco_led_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_led_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_led_title', + }, + class: 'neobot_soco_led', + isNotFor: ['neobot_soco'], + events: {}, + }, neobot_soco_led_on: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -972,7 +1022,11 @@ Entry.NeobotSoco.getBlocks = function() { Entry.console.print('==========================', 'speak'); } - if ((duration != '계속' && duration != 'constantly') && Entry.parseNumber(duration) <= 0) { + if ( + duration != '계속' && + duration != 'constantly' && + Entry.parseNumber(duration) <= 0 + ) { return script.callReturn(); } @@ -999,7 +1053,8 @@ Entry.NeobotSoco.getBlocks = function() { } else { Entry.hw.sendQueue[port] = 0; } - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_led_on : 0', 'speak'); + if (Entry.NeobotSoco.log_to_console) + Entry.console.print('neobot_soco_led_on : 0', 'speak'); script.timeFlag = 0; }, durationValue * 1000); return script; @@ -1125,7 +1180,7 @@ Entry.NeobotSoco.getBlocks = function() { // edited 210421, IN 값 0~100 을 0~255로 변경, 센서 100 이상은 최대값으로 처리함. value = Math.max(value, 0); value = Math.min(value, 100); - value = Math.ceil(value / 100 * 255); + value = Math.ceil((value / 100) * 255); if (Entry.NeobotSoco.log_to_console) { Entry.console.print('=== neobot_soco_led_brightness_with_sensor ===', 'speak'); @@ -1259,38 +1314,67 @@ Entry.NeobotSoco.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = valRed; if (out2) Entry.hw.sendQueue['OUT2'] = valRed; if (out3) Entry.hw.sendQueue['OUT3'] = valRed; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_color_led_on : ' + valRed, 'speak'); - setTimeout(function() { // set red + if (Entry.NeobotSoco.log_to_console) + Entry.console.print('neobot_soco_color_led_on : ' + valRed, 'speak'); + setTimeout(function() { + // set red if (out1) Entry.hw.sendQueue['OUT1'] = red; if (out2) Entry.hw.sendQueue['OUT2'] = red; if (out3) Entry.hw.sendQueue['OUT3'] = red; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_color_led_on : ' + red, 'speak'); - setTimeout(function() { // choose green + if (Entry.NeobotSoco.log_to_console) + Entry.console.print('neobot_soco_color_led_on : ' + red, 'speak'); + setTimeout(function() { + // choose green if (out1) Entry.hw.sendQueue['OUT1'] = valGreen; if (out2) Entry.hw.sendQueue['OUT2'] = valGreen; if (out3) Entry.hw.sendQueue['OUT3'] = valGreen; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_color_led_on : ' + valGreen, 'speak'); - setTimeout(function() { // set green + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_color_led_on : ' + valGreen, + 'speak' + ); + setTimeout(function() { + // set green if (out1) Entry.hw.sendQueue['OUT1'] = green; if (out2) Entry.hw.sendQueue['OUT2'] = green; if (out3) Entry.hw.sendQueue['OUT3'] = green; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_color_led_on : ' + green, 'speak'); - setTimeout(function() { // choose blue + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_color_led_on : ' + green, + 'speak' + ); + setTimeout(function() { + // choose blue if (out1) Entry.hw.sendQueue['OUT1'] = valBlue; if (out2) Entry.hw.sendQueue['OUT2'] = valBlue; if (out3) Entry.hw.sendQueue['OUT3'] = valBlue; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_color_led_on : ' + valBlue, 'speak'); - setTimeout(function() { // set blue + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_color_led_on : ' + valBlue, + 'speak' + ); + setTimeout(function() { + // set blue if (out1) Entry.hw.sendQueue['OUT1'] = blue; if (out2) Entry.hw.sendQueue['OUT2'] = blue; if (out3) Entry.hw.sendQueue['OUT3'] = blue; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_color_led_on : ' + blue, 'speak'); - setTimeout(function() { // accept + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_color_led_on : ' + blue, + 'speak' + ); + setTimeout(function() { + // accept if (out1) Entry.hw.sendQueue['OUT1'] = valAccept; if (out2) Entry.hw.sendQueue['OUT2'] = valAccept; if (out3) Entry.hw.sendQueue['OUT3'] = valAccept; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_color_led_on : ' + valAccept, 'speak'); - setTimeout(function() { // final delay + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_color_led_on : ' + valAccept, + 'speak' + ); + setTimeout(function() { + // final delay script.timeFlag = 0; }, 200); }, 200); @@ -1314,6 +1398,30 @@ Entry.NeobotSoco.getBlocks = function() { /************************* * class neobot_soco_output *************************/ + neobot_soco_output_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_output_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_output_title', + }, + class: 'neobot_soco_output', + isNotFor: ['neobot_soco'], + events: {}, + }, neobot_soco_set_output: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1391,6 +1499,30 @@ Entry.NeobotSoco.getBlocks = function() { /************************* * class neobot_soco_motor *************************/ + neobot_soco_motor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_motor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_motor_title', + }, + class: 'neobot_soco_motor', + isNotFor: ['neobot_soco'], + events: {}, + }, neobot_soco_robot: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1419,10 +1551,7 @@ Entry.NeobotSoco.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_soco_robot', }, paramsKeyMap: { @@ -1550,7 +1679,11 @@ Entry.NeobotSoco.getBlocks = function() { const speed = script.getStringValue('SPEED', script); const duration = script.getStringValue('DURATION', script); - if (duration != '계속' && duration != 'constantly' && Entry.parseNumber(duration) <= 0) { + if ( + duration != '계속' && + duration != 'constantly' && + Entry.parseNumber(duration) <= 0 + ) { return script.callReturn(); } @@ -1590,7 +1723,7 @@ Entry.NeobotSoco.getBlocks = function() { } speedValue = Math.max(speedValue, 0); speedValue = Math.min(speedValue, 100); - speedValue = Math.ceil(speedValue / 100 * 15); + speedValue = Math.ceil((speedValue / 100) * 15); const leftOutValue = leftDirectionValue + speedValue; const rightOutValue = rightDirectionValue + speedValue; @@ -1601,8 +1734,14 @@ Entry.NeobotSoco.getBlocks = function() { Entry.console.print('direction : ' + direction, 'speak'); Entry.console.print('speed : ' + speed, 'speak'); Entry.console.print('duration : ' + duration, 'speak'); - Entry.console.print('left direction value : ' + leftDirectionValue, 'speak'); - Entry.console.print('right direction value : ' + rightDirectionValue, 'speak'); + Entry.console.print( + 'left direction value : ' + leftDirectionValue, + 'speak' + ); + Entry.console.print( + 'right direction value : ' + rightDirectionValue, + 'speak' + ); Entry.console.print('speed value : ' + speedValue, 'speak'); Entry.console.print('left output value : ' + leftOutValue, 'speak'); Entry.console.print('right output value : ' + rightOutValue, 'speak'); @@ -1626,7 +1765,8 @@ Entry.NeobotSoco.getBlocks = function() { setTimeout(function() { Entry.hw.sendQueue['DCL'] = 0; Entry.hw.sendQueue['DCR'] = 0; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_motor_start : 0', 'speak'); + if (Entry.NeobotSoco.log_to_console) + Entry.console.print('neobot_soco_motor_start : 0', 'speak'); script.timeFlag = 0; }, durationValue * 1000); return script; @@ -1667,9 +1807,7 @@ Entry.NeobotSoco.getBlocks = function() { ], events: {}, def: { - params: [ - null, null, - ], + params: [null, null], type: 'neobot_soco_motor_stop', }, paramsKeyMap: { @@ -1701,6 +1839,30 @@ Entry.NeobotSoco.getBlocks = function() { /************************* * class neobot_soco_melody *************************/ + neobot_soco_buzzer_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_buzzer_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_buzzer_title', + }, + class: 'neobot_soco_melody', + isNotFor: ['neobot_soco'], + events: {}, + }, neobot_soco_play_note_for: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1799,9 +1961,10 @@ Entry.NeobotSoco.getBlocks = function() { Entry.hw.sendQueue['SND'] = value; setTimeout(function() { Entry.hw.sendQueue['SND'] = 0; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_play_note_for : 0', 'speak'); + if (Entry.NeobotSoco.log_to_console) + Entry.console.print('neobot_soco_play_note_for : 0', 'speak'); script.timeFlag = 0; - }, 1 / duration * 2000); + }, (1 / duration) * 2000); return script; } else if (script.timeFlag == 1) { return script; @@ -1840,9 +2003,7 @@ Entry.NeobotSoco.getBlocks = function() { ], events: {}, def: { - params: [ - null, null, - ], + params: [null, null], type: 'neobot_soco_melody_play_with_sensor', }, paramsKeyMap: { @@ -1857,7 +2018,7 @@ Entry.NeobotSoco.getBlocks = function() { // edited 210421, 0~100 을 0~65로 변환, 100 이상은 최대값으로 처리함. value = Math.max(value, 0); value = Math.min(value, 100); - value = Math.ceil(value / 100 * 65); + value = Math.ceil((value / 100) * 65); if (Entry.NeobotSoco.log_to_console) { Entry.console.print('=== neobot_soco_melody_play_with_sensor ===', 'speak'); @@ -1885,9 +2046,7 @@ Entry.NeobotSoco.getBlocks = function() { ], events: {}, def: { - params: [ - null, - ], + params: [null], type: 'neobot_soco_melody_stop', }, paramsKeyMap: {}, @@ -1908,6 +2067,30 @@ Entry.NeobotSoco.getBlocks = function() { /************************* * class neobot_soco_servo *************************/ + neobot_soco_servo_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_servo_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_servo_title', + }, + class: 'neobot_soco_servo', + isNotFor: ['neobot_soco'], + events: {}, + }, neobot_soco_servo_init: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1935,10 +2118,7 @@ Entry.NeobotSoco.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_soco_servo_init', }, paramsKeyMap: { @@ -1973,12 +2153,14 @@ Entry.NeobotSoco.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = resetValue; if (out2) Entry.hw.sendQueue['OUT2'] = resetValue; if (out3) Entry.hw.sendQueue['OUT3'] = resetValue; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_servo_init : ' + resetValue, 'speak'); + if (Entry.NeobotSoco.log_to_console) + Entry.console.print('neobot_soco_servo_init : ' + resetValue, 'speak'); setTimeout(function() { if (out1) Entry.hw.sendQueue['OUT1'] = initValue; if (out2) Entry.hw.sendQueue['OUT2'] = initValue; if (out3) Entry.hw.sendQueue['OUT3'] = initValue; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_servo_init : ' + initValue, 'speak'); + if (Entry.NeobotSoco.log_to_console) + Entry.console.print('neobot_soco_servo_init : ' + initValue, 'speak'); setTimeout(function() { script.timeFlag = 0; }, 100); @@ -2057,12 +2239,7 @@ Entry.NeobotSoco.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - null, - null, - ], + params: [null, null, null, null], type: 'neobot_soco_servo_rotate', }, paramsKeyMap: { @@ -2148,10 +2325,7 @@ Entry.NeobotSoco.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_soco_servo_stop', }, paramsKeyMap: { @@ -2333,18 +2507,33 @@ Entry.NeobotSoco.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = directionValue; if (out2) Entry.hw.sendQueue['OUT2'] = directionValue; if (out3) Entry.hw.sendQueue['OUT3'] = directionValue; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_servo_change_degree : ' + directionValue, 'speak'); - setTimeout(function() { // speed + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_servo_change_degree : ' + directionValue, + 'speak' + ); + setTimeout(function() { + // speed if (out1) Entry.hw.sendQueue['OUT1'] = speedValue; if (out2) Entry.hw.sendQueue['OUT2'] = speedValue; if (out3) Entry.hw.sendQueue['OUT3'] = speedValue; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_servo_change_degree : ' + speedValue, 'speak'); - setTimeout(function() { // degree + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_servo_change_degree : ' + speedValue, + 'speak' + ); + setTimeout(function() { + // degree if (out1) Entry.hw.sendQueue['OUT1'] = degreeValue; if (out2) Entry.hw.sendQueue['OUT2'] = degreeValue; if (out3) Entry.hw.sendQueue['OUT3'] = degreeValue; - if (Entry.NeobotSoco.log_to_console) Entry.console.print('neobot_soco_servo_change_degree : ' + degreeValue, 'speak'); - setTimeout(function() { // final delay + if (Entry.NeobotSoco.log_to_console) + Entry.console.print( + 'neobot_soco_servo_change_degree : ' + degreeValue, + 'speak' + ); + setTimeout(function() { + // final delay script.timeFlag = 0; }, 200); }, 200); diff --git a/src/playground/blocks/hardware/block_neobot_thinkcar.js b/src/playground/blocks/hardware/block_neobot_thinkcar.js index 54aac3a664..639d5c341e 100644 --- a/src/playground/blocks/hardware/block_neobot_thinkcar.js +++ b/src/playground/blocks/hardware/block_neobot_thinkcar.js @@ -47,6 +47,7 @@ Entry.NeobotThinkCar.setLanguage = function() { ko: { template: { // think car + neobot_think_car_auto_driving_title: '자율주행', neobot_think_car_line_tracer_start: '차로를 유지하며 속도 %1 으로 자율주행 %2', // neobot_think_car_line_tracer_change_speed: '자율주행 속도 변경 %1 %2', neobot_think_car_reverse_parking_start: '%1 표지판에서 후면 주차 %2', @@ -54,18 +55,16 @@ Entry.NeobotThinkCar.setLanguage = function() { neobot_think_car_driving_stop: '자율주행 중지 %1', // sensor + neobot_think_car_sensor_title: '센서', neobot_think_car_sensor_value: '%1', neobot_think_car_sensor_convert_scale: '%1 %2 ~ %3 를 %4 ~ %5 으로 변환', - - // decision neobot_think_car_decision_sensor_is_over: '%1 %2 %3', neobot_think_car_decision_equal_with_sensor: '%1 컬러가 %2', neobot_think_car_decision_sensor_angle: '%1 각도 %2 %3', - - // remote neobot_think_car_remote_button: '리모컨 버튼 %1 을 누름', // LED + neobot_think_car_led_title: 'LED', neobot_think_car_arg_led_duration: '%1', neobot_think_car_led_on: 'LED 켜기 %1 %2 %3 %4', neobot_think_car_output_led_off: '%1 LED 끄기 %2', @@ -73,9 +72,11 @@ Entry.NeobotThinkCar.setLanguage = function() { neobot_think_car_color_led_on: '%1 컬러LED 켜기 R %2 G %3 B %4 %5', // output + neobot_think_car_output_title: '출력', neobot_think_car_set_output: '%1 에 %2 값 출력하기 %3', // motor + neobot_think_car_motor_title: '회전모터', neobot_think_car_robot: '로봇 %1 %2', neobot_think_car_motor_start: '모터 회전하기 %1 %2 %3 %4 %5', neobot_think_car_motor_stop: '%1 모터 멈추기 %2', @@ -83,11 +84,13 @@ Entry.NeobotThinkCar.setLanguage = function() { neobot_think_car_arg_motor_duration: '%1', // melody + neobot_think_car_buzzer_title: '버저', neobot_think_car_play_note_for: '버저 울리기 옥타브: %2 음: %1 길이: %3 %4', neobot_think_car_melody_play_with_sensor: '%1 센서로 버저 울리기 %2', neobot_think_car_melody_stop: '버저 멈추기 %1', // servo + neobot_think_car_servo_title: '서보모터', get_servo_degree: '%1', neobot_think_car_servo_init: '%1 서보모터 리셋 %2', neobot_think_car_servo_rotate: '서보모터 회전하기 %1 %2 %3 %4', @@ -232,35 +235,40 @@ Entry.NeobotThinkCar.setLanguage = function() { // en.js에 작성하던 내용 template: { // think car - neobot_think_car_line_tracer_start: 'Start self-driving at %1 speed while keeping lanes %2', + neobot_think_car_auto_driving_title: 'Self-driving', + neobot_think_car_line_tracer_start: + 'Start self-driving at %1 speed while keeping lanes %2', // neobot_think_car_line_tracer_change_speed: 'Change the speed of self-driving %1 %2', neobot_think_car_reverse_parking_start: 'Start reverse parking at %1 sign %2', - neobot_think_car_line_change: 'Change the lane from primary %1 sign to secondary %2 sign %3', + neobot_think_car_line_change: + 'Change the lane from primary %1 sign to secondary %2 sign %3', neobot_think_car_driving_stop: 'Stop self-driving %1', // sensor + neobot_think_car_sensor_title: 'Sensor', neobot_think_car_sensor_value: '%1', - neobot_think_car_sensor_convert_scale: '%1 \'s changed value range: %2 ~ %3 conversion: %4 ~ %5', - - // decision + neobot_think_car_sensor_convert_scale: + "%1 's changed value range: %2 ~ %3 conversion: %4 ~ %5", neobot_think_car_decision_sensor_is_over: '%1 %2 %3', - neobot_think_car_decision_equal_with_sensor: '%1 \'s color is %2', + neobot_think_car_decision_equal_with_sensor: "%1 's color is %2", neobot_think_car_decision_sensor_angle: '%1 angle %2 %3', - - // remote neobot_think_car_remote_button: 'pressing button %1 of remote controller', // LED + neobot_think_car_led_title: 'LED', neobot_think_car_arg_led_duration: '%1', neobot_think_car_led_on: 'Turn on the LED %1 %2 %3 %4', neobot_think_car_output_led_off: 'Turn off the %1 LED %2', - neobot_think_car_led_brightness_with_sensor: 'Control %2 LED\'s brightness with %1 sensor %3', + neobot_think_car_led_brightness_with_sensor: + "Control %2 LED's brightness with %1 sensor %3", neobot_think_car_color_led_on: 'Turn on the %1 color LED R %2 G %3 B %4 %5', // output + neobot_think_car_output_title: 'Set output', neobot_think_car_set_output: 'Output %2 value to %1 port %3', // motor + neobot_think_car_motor_title: 'Motor', neobot_think_car_robot: 'Robot %1 %2', neobot_think_car_motor_start: 'Motor operation %1 %2 %3 %4 %5', neobot_think_car_motor_stop: 'Stop the %1 motor(s) %2', @@ -268,11 +276,13 @@ Entry.NeobotThinkCar.setLanguage = function() { neobot_think_car_arg_motor_duration: '%1', // melody + neobot_think_car_buzzer_title: 'Buzzer', neobot_think_car_play_note_for: 'Buzzer octave: %1 scale: %2 note: %3 %4', neobot_think_car_melody_play_with_sensor: 'Buzzer rings by %1 sensor value %2', neobot_think_car_melody_stop: 'Stop the buzzer %1', // servo + neobot_think_car_servo_title: 'Servo motor', get_servo_degree: '%1', neobot_think_car_servo_init: 'Reset the %1 servo motor %2', neobot_think_car_servo_rotate: 'Rotate the servo motor %1 %2 %3 %4', @@ -418,6 +428,7 @@ Entry.NeobotThinkCar.setLanguage = function() { Entry.NeobotThinkCar.blockMenuBlocks = [ // think car + 'neobot_think_car_auto_driving_title', 'neobot_think_car_line_tracer_start', // 'neobot_think_car_line_tracer_change_speed', 'neobot_think_car_reverse_parking_start', @@ -425,45 +436,71 @@ Entry.NeobotThinkCar.blockMenuBlocks = [ 'neobot_think_car_driving_stop', // sensor + 'neobot_think_car_sensor_title', 'neobot_think_car_sensor_value', 'neobot_think_car_sensor_convert_scale', - - // decision 'neobot_think_car_decision_sensor_is_over', 'neobot_think_car_decision_equal_with_sensor', 'neobot_think_car_decision_sensor_angle', - - // remote 'neobot_think_car_remote_button', // led + 'neobot_think_car_led_title', 'neobot_think_car_led_on', 'neobot_think_car_led_brightness_with_sensor', 'neobot_think_car_color_led_on', 'neobot_think_car_output_led_off', // output + 'neobot_think_car_output_title', 'neobot_think_car_set_output', // motor + 'neobot_think_car_motor_title', 'neobot_think_car_robot', 'neobot_think_car_motor_start', 'neobot_think_car_motor_stop', - // melody - 'neobot_think_car_play_note_for', - 'neobot_think_car_melody_play_with_sensor', - 'neobot_think_car_melody_stop', - // servo + 'neobot_think_car_servo_title', 'neobot_think_car_servo_init', 'neobot_think_car_servo_rotate', 'neobot_think_car_servo_stop', 'neobot_think_car_servo_change_degree', + + // melody + 'neobot_think_car_buzzer_title', + 'neobot_think_car_play_note_for', + 'neobot_think_car_melody_play_with_sensor', + 'neobot_think_car_melody_stop', ]; Entry.NeobotThinkCar.getBlocks = function() { return { + neobot_think_car_auto_driving_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_auto_driving_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_auto_driving_title', + }, + class: 'neobot_think_car_operation', + isNotFor: ['neobot_think_car'], + events: {}, + }, neobot_think_car_line_tracer_start: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -497,10 +534,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_think_car_line_tracer_start', }, paramsKeyMap: { @@ -519,9 +553,7 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.hw.sendQueue['OUT3'] = out3Value; Entry.hw.sendQueue['SND'] = buzzerValue; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_line_tracer_start ===', - 'speak'); + Entry.console.print('=== neobot_think_car_line_tracer_start ===', 'speak'); Entry.console.print('out3 : ' + out3Value, 'speak'); Entry.console.print('buzzer : ' + buzzerValue, 'speak'); } @@ -531,12 +563,8 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.hw.sendQueue['SND'] = 0; if (Entry.NeobotThinkCar.log_to_console) { Entry.console.print('out1 : ' + speed, 'speak'); - Entry.console.print( - 'buzzer : 0', - 'speak'); - Entry.console.print( - '==========================', - 'speak'); + Entry.console.print('buzzer : 0', 'speak'); + Entry.console.print('==========================', 'speak'); } script.timeFlag = 0; }, 300); @@ -578,10 +606,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_think_car_reverse_parking_start', }, paramsKeyMap: { @@ -603,7 +628,8 @@ Entry.NeobotThinkCar.getBlocks = function() { if (Entry.NeobotThinkCar.log_to_console) { Entry.console.print( '=== neobot_think_car_reverse_parking_start ===', - 'speak'); + 'speak' + ); Entry.console.print('out3 : ' + out3Value, 'speak'); Entry.console.print('buzzer : ' + buzzerValue, 'speak'); } @@ -612,13 +638,9 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.hw.sendQueue['OUT1'] = colorValue; Entry.hw.sendQueue['SND'] = 0; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('out1 : ' + colorValue, - 'speak'); - Entry.console.print( - 'buzzer : 0', 'speak'); - Entry.console.print( - '==========================', - 'speak'); + Entry.console.print('out1 : ' + colorValue, 'speak'); + Entry.console.print('buzzer : 0', 'speak'); + Entry.console.print('==========================', 'speak'); } script.timeFlag = 0; @@ -675,11 +697,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - null, - ], + params: [null, null, null], type: 'neobot_think_car_line_change', }, paramsKeyMap: { @@ -701,9 +719,7 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.hw.sendQueue['SND'] = buzzerValue; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_line_change ===', - 'speak'); + Entry.console.print('=== neobot_think_car_line_change ===', 'speak'); Entry.console.print('out3 : ' + out3Value, 'speak'); Entry.console.print('buzzer : ' + buzzerValue, 'speak'); } @@ -713,15 +729,10 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.hw.sendQueue['OUT2'] = toColorValue; Entry.hw.sendQueue['SND'] = 0; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('out1 : ' + fromColorValue, - 'speak'); - Entry.console.print('out2 : ' + toColorValue, - 'speak'); - Entry.console.print( - 'buzzer : 0', 'speak'); - Entry.console.print( - '==========================', - 'speak'); + Entry.console.print('out1 : ' + fromColorValue, 'speak'); + Entry.console.print('out2 : ' + toColorValue, 'speak'); + Entry.console.print('buzzer : 0', 'speak'); + Entry.console.print('==========================', 'speak'); } script.timeFlag = 0; @@ -752,9 +763,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - ], + params: [null], type: 'neobot_think_car_driving_stop', }, paramsKeyMap: {}, @@ -771,9 +780,7 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.hw.sendQueue['SND'] = buzzerValue; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_driving_stop ===', - 'speak'); + Entry.console.print('=== neobot_think_car_driving_stop ===', 'speak'); Entry.console.print('out3 : ' + out3Value, 'speak'); Entry.console.print('buzzer : ' + buzzerValue, 'speak'); } @@ -786,12 +793,8 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.console.print('out1 : 0', 'speak'); Entry.console.print('out2 : 0', 'speak'); Entry.console.print('out3 : 0', 'speak'); - Entry.console.print( - 'buzzer : 0', - 'speak'); - Entry.console.print( - '==========================', - 'speak'); + Entry.console.print('buzzer : 0', 'speak'); + Entry.console.print('==========================', 'speak'); } script.timeFlag = 0; }, 300); @@ -868,6 +871,30 @@ Entry.NeobotThinkCar.getBlocks = function() { /************************* * class neobot_think_car_sensor *************************/ + neobot_think_car_sensor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_sensor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_sensor_title', + }, + class: 'neobot_think_car_sensor', + isNotFor: ['neobot_think_car'], + events: {}, + }, neobot_think_car_sensor_value: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1004,9 +1031,6 @@ Entry.NeobotThinkCar.getBlocks = function() { }, }, - /************************* - * class neobot_think_car_decision - *************************/ neobot_think_car_decision_sensor_is_over: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1056,7 +1080,7 @@ Entry.NeobotThinkCar.getBlocks = function() { SYMBOL: 1, VALUE: 2, }, - class: 'neobot_think_car_decision', + class: 'neobot_think_car_sensor', isNotFor: ['neobot_think_car'], func: function(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -1143,7 +1167,7 @@ Entry.NeobotThinkCar.getBlocks = function() { SENSOR: 0, COLOR: 1, }, - class: 'neobot_think_car_decision', + class: 'neobot_think_car_sensor', isNotFor: ['neobot_think_car'], func: function(sprite, script) { var sensorTemp = script.getStringField('SENSOR'); @@ -1242,7 +1266,7 @@ Entry.NeobotThinkCar.getBlocks = function() { SYMBOL: 1, VALUE: 2, }, - class: 'neobot_think_car_decision', + class: 'neobot_think_car_sensor', isNotFor: ['neobot_think_car'], func: function(sprite, script) { var sensorTemp = script.getStringField('SENSOR'); @@ -1270,9 +1294,6 @@ Entry.NeobotThinkCar.getBlocks = function() { }, }, - /************************* - * class neobot_think_car_remote - *************************/ neobot_think_car_remote_button: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1306,7 +1327,7 @@ Entry.NeobotThinkCar.getBlocks = function() { paramsKeyMap: { KEY: 0, }, - class: 'neobot_think_car_remote', + class: 'neobot_think_car_sensor', isNotFor: ['neobot_think_car'], func: function(sprite, script) { var key = script.getNumberField('KEY'); @@ -1322,6 +1343,30 @@ Entry.NeobotThinkCar.getBlocks = function() { /************************* * class neobot_think_car_led *************************/ + neobot_think_car_led_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_led_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_led_title', + }, + class: 'neobot_think_car_led', + isNotFor: ['neobot_think_car'], + events: {}, + }, neobot_think_car_led_on: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1398,17 +1443,18 @@ Entry.NeobotThinkCar.getBlocks = function() { const duration = script.getStringValue('DURATION', script); if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('=== neobot_think_car_led_on ===', - 'speak'); + Entry.console.print('=== neobot_think_car_led_on ===', 'speak'); Entry.console.print('port : ' + port, 'speak'); Entry.console.print('brightness : ' + value, 'speak'); Entry.console.print('duration : ' + duration, 'speak'); - Entry.console.print('==========================', - 'speak'); + Entry.console.print('==========================', 'speak'); } - if ((duration != '계속' && duration != 'constantly') && - Entry.parseNumber(duration) <= 0) { + if ( + duration != '계속' && + duration != 'constantly' && + Entry.parseNumber(duration) <= 0 + ) { return script.callReturn(); } @@ -1435,8 +1481,8 @@ Entry.NeobotThinkCar.getBlocks = function() { } else { Entry.hw.sendQueue[port] = 0; } - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_led_on : 0', 'speak'); + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print('neobot_think_car_led_on : 0', 'speak'); script.timeFlag = 0; }, durationValue * 1000); return script; @@ -1490,8 +1536,7 @@ Entry.NeobotThinkCar.getBlocks = function() { const port = script.getStringField('PORT', script); if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_output_led_off ===', 'speak'); + Entry.console.print('=== neobot_think_car_output_led_off ===', 'speak'); Entry.console.print('port : ' + port, 'speak'); Entry.console.print('==========================', 'speak'); } @@ -1563,16 +1608,16 @@ Entry.NeobotThinkCar.getBlocks = function() { // edited 210421, IN 값 0~100 을 0~255로 변경, 센서 100 이상은 최대값으로 처리함. value = Math.max(value, 0); value = Math.min(value, 100); - value = Math.ceil(value / 100 * 255); + value = Math.ceil((value / 100) * 255); if (Entry.NeobotThinkCar.log_to_console) { Entry.console.print( '=== neobot_think_car_led_brightness_with_sensor ===', - 'speak'); + 'speak' + ); Entry.console.print('out port : ' + outPort, 'speak'); Entry.console.print('in port : ' + inPort, 'speak'); - Entry.console.print( - 'sensor value : ' + Entry.hw.portData[inPort], 'speak'); + Entry.console.print('sensor value : ' + Entry.hw.portData[inPort], 'speak'); Entry.console.print('output value : ' + value, 'speak'); Entry.console.print('==========================', 'speak'); } @@ -1681,14 +1726,12 @@ Entry.NeobotThinkCar.getBlocks = function() { blue = Math.min(blue, 251); if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_color_led_on ===', 'speak'); + Entry.console.print('=== neobot_think_car_color_led_on ===', 'speak'); Entry.console.print('port : ' + port, 'speak'); Entry.console.print('red : ' + red, 'speak'); Entry.console.print('green : ' + green, 'speak'); Entry.console.print('blue : ' + blue, 'speak'); - Entry.console.print('==========================', - 'speak'); + Entry.console.print('==========================', 'speak'); } const valRed = 252; @@ -1702,50 +1745,67 @@ Entry.NeobotThinkCar.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = valRed; if (out2) Entry.hw.sendQueue['OUT2'] = valRed; if (out3) Entry.hw.sendQueue['OUT3'] = valRed; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_color_led_on : ' + valRed, 'speak'); - setTimeout(function() { // set red + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print('neobot_think_car_color_led_on : ' + valRed, 'speak'); + setTimeout(function() { + // set red if (out1) Entry.hw.sendQueue['OUT1'] = red; if (out2) Entry.hw.sendQueue['OUT2'] = red; if (out3) Entry.hw.sendQueue['OUT3'] = red; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_color_led_on : ' + red, 'speak'); - setTimeout(function() { // choose green + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print('neobot_think_car_color_led_on : ' + red, 'speak'); + setTimeout(function() { + // choose green if (out1) Entry.hw.sendQueue['OUT1'] = valGreen; if (out2) Entry.hw.sendQueue['OUT2'] = valGreen; if (out3) Entry.hw.sendQueue['OUT3'] = valGreen; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_color_led_on : ' + valGreen, - 'speak'); - setTimeout(function() { // set green + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_color_led_on : ' + valGreen, + 'speak' + ); + setTimeout(function() { + // set green if (out1) Entry.hw.sendQueue['OUT1'] = green; if (out2) Entry.hw.sendQueue['OUT2'] = green; if (out3) Entry.hw.sendQueue['OUT3'] = green; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_color_led_on : ' + green, - 'speak'); - setTimeout(function() { // choose blue + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_color_led_on : ' + green, + 'speak' + ); + setTimeout(function() { + // choose blue if (out1) Entry.hw.sendQueue['OUT1'] = valBlue; if (out2) Entry.hw.sendQueue['OUT2'] = valBlue; if (out3) Entry.hw.sendQueue['OUT3'] = valBlue; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_color_led_on : ' + - valBlue, 'speak'); - setTimeout(function() { // set blue + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_color_led_on : ' + valBlue, + 'speak' + ); + setTimeout(function() { + // set blue if (out1) Entry.hw.sendQueue['OUT1'] = blue; if (out2) Entry.hw.sendQueue['OUT2'] = blue; if (out3) Entry.hw.sendQueue['OUT3'] = blue; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_color_led_on : ' + - blue, 'speak'); - setTimeout(function() { // accept + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_color_led_on : ' + blue, + 'speak' + ); + setTimeout(function() { + // accept if (out1) Entry.hw.sendQueue['OUT1'] = valAccept; if (out2) Entry.hw.sendQueue['OUT2'] = valAccept; if (out3) Entry.hw.sendQueue['OUT3'] = valAccept; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_color_led_on : ' + - valAccept, 'speak'); - setTimeout(function() { // final delay + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_color_led_on : ' + valAccept, + 'speak' + ); + setTimeout(function() { + // final delay script.timeFlag = 0; }, 200); }, 200); @@ -1769,6 +1829,30 @@ Entry.NeobotThinkCar.getBlocks = function() { /************************* * class neobot_think_car_output *************************/ + neobot_think_car_output_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_output_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_output_title', + }, + class: 'neobot_think_car_output', + isNotFor: ['neobot_think_car'], + events: {}, + }, neobot_think_car_set_output: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1826,8 +1910,7 @@ Entry.NeobotThinkCar.getBlocks = function() { } if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('=== neobot_think_car_set_output ===', - 'speak'); + Entry.console.print('=== neobot_think_car_set_output ===', 'speak'); Entry.console.print('port : ' + port, 'speak'); Entry.console.print('value : ' + value, 'speak'); Entry.console.print('==========================', 'speak'); @@ -1847,6 +1930,30 @@ Entry.NeobotThinkCar.getBlocks = function() { /************************* * class neobot_think_car_motor *************************/ + neobot_think_car_motor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_motor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_motor_title', + }, + class: 'neobot_think_car_motor', + isNotFor: ['neobot_think_car'], + events: {}, + }, neobot_think_car_robot: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1875,10 +1982,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_think_car_robot', }, paramsKeyMap: { @@ -1914,8 +2018,7 @@ Entry.NeobotThinkCar.getBlocks = function() { } if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('=== neobot_think_car_robot ===', - 'speak'); + Entry.console.print('=== neobot_think_car_robot ===', 'speak'); Entry.console.print('move : ' + move, 'speak'); Entry.console.print('left value : ' + leftValue, 'speak'); Entry.console.print('right value : ' + rightValue, 'speak'); @@ -2003,13 +2106,15 @@ Entry.NeobotThinkCar.getBlocks = function() { func: function(sprite, script) { if (!script.isStart) { const motor = script.getStringField('MOTOR', script); - const direction = script.getStringField('DIRECTION', - script); + const direction = script.getStringField('DIRECTION', script); const speed = script.getStringValue('SPEED', script); const duration = script.getStringValue('DURATION', script); - if (duration != '계속' && duration != 'constantly' && - Entry.parseNumber(duration) <= 0) { + if ( + duration != '계속' && + duration != 'constantly' && + Entry.parseNumber(duration) <= 0 + ) { return script.callReturn(); } @@ -2049,33 +2154,29 @@ Entry.NeobotThinkCar.getBlocks = function() { } speedValue = Math.max(speedValue, 0); speedValue = Math.min(speedValue, 100); - speedValue = Math.ceil(speedValue / 100 * 15); + speedValue = Math.ceil((speedValue / 100) * 15); const leftOutValue = leftDirectionValue + speedValue; const rightOutValue = rightDirectionValue + speedValue; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_motor_start ===', 'speak'); + Entry.console.print('=== neobot_think_car_motor_start ===', 'speak'); Entry.console.print('motor : ' + motor, 'speak'); - Entry.console.print('direction : ' + direction, - 'speak'); + Entry.console.print('direction : ' + direction, 'speak'); Entry.console.print('speed : ' + speed, 'speak'); Entry.console.print('duration : ' + duration, 'speak'); Entry.console.print( 'left direction value : ' + leftDirectionValue, - 'speak'); + 'speak' + ); Entry.console.print( 'right direction value : ' + rightDirectionValue, - 'speak'); - Entry.console.print('speed value : ' + speedValue, - 'speak'); - Entry.console.print( - 'left output value : ' + leftOutValue, 'speak'); - Entry.console.print( - 'right output value : ' + rightOutValue, 'speak'); - Entry.console.print('==========================', - 'speak'); + 'speak' + ); + Entry.console.print('speed value : ' + speedValue, 'speak'); + Entry.console.print('left output value : ' + leftOutValue, 'speak'); + Entry.console.print('right output value : ' + rightOutValue, 'speak'); + Entry.console.print('==========================', 'speak'); } if (moveLeft) { @@ -2095,8 +2196,8 @@ Entry.NeobotThinkCar.getBlocks = function() { setTimeout(function() { Entry.hw.sendQueue['DCL'] = 0; Entry.hw.sendQueue['DCR'] = 0; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_motor_start : 0', 'speak'); + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print('neobot_think_car_motor_start : 0', 'speak'); script.timeFlag = 0; }, durationValue * 1000); return script; @@ -2137,9 +2238,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, null, - ], + params: [null, null], type: 'neobot_think_car_motor_stop', }, paramsKeyMap: { @@ -2151,8 +2250,7 @@ Entry.NeobotThinkCar.getBlocks = function() { const motor = script.getNumberField('MOTOR'); if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('=== neobot_think_car_motor_stop ===', - 'speak'); + Entry.console.print('=== neobot_think_car_motor_stop ===', 'speak'); Entry.console.print('motor : ' + motor, 'speak'); Entry.console.print('==========================', 'speak'); } @@ -2172,6 +2270,30 @@ Entry.NeobotThinkCar.getBlocks = function() { /************************* * class neobot_think_car_melody *************************/ + neobot_think_car_buzzer_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_buzzer_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_buzzer_title', + }, + class: 'neobot_think_car_melody', + isNotFor: ['neobot_think_car'], + events: {}, + }, neobot_think_car_play_note_for: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2221,9 +2343,7 @@ Entry.NeobotThinkCar.getBlocks = function() { [Lang.Blocks.neobot_think_car_sound_half_note, '2'], [Lang.Blocks.neobot_think_car_sound_quarter_note, '4'], [Lang.Blocks.neobot_think_car_sound_eighth_note, '8'], - [ - Lang.Blocks.neobot_think_car_sound_sixteenth_note, - '16'], + [Lang.Blocks.neobot_think_car_sound_sixteenth_note, '16'], ], value: '2', fontSize: 11, @@ -2258,14 +2378,12 @@ Entry.NeobotThinkCar.getBlocks = function() { value = Math.min(value, 72); if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_play_note_for ===', 'speak'); + Entry.console.print('=== neobot_think_car_play_note_for ===', 'speak'); Entry.console.print('note : ' + note, 'speak'); Entry.console.print('octave : ' + octave, 'speak'); Entry.console.print('duration : ' + duration, 'speak'); Entry.console.print('value : ' + value, 'speak'); - Entry.console.print('==========================', - 'speak'); + Entry.console.print('==========================', 'speak'); } script.isStart = true; @@ -2274,10 +2392,10 @@ Entry.NeobotThinkCar.getBlocks = function() { Entry.hw.sendQueue['SND'] = value; setTimeout(function() { Entry.hw.sendQueue['SND'] = 0; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_play_note_for : 0', 'speak'); + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print('neobot_think_car_play_note_for : 0', 'speak'); script.timeFlag = 0; - }, 1 / duration * 2000); + }, (1 / duration) * 2000); return script; } else if (script.timeFlag == 1) { return script; @@ -2316,9 +2434,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, null, - ], + params: [null, null], type: 'neobot_think_car_melody_play_with_sensor', }, paramsKeyMap: { @@ -2333,12 +2449,13 @@ Entry.NeobotThinkCar.getBlocks = function() { // edited 210421, 0~100 을 0~65로 변환, 100 이상은 최대값으로 처리함. value = Math.max(value, 0); value = Math.min(value, 100); - value = Math.ceil(value / 100 * 65); + value = Math.ceil((value / 100) * 65); if (Entry.NeobotThinkCar.log_to_console) { Entry.console.print( '=== neobot_think_car_melody_play_with_sensor ===', - 'speak'); + 'speak' + ); Entry.console.print('input : ' + input, 'speak'); Entry.console.print('value : ' + value, 'speak'); Entry.console.print('==========================', 'speak'); @@ -2363,9 +2480,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - ], + params: [null], type: 'neobot_think_car_melody_stop', }, paramsKeyMap: {}, @@ -2373,8 +2488,7 @@ Entry.NeobotThinkCar.getBlocks = function() { isNotFor: ['neobot_think_car'], func: function(sprite, script) { if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('=== neobot_think_car_melody_stop ===', - 'speak'); + Entry.console.print('=== neobot_think_car_melody_stop ===', 'speak'); Entry.console.print('value : 0', 'speak'); Entry.console.print('==========================', 'speak'); } @@ -2387,6 +2501,30 @@ Entry.NeobotThinkCar.getBlocks = function() { /************************* * class neobot_think_car_servo *************************/ + neobot_think_car_servo_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_servo_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_servo_title', + }, + class: 'neobot_think_car_servo', + isNotFor: ['neobot_think_car'], + events: {}, + }, neobot_think_car_servo_init: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2414,10 +2552,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_think_car_servo_init', }, paramsKeyMap: { @@ -2432,11 +2567,9 @@ Entry.NeobotThinkCar.getBlocks = function() { const initValue = 1; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_servo_init ===', 'speak'); + Entry.console.print('=== neobot_think_car_servo_init ===', 'speak'); Entry.console.print('port : ' + port, 'speak'); - Entry.console.print('==========================', - 'speak'); + Entry.console.print('==========================', 'speak'); } let out1 = port == 'OUT1'; @@ -2454,15 +2587,17 @@ Entry.NeobotThinkCar.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = resetValue; if (out2) Entry.hw.sendQueue['OUT2'] = resetValue; if (out3) Entry.hw.sendQueue['OUT3'] = resetValue; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_servo_init : ' + resetValue, 'speak'); + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print('neobot_think_car_servo_init : ' + resetValue, 'speak'); setTimeout(function() { if (out1) Entry.hw.sendQueue['OUT1'] = initValue; if (out2) Entry.hw.sendQueue['OUT2'] = initValue; if (out3) Entry.hw.sendQueue['OUT3'] = initValue; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_servo_init : ' + initValue, - 'speak'); + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_servo_init : ' + initValue, + 'speak' + ); setTimeout(function() { script.timeFlag = 0; }, 100); @@ -2541,12 +2676,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - null, - null, - ], + params: [null, null, null, null], type: 'neobot_think_car_servo_rotate', }, paramsKeyMap: { @@ -2585,13 +2715,11 @@ Entry.NeobotThinkCar.getBlocks = function() { } if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print( - '=== neobot_think_car_servo_rotate ==='); + Entry.console.print('=== neobot_think_car_servo_rotate ==='); Entry.console.print('port : ' + port, 'speak'); Entry.console.print('direction : ' + direction, 'speak'); Entry.console.print('speed : ' + speed, 'speak'); - Entry.console.print('direction value : ' + directionValue, - 'speak'); + Entry.console.print('direction value : ' + directionValue, 'speak'); Entry.console.print('speed value : ' + speedValue, 'speak'); Entry.console.print('output value : ' + outValue, 'speak'); Entry.console.print('==========================', 'speak'); @@ -2634,10 +2762,7 @@ Entry.NeobotThinkCar.getBlocks = function() { ], events: {}, def: { - params: [ - null, - null, - ], + params: [null, null], type: 'neobot_think_car_servo_stop', }, paramsKeyMap: { @@ -2650,8 +2775,7 @@ Entry.NeobotThinkCar.getBlocks = function() { let outValue = 254; if (Entry.NeobotThinkCar.log_to_console) { - Entry.console.print('=== neobot_think_car_servo_stop ===', - 'speak'); + Entry.console.print('=== neobot_think_car_servo_stop ===', 'speak'); Entry.console.print('port : ' + port, 'speak'); Entry.console.print('output value: ' + outValue, 'speak'); Entry.console.print('==========================', 'speak'); @@ -2790,8 +2914,7 @@ Entry.NeobotThinkCar.getBlocks = function() { if (Entry.Utils.isNumber(degree)) { degreeValue = Entry.parseNumber(degree); } else { - if (degree == 'IN1' || degree == 'IN2' || degree == - 'IN3') { + if (degree == 'IN1' || degree == 'IN2' || degree == 'IN3') { degreeValue = Entry.hw.portData[degree]; } else { degreeValue = 0; @@ -2805,20 +2928,16 @@ Entry.NeobotThinkCar.getBlocks = function() { if (Entry.NeobotThinkCar.log_to_console) { Entry.console.print( '=== neobot_think_car_servo_change_degree ===', - 'speak'); + 'speak' + ); Entry.console.print('port : ' + port, 'speak'); - Entry.console.print('direction : ' + direction, - 'speak'); + Entry.console.print('direction : ' + direction, 'speak'); Entry.console.print('speed : ' + speed, 'speak'); Entry.console.print('degree : ' + degree, 'speak'); - Entry.console.print( - 'directionValue : ' + directionValue, 'speak'); - Entry.console.print('speedValue : ' + speedValue, - 'speak'); - Entry.console.print('degreeValue : ' + degreeValue, - 'speak'); - Entry.console.print('==========================', - 'speak'); + Entry.console.print('directionValue : ' + directionValue, 'speak'); + Entry.console.print('speedValue : ' + speedValue, 'speak'); + Entry.console.print('degreeValue : ' + degreeValue, 'speak'); + Entry.console.print('==========================', 'speak'); } script.isStart = true; @@ -2828,24 +2947,33 @@ Entry.NeobotThinkCar.getBlocks = function() { if (out1) Entry.hw.sendQueue['OUT1'] = directionValue; if (out2) Entry.hw.sendQueue['OUT2'] = directionValue; if (out3) Entry.hw.sendQueue['OUT3'] = directionValue; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_servo_change_degree : ' + - directionValue, 'speak'); - setTimeout(function() { // speed + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_servo_change_degree : ' + directionValue, + 'speak' + ); + setTimeout(function() { + // speed if (out1) Entry.hw.sendQueue['OUT1'] = speedValue; if (out2) Entry.hw.sendQueue['OUT2'] = speedValue; if (out3) Entry.hw.sendQueue['OUT3'] = speedValue; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_servo_change_degree : ' + - speedValue, 'speak'); - setTimeout(function() { // degree + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_servo_change_degree : ' + speedValue, + 'speak' + ); + setTimeout(function() { + // degree if (out1) Entry.hw.sendQueue['OUT1'] = degreeValue; if (out2) Entry.hw.sendQueue['OUT2'] = degreeValue; if (out3) Entry.hw.sendQueue['OUT3'] = degreeValue; - if (Entry.NeobotThinkCar.log_to_console) Entry.console.print( - 'neobot_think_car_servo_change_degree : ' + - degreeValue, 'speak'); - setTimeout(function() { // final delay + if (Entry.NeobotThinkCar.log_to_console) + Entry.console.print( + 'neobot_think_car_servo_change_degree : ' + degreeValue, + 'speak' + ); + setTimeout(function() { + // final delay script.timeFlag = 0; }, 200); }, 200); diff --git a/src/playground/blocks/hardwareLite/block_neo_lite.js b/src/playground/blocks/hardwareLite/block_neo_lite.js index 9d3f733c4b..2aabaf68fe 100644 --- a/src/playground/blocks/hardwareLite/block_neo_lite.js +++ b/src/playground/blocks/hardwareLite/block_neo_lite.js @@ -310,13 +310,14 @@ } setZero() { - /*if (Entry.Lite) { - Entry.hwLite.update(); - }*/ if (Entry.hwLite) { const blockId = this.generateBlockId(); - const pdu = this.makePdu([FrameCode.BASIC, PduCode.CONTROLLER_COMMAND, blockId, 0x04]); - // Entry.hwLite.writer.write(Buffer.from(pdu)); + const pdu = this.makePdu([ + FrameCode.BASIC, + PduCode.CONTROLLER_COMMAND, + blockId, + 0x04, + ]); this.executeList = [ { blockId, @@ -467,7 +468,6 @@ this.pendingResponseList[responseData.blockId] = 'pending'; } if (responseData.result === 0x01) { - // this.pendingResponseList[responseData.blockId] = 'completed'; delete this.pendingResponseList[responseData.blockId]; } } @@ -659,6 +659,20 @@ }); } + requestExt2Command(blockId, type, params) { + if (this.pendingResponseList[blockId]) { + delete this.pendingResponseList[blockId]; + } + this.pendingResponseList[blockId] = 'executed'; + const command = this.makeCommandExt2(blockId, type, params); + if (!command) return; + const pdu = this.makePdu(command); + this.executeList.push({ + blockId, + pdu, + }); + } + generateBlockId() { this.seqBlockId += 1; if (this.seqBlockId > 255) { @@ -716,7 +730,7 @@ // led neo_lite_led_title: 'LED', - neo_lite_led_on: 'LED 켜기 %1 %2 %3', + neo_lite_led_on: 'LED 켜기 %1 %2 %3 %4', neo_lite_led_blink: 'LED 깜빡이기 %1 %2 %3 %4', neo_lite_led_off: 'LED 끄기 %1 %2', @@ -1110,21 +1124,19 @@ neo_lite_buzzer_quarter_note: '4분 음표', neo_lite_buzzer_8th_note: '8분 음표', - neo_lite_lcd_image_1: '1', - neo_lite_lcd_image_2: '2', - neo_lite_lcd_image_3: '3', - neo_lite_lcd_image_4: '4', - neo_lite_lcd_image_5: '5', - neo_lite_lcd_image_6: '6', - neo_lite_lcd_image_7: '7', - neo_lite_lcd_image_8: '8', - neo_lite_lcd_image_9: '9', - neo_lite_lcd_image_10: '10', - neo_lite_lcd_image_11: '11', - neo_lite_lcd_image_12: '12', - neo_lite_lcd_image_13: '13', - neo_lite_lcd_image_14: '14', - neo_lite_lcd_image_15: '15', + neo_lite_lcd_image_1: '화남', + neo_lite_lcd_image_2: '어지러움', + neo_lite_lcd_image_3: '똑똑함', + neo_lite_lcd_image_4: '활기참', + neo_lite_lcd_image_5: '뽀뽀', + neo_lite_lcd_image_6: '사랑해', + neo_lite_lcd_image_7: '윙크', + neo_lite_lcd_image_8: '폭풍눈물', + neo_lite_lcd_image_9: '졸림', + neo_lite_lcd_image_10: '미소', + neo_lite_lcd_image_11: '깜찍함', + neo_lite_lcd_image_12: '의심', + neo_lite_lcd_image_13: '못마땅', }, }, en: { @@ -1141,7 +1153,8 @@ // servo neo_lite_servo_title: 'Servo motor', - neo_lite_servo_reset: 'Reset the current position of %1 servo motor to 0 degree %2', + neo_lite_servo_reset: + 'Reset the current position of %1 servo motor to 0 degree %2', neo_lite_servo_angle: 'Change servo angle %1 %2 %3 %4', neo_lite_servo_angle_var: 'Change servo angle %1 %2 %3 %4', neo_lite_servo_angle_wait: 'Wait to change servo angle %1 %2 %3 %4', @@ -1176,7 +1189,7 @@ // led neo_lite_led_title: 'LED', - neo_lite_led_on: 'Turn on the LED %1 %2 %3', + neo_lite_led_on: 'Turn on the LED %1 %2 %3 %4', neo_lite_led_blink: 'Blink the LED %1 %2 %3 %4', neo_lite_led_off: 'Turn off the LED %1 %2', @@ -1184,7 +1197,8 @@ neo_lite_color_led_title: 'Color LED', neo_lite_color_led_on: 'Turn on the color LED %1 %2 %3 %4', neo_lite_color_led_off: 'Turn off the color LED %1 %2', - neo_lite_color_led_on_with_sensor: 'Turn on the color LED %2 with color sensor %1 %3', + neo_lite_color_led_on_with_sensor: + 'Turn on the color LED %2 with color sensor %1 %3', // set output neo_lite_set_output_title: 'Set output', @@ -1265,14 +1279,14 @@ neo_lite_duration_c: 'constantly', neo_lite_duration_0: '0 second', neo_lite_duration_1: '1 second', - neo_lite_duration_2: '2 second', - neo_lite_duration_3: '3 second', - neo_lite_duration_4: '4 second', - neo_lite_duration_5: '5 second', - neo_lite_duration_6: '6 second', - neo_lite_duration_7: '7 second', - neo_lite_duration_8: '8 second', - neo_lite_duration_9: '9 second', + neo_lite_duration_2: '2 seconds', + neo_lite_duration_3: '3 seconds', + neo_lite_duration_4: '4 seconds', + neo_lite_duration_5: '5 seconds', + neo_lite_duration_6: '6 seconds', + neo_lite_duration_7: '7 seconds', + neo_lite_duration_8: '8 seconds', + neo_lite_duration_9: '9 seconds', neo_lite_compare_gt: '≥', neo_lite_compare_g: '>', @@ -1467,10 +1481,10 @@ neo_lite_led_brightness_100: '100%', neo_lite_led_blink_speed_1: '1 step', - neo_lite_led_blink_speed_2: '2 step', - neo_lite_led_blink_speed_3: '3 step', - neo_lite_led_blink_speed_4: '4 step', - neo_lite_led_blink_speed_5: '5 step', + neo_lite_led_blink_speed_2: '2 steps', + neo_lite_led_blink_speed_3: '3 steps', + neo_lite_led_blink_speed_4: '4 steps', + neo_lite_led_blink_speed_5: '5 steps', neo_lite_set_output_value_0: '0', neo_lite_set_output_value_5: '5', @@ -1570,21 +1584,19 @@ neo_lite_buzzer_quarter_note: 'a quarter note', neo_lite_buzzer_8th_note: 'a eighth note', - neo_lite_lcd_image_1: '1', - neo_lite_lcd_image_2: '2', - neo_lite_lcd_image_3: '3', - neo_lite_lcd_image_4: '4', - neo_lite_lcd_image_5: '5', - neo_lite_lcd_image_6: '6', - neo_lite_lcd_image_7: '7', - neo_lite_lcd_image_8: '8', - neo_lite_lcd_image_9: '9', - neo_lite_lcd_image_10: '10', - neo_lite_lcd_image_11: '11', - neo_lite_lcd_image_12: '12', - neo_lite_lcd_image_13: '13', - neo_lite_lcd_image_14: '14', - neo_lite_lcd_image_15: '15', + neo_lite_lcd_image_1: 'angry', + neo_lite_lcd_image_2: 'dizzy', + neo_lite_lcd_image_3: 'smart', + neo_lite_lcd_image_4: 'lively', + neo_lite_lcd_image_5: 'kiss', + neo_lite_lcd_image_6: 'lovely', + neo_lite_lcd_image_7: 'wink', + neo_lite_lcd_image_8: 'cry', + neo_lite_lcd_image_9: 'sleepy', + neo_lite_lcd_image_10: 'smiley', + neo_lite_lcd_image_11: 'cute', + neo_lite_lcd_image_12: 'doubt', + neo_lite_lcd_image_13: 'bad', }, }, // }; @@ -1726,8 +1738,11 @@ const speed = script.getStringField('SPEED', script); const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); - if (speed === 'IN1' || speed === 'IN2' || speed === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.MOTOR_MOVE, [dc, speed]); + if (speed.indexOf('IN') >= 0) { + this.requestExtCommand(blockId, NeoBlockType.MOTOR_MOVE, [ + dc, + speed, + ]); } else { this.requestCommand(blockId, NeoBlockType.MOTOR_MOVE, [dc, speed]); } @@ -1805,13 +1820,16 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const speedL = script.getNumberValue('SPEED_L', script); const speedR = script.getNumberValue('SPEED_R', script); const blockId = this.generateBlockId(); script.block_id = blockId; - this.requestCommand(blockId, NeoBlockType.MOTOR_MOVE_BOTH, [speedL, speedR]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + this.requestCommand(blockId, NeoBlockType.MOTOR_MOVE_BOTH, [ + speedL, + speedR, + ]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -1911,10 +1929,16 @@ const speed = script.getStringField('SPEED', script); const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); - if (speed === 'IN1' || speed === 'IN2' || speed === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.ROBOT_MOVE, [direction, speed]); + if (speed.indexOf('IN') >= 0) { + this.requestExtCommand(blockId, NeoBlockType.ROBOT_MOVE, [ + direction, + speed, + ]); } else { - this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [direction, speed]); + this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [ + direction, + speed, + ]); } if (duration === 'c' || !Entry.parseNumber(duration)) { script.block_id = blockId; @@ -1982,10 +2006,20 @@ class: 'neo_lite_motor', isNotFor: ['NeoLite'], func: (sprite, script) => { - const dc = script.getStringValue('DC', script); - const blockId = this.generateBlockId(); - this.requestCommand(blockId, NeoBlockType.MOTOR_STOP, [dc]); - return script.callReturn(); + if (!script.exec_phase) { + const dc = script.getStringValue('DC', script); + const blockId = this.generateBlockId(); + script.block_id = blockId; + script.exec_phase = ExecPhase.PENDING_RESPONSE; + this.requestCommand(blockId, NeoBlockType.MOTOR_STOP, [dc]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { + if (!this.pendingResponseList[script.block_id]) { + delete script.block_id; + delete script.exec_phase; + return script.callReturn(); + } + } + return script; }, }, neo_lite_robot_stop: { @@ -2011,9 +2045,19 @@ class: 'neo_lite_motor', isNotFor: ['NeoLite'], func: (sprite, script) => { - const blockId = this.generateBlockId(); - this.requestCommand(blockId, NeoBlockType.ROBOT_STOP, []); - return script.callReturn(); + if (!script.exec_phase) { + const blockId = this.generateBlockId(); + script.block_id = blockId; + script.exec_phase = ExecPhase.PENDING_RESPONSE; + this.requestCommand(blockId, NeoBlockType.ROBOT_STOP, []); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { + if (!this.pendingResponseList[script.block_id]) { + delete script.block_id; + delete script.exec_phase; + return script.callReturn(); + } + } + return script; }, }, /** @@ -2244,22 +2288,36 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringField('OUTPUT', script); const angle = script.getStringField('ANGLE', script); const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; - if (angle === 'IN1' || angle === 'IN2' || angle === 'IN3') { - if (speed === 'IN1' || angle === 'IN2' || angle === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); + const isExt2 = angle.indexOf('IN') >= 0 && speed.indexOf('IN') >= 0; + if (isExt2) { + this.requestExt2Command(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); + } else { + const isExt1 = angle.indexOf('IN') >= 0 || speed.indexOf('IN') >= 0; + if (isExt1) { + this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); } else { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); + this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); } - } else { - this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); } - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2350,8 +2408,12 @@ const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; - this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [output, angle, speed]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE, [ + output, + angle, + speed, + ]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2512,22 +2574,28 @@ const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; - if (angle === 'IN1' || angle === 'IN2' || angle === 'IN3') { - if (speed === 'IN1' || angle === 'IN2' || angle === 'IN3') { + const isExt2 = angle.indexOf('IN') >= 0 && speed.indexOf('IN') >= 0; + if (isExt2) { + this.requestExt2Command(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [ + output, + angle, + speed, + ]); + } else { + const isExt1 = angle.indexOf('IN') >= 0 || speed.indexOf('IN') >= 0; + if (isExt1) { this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [ output, angle, speed, ]); } else { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [ + this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [ output, angle, speed, ]); } - } else { - this.requestCommand(blockId, NeoBlockType.SERVO_ANGLE_WAIT, [output, angle, speed]); } } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { @@ -2613,18 +2681,26 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringField('OUTPUT', script); const direction = script.getStringField('DIRECTION', script); const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; if (speed.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.SERVO_ROTATE, [output, direction, speed]); + this.requestExtCommand(blockId, NeoBlockType.SERVO_ROTATE, [ + output, + direction, + speed, + ]); } else { - this.requestCommand(blockId, NeoBlockType.SERVO_ROTATE, [output, direction, speed]); + this.requestCommand(blockId, NeoBlockType.SERVO_ROTATE, [ + output, + direction, + speed, + ]); } - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2672,12 +2748,12 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.SERVO_STOP, [output]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -2774,10 +2850,14 @@ const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); const duration = script.getStringValue('DURATION', script); - if (speed === 'IN1' || speed === 'IN2' || speed === 'IN3') { - this.requestExtCommand(blockId, NeoBlockType.LINE_TRACER_START, [speed]); + if (speed.indexOf('IN') >= 0) { + this.requestExtCommand(blockId, NeoBlockType.LINE_TRACER_START, [ + speed, + ]); } else { - this.requestCommand(blockId, NeoBlockType.LINE_TRACER_START, [speed]); + this.requestCommand(blockId, NeoBlockType.LINE_TRACER_START, [ + speed, + ]); } if (duration === 'c' || !Entry.parseNumber(duration)) { script.block_id = blockId; @@ -3008,9 +3088,13 @@ const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); if (speed.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.AUTO_DRIVING_START, [speed]); + this.requestExtCommand(blockId, NeoBlockType.AUTO_DRIVING_START, [ + speed, + ]); } else { - this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_START, [speed]); + this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_START, [ + speed, + ]); } if (duration === 'c' || !Entry.parseNumber(duration)) { script.block_id = blockId; @@ -3104,20 +3188,25 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const sensor = script.getNumberField('SENSOR', script); const speed = script.getStringField('SPEED', script); const blockId = this.generateBlockId(); script.block_id = blockId; if (speed.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.AUTO_DRIVING_SENSOR_START, [ - sensor, - speed, - ]); + this.requestExtCommand( + blockId, + NeoBlockType.AUTO_DRIVING_SENSOR_START, + [sensor, speed] + ); } else { - this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_SENSOR_START, [sensor, speed]); + this.requestCommand( + blockId, + NeoBlockType.AUTO_DRIVING_SENSOR_START, + [sensor, speed] + ); } - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3151,11 +3240,11 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.AUTO_DRIVING_STOP, []); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3581,9 +3670,15 @@ const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); if (brightness.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.LED_ON, [output, brightness]); + this.requestExtCommand(blockId, NeoBlockType.LED_ON, [ + output, + brightness, + ]); } else { - this.requestCommand(blockId, NeoBlockType.LED_ON, [output, brightness]); + this.requestCommand(blockId, NeoBlockType.LED_ON, [ + output, + brightness, + ]); } if (duration === 'c' || !Entry.parseNumber(duration)) { script.block_id = blockId; @@ -3686,7 +3781,11 @@ const speed = script.getStringValue('SPEED', script); const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); - this.requestCommand(blockId, NeoBlockType.LED_BLINK, [output, speed, 100]); + this.requestCommand(blockId, NeoBlockType.LED_BLINK, [ + output, + speed, + 100, + ]); if (duration === 'c' || !Entry.parseNumber(duration)) { script.exec_phase = ExecPhase.PENDING_STOP; script.block_id = blockId; @@ -3756,12 +3855,12 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.LED_OFF, [output]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3857,7 +3956,10 @@ const color = script.getStringValue('COLOR', script); const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); - this.requestCommand(blockId, NeoBlockType.COLOR_LED_ON, [output, color]); + this.requestCommand(blockId, NeoBlockType.COLOR_LED_ON, [ + output, + color, + ]); if (duration === 'c' || !Entry.parseNumber(duration)) { script.exec_phase = ExecPhase.PENDING_STOP; script.block_id = blockId; @@ -3927,12 +4029,12 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; this.requestCommand(blockId, NeoBlockType.COLOR_LED_OFF, [output]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -3993,13 +4095,16 @@ isNotFor: ['NeoLite'], func: (sprite, script) => { if (!script.exec_phase) { - script.exec_phase = ExecPhase.PENDING_STOP; + script.exec_phase = ExecPhase.PENDING_RESPONSE; const output = script.getStringValue('OUTPUT', script); const input = script.getStringValue('INPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; - this.requestExtCommand(blockId, NeoBlockType.COLOR_LED_ON_SENSOR, [output, input]); - } else if (script.exec_phase === ExecPhase.PENDING_STOP) { + this.requestExtCommand(blockId, NeoBlockType.COLOR_LED_ON_SENSOR, [ + output, + input, + ]); + } else if (script.exec_phase === ExecPhase.PENDING_RESPONSE) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; delete script.exec_phase; @@ -4157,9 +4262,15 @@ const duration = script.getStringValue('DURATION', script); const blockId = this.generateBlockId(); if (value.indexOf('IN') >= 0) { - this.requestExtCommand(blockId, NeoBlockType.SET_OUTPUT, [output, value]); + this.requestExtCommand(blockId, NeoBlockType.SET_OUTPUT, [ + output, + value, + ]); } else { - this.requestCommand(blockId, NeoBlockType.SET_OUTPUT, [output, value]); + this.requestCommand(blockId, NeoBlockType.SET_OUTPUT, [ + output, + value, + ]); } if (duration === 'c' || !Entry.parseNumber(duration)) { script.exec_phase = ExecPhase.PENDING_STOP; @@ -4660,27 +4771,33 @@ const sensor3 = sensorData['in3Values'][0]; let lResult = false; if (lSymbol === '=') { - lResult = lValue === sensor1 && lValue === sensor2 && lValue === sensor3; + lResult = + lValue === sensor1 && lValue === sensor2 && lValue === sensor3; } else if (lSymbol === '>') { lResult = lValue > sensor1 && lValue > sensor2 && lValue > sensor3; } else if (lSymbol === '<') { lResult = lValue < sensor1 && lValue < sensor2 && lValue < sensor3; } else if (lSymbol === '>=') { - lResult = lValue >= sensor1 && lValue >= sensor2 && lValue >= sensor3; + lResult = + lValue >= sensor1 && lValue >= sensor2 && lValue >= sensor3; } else if (lSymbol === '<=') { - lResult = lValue <= sensor1 && lValue <= sensor2 && lValue <= sensor3; + lResult = + lValue <= sensor1 && lValue <= sensor2 && lValue <= sensor3; } let rResult = false; if (rSymbol === '=') { - rResult = sensor1 === rValue && sensor2 === rValue && sensor3 === rValue; + rResult = + sensor1 === rValue && sensor2 === rValue && sensor3 === rValue; } else if (rSymbol === '>') { rResult = sensor1 > rValue && sensor2 > rValue && sensor3 > rValue; } else if (rSymbol === '<') { rResult = sensor1 < rValue && sensor2 < rValue && sensor3 < rValue; } else if (rSymbol === '>=') { - rResult = sensor1 >= rValue && sensor2 >= rValue && sensor3 >= rValue; + rResult = + sensor1 >= rValue && sensor2 >= rValue && sensor3 >= rValue; } else if (rSymbol === '<=') { - rResult = sensor1 <= rValue && sensor2 <= rValue && sensor3 <= rValue; + rResult = + sensor1 <= rValue && sensor2 <= rValue && sensor3 <= rValue; } return lResult && rResult; } else { @@ -4776,32 +4893,68 @@ const input = script.getStringField('INPUT'); const sensorData = this.sensorValues; const color = script.getNumberField('COLOR'); - let sensorValue = 0; - switch (input) { - case 'in1': - sensorValue = sensorData['in1Values'][0]; - break; - case 'in2': - sensorValue = sensorData['in2Values'][0]; - break; - case 'in3': - sensorValue = sensorData['in3Values'][0]; - break; - } + if (input === 'IN12') { + const sensor1 = sensorData['in1Values'][0]; + const sensor2 = sensorData['in2Values'][0]; + if (color === 1) { + return sensor1 === 0 && sensor2 === 0; + } else if (color === 2) { + return sensor1 === 40 && sensor2 === 40; + } else if (color === 3) { + return sensor1 === 80 && sensor2 === 80; + } else if (color === 4) { + return sensor1 === 120 && sensor2 === 120; + } else if (color === 5) { + return sensor1 === 160 && sensor2 === 160; + } else if (color === 6) { + return sensor1 === 200 && sensor2 === 200; + } + } else if (input === 'IN123') { + const sensor1 = sensorData['in1Values'][0]; + const sensor2 = sensorData['in2Values'][0]; + const sensor3 = sensorData['in3Values'][0]; + if (color === 1) { + return sensor1 === 0 && sensor2 === 0 && sensor3 === 0; + } else if (color === 2) { + return sensor1 === 40 && sensor2 === 40 && sensor3 === 40; + } else if (color === 3) { + return sensor1 === 80 && sensor2 === 80 && sensor3 === 80; + } else if (color === 4) { + return sensor1 === 120 && sensor2 === 120 && sensor3 === 120; + } else if (color === 5) { + return sensor1 === 160 && sensor2 === 160 && sensor3 === 160; + } else if (color === 6) { + return sensor1 === 200 && sensor2 === 200 && sensor3 === 200; + } + } else { + let sensorValue = 0; + switch (input) { + case 'IN1': + sensorValue = sensorData['in1Values'][0]; + break; + case 'IN2': + sensorValue = sensorData['in2Values'][0]; + break; + case 'IN3': + sensorValue = sensorData['in3Values'][0]; + break; + } - if (color === 1) { - return sensorValue === 0; - } else if (color === 2) { - return sensorValue === 0; - } else if (color === 3) { - return sensorValue === 0; - } else if (color === 4) { - return sensorValue === 0; - } else if (color === 5) { - return sensorValue === 0; - } else if (color === 6) { - return sensorValue === 0; + if (color === 1) { + return sensorValue === 0; + } else if (color === 2) { + return sensorValue === 40; + } else if (color === 3) { + return sensorValue === 80; + } else if (color === 4) { + return sensorValue === 120; + } else if (color === 5) { + return sensorValue === 160; + } else if (color === 6) { + return sensorValue === 200; + } } + return false; }, }, @@ -5039,7 +5192,9 @@ const input = script.getStringValue('INPUT', script); const blockId = this.generateBlockId(); script.block_id = blockId; - this.requestExtCommand(blockId, NeoBlockType.BUZZER_WITH_SENSOR, [input]); + this.requestExtCommand(blockId, NeoBlockType.BUZZER_WITH_SENSOR, [ + input, + ]); } else if (script.exec_phase === ExecPhase.PENDING_STOP) { if (!this.pendingResponseList[script.block_id]) { delete script.block_id; @@ -5148,8 +5303,6 @@ [Lang.Blocks.neo_lite_lcd_image_11, '11'], [Lang.Blocks.neo_lite_lcd_image_12, '12'], [Lang.Blocks.neo_lite_lcd_image_13, '13'], - [Lang.Blocks.neo_lite_lcd_image_14, '14'], - [Lang.Blocks.neo_lite_lcd_image_15, '15'], ], value: '1', fontSize: 11, @@ -5252,7 +5405,7 @@ /** * ARG Blocks */ - neo_lite_arg_motor_speed: { + neo_lite_arg_duration: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, skeleton: 'basic_string_field', @@ -5261,29 +5414,19 @@ { type: 'Dropdown', options: [ - [Lang.Blocks.neo_lite_motor_speed_100, '100'], - [Lang.Blocks.neo_lite_motor_speed_90, '90'], - [Lang.Blocks.neo_lite_motor_speed_80, '80'], - [Lang.Blocks.neo_lite_motor_speed_70, '70'], - [Lang.Blocks.neo_lite_motor_speed_60, '60'], - [Lang.Blocks.neo_lite_motor_speed_50, '50'], - [Lang.Blocks.neo_lite_motor_speed_40, '40'], - [Lang.Blocks.neo_lite_motor_speed_30, '30'], - [Lang.Blocks.neo_lite_motor_speed_20, '20'], - [Lang.Blocks.neo_lite_motor_speed_10, '10'], - [Lang.Blocks.neo_lite_motor_speed_0, '0'], - [Lang.Blocks.neo_lite_motor_speed_n10, '-10'], - [Lang.Blocks.neo_lite_motor_speed_n20, '-20'], - [Lang.Blocks.neo_lite_motor_speed_n30, '-30'], - [Lang.Blocks.neo_lite_motor_speed_n40, '-40'], - [Lang.Blocks.neo_lite_motor_speed_n50, '-50'], - [Lang.Blocks.neo_lite_motor_speed_n60, '-60'], - [Lang.Blocks.neo_lite_motor_speed_n70, '-70'], - [Lang.Blocks.neo_lite_motor_speed_n80, '-80'], - [Lang.Blocks.neo_lite_motor_speed_n90, '-90'], - [Lang.Blocks.neo_lite_motor_speed_n100, '-100'], + [Lang.Blocks.neo_lite_duration_c, 'c'], + [Lang.Blocks.neo_lite_duration_0, '0'], + [Lang.Blocks.neo_lite_duration_1, '1'], + [Lang.Blocks.neo_lite_duration_2, '2'], + [Lang.Blocks.neo_lite_duration_3, '3'], + [Lang.Blocks.neo_lite_duration_4, '4'], + [Lang.Blocks.neo_lite_duration_5, '5'], + [Lang.Blocks.neo_lite_duration_6, '6'], + [Lang.Blocks.neo_lite_duration_7, '7'], + [Lang.Blocks.neo_lite_duration_8, '8'], + [Lang.Blocks.neo_lite_duration_9, '9'], ], - value: '100', + value: 'c', fontSize: 11, bgColor: EntryStatic.colorSet.block.darken.HARDWARE, arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, @@ -5302,7 +5445,7 @@ return script.getStringField('VALUE'); }, }, - neo_lite_arg_duration: { + neo_lite_arg_motor_speed: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, skeleton: 'basic_string_field', @@ -5311,19 +5454,29 @@ { type: 'Dropdown', options: [ - [Lang.Blocks.neo_lite_duration_c, 'c'], - [Lang.Blocks.neo_lite_duration_0, '0'], - [Lang.Blocks.neo_lite_duration_1, '1'], - [Lang.Blocks.neo_lite_duration_2, '2'], - [Lang.Blocks.neo_lite_duration_3, '3'], - [Lang.Blocks.neo_lite_duration_4, '4'], - [Lang.Blocks.neo_lite_duration_5, '5'], - [Lang.Blocks.neo_lite_duration_6, '6'], - [Lang.Blocks.neo_lite_duration_7, '7'], - [Lang.Blocks.neo_lite_duration_8, '8'], - [Lang.Blocks.neo_lite_duration_9, '9'], + [Lang.Blocks.neo_lite_motor_speed_100, '100'], + [Lang.Blocks.neo_lite_motor_speed_90, '90'], + [Lang.Blocks.neo_lite_motor_speed_80, '80'], + [Lang.Blocks.neo_lite_motor_speed_70, '70'], + [Lang.Blocks.neo_lite_motor_speed_60, '60'], + [Lang.Blocks.neo_lite_motor_speed_50, '50'], + [Lang.Blocks.neo_lite_motor_speed_40, '40'], + [Lang.Blocks.neo_lite_motor_speed_30, '30'], + [Lang.Blocks.neo_lite_motor_speed_20, '20'], + [Lang.Blocks.neo_lite_motor_speed_10, '10'], + [Lang.Blocks.neo_lite_motor_speed_0, '0'], + [Lang.Blocks.neo_lite_motor_speed_n10, '-10'], + [Lang.Blocks.neo_lite_motor_speed_n20, '-20'], + [Lang.Blocks.neo_lite_motor_speed_n30, '-30'], + [Lang.Blocks.neo_lite_motor_speed_n40, '-40'], + [Lang.Blocks.neo_lite_motor_speed_n50, '-50'], + [Lang.Blocks.neo_lite_motor_speed_n60, '-60'], + [Lang.Blocks.neo_lite_motor_speed_n70, '-70'], + [Lang.Blocks.neo_lite_motor_speed_n80, '-80'], + [Lang.Blocks.neo_lite_motor_speed_n90, '-90'], + [Lang.Blocks.neo_lite_motor_speed_n100, '-100'], ], - value: 'c', + value: '100', fontSize: 11, bgColor: EntryStatic.colorSet.block.darken.HARDWARE, arrowColor: EntryStatic.colorSet.arrow.default.HARDWARE, @@ -5791,7 +5944,10 @@ data.writeInt16LE(speed, 0); data.writeInt16LE(robotCommand, 2); body.push(...data); - } else if (type === NeoBlockType.MOTOR_STOP || type === NeoBlockType.AUTO_DRIVING_STOP) { + } else if ( + type === NeoBlockType.MOTOR_STOP || + type === NeoBlockType.AUTO_DRIVING_STOP + ) { const which = params[0]; const direction = 1; body.push(UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.MOTOR); @@ -5892,7 +6048,11 @@ body.push(...data); } else if (type === NeoBlockType.AUTO_DETECT_WALL_TURN) { const direction = params[0]; - body.push(UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.AUTO_DETECT_WALL); + body.push( + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.AUTO_DETECT_WALL + ); const data = Buffer.from([0, 0, 0, 0]); data.writeInt16LE(60, 0); data.writeInt16LE(direction, 2); @@ -5978,22 +6138,38 @@ if (type === NeoBlockType.MOTOR_MOVE) { const which = params[0]; const unitId = this.getUnitId(params[1]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.MOTOR); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.MOTOR + ); const data = Buffer.from([unitId, 0, which, 0, 0, 0]); body.push(...data); } else if (type === NeoBlockType.ROBOT_MOVE) { const robotCommand = params[0]; const unitId = this.getUnitId(params[1]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.ROBOT); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.ROBOT + ); const data = Buffer.from([unitId, 0, 0, 0]); data.writeInt16LE(robotCommand, 2); body.push(...data); - } else if (type === NeoBlockType.SERVO_ANGLE || type === NeoBlockType.SERVO_ANGLE_WAIT) { + } else if ( + type === NeoBlockType.SERVO_ANGLE || + type === NeoBlockType.SERVO_ANGLE_WAIT + ) { const unitId = this.getUnitId(params[0]); - const inUnitId = this.getUnitId(params[1]); - const speed = params[2]; + let angle = params[1]; + let speed = params[2]; + if (angle.indexOf('IN') >= 0) angle = this.getUnitId(angle); body.push(PduCode.EXTEND_1, blockId, unitId, ActorKind.SERVO, ServoCommand.ANGLE); - const data = Buffer.from([inUnitId, 0, 0, 0, 1, 0]); + const data = Buffer.from([angle, 0, 0, 0, 1, 0]); data.writeInt16LE(speed, 2); body.push(...data); } else if (type === NeoBlockType.SERVO_ROTATE) { @@ -6010,13 +6186,25 @@ type === NeoBlockType.AUTO_DETECT_WALL_START ) { const unitId = this.getUnitId(params[0]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.ROBOT); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.ROBOT + ); const data = Buffer.from([unitId, 0, 0x10, 0]); body.push(...data); } else if (type === NeoBlockType.AUTO_DRIVING_SENSOR_START) { const sensor = params[0]; const unitId = this.getUnitId(params[1]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.ROBOT); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.ROBOT + ); const data = Buffer.from([0, 0, 0, 0]); data.writeInt16LE(unitId, 0); data.writeInt16LE(sensor, 2); @@ -6035,7 +6223,13 @@ body.push(...data); } else if (type === NeoBlockType.BUZZER_WITH_SENSOR) { const sensorUnitId = this.getUnitId(params[0]); - body.push(PduCode.EXTEND_1, blockId, UnitId.CONTROLLER, ActorKind.CONTROLLER, ControllerCommand.BUZZER); + body.push( + PduCode.EXTEND_1, + blockId, + UnitId.CONTROLLER, + ActorKind.CONTROLLER, + ControllerCommand.BUZZER + ); const data = Buffer.from([0, 0]); data.writeInt16LE(sensorUnitId, 0); body.push(...data); @@ -6049,6 +6243,18 @@ return body; } + makeCommandExt2(blockId, type, params) { + const body = [FrameCode.BASIC]; + if (type === NeoBlockType.SERVO_ANGLE || type === NeoBlockType.SERVO_ANGLE_WAIT) { + const unitId = this.getUnitId(params[0]); + const angleInUnitId = this.getUnitId(params[1]); + const speedInUnitId = this.getUnitId(params[2]); + body.push(PduCode.EXTEND_2, blockId, unitId, ActorKind.SERVO, ServoCommand.ANGLE); + const data = Buffer.from([angleInUnitId, 0, speedInUnitId, 0, 1, 0]); + body.push(...data); + } + return body; + } /* 후면주차 실행 (pending response 하지 않고 바로 다음 단계로 넘어감 : phase 가 너무 많아서 간소화) 주석은 왼쪽 기준으로 오른쪽에서는 좌우만 바꿔준다. @@ -6078,7 +6284,8 @@ this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [which === 1 ? 5 : 6, 20]); } else if (script.exec_phase === '5_wait_sensor') { // 5. IN2 40 초과 기다리기 - const compareValue = which === 1 ? sensorData.in2Values[0] : sensorData.in1Values[0]; + const compareValue = + which === 1 ? sensorData.in2Values[0] : sensorData.in1Values[0]; if (compareValue > 40) { script.exec_phase = '6_stop_robot'; } @@ -6099,7 +6306,8 @@ this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [2, 20]); } else if (script.exec_phase === '9_wait_sensor') { // 9. IN1 20초과 기다리기 - const compareValue = which === 1 ? sensorData.in1Values[0] : sensorData.in2Values[0]; + const compareValue = + which === 1 ? sensorData.in1Values[0] : sensorData.in2Values[0]; if (compareValue > 20) { script.exec_phase = '10_stop_robot'; } @@ -6191,13 +6399,15 @@ this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [2, 30]); } else if (script.exec_phase === '5_wait_sensor') { // 5. IN1 40 초과 기다리기 - const compareValue = which === 1 ? sensorData.in1Values[0] : sensorData.in2Values[0]; + const compareValue = + which === 1 ? sensorData.in1Values[0] : sensorData.in2Values[0]; if (compareValue > 40) { script.exec_phase = '6_wait_sensor'; } } else if (script.exec_phase === '6_wait_sensor') { // 6. IN2 40 초과 기다리기 - const compareValue = which === 1 ? sensorData.in2Values[0] : sensorData.in1Values[0]; + const compareValue = + which === 1 ? sensorData.in2Values[0] : sensorData.in1Values[0]; if (compareValue > 40) { script.exec_phase = '7_robot_stop'; } @@ -6218,7 +6428,8 @@ this.requestCommand(blockId, NeoBlockType.ROBOT_MOVE, [which === 1 ? 5 : 6, 20]); } else if (script.exec_phase === '10_wait_sensor') { // 10. IN1 40초과 기다리기 - const compareValue = which === 1 ? sensorData.in1Values[0] : sensorData.in2Values[0]; + const compareValue = + which === 1 ? sensorData.in1Values[0] : sensorData.in2Values[0]; if (compareValue > 40) { script.exec_phase = '11_stop_robot'; } diff --git a/src/playground/blocks/hardwareLite/block_neobot_purple_lite.js b/src/playground/blocks/hardwareLite/block_neobot_purple_lite.js index 61250f880a..add61313a3 100644 --- a/src/playground/blocks/hardwareLite/block_neobot_purple_lite.js +++ b/src/playground/blocks/hardwareLite/block_neobot_purple_lite.js @@ -1,5 +1,6 @@ 'use strict'; (function() { + const HEADER = [0xab, 0xcd]; Entry.NeobotPurpleLite = new (class NeobotPurpleLite { constructor() { this.id = '5.5'; @@ -27,8 +28,8 @@ OUT1: 0, OUT2: 0, OUT3: 0, - DCR: 0, DCL: 0, + DCR: 0, SND: 0, FND: 0, OPT: 0, @@ -37,41 +38,43 @@ this.blockMenuBlocks = [ // sensor + 'neobot_purple_lite_sensor_title', 'neobot_purple_lite_sensor_value', 'neobot_purple_lite_sensor_convert_scale', - - // decision 'neobot_purple_lite_decision_sensor_is_over', 'neobot_purple_lite_decision_equal_with_sensor', 'neobot_purple_lite_decision_sensor_angle', - - // remote 'neobot_purple_lite_remote_button', // led + 'neobot_purple_lite_led_title', 'neobot_purple_lite_led_on', 'neobot_purple_lite_led_brightness_with_sensor', 'neobot_purple_lite_color_led_on', 'neobot_purple_lite_output_led_off', // output + 'neobot_purple_lite_output_title', 'neobot_purple_lite_set_output', // motor + 'neobot_purple_lite_motor_title', 'neobot_purple_lite_robot', 'neobot_purple_lite_motor_start', 'neobot_purple_lite_motor_stop', - // melody - 'neobot_purple_lite_play_note_for', - 'neobot_purple_lite_melody_play_with_sensor', - 'neobot_purple_lite_melody_stop', - // servo + 'neobot_purple_lite_servo_title', 'neobot_purple_lite_servo_init', 'neobot_purple_lite_servo_rotate', 'neobot_purple_lite_servo_stop', 'neobot_purple_lite_servo_change_degree', + + // melody + 'neobot_purple_lite_buzzer_title', + 'neobot_purple_lite_play_note_for', + 'neobot_purple_lite_melody_play_with_sensor', + 'neobot_purple_lite_melody_stop', ]; this.setZero(); @@ -79,7 +82,7 @@ get monitorTemplate() { return { - imgPath: 'hw_lite/neobot_purple_lite.png', + imgPath: 'hw/neobot_purple.png', width: 700, height: 700, listPorts: { @@ -147,8 +150,8 @@ OUT1: 0, OUT2: 0, OUT3: 0, - DCR: 0, DCL: 0, + DCR: 0, SND: 0, FND: 0, OPT: 0, @@ -159,17 +162,95 @@ } handleLocalData(data) { - for (let i = 0; i < data.length - 1; i++) { - if (data[i] === 171 && data[i + 1] === 205) { - const dataSet = data.slice(i + 2, i + 7); - dataSet.forEach((value, idx) => { - this.localBuffer[this.LOCAL_MAP[idx]] = value; - }); + let validPdu = this.getValidPdu(data); + while (validPdu) { + this.onReceivePdu(validPdu); + if (!this.remainingPdu || this.remainingPdu.length <= 0) { break; } + validPdu = this.getValidPdu([]); } } + onReceivePdu(pdu) { + if (pdu[0] === HEADER[0] && pdu[1] === HEADER[1]) { + this.localBuffer['IN1'] = pdu[2]; + this.localBuffer['IN2'] = pdu[3]; + this.localBuffer['IN3'] = pdu[4]; + this.localBuffer['IR'] = pdu[5]; + this.localBuffer['BAT'] = pdu[6]; + } + } + + getValidPdu(pdu) { + const mergedPdu = []; + if (this.remainingPdu) { + mergedPdu.push(...this.remainingPdu); + this.remainingPdu = null; + } + mergedPdu.push(...pdu); + if (mergedPdu.length < 2) { + this.remainingPdu = [...mergedPdu]; + return null; + } + + // 헤더 불일치는 버림 + if (!this.checkHeader(mergedPdu)) { + return null; + } + + // 유효 데이터 길이는 header 2 + body 5 + checksum 1 = 8 + const validDataLength = 8; + /* + 전체 길이가 유효 데이터 길이보다 작을 경우 + 아직 도착하지 않은 부분이 있으므로 병합을 위해 remainingPdu 에 저장 + */ + if (mergedPdu.length < validDataLength) { + this.remainingPdu = [...mergedPdu]; + return null; + } + + /* + 전체 길이가 유효 데이터 길이보다 클 경우 + 유효한 부분만 잘라내고 나머지는 remainingPdu 에 저장 + */ + if (mergedPdu.length > validDataLength) { + this.remainingPdu = mergedPdu.slice(validDataLength, mergedPdu.length); + } + + const validPdu = mergedPdu.slice(0, validDataLength); + + /* + 유효 Pdu 의 checksum 확인 + */ + const dataLength = 5; + let checkSum = 0; + for (let i = 0; i < dataLength; i++) { + checkSum += validPdu[i + 2]; + } + checkSum = checkSum & 255; + const pduCheckSum = validPdu[7]; + if (pduCheckSum !== checkSum) { + return null; + } + + return validPdu; + } + + checkHeader(pdu) { + if (pdu.length < HEADER.length) { + return false; + } + + for (let i = 0; i < HEADER.length; i++) { + if (HEADER[i] !== pdu[i]) { + return false; + } + } + + return true; + } + requestLocalData() { const requestData = []; @@ -201,18 +282,16 @@ ko: { template: { // sensor + neobot_purple_lite_sensor_title: '센서', neobot_purple_lite_sensor_value: '%1', neobot_purple_lite_sensor_convert_scale: '%1 %2 ~ %3 를 %4 ~ %5 으로 변환', - - // decision neobot_purple_lite_decision_sensor_is_over: '%1 %2 %3', neobot_purple_lite_decision_equal_with_sensor: '%1 컬러가 %2', neobot_purple_lite_decision_sensor_angle: '%1 각도 %2 %3', - - // remote neobot_purple_lite_remote_button: '리모컨 버튼 %1 을 누름', // LED + neobot_purple_lite_led_title: 'LED', neobot_purple_lite_arg_led_duration: '%1', neobot_purple_lite_led_on: 'LED 켜기 %1 %2 %3 %4', neobot_purple_lite_output_led_off: '%1 LED 끄기 %2', @@ -220,9 +299,11 @@ neobot_purple_lite_color_led_on: '%1 컬러LED 켜기 R %2 G %3 B %4 %5', // output + neobot_purple_lite_output_title: '출력', neobot_purple_lite_set_output: '%1 에 %2 값 출력하기 %3', // motor + neobot_purple_lite_motor_title: '회전모터', neobot_purple_lite_robot: '로봇 %1 %2', neobot_purple_lite_motor_start: '모터 회전하기 %1 %2 %3 %4 %5', neobot_purple_lite_motor_stop: '%1 모터 멈추기 %2', @@ -230,12 +311,14 @@ neobot_purple_lite_arg_motor_duration: '%1', // melody + neobot_purple_lite_buzzer_title: '버저', neobot_purple_lite_play_note_for: '버저 울리기 옥타브: %2 음: %1 길이: %3 %4', neobot_purple_lite_melody_play_with_sensor: '%1 센서로 버저 울리기 %2', neobot_purple_lite_melody_stop: '버저 멈추기 %1', // servo + neobot_purple_lite_servo_title: '서보모터', get_servo_degree: '%1', neobot_purple_lite_servo_init: '%1 서보모터 리셋 %2', neobot_purple_lite_servo_rotate: '서보모터 회전하기 %1 %2 %3 %4', @@ -376,19 +459,17 @@ // en.js에 작성하던 내용 template: { // sensor + neobot_purple_lite_sensor_title: 'Sensor', neobot_purple_lite_sensor_value: '%1', neobot_purple_lite_sensor_convert_scale: "%1 's changed value range: %2 ~ %3 conversion: %4 ~ %5", - - // decision neobot_purple_lite_decision_sensor_is_over: '%1 %2 %3', neobot_purple_lite_decision_equal_with_sensor: "%1 's color is %2", neobot_purple_lite_decision_sensor_angle: '%1 angle %2 %3', - - // remote neobot_purple_lite_remote_button: 'pressing button %1 of remote controller', // LED + neobot_purple_lite_led_title: 'LED', neobot_purple_lite_arg_led_duration: '%1', neobot_purple_lite_led_on: 'Turn on the LED %1 %2 %3 %4', neobot_purple_lite_output_led_off: 'Turn off the %1 LED %2', @@ -398,9 +479,11 @@ 'Turn on the %1 color LED R %2 G %3 B %4 %5', // output + neobot_purple_lite_output_title: 'Set output', neobot_purple_lite_set_output: 'Output %2 value to %1 port %3', // motor + neobot_purple_lite_motor_title: 'Motor', neobot_purple_lite_robot: 'Robot %1 %2', neobot_purple_lite_motor_start: 'Motor operation %1 %2 %3 %4 %5', neobot_purple_lite_motor_stop: 'Stop the %1 motor(s) %2', @@ -408,6 +491,7 @@ neobot_purple_lite_arg_motor_duration: '%1', // melody + neobot_purple_lite_buzzer_title: 'Buzzer', neobot_purple_lite_play_note_for: 'Buzzer octave: %1 scale: %2 note: %3 %4', neobot_purple_lite_melody_play_with_sensor: @@ -415,6 +499,7 @@ neobot_purple_lite_melody_stop: 'Stop the buzzer %1', // servo + neobot_purple_lite_servo_title: 'Servo motor', neobot_purple_lite_servo_init: 'Reset the %1 servo motor %2', neobot_purple_lite_servo_rotate: 'Rotate the servo motor %1 %2 %3 %4', neobot_purple_lite_servo_stop: 'Stop the %1 servo motor %2', @@ -558,6 +643,30 @@ /************************* * class neobot_purple_lite_sensor *************************/ + neobot_purple_lite_sensor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_lite_sensor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_lite_sensor_title', + }, + class: 'neobot_purple_lite_sensor', + isNotFor: ['NeobotPurpleLite'], + events: {}, + }, neobot_purple_lite_sensor_value: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -693,10 +802,6 @@ return Math.round(value); }, }, - - /************************* - * class neobot_purple_lite_decision - *************************/ neobot_purple_lite_decision_sensor_is_over: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -746,7 +851,7 @@ SYMBOL: 1, VALUE: 2, }, - class: 'neobot_purple_lite_decision', + class: 'neobot_purple_lite_sensor', isNotFor: ['NeobotPurpleLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -848,7 +953,7 @@ SENSOR: 0, COLOR: 1, }, - class: 'neobot_purple_lite_decision', + class: 'neobot_purple_lite_sensor', isNotFor: ['NeobotPurpleLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -962,7 +1067,7 @@ SYMBOL: 1, VALUE: 2, }, - class: 'neobot_purple_lite_decision', + class: 'neobot_purple_lite_sensor', isNotFor: ['NeobotPurpleLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -1004,10 +1109,6 @@ return false; }, }, - - /************************* - * class neobot_purple_lite_remote - *************************/ neobot_purple_lite_remote_button: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1041,7 +1142,7 @@ paramsKeyMap: { KEY: 0, }, - class: 'neobot_purple_lite_remote', + class: 'neobot_purple_lite_sensor', isNotFor: ['NeobotPurpleLite'], func(sprite, script) { const key = script.getNumberField('KEY'); @@ -1057,6 +1158,30 @@ /************************* * class neobot_purple_lite_led *************************/ + neobot_purple_lite_led_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_lite_led_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_lite_led_title', + }, + class: 'neobot_purple_lite_led', + isNotFor: ['NeobotPurpleLite'], + events: {}, + }, neobot_purple_lite_led_on: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1584,6 +1709,30 @@ /************************* * class neobot_purple_lite_output *************************/ + neobot_purple_lite_output_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_lite_output_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_lite_output_title', + }, + class: 'neobot_purple_lite_output', + isNotFor: ['NeobotPurpleLite'], + events: {}, + }, neobot_purple_lite_set_output: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1661,6 +1810,30 @@ /************************* * class neobot_purple_lite_motor *************************/ + neobot_purple_lite_motor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_lite_motor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_lite_motor_title', + }, + class: 'neobot_purple_lite_motor', + isNotFor: ['NeobotPurpleLite'], + events: {}, + }, neobot_purple_lite_robot: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1987,6 +2160,30 @@ /************************* * class neobot_purple_lite_melody *************************/ + neobot_purple_lite_buzzer_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_lite_buzzer_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_lite_buzzer_title', + }, + class: 'neobot_purple_lite_buzzer', + isNotFor: ['NeobotPurpleLite'], + events: {}, + }, neobot_purple_lite_play_note_for: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2059,7 +2256,7 @@ OCTAVE: 1, DURATION: 2, }, - class: 'neobot_purple_lite_melody', + class: 'neobot_purple_lite_buzzer', isNotFor: ['NeobotPurpleLite'], func(sprite, script) { if (!script.isStart) { @@ -2140,7 +2337,7 @@ paramsKeyMap: { INPUT: 0, }, - class: 'neobot_purple_lite_melody', + class: 'neobot_purple_lite_buzzer', isNotFor: ['NeobotPurpleLite'], func(sprite, script) { const input = script.getStringField('INPUT'); @@ -2184,7 +2381,7 @@ type: 'neobot_purple_lite_melody_stop', }, paramsKeyMap: {}, - class: 'neobot_purple_lite_melody', + class: 'neobot_purple_lite_buzzer', isNotFor: ['NeobotPurpleLite'], func(sprite, script) { if (Entry.NeobotPurpleLite.log_to_console) { @@ -2201,6 +2398,30 @@ /************************* * class neobot_purple_lite_servo *************************/ + neobot_purple_lite_servo_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_purple_lite_servo_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_purple_lite_servo_title', + }, + class: 'neobot_purple_lite_servo', + isNotFor: ['NeobotPurpleLite'], + events: {}, + }, neobot_purple_lite_servo_init: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, diff --git a/src/playground/blocks/hardwareLite/block_neobot_soco_lite.js b/src/playground/blocks/hardwareLite/block_neobot_soco_lite.js index f06d91f5ea..de221e2bd7 100644 --- a/src/playground/blocks/hardwareLite/block_neobot_soco_lite.js +++ b/src/playground/blocks/hardwareLite/block_neobot_soco_lite.js @@ -1,5 +1,6 @@ 'use strict'; (function() { + const HEADER = [0xab, 0xcd]; Entry.NeobotSocoLite = new (class NeobotSocoLite { constructor() { this.id = '5.6'; @@ -27,8 +28,8 @@ OUT1: 0, OUT2: 0, OUT3: 0, - DCR: 0, DCL: 0, + DCR: 0, SND: 0, FND: 0, OPT: 0, @@ -37,41 +38,43 @@ this.blockMenuBlocks = [ // sensor + 'neobot_soco_lite_sensor_title', 'neobot_soco_lite_sensor_value', 'neobot_soco_lite_sensor_convert_scale', - - // decision 'neobot_soco_lite_decision_sensor_is_over', 'neobot_soco_lite_decision_equal_with_sensor', 'neobot_soco_lite_decision_sensor_angle', - - // remote 'neobot_soco_lite_remote_button', // led + 'neobot_soco_lite_led_title', 'neobot_soco_lite_led_on', 'neobot_soco_lite_led_brightness_with_sensor', 'neobot_soco_lite_color_led_on', 'neobot_soco_lite_output_led_off', // output + 'neobot_soco_lite_output_title', 'neobot_soco_lite_set_output', // motor + 'neobot_soco_lite_motor_title', 'neobot_soco_lite_robot', 'neobot_soco_lite_motor_start', 'neobot_soco_lite_motor_stop', - // melody - 'neobot_soco_lite_play_note_for', - 'neobot_soco_lite_melody_play_with_sensor', - 'neobot_soco_lite_melody_stop', - // servo + 'neobot_soco_lite_servo_title', 'neobot_soco_lite_servo_init', 'neobot_soco_lite_servo_rotate', 'neobot_soco_lite_servo_stop', 'neobot_soco_lite_servo_change_degree', + + // buzzer + 'neobot_soco_lite_buzzer_title', + 'neobot_soco_lite_play_note_for', + 'neobot_soco_lite_melody_play_with_sensor', + 'neobot_soco_lite_melody_stop', ]; this.setZero(); @@ -79,7 +82,7 @@ get monitorTemplate() { return { - imgPath: 'hw_lite/neobot_soco_lite.png', + imgPath: 'hw/neobot_soco.png', width: 700, height: 700, listPorts: { @@ -111,8 +114,8 @@ OUT1: 0, OUT2: 0, OUT3: 0, - DCR: 0, DCL: 0, + DCR: 0, SND: 0, FND: 0, OPT: 0, @@ -123,15 +126,93 @@ } handleLocalData(data) { - for (let i = 0; i < data.length - 1; i++) { - if (data[i] === 171 && data[i + 1] === 205) { - const dataSet = data.slice(i + 2, i + 7); - dataSet.forEach((value, idx) => { - this.localBuffer[this.LOCAL_MAP[idx]] = value; - }); + let validPdu = this.getValidPdu(data); + while (validPdu) { + this.onReceivePdu(validPdu); + if (!this.remainingPdu || this.remainingPdu.length <= 0) { break; } + validPdu = this.getValidPdu([]); + } + } + + onReceivePdu(pdu) { + if (pdu[0] === HEADER[0] && pdu[1] === HEADER[1]) { + this.localBuffer['IN1'] = pdu[2]; + this.localBuffer['IN2'] = pdu[3]; + this.localBuffer['IN3'] = pdu[4]; + this.localBuffer['IR'] = pdu[5]; + this.localBuffer['BAT'] = pdu[6]; + } + } + + getValidPdu(pdu) { + const mergedPdu = []; + if (this.remainingPdu) { + mergedPdu.push(...this.remainingPdu); + this.remainingPdu = null; + } + mergedPdu.push(...pdu); + if (mergedPdu.length < 2) { + this.remainingPdu = [...mergedPdu]; + return null; + } + + // 헤더 불일치는 버림 + if (!this.checkHeader(mergedPdu)) { + return null; + } + + // 유효 데이터 길이는 header 2 + body 5 + checksum 1 = 8 + const validDataLength = 8; + /* + 전체 길이가 유효 데이터 길이보다 작을 경우 + 아직 도착하지 않은 부분이 있으므로 병합을 위해 remainingPdu 에 저장 + */ + if (mergedPdu.length < validDataLength) { + this.remainingPdu = [...mergedPdu]; + return null; + } + + /* + 전체 길이가 유효 데이터 길이보다 클 경우 + 유효한 부분만 잘라내고 나머지는 remainingPdu 에 저장 + */ + if (mergedPdu.length > validDataLength) { + this.remainingPdu = mergedPdu.slice(validDataLength, mergedPdu.length); + } + + const validPdu = mergedPdu.slice(0, validDataLength); + + /* + 유효 Pdu 의 checksum 확인 + */ + const dataLength = 5; + let checkSum = 0; + for (let i = 0; i < dataLength; i++) { + checkSum += validPdu[i + 2]; + } + checkSum = checkSum & 255; + const pduCheckSum = validPdu[7]; + if (pduCheckSum !== checkSum) { + return null; + } + + return validPdu; + } + + checkHeader(pdu) { + if (pdu.length < HEADER.length) { + return false; + } + + for (let i = 0; i < HEADER.length; i++) { + if (HEADER[i] !== pdu[i]) { + return false; + } } + + return true; } requestLocalData() { @@ -165,18 +246,16 @@ ko: { template: { // sensor + neobot_soco_lite_sensor_title: '센서', neobot_soco_lite_sensor_value: '%1', neobot_soco_lite_sensor_convert_scale: '%1 %2 ~ %3 를 %4 ~ %5 으로 변환', - - // decision neobot_soco_lite_decision_sensor_is_over: '%1 %2 %3', neobot_soco_lite_decision_equal_with_sensor: '%1 컬러가 %2', neobot_soco_lite_decision_sensor_angle: '%1 각도 %2 %3', - - // remote neobot_soco_lite_remote_button: '리모컨 버튼 %1 을 누름', // LED + neobot_soco_lite_led_title: 'LED', neobot_soco_lite_arg_led_duration: '%1', neobot_soco_lite_led_on: 'LED 켜기 %1 %2 %3 %4', neobot_soco_lite_output_led_off: '%1 LED 끄기 %2', @@ -184,9 +263,11 @@ neobot_soco_lite_color_led_on: '%1 컬러LED 켜기 R %2 G %3 B %4 %5', // output + neobot_soco_lite_output_title: '출력', neobot_soco_lite_set_output: '%1 에 %2 값 출력하기 %3', // motor + neobot_soco_lite_motor_title: '회전모터', neobot_soco_lite_robot: '로봇 %1 %2', neobot_soco_lite_motor_start: '모터 회전하기 %1 %2 %3 %4 %5', neobot_soco_lite_motor_stop: '%1 모터 멈추기 %2', @@ -194,12 +275,14 @@ neobot_soco_lite_arg_motor_duration: '%1', // melody + neobot_soco_lite_buzzer_title: '버저', neobot_soco_lite_play_note_for: '버저 울리기 옥타브: %2 음: %1 길이: %3 %4', neobot_soco_lite_melody_play_with_sensor: '%1 센서로 버저 울리기 %2', neobot_soco_lite_melody_stop: '버저 멈추기 %1', // servo + neobot_soco_lite_servo_title: '서보모터', get_servo_degree: '%1', neobot_soco_lite_servo_init: '%1 서보모터 리셋 %2', neobot_soco_lite_servo_rotate: '서보모터 회전하기 %1 %2 %3 %4', @@ -340,19 +423,17 @@ // en.js에 작성하던 내용 template: { // sensor + neobot_soco_lite_sensor_title: 'Sensor', neobot_soco_lite_sensor_value: '%1', neobot_soco_lite_sensor_convert_scale: "%1 's changed value range: %2 ~ %3 conversion: %4 ~ %5", - - // decision neobot_soco_lite_decision_sensor_is_over: '%1 %2 %3', neobot_soco_lite_decision_equal_with_sensor: "%1 's color is %2", neobot_soco_lite_decision_sensor_angle: '%1 angle %2 %3', - - // remote neobot_soco_lite_remote_button: 'pressing button %1 of remote controller', // LED + neobot_soco_lite_led_title: 'LED', neobot_soco_lite_arg_led_duration: '%1', neobot_soco_lite_led_on: 'Turn on the LED %1 %2 %3 %4', neobot_soco_lite_output_led_off: 'Turn off the %1 LED %2', @@ -362,9 +443,11 @@ 'Turn on the %1 color LED R %2 G %3 B %4 %5', // output + neobot_soco_lite_output_title: 'Set output', neobot_soco_lite_set_output: 'Output %2 value to %1 port %3', // motor + neobot_soco_lite_motor_title: 'Motor', neobot_soco_lite_robot: 'Robot %1 %2', neobot_soco_lite_motor_start: 'Motor operation %1 %2 %3 %4 %5', neobot_soco_lite_motor_stop: 'Stop the %1 motor(s) %2', @@ -372,12 +455,14 @@ neobot_soco_lite_arg_motor_duration: '%1', // melody + neobot_soco_lite_buzzer_title: 'Buzzer', neobot_soco_lite_play_note_for: 'Buzzer octave: %1 scale: %2 note: %3 %4', neobot_soco_lite_melody_play_with_sensor: 'Buzzer rings by %1 sensor value %2', neobot_soco_lite_melody_stop: 'Stop the buzzer %1', // servo + neobot_soco_lite_servo_title: 'Servo motor', neobot_soco_lite_servo_init: 'Reset the %1 servo motor %2', neobot_soco_lite_servo_rotate: 'Rotate the servo motor %1 %2 %3 %4', neobot_soco_lite_servo_stop: 'Stop the %1 servo motor %2', @@ -520,6 +605,30 @@ /************************* * class neobot_soco_lite_sensor *************************/ + neobot_soco_lite_sensor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_lite_sensor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_lite_sensor_title', + }, + class: 'neobot_soco_lite_sensor', + isNotFor: ['NeobotSocoLite'], + events: {}, + }, neobot_soco_lite_sensor_value: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -655,10 +764,6 @@ return Math.round(value); }, }, - - /************************* - * class neobot_soco_lite_decision - *************************/ neobot_soco_lite_decision_sensor_is_over: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -708,7 +813,7 @@ SYMBOL: 1, VALUE: 2, }, - class: 'neobot_soco_lite_decision', + class: 'neobot_soco_lite_sensor', isNotFor: ['NeobotSocoLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -810,7 +915,7 @@ SENSOR: 0, COLOR: 1, }, - class: 'neobot_soco_lite_decision', + class: 'neobot_soco_lite_sensor', isNotFor: ['NeobotSocoLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -924,7 +1029,7 @@ SYMBOL: 1, VALUE: 2, }, - class: 'neobot_soco_lite_decision', + class: 'neobot_soco_lite_sensor', isNotFor: ['NeobotSocoLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -967,9 +1072,6 @@ }, }, - /************************* - * class neobot_soco_lite_remote - *************************/ neobot_soco_lite_remote_button: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1003,7 +1105,7 @@ paramsKeyMap: { KEY: 0, }, - class: 'neobot_soco_lite_remote', + class: 'neobot_soco_lite_sensor', isNotFor: ['NeobotSocoLite'], func(sprite, script) { const key = script.getNumberField('KEY'); @@ -1019,6 +1121,30 @@ /************************* * class neobot_soco_lite_led *************************/ + neobot_soco_lite_led_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_lite_led_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_lite_led_title', + }, + class: 'neobot_soco_lite_led', + isNotFor: ['NeobotSocoLite'], + events: {}, + }, neobot_soco_lite_led_on: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1543,6 +1669,30 @@ /************************* * class neobot_soco_lite_output *************************/ + neobot_soco_lite_output_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_lite_output_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_lite_output_title', + }, + class: 'neobot_soco_lite_output', + isNotFor: ['NeobotSocoLite'], + events: {}, + }, neobot_soco_lite_set_output: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1620,6 +1770,30 @@ /************************* * class neobot_soco_lite_motor *************************/ + neobot_soco_lite_motor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_lite_motor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_lite_motor_title', + }, + class: 'neobot_soco_lite_motor', + isNotFor: ['NeobotSocoLite'], + events: {}, + }, neobot_soco_lite_robot: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1946,6 +2120,30 @@ /************************* * class neobot_soco_lite_melody *************************/ + neobot_soco_lite_buzzer_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_lite_buzzer_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_lite_buzzer_title', + }, + class: 'neobot_soco_lite_melody', + isNotFor: ['NeobotSocoLite'], + events: {}, + }, neobot_soco_lite_play_note_for: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2160,6 +2358,30 @@ /************************* * class neobot_soco_lite_servo *************************/ + neobot_soco_lite_servo_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_soco_lite_servo_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_soco_lite_servo_title', + }, + class: 'neobot_soco_lite_servo', + isNotFor: ['NeobotSocoLite'], + events: {}, + }, neobot_soco_lite_servo_init: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, diff --git a/src/playground/blocks/hardwareLite/block_neobot_thinkcar_lite.js b/src/playground/blocks/hardwareLite/block_neobot_thinkcar_lite.js index 978b395351..aba040d809 100644 --- a/src/playground/blocks/hardwareLite/block_neobot_thinkcar_lite.js +++ b/src/playground/blocks/hardwareLite/block_neobot_thinkcar_lite.js @@ -1,5 +1,7 @@ 'use strict'; (function() { + const HEADER = [0xab, 0xcd]; + Entry.NeobotThinkCarLite = new (class NeobotThinkCarLite { constructor() { this.id = '5.7'; @@ -27,8 +29,8 @@ OUT1: 0, OUT2: 0, OUT3: 0, - DCR: 0, DCL: 0, + DCR: 0, SND: 0, FND: 0, OPT: 0, @@ -37,6 +39,7 @@ this.blockMenuBlocks = [ // think car + 'neobot_think_car_lite_auto_driving_title', 'neobot_think_car_lite_line_tracer_start', // 'neobot_think_car_lite_line_tracer_change_speed', 'neobot_think_car_lite_reverse_parking_start', @@ -44,41 +47,43 @@ 'neobot_think_car_lite_driving_stop', // sensor + 'neobot_think_car_lite_sensor_title', 'neobot_think_car_lite_sensor_value', 'neobot_think_car_lite_sensor_convert_scale', - - // decision 'neobot_think_car_lite_decision_sensor_is_over', 'neobot_think_car_lite_decision_equal_with_sensor', 'neobot_think_car_lite_decision_sensor_angle', - - // remote 'neobot_think_car_lite_remote_button', // led + 'neobot_think_car_lite_led_title', 'neobot_think_car_lite_led_on', 'neobot_think_car_lite_led_brightness_with_sensor', 'neobot_think_car_lite_color_led_on', 'neobot_think_car_lite_output_led_off', // output + 'neobot_think_car_lite_output_title', 'neobot_think_car_lite_set_output', // motor + 'neobot_think_car_lite_motor_title', 'neobot_think_car_lite_robot', 'neobot_think_car_lite_motor_start', 'neobot_think_car_lite_motor_stop', - // melody - 'neobot_think_car_lite_play_note_for', - 'neobot_think_car_lite_melody_play_with_sensor', - 'neobot_think_car_lite_melody_stop', - // servo + 'neobot_think_car_lite_servo_title', 'neobot_think_car_lite_servo_init', 'neobot_think_car_lite_servo_rotate', 'neobot_think_car_lite_servo_stop', 'neobot_think_car_lite_servo_change_degree', + + // melody + 'neobot_think_car_lite_buzzer_title', + 'neobot_think_car_lite_play_note_for', + 'neobot_think_car_lite_melody_play_with_sensor', + 'neobot_think_car_lite_melody_stop', ]; this.setZero(); @@ -86,7 +91,7 @@ get monitorTemplate() { return { - imgPath: 'hw_lite/neobot_thinkcar_lite.png', + imgPath: 'hw/neobot_thinkcar.png', width: 700, height: 700, listPorts: { @@ -118,8 +123,8 @@ OUT1: 0, OUT2: 0, OUT3: 0, - DCR: 0, DCL: 0, + DCR: 0, SND: 0, FND: 0, OPT: 0, @@ -130,17 +135,95 @@ } handleLocalData(data) { - for (let i = 0; i < data.length - 1; i++) { - if (data[i] === 171 && data[i + 1] === 205) { - const dataSet = data.slice(i + 2, i + 7); - dataSet.forEach((value, idx) => { - this.localBuffer[this.LOCAL_MAP[idx]] = value; - }); + let validPdu = this.getValidPdu(data); + while (validPdu) { + this.onReceivePdu(validPdu); + if (!this.remainingPdu || this.remainingPdu.length <= 0) { break; } + validPdu = this.getValidPdu([]); + } + } + + onReceivePdu(pdu) { + if (pdu[0] === HEADER[0] && pdu[1] === HEADER[1]) { + this.localBuffer['IN1'] = pdu[2]; + this.localBuffer['IN2'] = pdu[3]; + this.localBuffer['IN3'] = pdu[4]; + this.localBuffer['IR'] = pdu[5]; + this.localBuffer['BAT'] = pdu[6]; } } + getValidPdu(pdu) { + const mergedPdu = []; + if (this.remainingPdu) { + mergedPdu.push(...this.remainingPdu); + this.remainingPdu = null; + } + mergedPdu.push(...pdu); + if (mergedPdu.length < 2) { + this.remainingPdu = [...mergedPdu]; + return null; + } + + // 헤더 불일치는 버림 + if (!this.checkHeader(mergedPdu)) { + return null; + } + + // 유효 데이터 길이는 header 2 + body 5 + checksum 1 = 8 + const validDataLength = 8; + /* + 전체 길이가 유효 데이터 길이보다 작을 경우 + 아직 도착하지 않은 부분이 있으므로 병합을 위해 remainingPdu 에 저장 + */ + if (mergedPdu.length < validDataLength) { + this.remainingPdu = [...mergedPdu]; + return null; + } + + /* + 전체 길이가 유효 데이터 길이보다 클 경우 + 유효한 부분만 잘라내고 나머지는 remainingPdu 에 저장 + */ + if (mergedPdu.length > validDataLength) { + this.remainingPdu = mergedPdu.slice(validDataLength, mergedPdu.length); + } + + const validPdu = mergedPdu.slice(0, validDataLength); + + /* + 유효 Pdu 의 checksum 확인 + */ + const dataLength = 5; + let checkSum = 0; + for (let i = 0; i < dataLength; i++) { + checkSum += validPdu[i + 2]; + } + checkSum = checkSum & 255; + const pduCheckSum = validPdu[7]; + if (pduCheckSum !== checkSum) { + return null; + } + + return validPdu; + } + + checkHeader(pdu) { + if (pdu.length < HEADER.length) { + return false; + } + + for (let i = 0; i < HEADER.length; i++) { + if (HEADER[i] !== pdu[i]) { + return false; + } + } + + return true; + } + requestLocalData() { const requestData = []; @@ -172,6 +255,7 @@ ko: { template: { // think car + neobot_think_car_lite_auto_driving_title: '자율주행', neobot_think_car_lite_line_tracer_start: '차로를 유지하며 속도 %1 으로 자율주행 %2', // neobot_think_car_lite_line_tracer_change_speed: '자율주행 속도 변경 %1 %2', @@ -181,19 +265,17 @@ neobot_think_car_lite_driving_stop: '자율주행 중지 %1', // sensor + neobot_think_car_lite_sensor_title: '센서', neobot_think_car_lite_sensor_value: '%1', neobot_think_car_lite_sensor_convert_scale: '%1 %2 ~ %3 를 %4 ~ %5 으로 변환', - - // decision neobot_think_car_lite_decision_sensor_is_over: '%1 %2 %3', neobot_think_car_lite_decision_equal_with_sensor: '%1 컬러가 %2', neobot_think_car_lite_decision_sensor_angle: '%1 각도 %2 %3', - - // remote neobot_think_car_lite_remote_button: '리모컨 버튼 %1 을 누름', // LED + neobot_think_car_lite_led_title: 'LED', neobot_think_car_lite_arg_led_duration: '%1', neobot_think_car_lite_led_on: 'LED 켜기 %1 %2 %3 %4', neobot_think_car_lite_output_led_off: '%1 LED 끄기 %2', @@ -201,9 +283,11 @@ neobot_think_car_lite_color_led_on: '%1 컬러LED 켜기 R %2 G %3 B %4 %5', // output + neobot_think_car_lite_output_title: '출력', neobot_think_car_lite_set_output: '%1 에 %2 값 출력하기 %3', // motor + neobot_think_car_lite_motor_title: '회전모터', neobot_think_car_lite_robot: '로봇 %1 %2', neobot_think_car_lite_motor_start: '모터 회전하기 %1 %2 %3 %4 %5', neobot_think_car_lite_motor_stop: '%1 모터 멈추기 %2', @@ -211,12 +295,14 @@ neobot_think_car_lite_arg_motor_duration: '%1', // melody + neobot_think_car_lite_buzzer_title: '버저', neobot_think_car_lite_play_note_for: '버저 울리기 옥타브: %2 음: %1 길이: %3 %4', neobot_think_car_lite_melody_play_with_sensor: '%1 센서로 버저 울리기 %2', neobot_think_car_lite_melody_stop: '버저 멈추기 %1', // servo + neobot_think_car_lite_servo_title: '서보모터', get_servo_degree: '%1', neobot_think_car_lite_servo_init: '%1 서보모터 리셋 %2', neobot_think_car_lite_servo_rotate: '서보모터 회전하기 %1 %2 %3 %4', @@ -362,6 +448,7 @@ // en.js에 작성하던 내용 template: { // think car + neobot_think_car_lite_auto_driving_title: 'Self-driving', neobot_think_car_lite_line_tracer_start: 'Start self-driving at %1 speed while keeping lanes %2', // neobot_think_car_lite_line_tracer_change_speed: 'Change the speed of self-driving %1 %2', @@ -372,20 +459,18 @@ neobot_think_car_lite_driving_stop: 'Stop self-driving %1', // sensor + neobot_think_car_lite_sensor_title: 'Sensor', neobot_think_car_lite_sensor_value: '%1', neobot_think_car_lite_sensor_convert_scale: "%1 's changed value range: %2 ~ %3 conversion: %4 ~ %5", - - // decision neobot_think_car_lite_decision_sensor_is_over: '%1 %2 %3', neobot_think_car_lite_decision_equal_with_sensor: "%1 's color is %2", neobot_think_car_lite_decision_sensor_angle: '%1 angle %2 %3', - - // remote neobot_think_car_lite_remote_button: 'pressing button %1 of remote controller', // LED + neobot_think_car_lite_led_title: 'LED', neobot_think_car_lite_arg_led_duration: '%1', neobot_think_car_lite_led_on: 'Turn on the LED %1 %2 %3 %4', neobot_think_car_lite_output_led_off: 'Turn off the %1 LED %2', @@ -395,16 +480,19 @@ 'Turn on the %1 color LED R %2 G %3 B %4 %5', // output + neobot_think_car_lite_output_title: 'Set output', neobot_think_car_lite_set_output: 'Output %2 value to %1 port %3', // motor + neobot_think_car_lite_motor_title: 'Motor', neobot_think_car_lite_robot: 'Robot %1 %2', neobot_think_car_lite_motor_start: 'Motor operation %1 %2 %3 %4 %5', neobot_think_car_lite_motor_stop: 'Stop the %1 motor(s) %2', neobot_think_car_lite_arg_motor_speed: '%1', neobot_think_car_lite_arg_motor_duration: '%1', - // melody + // buzzer + neobot_think_car_lite_buzzer_title: 'Buzzer', neobot_think_car_lite_play_note_for: 'Buzzer octave: %1 scale: %2 note: %3 %4', neobot_think_car_lite_melody_play_with_sensor: @@ -412,6 +500,7 @@ neobot_think_car_lite_melody_stop: 'Stop the buzzer %1', // servo + neobot_think_car_lite_servo_title: 'Servo motor', get_servo_degree: '%1', neobot_think_car_lite_servo_init: 'Reset the %1 servo motor %2', neobot_think_car_lite_servo_rotate: 'Rotate the servo motor %1 %2 %3 %4', @@ -558,6 +647,30 @@ getBlocks = function() { return { + neobot_think_car_lite_auto_driving_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_lite_auto_driving_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_lite_auto_driving_title', + }, + class: 'neobot_think_car_lite_operation', + isNotFor: ['NeobotThinkCarLite'], + events: {}, + }, neobot_think_car_lite_line_tracer_start: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -937,6 +1050,30 @@ /************************* * class neobot_think_car_lite_sensor *************************/ + neobot_think_car_lite_sensor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_lite_sensor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_lite_sensor_title', + }, + class: 'neobot_think_car_lite_sensor', + isNotFor: ['NeobotThinkCarLite'], + events: {}, + }, neobot_think_car_lite_sensor_value: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -974,7 +1111,6 @@ return Entry.NeobotThinkCarLite.localBuffer[port]; }, }, - neobot_think_car_lite_sensor_convert_scale: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1072,10 +1208,6 @@ return Math.round(value); }, }, - - /************************* - * class neobot_think_car_lite_decision - *************************/ neobot_think_car_lite_decision_sensor_is_over: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1125,7 +1257,7 @@ SYMBOL: 1, VALUE: 2, }, - class: 'neobot_think_car_lite_decision', + class: 'neobot_think_car_lite_sensor', isNotFor: ['NeobotThinkCarLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -1183,7 +1315,6 @@ return false; }, }, - neobot_think_car_lite_decision_equal_with_sensor: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1227,7 +1358,7 @@ SENSOR: 0, COLOR: 1, }, - class: 'neobot_think_car_lite_decision', + class: 'neobot_think_car_lite_sensor', isNotFor: ['NeobotThinkCarLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -1268,7 +1399,6 @@ return false; }, }, - neobot_think_car_lite_decision_sensor_angle: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1341,7 +1471,7 @@ SYMBOL: 1, VALUE: 2, }, - class: 'neobot_think_car_lite_decision', + class: 'neobot_think_car_lite_sensor', isNotFor: ['NeobotThinkCarLite'], func(sprite, script) { const sensorTemp = script.getStringField('SENSOR'); @@ -1383,10 +1513,6 @@ return false; }, }, - - /************************* - * class neobot_think_car_lite_remote - *************************/ neobot_think_car_lite_remote_button: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1420,7 +1546,7 @@ paramsKeyMap: { KEY: 0, }, - class: 'neobot_think_car_lite_remote', + class: 'neobot_think_car_lite_sensor', isNotFor: ['NeobotThinkCarLite'], func(sprite, script) { const key = script.getNumberField('KEY'); @@ -1436,6 +1562,30 @@ /************************* * class neobot_think_car_lite_led *************************/ + neobot_think_car_lite_led_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_lite_led_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_lite_led_title', + }, + class: 'neobot_think_car_lite_led', + isNotFor: ['NeobotThinkCarLite'], + events: {}, + }, neobot_think_car_lite_led_on: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1572,7 +1722,6 @@ } }, }, - neobot_think_car_lite_output_led_off: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1630,7 +1779,6 @@ return script.callReturn(); }, }, - neobot_think_car_lite_led_brightness_with_sensor: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1714,7 +1862,6 @@ return script.callReturn(); }, }, - neobot_think_car_lite_color_led_on: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -1969,6 +2116,30 @@ /************************* * class neobot_think_car_lite_output *************************/ + neobot_think_car_lite_output_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_lite_output_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_lite_output_title', + }, + class: 'neobot_think_car_lite_output', + isNotFor: ['NeobotThinkCarLite'], + events: {}, + }, neobot_think_car_lite_set_output: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2049,6 +2220,30 @@ /************************* * class neobot_think_car_lite_motor *************************/ + neobot_think_car_lite_motor_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_lite_motor_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_lite_motor_title', + }, + class: 'neobot_think_car_lite_motor', + isNotFor: ['NeobotThinkCarLite'], + events: {}, + }, neobot_think_car_lite_robot: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2125,7 +2320,6 @@ return script.callReturn(); }, }, - neobot_think_car_lite_motor_start: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2316,7 +2510,6 @@ } }, }, - neobot_think_car_lite_motor_stop: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2378,6 +2571,30 @@ /************************* * class neobot_think_car_lite_melody *************************/ + neobot_think_car_lite_buzzer_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_lite_buzzer_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_lite_buzzer_title', + }, + class: 'neobot_think_car_lite_melody', + isNotFor: ['NeobotThinkCarLite'], + events: {}, + }, neobot_think_car_lite_play_note_for: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2498,7 +2715,6 @@ } }, }, - neobot_think_car_lite_melody_play_with_sensor: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2556,7 +2772,6 @@ return script.callReturn(); }, }, - neobot_think_car_lite_melody_stop: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2595,6 +2810,30 @@ /************************* * class neobot_think_car_lite_servo *************************/ + neobot_think_car_lite_servo_title: { + color: EntryStatic.colorSet.common.TRANSPARENT, + fontColor: '#191970', + skeleton: 'basic_text', + skeletonOptions: { + contentPos: { + x: 5, + }, + }, + params: [ + { + type: 'Text', + text: Lang.template.neobot_think_car_lite_servo_title, + color: '#191970', + align: 'left', + }, + ], + def: { + type: 'neobot_think_car_lite_servo_title', + }, + class: 'neobot_think_car_lite_servo', + isNotFor: ['NeobotThinkCarLite'], + events: {}, + }, neobot_think_car_lite_servo_init: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2704,7 +2943,6 @@ } }, }, - neobot_think_car_lite_servo_rotate: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE, @@ -2884,7 +3122,6 @@ return script.callReturn(); }, }, - neobot_think_car_lite_servo_change_degree: { color: EntryStatic.colorSet.block.default.HARDWARE, outerLine: EntryStatic.colorSet.block.darken.HARDWARE,