|
@@ -505,10 +505,10 @@ Blockly.Blocks['extension_servo_write_on_ai'] = {
|
|
.appendField(new Blockly.FieldDropdown([
|
|
.appendField(new Blockly.FieldDropdown([
|
|
["S1", "S1"],
|
|
["S1", "S1"],
|
|
["S2", "S2"],
|
|
["S2", "S2"],
|
|
- ["P0", "0"],
|
|
|
|
- ["P1", "1"],
|
|
|
|
- ["P2", "2"],
|
|
|
|
- ["P3", "3"]
|
|
|
|
|
|
+ ["P0", "P0"],
|
|
|
|
+ ["P1", "P1"],
|
|
|
|
+ ["P2", "P2"],
|
|
|
|
+ ["P3", "P3"]
|
|
]), "gpio");
|
|
]), "gpio");
|
|
this.appendValueInput("degree")
|
|
this.appendValueInput("degree")
|
|
.setCheck(null)
|
|
.setCheck(null)
|
|
@@ -524,26 +524,38 @@ Blockly.Blocks['extension_servo_write_on_ai'] = {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+
|
|
|
|
+let extension_servo_write_on_ai_list = []
|
|
Blockly.Python['extension_servo_write_on_ai'] = function (block) {
|
|
Blockly.Python['extension_servo_write_on_ai'] = function (block) {
|
|
var value_degree = Blockly.Python.valueToCode(block, 'degree', Blockly.Python.ORDER_ATOMIC);
|
|
var value_degree = Blockly.Python.valueToCode(block, 'degree', Blockly.Python.ORDER_ATOMIC);
|
|
var value_gpio = block.getFieldValue('gpio');
|
|
var value_gpio = block.getFieldValue('gpio');
|
|
Blockly.Python.definitions_['v831_import_smbus2'] = `import smbus2`
|
|
Blockly.Python.definitions_['v831_import_smbus2'] = `import smbus2`
|
|
Blockly.Python.definitions_['v831_import_time'] = `import time`
|
|
Blockly.Python.definitions_['v831_import_time'] = `import time`
|
|
- var code = ``
|
|
|
|
- if (value_gpio == "S1" || value_gpio == "S2") {
|
|
|
|
- Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
|
|
+ Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
sys.path.append("/root/")`
|
|
sys.path.append("/root/")`
|
|
|
|
+ let code = ""
|
|
|
|
+ if (value_gpio == "S1" || value_gpio == "S2") {
|
|
Blockly.Python.definitions_['v831_import_CocoPi_multiFuncGpio'] = `from CocoPi import multiFuncGpio`;
|
|
Blockly.Python.definitions_['v831_import_CocoPi_multiFuncGpio'] = `from CocoPi import multiFuncGpio`;
|
|
- Blockly.Python.definitions_["v831_servo_init" + value_gpio] = `${value_gpio}= multiFuncGpio(${value_gpio[1] - 1},1)`
|
|
|
|
- code = `${value_gpio}.servoCtrl(${value_degree})
|
|
|
|
-`
|
|
|
|
|
|
+ const allBlocks = getBlocksByTypeName("extension_servo_write_on_ai")
|
|
|
|
+ let onedegree = allBlocks[0].innerText
|
|
|
|
+ let degree = 0
|
|
|
|
+ let degree1 = 0
|
|
|
|
+ try {
|
|
|
|
+ if (value_gpio == "S1") {
|
|
|
|
+ degree = onedegree.indexOf("S1") == 0 ? allBlocks[0].children[1].innerText : allBlocks[Math.floor((onedegree.indexOf("S1")) / 4)].children[1].innerText
|
|
|
|
+ } else {
|
|
|
|
+ degree1 = onedegree.indexOf("S2") == 0 ? allBlocks[0].children[1].innerText : allBlocks[Math.floor((onedegree.indexOf("S2")) / 4)].children[1].innerText
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.log("error", e)
|
|
|
|
+ }
|
|
|
|
+ Blockly.Python.definitions_["v831_servo_init" + value_gpio] = `${value_gpio}= multiFuncGpio(${value_gpio[1] - 1},1)
|
|
|
|
+${value_gpio}.servoCtrl(${allBlocks.length > 1 ? value_gpio == "S1" ? degree : degree1 : value_degree})`
|
|
|
|
+ code = `${value_gpio}.servoCtrl(${value_degree})\n`
|
|
} else {
|
|
} else {
|
|
- Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
-sys.path.append("/home/drivers/pylib/")`
|
|
|
|
- Blockly.Python.definitions_['v831_import_CocoPi_multiFuncGpio'] = `from power import CocoPiPCA9685`;
|
|
|
|
- Blockly.Python.definitions_['v831_import_CocoPiPCA9685_init'] = `Servo=CocoPiPCA9685()`
|
|
|
|
- code = `Servo.position(${value_gpio},${value_degree})
|
|
|
|
-`
|
|
|
|
|
|
+ Blockly.Python.definitions_['v831_import_CocoPi_extServo'] = `from CocoPi import extServo`;
|
|
|
|
+ Blockly.Python.definitions_["v831_servo_init_" + value_gpio] = `${value_gpio} = extServo(${value_gpio[1]})`
|
|
|
|
+ code = `${value_gpio}.position(${value_degree})\n`
|
|
}
|
|
}
|
|
|
|
|
|
return code;
|
|
return code;
|
|
@@ -791,38 +803,33 @@ Blockly.Python['ai_motor_run'] = function (block) {
|
|
var dropdown_motor_type = block.getFieldValue('motor_type');
|
|
var dropdown_motor_type = block.getFieldValue('motor_type');
|
|
var value_speed = Blockly.Python.valueToCode(block, 'speed', Blockly.Python.ORDER_ATOMIC);
|
|
var value_speed = Blockly.Python.valueToCode(block, 'speed', Blockly.Python.ORDER_ATOMIC);
|
|
var dropdown_direction = block.getFieldValue('direction');
|
|
var dropdown_direction = block.getFieldValue('direction');
|
|
- console.log(dropdown_direction,value_speed)
|
|
|
|
// TODO: Assemble Python into code variable.
|
|
// TODO: Assemble Python into code variable.
|
|
- // Blockly.Python.definitions_['v831_import_smbus2'] = `import smbus2`
|
|
|
|
- // Blockly.Python.definitions_['v831_import_time'] = `import time`
|
|
|
|
- if (dropdown_motor_type == "M1" || dropdown_motor_type == "M2") {
|
|
|
|
- Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
|
|
+ Blockly.Python.definitions_['v831_import_smbus2'] = `import smbus2`
|
|
|
|
+ Blockly.Python.definitions_['v831_import_time'] = `import time`
|
|
|
|
+ Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
sys.path.append("/root/")`
|
|
sys.path.append("/root/")`
|
|
|
|
+ var code = ''
|
|
|
|
+ if (dropdown_motor_type == "M1" || dropdown_motor_type == "M2") {
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s_init'] = `from CocoPi import stm8s
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s_init'] = `from CocoPi import stm8s
|
|
iic_slaver=stm8s()
|
|
iic_slaver=stm8s()
|
|
iic_slaver.clear()
|
|
iic_slaver.clear()
|
|
del iic_slaver`;
|
|
del iic_slaver`;
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s'] = `from CocoPi import dcMotor`;
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s'] = `from CocoPi import dcMotor`;
|
|
Blockly.Python.definitions_["v831dcMotorCtrlFun" + dropdown_motor_type] = `${dropdown_motor_type} = dcMotor(${dropdown_motor_type.slice(1, 2)})`
|
|
Blockly.Python.definitions_["v831dcMotorCtrlFun" + dropdown_motor_type] = `${dropdown_motor_type} = dcMotor(${dropdown_motor_type.slice(1, 2)})`
|
|
- } else {
|
|
|
|
- Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
-sys.path.append("/home/drivers/pylib/")`
|
|
|
|
- Blockly.Python.definitions_['v831_import_CocoPi_multiFuncGpio'] = `from power import CocoPiPCA9685`;
|
|
|
|
- Blockly.Python.definitions_['v831_import_CocoPiPCA9685_motor_init'] = `Motor=CocoPiPCA9685()`
|
|
|
|
- }
|
|
|
|
- var code = ''
|
|
|
|
- if (dropdown_direction == 'pos') {
|
|
|
|
- if (dropdown_motor_type == "M1" || dropdown_motor_type == "M2") {
|
|
|
|
- code = `${dropdown_motor_type}.dcMotorCtrl(1,${value_speed}) \n`
|
|
|
|
- } else {
|
|
|
|
- code = `Motor.speedControl("${dropdown_motor_type}",${value_speed})\n`
|
|
|
|
|
|
+ if (dropdown_direction == 'pos') {
|
|
|
|
+ code = `${dropdown_motor_type}.dcMotorCtrl(1,${value_speed})\n`
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else {
|
|
|
|
- if (dropdown_motor_type == "M1" || dropdown_motor_type == "M2") {
|
|
|
|
|
|
+ else {
|
|
code = `${dropdown_motor_type}.dcMotorCtrl(0,${value_speed})\n`
|
|
code = `${dropdown_motor_type}.dcMotorCtrl(0,${value_speed})\n`
|
|
- } else {
|
|
|
|
- code = `Motor.speedControl("${dropdown_motor_type}",-${value_speed})\n`
|
|
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ Blockly.Python.definitions_['v831_import_CocoPi_extDcMotor'] = `from CocoPi import extDcMotor`;
|
|
|
|
+ Blockly.Python.definitions_["v831dcMotorCtrlFun" + dropdown_motor_type] = `${dropdown_motor_type} = extDcMotor("${dropdown_motor_type}")`
|
|
|
|
+ if (dropdown_direction == 'pos') {
|
|
|
|
+ code = `${dropdown_motor_type}.speedControl(${value_speed})\n`
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ code = `${dropdown_motor_type}.speedControl(-${value_speed})\n`
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return code;
|
|
return code;
|
|
@@ -856,28 +863,23 @@ Blockly.Python['ai_motor_stop'] = function (block) {
|
|
// TODO: Assemble Python into code variable.
|
|
// TODO: Assemble Python into code variable.
|
|
Blockly.Python.definitions_['v831_import_smbus2'] = `import smbus2`
|
|
Blockly.Python.definitions_['v831_import_smbus2'] = `import smbus2`
|
|
Blockly.Python.definitions_['v831_import_time'] = `import time`
|
|
Blockly.Python.definitions_['v831_import_time'] = `import time`
|
|
- if (dropdown_motor_type == "M1" || dropdown_motor_type == "M2") {
|
|
|
|
- Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
|
|
+ Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
sys.path.append("/root/")`
|
|
sys.path.append("/root/")`
|
|
|
|
+ var code = ''
|
|
|
|
+ if (dropdown_motor_type == "M1" || dropdown_motor_type == "M2") {
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s_init'] = `from CocoPi import stm8s
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s_init'] = `from CocoPi import stm8s
|
|
iic_slaver=stm8s()
|
|
iic_slaver=stm8s()
|
|
iic_slaver.clear()
|
|
iic_slaver.clear()
|
|
del iic_slaver`;
|
|
del iic_slaver`;
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s'] = `from CocoPi import dcMotor`;
|
|
Blockly.Python.definitions_['v831_import_CocoPi_stm8s'] = `from CocoPi import dcMotor`;
|
|
Blockly.Python.definitions_["v831dcMotorCtrlFun" + dropdown_motor_type] = `${dropdown_motor_type} = dcMotor(${dropdown_motor_type.slice(1, 2)})`
|
|
Blockly.Python.definitions_["v831dcMotorCtrlFun" + dropdown_motor_type] = `${dropdown_motor_type} = dcMotor(${dropdown_motor_type.slice(1, 2)})`
|
|
|
|
+
|
|
|
|
+ code = `${dropdown_motor_type}.dcMotorCtrl(0,0)\n`
|
|
} else {
|
|
} else {
|
|
- Blockly.Python.definitions_['v831_import_sys'] = `import sys
|
|
|
|
-sys.path.append("/home/drivers/pylib/")`
|
|
|
|
- Blockly.Python.definitions_['v831_import_CocoPi_multiFuncGpio'] = `from power import CocoPiPCA9685`;
|
|
|
|
- Blockly.Python.definitions_['v831_import_CocoPiPCA9685_motor_init'] = `Motor=CocoPiPCA9685()`
|
|
|
|
- }
|
|
|
|
- var code = ''
|
|
|
|
- if (dropdown_motor_type == "M1" || dropdown_motor_type == "M2") {
|
|
|
|
- code = `${dropdown_motor_type}.dcMotorCtrl(1,0)\n`
|
|
|
|
- } else {
|
|
|
|
- code = `Motor.speedControl("${dropdown_motor_type}",0)\n`
|
|
|
|
|
|
+ Blockly.Python.definitions_['v831_import_CocoPi_extDcMotor'] = `from CocoPi import extDcMotor`;
|
|
|
|
+ Blockly.Python.definitions_["v831dcMotorCtrlFun" + dropdown_motor_type] = `${dropdown_motor_type} = extDcMotor("${dropdown_motor_type}")`
|
|
|
|
+ code = `${dropdown_motor_type}.speedControl(0)\n`
|
|
}
|
|
}
|
|
-
|
|
|
|
return code;
|
|
return code;
|
|
};
|
|
};
|
|
/*
|
|
/*
|