mpy 外接传感增加旋转解码器

This commit is contained in:
Irene-Maxine
2025-09-17 21:45:18 +08:00
parent bdad0d0321
commit f9b7f4a13e
9 changed files with 236 additions and 0 deletions

View File

@@ -2415,4 +2415,41 @@ export const get_keboards_value = {
this.setOutput(true);
this.setInputsInline(true);
}
}
export const init_init_rotary_encoder = {
init:function(){
this.setColour(SENSOR_EXTERN_HUE);
this.appendValueInput('SUB')
.appendField(Blockly.Msg.MIXLY_SETUP)
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_AS + Blockly.Msg.MIXLY_ROTARY_ENCODER)
this.appendValueInput('PIN1')
.appendField('PINA#')
this.appendValueInput('PIN2')
.appendField('PINB#')
this.appendValueInput('KEY')
.appendField('KEY#')
this.appendValueInput('METHOD')
.appendField(Blockly.Msg.MIXLY_DO)
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
}
}
export const rotary_key = {
init:function(){
this.setColour(SENSOR_EXTERN_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ROTARY_ENCODER)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.CLOCKWISE + Blockly.Msg.MIXLY_REVOLVE,"ROT_CW"],
[Blockly.Msg.ANTI_CLOCKWISE + Blockly.Msg.MIXLY_REVOLVE,"ROT_CCW"],
[Blockly.Msg.MIXLY_BUTTON2 + Blockly.Msg.MIXLY_BUTTON_PRESSED, "SW_PRESS"],
[Blockly.Msg.MIXLY_BUTTON2 + Blockly.Msg.MIXLY_BUTTON_RELEASED,"SW_RELEASE"]
]),"key")
this.setOutput(true);
this.setInputsInline(true);
}
}

View File

@@ -1168,4 +1168,22 @@ export const get_keboards_value = function (_, generator) {
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
var code = varName + '.read_keypad()'
return [code, generator.ORDER_ATOMIC];
}
export const init_init_rotary_encoder = function (_, generator) {
generator.definitions_['import_rotary'] = 'import rotary';
var v = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
var p1 = generator.valueToCode(this, 'PIN1', generator.ORDER_ATOMIC);
var p2 = generator.valueToCode(this, 'PIN2', generator.ORDER_ATOMIC);
var key = generator.valueToCode(this, 'KEY', generator.ORDER_ATOMIC);
var m = generator.valueToCode(this, 'METHOD', generator.ORDER_ATOMIC);
var code = v + " = rotary.Encoder("+ p1 +","+ p2 +","+ key +","+ m +")\n";
return code;
}
export const rotary_key = function (_, generator) {
generator.definitions_['import_rotary'] = 'import rotary';
var key = this.getFieldValue("key");
var code = 'rotary.'+ key ;
return [code,generator.ORDER_ATOMIC];
}

View File

@@ -4349,6 +4349,41 @@
</shadow>
</value>
</block>
<block type="init_init_rotary_encoder">
<value name="SUB">
<shadow type="variables_get">
<field name="VAR">var_re</field>
</shadow>
</value>
<value name="PIN1">
<shadow type="pins_digital_pin">3
</shadow>
</value>
<value name="PIN2">
<shadow type="pins_digital_pin">4
</shadow>
</value>
<value name="KEY">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<value name="METHOD">
<shadow type="factory_block_return">
<field name="VALUE">rotary_cb</field>
</shadow>
</value>
</block>
<block type="rotary_key"></block>
<block type="procedures_defnoreturn">
<mutation>
<arg name="value"></arg>
</mutation>
<field name="NAME">rotary_cb</field>
<statement name="STACK">
<block type="controls_pass"></block>
</statement>
</block>
</category>
<category id="catExternActuator" colour='#74A55B' m-hide="micropython:esp32:rm_e1">

View File

@@ -4260,6 +4260,41 @@
</shadow>
</value>
</block>
<block type="init_init_rotary_encoder">
<value name="SUB">
<shadow type="variables_get">
<field name="VAR">var_re</field>
</shadow>
</value>
<value name="PIN1">
<shadow type="pins_digital_pin">3
</shadow>
</value>
<value name="PIN2">
<shadow type="pins_digital_pin">4
</shadow>
</value>
<value name="KEY">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<value name="METHOD">
<shadow type="factory_block_return">
<field name="VALUE">rotary_cb</field>
</shadow>
</value>
</block>
<block type="rotary_key"></block>
<block type="procedures_defnoreturn">
<mutation>
<arg name="value"></arg>
</mutation>
<field name="NAME">rotary_cb</field>
<statement name="STACK">
<block type="controls_pass"></block>
</statement>
</block>
</category>
<category id="catExternActuator" colour='#74A55B'>
<block type="servo_move" m-show='micropython:esp32c3:mixgocar_c3'>

View File

@@ -4144,6 +4144,76 @@
</shadow>
</value>
</block>
<block type="init_init_rotary_encoder">
<value name="SUB">
<shadow type="variables_get">
<field name="VAR">var_re</field>
</shadow>
</value>
<value name="PIN1">
<shadow type="pins_digital_pin">3
</shadow>
</value>
<value name="PIN2">
<shadow type="pins_digital_pin">4
</shadow>
</value>
<value name="KEY">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<value name="METHOD">
<shadow type="factory_block_return">
<field name="VALUE">rotary_cb</field>
</shadow>
</value>
</block>
<block type="rotary_key"></block>
<block type="procedures_defnoreturn">
<mutation>
<arg name="value"></arg>
</mutation>
<field name="NAME">rotary_cb</field>
<statement name="STACK">
<block type="controls_pass"></block>
</statement>
</block>
<block type="init_init_rotary_encoder">
<value name="SUB">
<shadow type="variables_get">
<field name="VAR">var_re</field>
</shadow>
</value>
<value name="PIN1">
<shadow type="pins_digital_pin">3
</shadow>
</value>
<value name="PIN2">
<shadow type="pins_digital_pin">4
</shadow>
</value>
<value name="KEY">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<value name="METHOD">
<shadow type="factory_block_return">
<field name="VALUE">rotary_cb</field>
</shadow>
</value>
</block>
<block type="rotary_key"></block>
<block type="procedures_defnoreturn">
<mutation>
<arg name="value"></arg>
</mutation>
<field name="NAME">rotary_cb</field>
<statement name="STACK">
<block type="controls_pass"></block>
</statement>
</block>
</category>
<category id="catExternActuator" colour='#74A55B'>
<block type="servo_move" m-show='micropython:esp32c3:mixgocar_c3'>

View File

@@ -4610,6 +4610,41 @@
<block type="get_keboards_value">
<field name ="VAR">KEYPAD_4_4</field>
</block>
<block type="init_init_rotary_encoder">
<value name="SUB">
<shadow type="variables_get">
<field name="VAR">var_re</field>
</shadow>
</value>
<value name="PIN1">
<shadow type="pins_digital_pin">3
</shadow>
</value>
<value name="PIN2">
<shadow type="pins_digital_pin">4
</shadow>
</value>
<value name="KEY">
<shadow type="math_number">
<field name="NUM">5</field>
</shadow>
</value>
<value name="METHOD">
<shadow type="factory_block_return">
<field name="VALUE">rotary_cb</field>
</shadow>
</value>
</block>
<block type="rotary_key"></block>
<block type="procedures_defnoreturn">
<mutation>
<arg name="value"></arg>
</mutation>
<field name="NAME">rotary_cb</field>
<statement name="STACK">
<block type="controls_pass"></block>
</statement>
</block>
</category>
<category id="catExternActuator" colour='#74A55B'>