diff --git a/index.js b/index.js index 44e48fd..7a18949 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,51 @@ -const ArgumentType = require('../../extension-support/argument-type'); -const BlockType = require('../../extension-support/block-type'); -const formatMessage = require('format-message'); -const io = require('socket.io-client'); // yarn add socket.io-client socket.io-client@2.2.0 +const ArgumentType = require("../../extension-support/argument-type"); +const BlockType = require("../../extension-support/block-type"); +const formatMessage = require("format-message"); +const io = require("socket.io-client"); // yarn add socket.io-client socket.io-client@2.2.0 +const Cast = require('../../util/cast'); /** * Icon svg to be displayed at the left edge of each extension block, encoded as a data URI. * @type {string} */ // eslint-disable-next-line max-len -// const blockIconURI = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCA0MCA0MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48dGl0bGU+cGVuLWljb248L3RpdGxlPjxnIHN0cm9rZT0iIzU3NUU3NSIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxwYXRoIGQ9Ik04Ljc1MyAzNC42MDJsLTQuMjUgMS43OCAxLjc4My00LjIzN2MxLjIxOC0yLjg5MiAyLjkwNy01LjQyMyA1LjAzLTcuNTM4TDMxLjA2NiA0LjkzYy44NDYtLjg0MiAyLjY1LS40MSA0LjAzMi45NjcgMS4zOCAxLjM3NSAxLjgxNiAzLjE3My45NyA0LjAxNUwxNi4zMTggMjkuNTljLTIuMTIzIDIuMTE2LTQuNjY0IDMuOC03LjU2NSA1LjAxMiIgZmlsbD0iI0ZGRiIvPjxwYXRoIGQ9Ik0yOS40MSA2LjExcy00LjQ1LTIuMzc4LTguMjAyIDUuNzcyYy0xLjczNCAzLjc2Ni00LjM1IDEuNTQ2LTQuMzUgMS41NDYiLz48cGF0aCBkPSJNMzYuNDIgOC44MjVj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DM1MTU2IDE3MS4yMzQzNzUgMTE1LjIyNjU2MiAxNjguOTQ5MjE5IDExNS44MTY0MDYgMTYzLjk2MDkzOCBDIDExNi40MTAxNTYgMTU4Ljk3NjU2MiAxMTYuNjgzNTk0IDE2MS41IDExNy4yOTI5NjkgMTUyLjI3NzM0NCBDIDExNy44OTg0MzggMTQzLjA1NDY4OCAxMTcuMjkyOTY5IDEzNC44OTQ1MzEgMTE3LjI5Mjk2OSAxMjguNjI4OTA2IEMgMTE3LjI5Mjk2OSAxMjIuMzYzMjgxIDEwOC4yODkwNjIgMTA0Ljc4NTE1NiAxMjAuNzE0ODQ0IDEwNC43ODUxNTYgQyAxMjYuNDAyMzQ0IDEwNy4wNTg1OTQgMTIzLjU1MDc4MSAxMTMuMDQ2ODc1IDEyMy41NTA3ODEgMTE4LjUzMTI1IEMgMTIzLjU1MDc4MSAxMjQuODAwNzgxIDEyMy41NTA3ODEgMTI3LjQxMDE1NiAxMjMuNTUwNzgxIDEzMC43OTY4NzUgQyAxMjMuNTUwNzgxIDEzNC4xODc1IDEyMy41NTA3ODEgMTQ2LjYwNTQ2OSAxMjMuNTUwNzgxIDE1NS40ODA0NjkgQyAxMjMuNTUwNzgxIDE2NC4zNTU0NjkgMTIzLjM0Mzc1IDE3MS4yMzQzNzUgMTIwLjY4NzUgMTcxLjIzNDM3NSBaIE0gMTIwLjY4NzUgMTcxLjIzNDM3NSAiLz4KPC9nPgo8L3N2Zz4K"; const menuIconURI = blockIconURI; -const TOPIC = 'eim/arduino'; +/** + * Enum for icon parameter values. + * @readonly + * @enum {string} + */ + +var board = { + digital_pin_2: "None", + digital_pin_3: "None", + digital_pin_4: "None", + digital_pin_5: "None", + digital_pin_6: "None", + digital_pin_7: "None", + digital_pin_8: "None", + digital_pin_9: "None", + digital_pin_10: "None", + digital_pin_11: "None", + digital_pin_12: "None", + digital_pin_13: "None", + analog_pin_0: "None", + analog_pin_1: "None", + analog_pin_2: "None", + analog_pin_3: "None", + analog_pin_4: "None", + analog_pin_5: "None", + analog_pin_6: "None", + analog_pin_7: "None" +}; + +const USBSendInterval = 100; -// EIM: Everything Is Message -class ArduinoBlocks { + +class arduinoBlocks { constructor(runtime) { /** * The runtime instantiating this block package. @@ -25,34 +54,55 @@ class ArduinoBlocks { this.runtime = runtime; const url = new URL(window.location.href); - var adapterHost = url.searchParams.get('adapter_host'); // 支持树莓派(分布式使用) + var adapterHost = url.searchParams.get("adapter_host"); // 支持树莓派(分布式使用) if (!adapterHost) { var adapterHost = "codelab-adapter.codelab.club"; } - this.socket = io(`//${adapterHost}:12358` + '/test', { - transports: ['websocket'] + this.socket = io(`//${adapterHost}:12358` + "/test", { + transports: ["websocket"] }); - this.socket.on('sensor', msg => { - console.log(msg.data); - this.data = msg.data; - const topic = this.data.topic; - const message = this.data.payload; - - // 任何消息都进入 + this.socket.on("sensor", msg => { + this.message = msg.message; + const topic = this.message.topic; + const message = this.message.payload; + const first_start = this.message.first_sart this.message = message; // 可能被清空 this.topic = topic; this.origin_message = message; - // } + if (this.topic == "eim/arduino/init") { + console.log("extention start"); + board = { + digital_pin_2: "None", + digital_pin_3: "None", + digital_pin_4: "None", + digital_pin_5: "None", + digital_pin_6: "None", + digital_pin_7: "None", + digital_pin_8: "None", + digital_pin_9: "None", + digital_pin_10: "None", + digital_pin_11: "None", + digital_pin_12: "None", + digital_pin_13: "None", + analog_pin_0: "None", + analog_pin_1: "None", + analog_pin_2: "None", + analog_pin_3: "None", + analog_pin_4: "None", + analog_pin_5: "None", + analog_pin_6: "None", + analog_pin_7: "None" + }; + } }); } - /** * The key to load & store a target's test-related state. * @type {string} */ static get STATE_KEY() { - return 'Scratch.arduino'; + return "Scratch.arduino"; } /** @@ -60,41 +110,124 @@ class ArduinoBlocks { */ getInfo() { return { - id: 'arduino', - name: 'Arduino', + id: "arduino", + name: "arduino", menuIconURI: menuIconURI, blockIconURI: blockIconURI, blocks: [ { - opcode: 'setLed', + opcode: "read_analog_value", + blockType: BlockType.REPORTER, // BOOLEAN, COMMAND + text: formatMessage({ + id: "arduino.read_analog_value", + default: "read analog value from [analogPinNumber] ", + description: "read_analog_value" + }), + arguments: { + analogPinNumber: { + type: ArgumentType.STRING, + menu: "analogPinNumber", + defaultValue: "0" + } + } + }, + { + opcode: "changeLedState", blockType: BlockType.COMMAND, text: formatMessage({ - id: 'arduino.sendTopicMessage', - default: 'led index[index] red[red] green[green] blue[blue]', - description: - 'set led' + id: "arduino.changeLedState", + default: "led [digitalPinNumber] set [logicState]", + description: "changeLedState" }), arguments: { - index: { - type: ArgumentType.NUMBER, - defaultValue: 0 + digitalPinNumber: { + type: ArgumentType.STRING, + menu: "digitalPinNumber", + defaultValue: "2" }, - red: { - type: ArgumentType.NUMBER, - defaultValue: 255 + logicState: { + type: ArgumentType.STRING, + menu: "logicState", + defaultValue: "1" + } + } + }, + { + opcode: "changePwmLedValue", + blockType: BlockType.COMMAND, + text: formatMessage({ + id: "arduino.changePwmLedValue", + default: "Pwm_led [PwmPinNumber] set [pwmValue]", + description: "changeLedState" + }), + arguments: { + PwmPinNumber: { + type: ArgumentType.STRING, + menu: "PwmPinNumber", + defaultValue: "9" }, - green: { - type: ArgumentType.NUMBER, - defaultValue: 0 + pwmValue: { + type: ArgumentType.STRING, + defaultValue: "50" + } + } + }, + { + opcode: "read_button_state", + blockType: BlockType.REPORTER, // BOOLEAN, COMMAND + text: formatMessage({ + id: "arduino.read_button_state", + default: "read button [digitalPinNumber] state", + description: "read_button_state" + }), + arguments: { + digitalPinNumber: { + type: ArgumentType.STRING, + menu: "digitalPinNumber", + defaultValue: "12" + } + } + }, + { + opcode: "changeServoDegree", + blockType: BlockType.COMMAND, + text: formatMessage({ + id: "arduino.changeServoDegree", + default: "servo [PwmPinNumber] set [degree]", + description: "changeServoDegree" + }), + arguments: { + PwmPinNumber: { + type: ArgumentType.STRING, + menu: "PwmPinNumber", + defaultValue: "9" }, - blue: { - type: ArgumentType.NUMBER, - defaultValue: 0 + degree: { + type: ArgumentType.STRING, + defaultValue: "0" } } } ], - menus: {} + menus: { + digitalPinNumber: [ + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13" + ], + analogPinNumber: ["0", "1", "2", "3", "4", "5", "6", "7"], + PwmPinNumber: ["3", "5", "6", "9", "10", "11"], + logicState: ["1", "0"] + } }; } @@ -103,12 +236,186 @@ class ArduinoBlocks { * @return {object.} Mapping of opcode to Function. */ - setLed (args) { - const payload = `ser.write(bytearray([0xff,0xaa,0x9,0x0,0x2,0x8,0x7,0x2,${args.index},${args.red},${args.green},${args.blue}]))`; - this.socket.emit('actuator', {topic: TOPIC, payload: payload}); - return; + read_analog_value(args) { + const topic = "eim/arduino"; + let message = ""; + if (board["analog_pin_" + args.analogPinNumber] == "ANALOG") { + if (this.topic == topic) { + return this.origin_message[ + "analog_pin_" + args.analogPinNumber + ]; + } + } else { + message = + "board.set_pin_mode(" + + args.analogPinNumber + + ", Constants.ANALOG)"; + board["analog_pin_" + args.analogPinNumber] = "ANALOG"; + console.log(message); + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + if (this.topic == topic) { + return this.origin_message[ + "analog_pin_" + args.analogPinNumber + ]; + } + } } -} + changeLedState(args, util) { + const topic = "eim/arduino"; + let message = ""; + if (board["digital_pin_" + args.digitalPinNumber] == "OUTPUT") { + message = + "board.digital_write(" + + args.digitalPinNumber + + "," + + args.logicState + + ")"; + console.log(message); + } else { + message = + "board.set_pin_mode(" + + args.digitalPinNumber + + ", Constants.OUTPUT)"; + board["digital_pin_" + args.digitalPinNumber] = "OUTPUT"; + console.log(message); + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + message = + "board.digital_write(" + + args.digitalPinNumber + + "," + + args.logicState + + ")"; + console.log(message); + } + + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + + + return new Promise(resolve => { + setTimeout(() => { + resolve(); + }, USBSendInterval); + }); + } + + read_button_state(args) { + const topic = "eim/arduino"; + let message = ""; + if (board["digital_pin_" + args.digitalPinNumber] == "INPUT") { + if (this.topic == topic) { + return this.origin_message[ + "digital_pin_" + args.digitalPinNumber + ]; + } + } else { + const message = + "board.set_pin_mode(" + + args.digitalPinNumber + + ", Constants.INPUT)"; + board["digital_pin_" + args.digitalPinNumber] = "INPUT"; + console.log(message); + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + if (this.topic == topic) { + return this.origin_message[ + "digital_pin_" + args.digitalPinNumber + ]; + } + } + } + + changeServoDegree(args) { + const topic = "eim/arduino"; + let message = ""; + if (board["digital_pin_" + args.digitalPinNumber] == "SERVO") { + message = + "board.analog_write(" + + args.PwmPinNumber + + "," + + args.degree + + ")"; + console.log(message); + } else { + message = "board.servo_config(" + args.PwmPinNumber + ")"; + + board["digital_pin_" + args.digitalPinNumber] = "SERVO"; + console.log(message); + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + message = + "board.analog_write(" + + args.PwmPinNumber + + "," + + args.degree + + ")"; + console.log(message); + } + + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + + return new Promise(resolve => { + setTimeout(() => { + resolve(); + }, USBSendInterval); + }); + } + + changePwmLedValue(args) { + const topic = "eim/arduino"; + let message = ""; + if (board["digital_pin_" + args.PwmPinNumber] == "PWM") { + message = + "board.analog_write(" + + args.PwmPinNumber + + "," + + args.pwmValue + + ")"; + console.log(message); + } else { + message = + "board.set_pin_mode(" + args.PwmPinNumber + ", Constants.PWM)"; + board["digital_pin_" + args.PwmPinNumber] = "PWM"; + console.log(message); + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + message = + "board.analog_write(" + + args.PwmPinNumber + + "," + + args.pwmValue + + ")"; + console.log(message); + } + + this.socket.emit("actuator", { + topic: topic, + payload: message + }); + return new Promise(resolve => { + setTimeout(() => { + resolve(); + }, USBSendInterval); + }); + } +} -module.exports = ArduinoBlocks; +module.exports = arduinoBlocks;