From 135a501e5c3bded83f361c866eaed0e9eb281d49 Mon Sep 17 00:00:00 2001 From: Irene-Maxine <114802521+Irene-Maxine@users.noreply.github.com> Date: Wed, 19 Feb 2025 23:30:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=93=9D=E7=89=99=E9=94=AE=E9=BC=A0=E5=90=88?= =?UTF-8?q?=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micropython/blocks/actuator_onboard.js | 111 ++++++++++ .../generators/actuator_onboard.js | 53 +++++ .../micropython_educore/template.xml | 58 ++++- .../micropython_esp32/template.xml | 198 +++++++++++------- .../micropython_esp32c2/template.xml | 68 +++++- .../micropython_esp32c3/template.xml | 58 ++++- .../micropython_esp32s3/template.xml | 58 ++++- 7 files changed, 524 insertions(+), 80 deletions(-) diff --git a/boards/default_src/micropython/blocks/actuator_onboard.js b/boards/default_src/micropython/blocks/actuator_onboard.js index a6516d00..6b5785fa 100644 --- a/boards/default_src/micropython/blocks/actuator_onboard.js +++ b/boards/default_src/micropython/blocks/actuator_onboard.js @@ -1518,6 +1518,117 @@ export const analog_ble_mouse_send_battery = { } } +export const analog_ble_keyboard_mouse_init = { + init: function () { + this.setColour(ACTUATOR_ONBOARD_HUE); + this.appendDummyInput() + .appendField(Blockly.Msg.LISTS_SET_INDEX_SET + Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD + Blockly.Msg.MIXLY_MOUSE); + this.appendValueInput('kname') + .appendField(Blockly.Msg.MIXLY_MICROBIT_JS_SYSTEM_DEVICE_NAME); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setInputsInline(true); + } +} + +export const ble_keyboard_mouse_get_mac = { + init: function () { + this.setColour(ACTUATOR_ONBOARD_HUE); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_GET + Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD + Blockly.Msg.MIXLY_MOUSE + Blockly.Msg.MIXLY_BELONG + Blockly.Msg.MIXLY_ETHERNET_MAC_ADDRESS); + this.setOutput(true); + this.setInputsInline(true); + } +} + +export const ble_keyboard_mouse_connect = { + init: function () { + this.setColour(ACTUATOR_ONBOARD_HUE); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD + Blockly.Msg.MIXLY_MOUSE + Blockly.Msg.MIXLY_IS_CONNECT); + this.setOutput(true); + this.setInputsInline(true); + } +} + +export const analog_ble_keyboard_mouse_send_battery = { + init: function () { + this.setColour(ACTUATOR_ONBOARD_HUE); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD + Blockly.Msg.MIXLY_MOUSE); + this.appendValueInput('battery') + .appendField(Blockly.Msg.MIXLY_SEND_KEYBOARD + Blockly.Msg.MIXLY_MOUSE + Blockly.Msg.MIXLY_BELONG + Blockly.Msg.MIXLY_BATTERY + Blockly.Msg.LISTS_SET_INDEX_INPUT_TO); + this.appendDummyInput() + .appendField('%'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setInputsInline(true); + } +} + +export const analog_ble_keyboard_mouse_input = { + init: function () { + this.setColour(ACTUATOR_ONBOARD_HUE); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD + Blockly.Msg.MIXLY_MOUSE) + .appendField(Blockly.Msg.MIXLY_SEND_KEYBOARD); + this.appendValueInput('special'); + this.appendValueInput('general'); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_RELEASE) + .appendField(new Blockly.FieldDropdown([ + [Blockly.Msg.MICROPYTHON_DISPLAY_YES, "True"], + [Blockly.Msg.MICROPYTHON_DISPLAY_NO, "False"] + ]), 'release'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setInputsInline(true); + this.setTooltip(Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD_INPUT); + } +}; + +export const analog_ble_keyboard_mouse_str = { + init: function () { + this.setColour(ACTUATOR_ONBOARD_HUE); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD + Blockly.Msg.MIXLY_MOUSE); + this.appendValueInput('str') + .appendField(Blockly.Msg.MIXLY_SEND_KEYBOARD + Blockly.Msg.MIXLY_STR_PRINT); + this.appendValueInput('time') + .appendField(Blockly.Msg.MIXLY_STR_PRINT_TIME_DELAY); + this.appendDummyInput() + .appendField('ms'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setInputsInline(true); + } +} + +export const analog_ble_mouse_keyboard_input = { + init: function () { + this.setColour(ACTUATOR_ONBOARD_HUE); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG+ Blockly.Msg.MIXLY_KEYBOARD + Blockly.Msg.MIXLY_MOUSE) + .appendField(Blockly.Msg.MIXLY_SEND + Blockly.Msg.MIXLY_MOUSE_INPUT); + this.appendValueInput('key'); + this.appendValueInput('x') + .appendField(Blockly.Msg.MIXLY_X_CHANGES); + this.appendValueInput('y') + .appendField(Blockly.Msg.MIXLY_Y_CHANGES); + this.appendValueInput('wheel') + .appendField(Blockly.Msg.MIXLY_WHEEL_CHANGES); + this.appendDummyInput() + .appendField(Blockly.Msg.MIXLY_RELEASE) + .appendField(new Blockly.FieldDropdown([ + [Blockly.Msg.MICROPYTHON_DISPLAY_YES, "True"], + [Blockly.Msg.MICROPYTHON_DISPLAY_NO, "False"] + ]), 'release'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setInputsInline(true); + this.setTooltip(Blockly.Msg.MIXLY_BLUETOOTH + Blockly.Msg.ANALOG + Blockly.Msg.MIXLY_KEYBOARD_INPUT); + } +}; //educore actuator export const educore_buzzer = { init: function () { diff --git a/boards/default_src/micropython/generators/actuator_onboard.js b/boards/default_src/micropython/generators/actuator_onboard.js index 2a202a30..2aa9df00 100644 --- a/boards/default_src/micropython/generators/actuator_onboard.js +++ b/boards/default_src/micropython/generators/actuator_onboard.js @@ -587,6 +587,59 @@ export const analog_ble_mouse_send_battery = function (_, generator) { return code; } +export const analog_ble_keyboard_mouse_init = function (_, generator) { + generator.definitions_['import_HID_ble_hid'] = 'from ble_hid import HID'; + var kname = generator.valueToCode(this, 'kname', generator.ORDER_ATOMIC) + var code = 'ble_hid = HID(' + kname + ')\n'; + return code; +} + +export const ble_keyboard_mouse_get_mac = function (_, generator) { + generator.definitions_['import_HID_ble_hid'] = 'from ble_hid import HID'; + var code = 'ble_hid.mac'; + return [code, generator.ORDER_ATOMIC]; +} + +export const ble_keyboard_mouse_connect = function (_, generator) { + generator.definitions_['import_HID_ble_hid'] = 'from ble_hid import HID'; + var code = 'ble_hid.is_connected()'; + return [code, generator.ORDER_ATOMIC]; +} + +export const analog_ble_keyboard_mouse_send_battery = function (_, generator) { + var b = generator.valueToCode(this, 'battery', generator.ORDER_ATOMIC); + generator.definitions_['import_HID_ble_hid'] = 'from ble_hid import HID'; + var code = "ble_hid.battery_notify(" + b + ")\n"; + return code; +} + +export const analog_ble_keyboard_mouse_input = function (_, generator) { + var sp = generator.valueToCode(this, 'special', generator.ORDER_ATOMIC); + var ge = generator.valueToCode(this, 'general', generator.ORDER_ATOMIC); + var re = this.getFieldValue('release'); + generator.definitions_['import_HID_ble_hid'] = 'from ble_hid import HID'; + var code = "ble_hid.keyboard_notify(" + sp + "," + ge + "," + re + ")\n"; + return code; +} + +export const analog_ble_keyboard_mouse_str = function (_, generator) { + var str = generator.valueToCode(this, 'str', generator.ORDER_ATOMIC); + var t = generator.valueToCode(this, 'time', generator.ORDER_ATOMIC); + generator.definitions_['import_HID_ble_hid'] = 'from ble_hid import HID'; + var code = "ble_hid.keyboard_str(" + str + ",delay=" + t + ")\n"; + return code; +} + +export const analog_ble_mouse_keyboard_input = function (_, generator) { + var key = generator.valueToCode(this, 'key', generator.ORDER_ATOMIC); + var x = generator.valueToCode(this, 'x', generator.ORDER_ATOMIC); + var y = generator.valueToCode(this, 'y', generator.ORDER_ATOMIC); + var wheel = generator.valueToCode(this, 'wheel', generator.ORDER_ATOMIC); + var re = this.getFieldValue('release'); + generator.definitions_['import_HID_ble_hid'] = 'from ble_hid import HID'; + var code = "ble_hid.mouse_notify(" + key + ",(" + x + "," + y + ")," + wheel + "," + re + ")\n"; + return code; +} //educore actuator export const educore_buzzer = function (_, generator) { var version = Boards.getSelectedBoardKey().split(':')[2] diff --git a/boards/default_src/micropython_educore/template.xml b/boards/default_src/micropython_educore/template.xml index 22d2cda0..cdb0014a 100644 --- a/boards/default_src/micropython_educore/template.xml +++ b/boards/default_src/micropython_educore/template.xml @@ -2991,7 +2991,7 @@ - + + + + + ble_keyboard_mouse + + + + + + + + + 10 + + + + + + + + + + + + + + + + + Hello, Mixly! + + + + + 10 + + + + + + + + + + + + + + + + + + + + diff --git a/boards/default_src/micropython_esp32/template.xml b/boards/default_src/micropython_esp32/template.xml index c1c118b9..bc9a0947 100644 --- a/boards/default_src/micropython_esp32/template.xml +++ b/boards/default_src/micropython_esp32/template.xml @@ -2957,78 +2957,134 @@ - - - - ble_keyboard - - - - - - - - + + + + + ble_keyboard_mouse + + + + + + + + + 10 + + + + + + + + + + + + + + + + + Hello, Mixly! + + + + + 10 + + + + + + + + + + + + + + + + + + + + + diff --git a/boards/default_src/micropython_esp32c2/template.xml b/boards/default_src/micropython_esp32c2/template.xml index 027a0371..e133d9be 100644 --- a/boards/default_src/micropython_esp32c2/template.xml +++ b/boards/default_src/micropython_esp32c2/template.xml @@ -2802,12 +2802,12 @@ - - - - ble_keyboard - - + + + + + ble_keyboard_mouse + + + + + + + + + 10 + + + + + + + + + + + + + + + + + Hello, Mixly! + + + + + 10 + + + + + + + + + + + + + + + + + + + + diff --git a/boards/default_src/micropython_esp32c3/template.xml b/boards/default_src/micropython_esp32c3/template.xml index 5526750c..3bc72b4c 100644 --- a/boards/default_src/micropython_esp32c3/template.xml +++ b/boards/default_src/micropython_esp32c3/template.xml @@ -2751,7 +2751,7 @@ - + + + + + ble_keyboard_mouse + + + + + + + + + 10 + + + + + + + + + + + + + + + + + Hello, Mixly! + + + + + 10 + + + + + + + + + + + + + + + + + + + + diff --git a/boards/default_src/micropython_esp32s3/template.xml b/boards/default_src/micropython_esp32s3/template.xml index c1a5d7e4..10c4ebe8 100644 --- a/boards/default_src/micropython_esp32s3/template.xml +++ b/boards/default_src/micropython_esp32s3/template.xml @@ -3131,7 +3131,7 @@ - + + + + + ble_keyboard_mouse + + + + + + + + + 10 + + + + + + + + + + + + + + + + + Hello, Mixly! + + + + + 10 + + + + + + + + + + + + + + + + + + + +