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