Skip to content

Commit a6b695a

Browse files
authored
Merge pull request #7 from lizlooney/pr_multiple_ports
Fix mrc_port python generator
2 parents cd01138 + c3e2d21 commit a6b695a

File tree

3 files changed

+147
-16
lines changed

3 files changed

+147
-16
lines changed

python_tools/generate_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import component
6262
import expansion_hub_motor
6363
import expansion_hub_servo
64+
import port
6465
import rev_touch_sensor
6566
import servo
6667
import smart_motor
@@ -123,6 +124,7 @@ def main(argv):
123124
component,
124125
expansion_hub_motor,
125126
expansion_hub_servo,
127+
port,
126128
rev_touch_sensor,
127129
servo,
128130
smart_motor,

src/blocks/mrc_port.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ export const pythonFromBlock = function (
149149
break;
150150
}
151151
code += `CompoundPort(port_type = port.PortType.${block.portType_},`;
152-
code += `\\ \n${generator.INDENT}port1 = port.Port(port_type = port.PortType.${port1Type}, location = ${ports[0]}), `;
153-
code += `\\ \n${generator.INDENT}port2 = port.Port(port_type = port.PortType.${port2Type}, location = ${ports[1]}))`;
152+
code += `\\ \n${generator.INDENT}port1 = port.SimplePort(port_type = port.PortType.${port1Type}, location = ${ports[0]}), `;
153+
code += `\\ \n${generator.INDENT}port2 = port.SimplePort(port_type = port.PortType.${port2Type}, location = ${ports[1]}))`;
154154
}
155155

156156
return [code, Order.ATOMIC];
157157
}
158158

159159
export function createPort(portType : string) {
160-
//TODO: Based off of the port type, create the right number and type of ports
160+
// Based off of the port type, create the right number and type of ports
161161
const ports : MrcPortType[] = [];
162162
switch(portType){
163163
case 'CAN_PORT':
@@ -184,9 +184,6 @@ export function createPort(portType : string) {
184184
case 'EXPANSION_HUB_SERVO_PORT':
185185
ports.push({ portType: 'servo', portNumber: 1 });
186186
break;
187-
case 'SMART_MOTOR_PORT':
188-
ports.push({ portType: 'MotionCore port', portNumber: 1 });
189-
break;
190187
case 'USB_HUB':
191188
ports.push({ portType: 'usb in', portNumber: 1 });
192189
ports.push({ portType: 'usb out', portNumber: 1 });
@@ -200,7 +197,7 @@ export function createPort(portType : string) {
200197
ports.push({ portType: 'servo', portNumber: 1 });
201198
break;
202199
default:
203-
ports.push({ portType: 'unknown:' + portType, portNumber: 1 });
200+
ports.push({ portType: 'unknown' + portType, portNumber: 1 });
204201
break;
205202
}
206203
return {

src/blocks/utils/generated/external_samples_data.json

Lines changed: 141 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@
11971197
"staticMethods": []
11981198
},
11991199
{
1200-
"className": "port.Port",
1200+
"className": "port.CompoundPort",
12011201
"classVariables": [],
12021202
"constructors": [
12031203
{
@@ -1207,26 +1207,72 @@
12071207
"name": "port_type",
12081208
"type": "port.PortType"
12091209
},
1210-
{
1211-
"defaultValue": "",
1212-
"name": "location",
1213-
"type": "int"
1214-
},
12151210
{
12161211
"defaultValue": "",
12171212
"name": "port1",
1218-
"type": "type[typing.Self]"
1213+
"type": "port.Port"
12191214
},
12201215
{
12211216
"defaultValue": "",
12221217
"name": "port2",
1223-
"type": "type[typing.Self]"
1218+
"type": "port.Port"
1219+
}
1220+
],
1221+
"declaringClassName": "port.CompoundPort",
1222+
"functionName": "__init__",
1223+
"returnType": "port.CompoundPort",
1224+
"tooltip": "\n Create a compound port from two other ports.\n\n Args:\n port_type: PortType for this port (must be a compound type)\n port1: First Port for compound ports\n port2: Second Port for compound ports\n "
1225+
}
1226+
],
1227+
"enums": [],
1228+
"instanceMethods": [
1229+
{
1230+
"args": [
1231+
{
1232+
"defaultValue": "",
1233+
"name": "self",
1234+
"type": "port.CompoundPort"
1235+
}
1236+
],
1237+
"declaringClassName": "port.CompoundPort",
1238+
"functionName": "get_all_ports",
1239+
"returnType": "list[tuple[port.PortType, int]]",
1240+
"tooltip": "Return a list of all simple ports contained in this compound port."
1241+
},
1242+
{
1243+
"args": [
1244+
{
1245+
"defaultValue": "",
1246+
"name": "self",
1247+
"type": "port.CompoundPort"
1248+
}
1249+
],
1250+
"declaringClassName": "port.CompoundPort",
1251+
"functionName": "get_type",
1252+
"returnType": "port.PortType",
1253+
"tooltip": "Returns the port type"
1254+
}
1255+
],
1256+
"instanceVariables": [],
1257+
"moduleName": "port",
1258+
"staticMethods": []
1259+
},
1260+
{
1261+
"className": "port.Port",
1262+
"classVariables": [],
1263+
"constructors": [
1264+
{
1265+
"args": [
1266+
{
1267+
"defaultValue": "",
1268+
"name": "port_type",
1269+
"type": "port.PortType"
12241270
}
12251271
],
12261272
"declaringClassName": "port.Port",
12271273
"functionName": "__init__",
12281274
"returnType": "port.Port",
1229-
"tooltip": "\n Create a port that can be either simple (type + location) or compound (two other ports).\n\n Args:\n port_type: PortType or CompoundPortType for this port\n location: int location for simple ports\n port1: First Port for compound ports\n port2: Second Port for compound ports\n "
1275+
"tooltip": ""
12301276
}
12311277
],
12321278
"enums": [],
@@ -1262,6 +1308,62 @@
12621308
"moduleName": "port",
12631309
"staticMethods": []
12641310
},
1311+
{
1312+
"className": "port.SimplePort",
1313+
"classVariables": [],
1314+
"constructors": [
1315+
{
1316+
"args": [
1317+
{
1318+
"defaultValue": "",
1319+
"name": "port_type",
1320+
"type": "port.PortType"
1321+
},
1322+
{
1323+
"defaultValue": "",
1324+
"name": "location",
1325+
"type": "int"
1326+
}
1327+
],
1328+
"declaringClassName": "port.SimplePort",
1329+
"functionName": "__init__",
1330+
"returnType": "port.SimplePort",
1331+
"tooltip": "\n Create a simple port with a type and location.\n\n Args:\n port_type: PortType for this port (must be a simple type)\n location: int location for this port\n "
1332+
}
1333+
],
1334+
"enums": [],
1335+
"instanceMethods": [
1336+
{
1337+
"args": [
1338+
{
1339+
"defaultValue": "",
1340+
"name": "self",
1341+
"type": "port.SimplePort"
1342+
}
1343+
],
1344+
"declaringClassName": "port.SimplePort",
1345+
"functionName": "get_all_ports",
1346+
"returnType": "list[tuple[port.PortType, int]]",
1347+
"tooltip": "Return a list containing this simple port."
1348+
},
1349+
{
1350+
"args": [
1351+
{
1352+
"defaultValue": "",
1353+
"name": "self",
1354+
"type": "port.SimplePort"
1355+
}
1356+
],
1357+
"declaringClassName": "port.SimplePort",
1358+
"functionName": "get_type",
1359+
"returnType": "port.PortType",
1360+
"tooltip": "Returns the port type"
1361+
}
1362+
],
1363+
"instanceVariables": [],
1364+
"moduleName": "port",
1365+
"staticMethods": []
1366+
},
12651367
{
12661368
"className": "rev_touch_sensor.RevTouchSensor",
12671369
"classVariables": [],
@@ -2668,6 +2770,32 @@
26682770
"moduleName": "expansion_hub_servo",
26692771
"moduleVariables": []
26702772
},
2773+
{
2774+
"enums": [
2775+
{
2776+
"enumClassName": "port.PortType",
2777+
"enumValues": [
2778+
"BASE_COMPOUND",
2779+
"CAN_PORT",
2780+
"EXPANSION_HUB_MOTOR",
2781+
"EXPANSION_HUB_MOTOR_PORT",
2782+
"EXPANSION_HUB_SERVO",
2783+
"EXPANSION_HUB_SERVO_PORT",
2784+
"I2C_PORT",
2785+
"SERVO_PORT",
2786+
"SMART_IO_PORT",
2787+
"SMART_MOTOR_PORT",
2788+
"USB_HUB",
2789+
"USB_PORT"
2790+
],
2791+
"moduleName": "port",
2792+
"tooltip": ""
2793+
}
2794+
],
2795+
"functions": [],
2796+
"moduleName": "port",
2797+
"moduleVariables": []
2798+
},
26712799
{
26722800
"enums": [],
26732801
"functions": [],
@@ -2709,6 +2837,10 @@
27092837
"smart_motor.SmartMotor",
27102838
"spark_mini.SparkMini",
27112839
"sparkfun_led_stick.SparkFunLEDStick"
2840+
],
2841+
"port.Port": [
2842+
"port.CompoundPort",
2843+
"port.SimplePort"
27122844
]
27132845
}
27142846
}

0 commit comments

Comments
 (0)