接下来我们会以创建一个虚构的衍生自 Arduino UNO 的主板 Hoho 的资源为例,演示如何编写添加设备资源。
首先在 ./devices
文件夹下创建一个新的文件夹以主板名称命名并遵循驼峰规则:hoho
mkdir ./devices/hoho
cd ./devices/hoho
index.js
文件index.js
是用来描述设备各个属性的文件,创建这个文件,并写入以下内容。
const hoho = formatMessage => ({
name: formatMessage({
id: 'hoho.name',
default: 'Hoho',
description: 'Name for the hoho device'
}),
deviceId: 'hoho_arduinoUno',
manufactor: 'Hoho inc.',
learnMore: 'www.openblock.cc',
iconURL: 'assets/hoho.png',
description: formatMessage({
id: 'hoho.description',
default: 'This is a device demo.',
description: 'Description for the hoho device'
}),
disabled: false,
bluetoothRequired: false,
serialportRequired: true,
defaultBaudRate: '9600',
pnpidList: [
'USB\\VID_10C4&PID_EA60', // CP2102
'USB\\VID_1A86&PID_7523' // CH340
],
internetConnectionRequired: false,
launchPeripheralConnectionFlow: true,
useAutoScan: false,
connectionIconURL: 'assets/hoho-illustration.svg',
connectionSmallIconURL: 'assets/hoho-small.svg',
programMode: ['realtime', 'upload'],
programLanguage: ['block', 'cpp'],
tags: ['kit'],
deviceExtensionsCompatible: 'arduinoUno',
helpLink: 'wiki.openblock.cc'
});
module.exports = hoho;
其中 deviceId: 'hoho_arduinoUno'
属性表明了它是一个继承自 arduinoUno 的设备,它拥有 Arduino UNO 全部的积木内容及功能,只是修改了其部分属性。
按照 index.js
文件中的定义,创建 assets
文件夹并下载放入下方的3张图片。
translations.js
文件此文件用于提供多语言翻译内容,创建 translations.js
文件,并将以下内容写入。
function getInterfaceTranslations () {
return {
"en": {
"hoho.name": "Hoho",
"hoho.description": "This is a device demo."
},
"ru": {
"hoho.name": "Hoho",
"hoho.description": "Это демо-версия устройства."
},
"zh-cn": {
"hoho.name": "Hoho",
"hoho.description": "这是一个设备演示。"
},
"zh-tw": {
"hoho.name": "Hoho",
"hoho.description": "這是一個設備演示。"
}
};
}
if (typeof module !== 'undefined') {
module.exports = {getInterfaceTranslations};
}
[1] hoho 设备资源包.zip