@@ -8,6 +8,7 @@ const RotationStyle = [
88] ;
99
1010const Ev3MotorMenu = [ 'A' , 'B' , 'C' , 'D' ] ;
11+ const Ev3SensorMenu = [ '1' , '2' , '3' , '4' ] ;
1112
1213/**
1314 * EV3 converter
@@ -18,6 +19,69 @@ const EV3Converter = {
1819 let block ;
1920 if ( ( this . _isSelf ( receiver ) || receiver === Opal . nil ) && ! rubyBlock ) {
2021 switch ( name ) {
22+ case 'ev3_motor_turn_this_way_for' :
23+ if ( args . length === 2 && this . _isString ( args [ 0 ] ) && this . _isNumberOrBlock ( args [ 1 ] ) ) {
24+ block = this . _createBlock ( 'ev3_motorTurnClockwise' , 'statement' ) ;
25+ const motor = Ev3MotorMenu . indexOf ( args [ 0 ] . _value ) ;
26+ args [ 0 ] . _value = motor + '' ;
27+ this . _addInput ( block ,
28+ 'PORT' ,
29+ this . _createFieldBlock ( 'ev3_menu_motorPorts' , 'motorPorts' , args [ 0 ] ) ) ;
30+ this . _addNumberInput ( block , 'TIME' , 'math_number' , args [ 1 ] , 1 ) ;
31+ }
32+ break ;
33+ case 'ev3_motor_turn_that_way_for' :
34+ if ( args . length === 2 && this . _isString ( args [ 0 ] ) && this . _isNumberOrBlock ( args [ 1 ] ) ) {
35+ block = this . _createBlock ( 'ev3_motorTurnCounterClockwise' , 'statement' ) ;
36+ const motor = Ev3MotorMenu . indexOf ( args [ 0 ] . _value ) ;
37+ args [ 0 ] . _value = motor + '' ;
38+ this . _addInput ( block ,
39+ 'PORT' ,
40+ this . _createFieldBlock ( 'ev3_menu_motorPorts' , 'motorPorts' , args [ 0 ] ) ) ;
41+ this . _addNumberInput ( block , 'TIME' , 'math_number' , args [ 1 ] , 1 ) ;
42+ }
43+ break ;
44+ case 'ev3_motor_set_power' :
45+ if ( args . length === 2 && this . _isString ( args [ 0 ] ) && this . _isNumberOrBlock ( args [ 1 ] ) ) {
46+ block = this . _createBlock ( 'ev3_motorSetPower' , 'statement' ) ;
47+ const motor = Ev3MotorMenu . indexOf ( args [ 0 ] . _value ) ;
48+ args [ 0 ] . _value = motor + '' ;
49+ this . _addInput ( block ,
50+ 'PORT' ,
51+ this . _createFieldBlock ( 'ev3_menu_motorPorts' , 'motorPorts' , args [ 0 ] ) ) ;
52+ this . _addNumberInput ( block , 'POWER' , 'math_number' , args [ 1 ] , 100 ) ;
53+ }
54+ break ;
55+ case 'ev3_motor_position' :
56+ if ( args . length === 1 && this . _isString ( args [ 0 ] ) ) {
57+ block = this . _createBlock ( 'ev3_getMotorPosition' , 'value' ) ;
58+ const motor = Ev3MotorMenu . indexOf ( args [ 0 ] . _value ) ;
59+ args [ 0 ] . _value = motor + '' ;
60+ this . _addInput ( block ,
61+ 'PORT' ,
62+ this . _createFieldBlock ( 'ev3_menu_motorPorts' , 'motorPorts' , args [ 0 ] ) ) ;
63+ }
64+ break ;
65+ case 'ev3_button_pressed?' :
66+ if ( args . length === 1 && this . _isString ( args [ 0 ] ) ) {
67+ block = this . _createBlock ( 'ev3_buttonPressed' , 'value_boolean' ) ;
68+ const sensor = Ev3SensorMenu . indexOf ( args [ 0 ] . _value ) ;
69+ args [ 0 ] . _value = sensor + '' ;
70+ this . _addInput ( block ,
71+ 'PORT' ,
72+ this . _createFieldBlock ( 'ev3_menu_sensorPorts' , 'sensorPorts' , args [ 0 ] ) ) ;
73+ }
74+ break ;
75+ case 'ev3_distance' :
76+ if ( args . length === 0 ) {
77+ block = this . _createBlock ( 'ev3_getDistance' , 'value' ) ;
78+ }
79+ break ;
80+ case 'ev3_brightness' :
81+ if ( args . length === 0 ) {
82+ block = this . _createBlock ( 'ev3_getBrightness' , 'value' ) ;
83+ }
84+ break ;
2185 case 'ev3_beep_note' :
2286 if ( args . length === 2 && this . _isNumberOrBlock ( args [ 0 ] ) && this . _isNumberOrBlock ( args [ 1 ] ) ) {
2387 block = this . _createBlock ( 'ev3_beep' , 'statement' ) ;
0 commit comments