diff --git a/docs/project-snapshot.md b/docs/project-snapshot.md
index a061b1bcd..507688ce3 100644
--- a/docs/project-snapshot.md
+++ b/docs/project-snapshot.md
@@ -155,7 +155,7 @@
## 代码与文档规模
-- `platform/tools`:`105` 个 Python 模块,`63228` 行;规模最大的模块如下。
+- `platform/tools`:`105` 个 Python 模块,`63237` 行;规模最大的模块如下。
| 模块 | 行数 |
| --- | ---: |
diff --git a/platform/tests/test_public_micropython_ui.mjs b/platform/tests/test_public_micropython_ui.mjs
index f5677523c..e5f4352a8 100644
--- a/platform/tests/test_public_micropython_ui.mjs
+++ b/platform/tests/test_public_micropython_ui.mjs
@@ -5,7 +5,7 @@ import fs from 'node:fs/promises';
import vm from 'node:vm';
import {PublicQemuRuntime} from '../web/public-qemu-runtime.js';
import {PublicMicroPythonRunner} from '../web/public-micropython.js';
-import {MODBUS_TCP_SERVER_EXAMPLE_ID, usesExampleStation, usesTextTcpPeer} from '../web/public-network-fixtures.js';
+import {LABEL_PLUS_EXAMPLE_ID, MODBUS_TCP_SERVER_EXAMPLE_ID, usesExampleStation, usesTextTcpPeer} from '../web/public-network-fixtures.js';
import {DUAL_KMETER_EXAMPLE_ID} from '../web/public-qemu-unit-examples.js';
const source=await fs.readFile(new URL('../web/public.js',import.meta.url),'utf8');
@@ -32,7 +32,7 @@ function fixture(){
const run={kind:'browser',generation:1,controller:runtime};
const state={run,runGeneration:1};
const context={state,$:id=>nodes[id],active:value=>value===state.run&&value.generation===state.runGeneration&&!value.stopping,
- PublicQemuRuntime,PublicMicroPythonRunner,DUAL_KMETER_EXAMPLE_ID,MODBUS_TCP_SERVER_EXAMPLE_ID,usesExampleStation,usesTextTcpPeer,
+ PublicQemuRuntime,PublicMicroPythonRunner,DUAL_KMETER_EXAMPLE_ID,LABEL_PLUS_EXAMPLE_ID,MODBUS_TCP_SERVER_EXAMPLE_ID,usesExampleStation,usesTextTcpPeer,
TextEncoder,Uint8Array,DOMException,
error:error=>{if(error.name!=='AbortError')errors.push(error);}};
vm.createContext(context);vm.runInContext(radio+'\n'+functions+'\n'+serial+'\n'+keyboard,context);
diff --git a/platform/tests/test_public_qemu_entry.mjs b/platform/tests/test_public_qemu_entry.mjs
index 9e8935755..079a59622 100644
--- a/platform/tests/test_public_qemu_entry.mjs
+++ b/platform/tests/test_public_qemu_entry.mjs
@@ -23,12 +23,18 @@ import * as servos8 from '../web/public-8servos-examples.js';
import * as capGps from '../web/public-cap-gps-examples.js';
import * as dofExamples from '../web/public-dof-examples.js';
import * as moduleRadios from '../web/public-module-radio-examples.js';
+import * as instruments from '../web/public-instrument-examples.js';
+import * as uartUnits from '../web/public-uart-unit-examples.js';
+import * as nbiotExamples from '../web/public-nbiot-examples.js';
+import * as mqttUnitExamples from '../web/public-mqtt-unit-examples.js';
import * as rui3Module from '../web/public-rui3-module-example.js';
import * as portAUnitExamples from '../web/public-port-a-examples.js';
import * as usbModuleExamples from '../web/public-usb-module-examples.js';
-import * as oledUnitExamples from '../web/public-oled-unit-examples.js';
+import * as displayUnitExamples from '../web/public-display-unit-examples.js';
+import * as driveModuleExamples from '../web/public-drive-module-examples.js';
import * as gpioExamples from '../web/public-gpio-unit-examples.js';
import * as portBUnitExamples from '../web/public-port-b-examples.js';
+import * as serialSensorExamples from '../web/public-serial-sensor-examples.js';
import * as pwmUnitExamples from '../web/public-pwm-unit-examples.js';
import * as thermalExamples from '../web/public-thermal-example.js';
import * as cores3SensorExamples from '../web/public-cores3-sensor-examples.js';
@@ -111,7 +117,7 @@ async function entry({search='',pageUrl=pageRoot,siteServiceUrl='',isolationErro
throw new Error('Unexpected fetch '+url);
};
const dependencies=Object.fromEntries(required.map(name=>[name,()=>{throw new Error(`Unexpected execution boundary ${name}`);} ]));
- Object.assign(dependencies,config,firmware,demoFirmware,uiflowFirmware,cloudStatus,qemuProfiles,qemuFrame,qemuServo,qemuPeerPair,qemuUnitExamples,qrcodeModule,facesModule,envExamples,moduleLlm,miniScales,servos8,capGps,rui3Module,dofExamples,moduleRadios,gpioExamples,portAUnitExamples,usbModuleExamples,oledUnitExamples,portBUnitExamples,pwmUnitExamples,thermalExamples,cores3SensorExamples,fingerprint2,modbusRtu,networkFixtures,usbHidExamples,audioModule,{
+ Object.assign(dependencies,config,firmware,demoFirmware,uiflowFirmware,cloudStatus,qemuProfiles,qemuFrame,qemuServo,qemuPeerPair,qemuUnitExamples,qrcodeModule,facesModule,envExamples,moduleLlm,miniScales,servos8,capGps,rui3Module,nbiotExamples,mqttUnitExamples,instruments,uartUnits,dofExamples,moduleRadios,gpioExamples,portAUnitExamples,usbModuleExamples,displayUnitExamples,driveModuleExamples,portBUnitExamples,serialSensorExamples,pwmUnitExamples,thermalExamples,cores3SensorExamples,fingerprint2,modbusRtu,networkFixtures,usbHidExamples,audioModule,{
siteRoot:()=>new URL(pageUrl),
ensurePublicIsolation:async()=>{events.push('isolation');if(isolationError)throw isolationError;return isolation;},
PublicMicroPythonRunner,deviceIdentityCapability,GNSS_EXAMPLE_ID,supportsQemuGnssWorkbench,
diff --git a/platform/tools/bootstrap_browser_runtime.py b/platform/tools/bootstrap_browser_runtime.py
index da305e61e..e820de468 100644
--- a/platform/tools/bootstrap_browser_runtime.py
+++ b/platform/tools/bootstrap_browser_runtime.py
@@ -21,21 +21,30 @@
ROOT = Path(__file__).resolve().parents[2]
SOURCE_URL = "https://github.com/m5agent/esp32sim.git"
-SOURCE_COMMIT = "d9b9e92bfc924aa2ac10ea540f516a3893fa96c8"
+SOURCE_COMMIT = "d1c930adffaa8d94d03856eb0276df17da668002"
BOARD_PROFILES = json.loads((ROOT / "platform/web/esp32sim-browser-boards.json").read_text())
SOURCE_PROFILES = [
"m5stack-cores3", "m5stack-cores3+dual-kmeter",
"m5stack-cores3+ultrasonic-i2c", "m5stack-cores3+relay", "m5stack-cores3+qrcode-module",
- "m5stack-cores3+mini-scales", "m5stack-cores3+fingerprint2", "m5stack-cores3+8servos", "m5stack-cores3+rui3-module", "m5stack-cores3+hall-effect",
+ "m5stack-cores3+mini-scales", "m5stack-cores3+finger-unit", "m5stack-cores3+fingerprint2", "m5stack-cores3+8servos", "m5stack-cores3+rui3-module", "m5stack-cores3+hall-effect",
"m5stack-cores3+dof6", "m5stack-cores3+dof9", "m5stack-cores3+dof10", "m5stack-cores3+bmm350",
- "m5stack-cores3+cc1101", "m5stack-cores3+lora868-v12", "m5stack-cores3+lora1262",
+ "m5stack-cores3+cc1101", "m5stack-cores3+lora868-sx1276", "m5stack-cores3+lora868-v12", "m5stack-cores3+lora1262",
"m5stack-cores3+usb-module-gpio", "m5stack-cores3+usb-module-mouse",
- "m5stack-cores3+glass", "m5stack-cores3+glass2", "m5stack-cores3+mini-oled", "m5stack-cores3+oled",
+ "m5stack-cores3+sim7020", "m5stack-cores3+sim7028",
+ "m5stack-cores3+mqtt-unit", "m5stack-cores3+mqttpoe-unit",
+ "m5stack-cores3+dc-motor-module", "m5stack-cores3+fan-module",
+ "m5stack-cores3+bldc-driver", "m5stack-cores3+hbridge",
+ "m5stack-cores3+lcd-unit", "m5stack-cores3+glass", "m5stack-cores3+glass2", "m5stack-cores3+mini-oled", "m5stack-cores3+oled",
+ "m5stack-cores3+laser-tx", "m5stack-cores3+midi-unit", "m5stack-cores3+synth-unit", "m5stack-cores3+asr-unit",
+ "m5stack-cores3+ecg-module",
+ "m5stack-cores3+module-16340", "m5stack-cores3+pps-module", "m5stack-cores3+rs232-module",
+ "m5stack-cores3+weight-unit", "m5stack-cores3+zigbee-unit", "m5stack-cores3+zigbee-module",
+ "m5stack-cores3+uhf-rfid-unit",
"m5stack-cores3+env-iii", "m5stack-cores3+env-pro",
- "m5stack-cores3+audio-module", "m5stack-cores3+byteswitch", "m5stack-cores3+step16", "m5stack-cores3+ncir2",
+ "m5stack-cores3+audio-module", "m5stack-cores3+pdm-unit", "m5stack-cores3+byteswitch", "m5stack-cores3+step16", "m5stack-cores3+ncir2",
"m5stack-cores3+key-unit", "m5stack-cores3+fader-unit", "m5stack-cores3+flashlight-unit",
"m5stack-cores3+servo180", "m5stack-cores3+servo360", "m5stack-cores3+catch-unit",
- "m5stack-cores3+watering-unit", "m5stack-cores3+grove2grove-unit",
+ "m5stack-cores3+rf433t-unit", "m5stack-cores3+watering-unit", "m5stack-cores3+grove2grove-unit",
"m5stack-cores3+thermal-unit", "m5stack-cores3+nfc-unit",
"m5stack-cores3+faces-calculator", "m5stack-cores3+faces-keyboard", "m5stack-cores3+faces-gamepad",
"m5stack-cores3+acssr-rtu", "m5stack-cores3+modbus-rtu-master", "m5stack-cores3+modbus-rtu-slave",
diff --git a/platform/web/index.html b/platform/web/index.html
index d90aa933a..36fc722ad 100644
--- a/platform/web/index.html
+++ b/platform/web/index.html
@@ -157,6 +157,21 @@
虚拟相机预览
8Servos 输出
+
@@ -170,6 +185,15 @@
8Servos 输出
+
@@ -195,6 +219,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -211,6 +248,23 @@
+
+
+
@@ -348,6 +402,7 @@ 加载固件
+
@@ -355,11 +410,14 @@ 加载固件
+
+
+
@@ -367,12 +425,22 @@ 加载固件
+
+
+
+
+
+
+
+
+
+
@@ -380,6 +448,8 @@ 加载固件
+
+
@@ -387,12 +457,23 @@ 加载固件
+
+
+
+
+
+
+
+
+
+
+
@@ -405,6 +486,7 @@ 加载固件
+
diff --git a/platform/web/public-audio-module.js b/platform/web/public-audio-module.js
index 868281b91..a39c03044 100644
--- a/platform/web/public-audio-module.js
+++ b/platform/web/public-audio-module.js
@@ -1,5 +1,7 @@
export const AUDIO_MODULE_ID = 'audio-module';
export const AUDIO_MODULE_BOARD = 'm5stack-cores3+audio-module';
+export const PDM_UNIT_ID = 'pdm-unit';
+export const PDM_UNIT_BOARD = 'm5stack-cores3+pdm-unit';
const officialSource = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/module/audio/';
const examples = new Map([
@@ -12,4 +14,10 @@ const examples = new Map([
]);
for (const example of examples.values()) Object.assign(example,{attachment:AUDIO_MODULE_ID,board:AUDIO_MODULE_BOARD});
+examples.set(PDM_UNIT_ID,{
+ attachment:PDM_UNIT_ID, board:PDM_UNIT_BOARD, name:'PDM Unit',
+ url:new URL('../../unit/pdm/pdm_cores3_example.py',officialSource).href, bytes:1863,
+ sha256:'d4e4bc2a87e3421cabeff9711bd16db35b3f7da89e4da4f8a3e51c692550de72',
+});
+
export function audioModuleExample(id) { return examples.get(id) || null; }
diff --git a/platform/web/public-browser-runtime.js b/platform/web/public-browser-runtime.js
index 14016628a..788763dc5 100644
--- a/platform/web/public-browser-runtime.js
+++ b/platform/web/public-browser-runtime.js
@@ -12,36 +12,41 @@ import { capGpsExample } from './public-cap-gps-examples.js';
import { gnssFixtureSentences } from './public-qemu-gnss-example.js';
import { portAUnitExample } from './public-port-a-examples.js';
import { HALL_EFFECT_ID, gpioUnitBoard } from './public-gpio-unit-examples.js';
+import { driveModuleExample } from './public-drive-module-examples.js';
import { isUsbModuleInput, usbModuleExample } from './public-usb-module-examples.js';
import { portBUnitExample } from './public-port-b-examples.js';
import { pwmUnitExample } from './public-pwm-unit-examples.js';
import { THERMAL_ID, thermalExample } from './public-thermal-example.js';
import { cores3SensorExample } from './public-cores3-sensor-examples.js';
-import { oledUnitExample } from './public-oled-unit-examples.js';
+import { displayUnitExample, hasDisplayUnitFrame } from './public-display-unit-examples.js';
+import { ASR_UNIT_ID, ECG_MODULE_ID, uartUnitExample } from './public-uart-unit-examples.js';
+import { isWeightSample, serialSensorExample } from './public-serial-sensor-examples.js';
import { dofBoard } from './public-dof-examples.js';
import { moduleRadioAttachment } from './public-module-radio-examples.js';
+import { instrumentExample,instrumentSamplesAvailable } from './public-instrument-examples.js';
+import { serialMqttAttachment } from './public-mqtt-unit-examples.js';
import { RUI3_MODULE_ID, RUI3_MODULE_BOARD } from './public-rui3-module-example.js';
-import { FINGERPRINT2_BOARD, FINGERPRINT2_ID } from './public-fingerprint2-examples.js';
+import { FINGER_BOARD, FINGER_ID, FINGERPRINT2_BOARD, FINGERPRINT2_ID } from './public-fingerprint2-examples.js';
import { SERVOS8_ID, SERVOS8_BOARD } from './public-8servos-examples.js';
import { MINI_SCALES_ID, MINI_SCALES_BOARD } from './public-mini-scales.js';
import { MODULE_LLM_EXAMPLE_BOARD, MODULE_LLM_EXAMPLE_ID } from './public-module-llm-example.js';
-import { AUDIO_MODULE_BOARD, AUDIO_MODULE_ID } from './public-audio-module.js';
+import { AUDIO_MODULE_BOARD, AUDIO_MODULE_ID, PDM_UNIT_BOARD, PDM_UNIT_ID } from './public-audio-module.js';
import { envBoard } from './public-env-examples.js';
import { facesModuleExample } from './public-faces-module.js';
import { WLAN_AP_EXAMPLE_ID, TCP_SERVER_EXAMPLE_ID, MODBUS_TCP_SERVER_EXAMPLE_ID, EASY_TCP_SERVER_EXAMPLE_ID, ARDUINO_RTC_EXAMPLE_ID, ARDUINO_RTC_FIRMWARE,
- ARDUINO_RTC_WIFI, networkFixtureSource, usesExampleStation, usesTextTcpPeer } from './public-network-fixtures.js';
+ ARDUINO_RTC_WIFI, LABEL_PLUS_EXAMPLE_ID, labelPlusEndpoint, networkFixtureSource, usesExampleStation, usesTextTcpPeer } from './public-network-fixtures.js';
import { QRCODE_MODULE_ID, QRCODE_MODULE_BOARD, QRCODE_MODULE_FIRMWARE } from './public-qrcode-module.js';
import { USB_HID_FIRMWARE, usbHidExample } from './public-usb-hid-examples.js';
import { MODBUS_RTU_FIRMWARE, modbusRtuExample } from './public-modbus-rtu.js';
import admittedBoards from './esp32sim-browser-boards.json' with {type:'json'};
-export const ESP32SIM_SOURCE_COMMIT = 'd9b9e92bfc924aa2ac10ea540f516a3893fa96c8';
+export const ESP32SIM_SOURCE_COMMIT = 'd1c930adffaa8d94d03856eb0276df17da668002';
export const ESP32SIM_LEGACY_COMMIT = '3cd3db3b7202e9fc559328c7247c11134c0437f9';
export const ESP32SIM_DUAL_KMETER_BOARD = 'm5stack-cores3+dual-kmeter';
-const CAP_RADIO_KIND = Object.freeze({cc1101:'02',lora1262:'01',lora868:'01'});
+const CAP_RADIO_KIND = Object.freeze({cc1101:'02',lora1262:'01',lora868:'01',sx1276:'03'});
export const ESP32SIM_CAP_RADIO_MAX_BYTES = 266;
export function esp32simCapRadioBoard(protocol) {
- return Object.hasOwn(CAP_RADIO_KIND,protocol) ? `m5stack-cardputer-adv+${protocol}` : null;
+ return protocol!=='sx1276' && Object.hasOwn(CAP_RADIO_KIND,protocol) ? `m5stack-cardputer-adv+${protocol}` : null;
}
export function validEsp32simCapRadioFrame(frame, protocol) {
return Object.hasOwn(CAP_RADIO_KIND,protocol) && typeof frame === 'string'
@@ -205,7 +210,7 @@ export class PublicBrowserRuntime {
try { data = JSON.parse(message.text); } catch { this.onSerial(String(message.text)); }
if (data?.t === 'serial') this.receiveSerial(data);
else if (data?.t === 'emu') this.onSerial(`[emulator] ${data.msg}\n`);
- else if (['mic-input','module-llm','ir-envelope','dual-kmeter-temperature','ultrasonic-distance','cap-radio-state','cap-radio-frame','cap-gps','qrcode-module-result','faces-input','env-sample','mini-scales-adc','fingerprint2-input','hall-magnet','rui3-payload','dof-sample','cores3-sensor-sample','usb-module-input','port-b-key','port-b-adc','thermal-scene','unit-example-value','rtu-peer','cardkb-key','usb-hid-host','review-server-send'].includes(data?.t)) {
+ else if (['mic-input','module-llm','ir-envelope','dual-kmeter-temperature','ultrasonic-distance','cap-radio-state','cap-radio-frame','cap-gps','qrcode-module-result','faces-input','env-sample','mini-scales-adc','finger-input','fingerprint2-input','hall-magnet','rui3-payload','drive-module-sample','nbiot-mqtt-message','mqtt-unit-message','instrument-sample','rs232-line','dof-sample','cores3-sensor-sample','usb-module-input','port-b-key','port-b-adc','weight-unit-sample','thermal-scene','uart-example-sample','unit-example-value','rtu-peer','cardkb-key','usb-hid-host','review-server-send','review-http-data'].includes(data?.t)) {
const pending = this.pending.get(data.t);
if (pending) {
this.pending.delete(data.t);
@@ -238,6 +243,25 @@ export class PublicBrowserRuntime {
else if (data?.t === 'unit-example-state' && data.unit === this.profile.unitExample) {
const value = data.value;
const count = n => Number.isSafeInteger(n) && n >= 0;
+ const sensor = serialSensorExample(data.unit);
+ if (data.unit === 'weight-unit' && isWeightSample(value?.['raw-setpoint'])
+ && (value['last-transferred'] === null || isWeightSample(value['last-transferred'])) && count(value.conversions)) {
+ this.lastUnitExampleState = {kind:data.unit,...value};
+ }
+ if (data.unit === 'uhf-rfid-unit' && value && typeof value.selected === 'boolean'
+ && [value.inventories,value.reads,value.writes].every(count)
+ && [null,0,1].includes(value['select-bank'])
+ && (value['last-error'] === null || count(value['last-error']) && value['last-error'] <= 255)
+ && Array.isArray(value.reserved) && value.reserved.length === 8
+ && value.reserved.every(byte=>count(byte)&&byte<=255)) {
+ this.lastUnitExampleState = {kind:data.unit,...value};
+ }
+ if (sensor?.uart && value?.uart === sensor.uart && typeof value.configured === 'boolean'
+ && [value.directed,value.broadcasts].every(count)
+ && [value['last-directed'],value['last-broadcast']].every(bytes=>Array.isArray(bytes)
+ && bytes.length<=92 && bytes.every(byte=>count(byte)&&byte<=255))) {
+ this.lastUnitExampleState = {kind:data.unit,...value};
+ }
if (data.unit === 'relay' && typeof value?.['output-level'] === 'boolean' && count(value['output-transitions'])) {
this.lastUnitExampleState = {kind:data.unit,level:value['output-level'],transitions:value['output-transitions']};
} else if (data.unit === 'ultrasonic-i2c' && Number.isInteger(value?.['distance-mm'])
@@ -253,6 +277,13 @@ export class PublicBrowserRuntime {
this.lastUnitExampleState = {kind:data.unit, angle:value.angle, rgb:value.rgb};
}
}
+ const readDriveState = driveModuleExample(data.unit);
+ if (readDriveState && count(value?.['read-bytes']) && count(value['written-bytes'])) {
+ const valid = data.unit === 'dc-motor-module'
+ ? Number.isInteger(value['motor-1-command']) && Number.isSafeInteger(value['encoder-1-count'])
+ : typeof value.enabled === 'boolean' && count(value['pwm-duty-percent']) && count(value['tach-rpm']);
+ if (valid) this.lastUnitExampleState = {kind:data.unit,...value};
+ }
if (usbModuleExample(data.unit)
&& typeof value?.connected === 'boolean' && typeof value.configured === 'boolean'
&& [value['gpio-in'],value['gpio-out']].every(n => count(n) && n <= 255)
@@ -265,7 +296,10 @@ export class PublicBrowserRuntime {
&& value.leds.every(rgb => Array.isArray(rgb) && rgb.length === 3 && rgb.every(n => count(n) && n <= 255));
const output = typeof value?.['output-high'] === 'boolean';
const adc = count(value?.['adc-raw']) && value['adc-raw'] <= 4095 && count(value['adc-conversions']);
- const valid = data.unit === 'key-unit'
+ const valid = portB.rmt
+ ? value?.gpio === 9 && count(value.frames) && Array.isArray(value.payload)
+ && value.payload.length <= 64 && value.payload.every(n => count(n) && n <= 255)
+ : data.unit === 'key-unit'
? typeof value?.pressed === 'boolean' && count(value['led-frames']) && leds(1)
: portB.adc
? adc && (portB.output ? output : leds(14))
@@ -283,16 +317,21 @@ export class PublicBrowserRuntime {
&& ['subpages','eeprom-words-read','ram-words-read'].every(key => count(value[key]))) {
this.lastUnitExampleState = {kind:data.unit,...value};
}
+ if (serialMqttAttachment(data.unit) && typeof value?.['mqtt-listening'] === 'boolean') {
+ this.lastUnitExampleState = {kind:data.unit,listening:value['mqtt-listening']};
+ }
if (data.unit === RUI3_MODULE_ID && typeof value?.listening === 'boolean') {
this.lastUnitExampleState = {kind:data.unit, listening:value.listening};
}
- const oled = oledUnitExample(data.unit);
- if (oled && value?.width === oled.width && value.height === oled.height
- && Array.isArray(value.frame) && value.frame.length === oled.width * oled.height / 8
- && value.frame.every(n => count(n) && n <= 255)
+ const displayUnit = displayUnitExample(data.unit);
+ if (displayUnit && hasDisplayUnitFrame(displayUnit, value)
&& count(value.commands) && count(value['data-bytes'])) {
this.lastUnitExampleState = {kind:data.unit, ...value};
}
+ if (uartUnitExample(data.unit) && value && count(value['tx-bytes']) && count(value['rx-bytes'])
+ && typeof value['tx-tail-hex'] === 'string' && /^(?:[a-f0-9]{2}){0,64}$/.test(value['tx-tail-hex'])) {
+ this.lastUnitExampleState = {kind:data.unit, ...value};
+ }
this.onState(this.observe());
}
else if (data?.t === 'stat') {
@@ -302,8 +341,11 @@ export class PublicBrowserRuntime {
this.display = {orientation:portrait ? 'portrait' : 'landscape',deviceRotationDeg:portrait ? rotation : 0};
this.onState(this.observe());
if (this.status === 'running' && (['relay','ultrasonic-i2c',SERVOS8_ID,RUI3_MODULE_ID,THERMAL_ID].includes(this.profile.unitExample)
- || usbModuleExample(this.profile.unitExample) || oledUnitExample(this.profile.unitExample)
- || pwmUnitExample(this.profile.unitExample) || portBUnitExample(this.profile.unitExample))) {
+ || usbModuleExample(this.profile.unitExample) || displayUnitExample(this.profile.unitExample)
+ || uartUnitExample(this.profile.unitExample) || driveModuleExample(this.profile.unitExample)
+ || serialMqttAttachment(this.profile.unitExample)
+ || pwmUnitExample(this.profile.unitExample) || portBUnitExample(this.profile.unitExample)
+ || serialSensorExample(this.profile.unitExample))) {
const now = performance.now();
if (now >= this.nextUnitObservationAt) {
this.nextUnitObservationAt = now + 250;
@@ -465,8 +507,11 @@ export class PublicBrowserRuntime {
const thermal = thermalExample(unitExample);
const usbModule = usbModuleExample(unitExample);
const pwmUnit = pwmUnitExample(unitExample);
+ const serialSensor = serialSensorExample(unitExample);
const portBUnit = portBUnitExample(unitExample);
- const oled = oledUnitExample(unitExample);
+ const displayUnit = displayUnitExample(unitExample);
+ const uartUnit = uartUnitExample(unitExample);
+ const driveModule = driveModuleExample(unitExample);
const moduleRadio = moduleRadioAttachment(unitExample);
const portAUnit = portAUnitExample(unitExample);
const usb = usbHidExample(unitExample);
@@ -488,16 +533,31 @@ export class PublicBrowserRuntime {
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
'browser_attachment_mismatch', 'DoF 或 BMM350 Unit 需使用匹配的 CoreS3 编程固件和浏览器内核。');
Object.assign(profile,{board:dof,unitExample});
- } else if (oled) {
- requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(oled.board)
+ } else if (displayUnit) {
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(displayUnit.board)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
'browser_attachment_mismatch', '此屏幕 Unit 需要匹配的 CoreS3 编程固件和浏览器内核。');
- Object.assign(profile,{board:oled.board,unitExample});
+ Object.assign(profile,{board:displayUnit.board,unitExample});
+ } else if (driveModule) {
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(driveModule.board)
+ && firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
+ 'browser_attachment_mismatch', '此 M-Bus 模块需要匹配的 CoreS3 编程固件和浏览器内核。');
+ Object.assign(profile,{board:driveModule.board,unitExample});
+ } else if (serialSensor) {
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(serialSensor.board)
+ && firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
+ 'browser_attachment_mismatch', '此附件需要匹配的 CoreS3 编程固件和浏览器内核。');
+ Object.assign(profile,{board:serialSensor.board,unitExample});
} else if (usbModule) {
requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(usbModule.board)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
'browser_attachment_mismatch', 'USB Module 需使用匹配的 CoreS3 编程固件和浏览器内核。');
Object.assign(profile,{board:usbModule.board,unitExample});
+ } else if (uartUnit) {
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(uartUnit.board)
+ && firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
+ 'browser_attachment_mismatch', '此 UART Unit 需要匹配的 CoreS3 编程固件和浏览器内核。');
+ Object.assign(profile,{board:uartUnit.board,unitExample});
} else if (portBUnit) {
requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(portBUnit.board)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
@@ -541,18 +601,30 @@ export class PublicBrowserRuntime {
'browser_attachment_mismatch', 'Modbus RTU 需使用匹配的 CoreS3 编程固件和浏览器内核。');
profile.board = rtu.board;
profile.unitExample = unitExample;
+ } else if (instrumentExample(unitExample)) {
+ const {board} = instrumentExample(unitExample);
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(board)
+ && firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
+ 'browser_attachment_mismatch', '此模块需要匹配的 CoreS3 编程固件和浏览器内核。');
+ Object.assign(profile,{board,unitExample});
+ } else if (serialMqttAttachment(unitExample)) {
+ const {board} = serialMqttAttachment(unitExample);
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(board)
+ && firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
+ 'browser_attachment_mismatch', '此 MQTT 例程需使用匹配的 CoreS3 编程固件和浏览器内核。');
+ Object.assign(profile,{board,unitExample});
} else if (unitExample === RUI3_MODULE_ID) {
requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(RUI3_MODULE_BOARD)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
'browser_attachment_mismatch', 'RUI3 模块需使用匹配的 CoreS3 编程固件和浏览器内核。');
profile.board = RUI3_MODULE_BOARD;
profile.unitExample = unitExample;
- } else if (unitExample === FINGERPRINT2_ID) {
- requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(FINGERPRINT2_BOARD)
+ } else if ([FINGER_ID,FINGERPRINT2_ID].includes(unitExample)) {
+ const board = unitExample === FINGER_ID ? FINGER_BOARD : FINGERPRINT2_BOARD;
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(board)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
- 'browser_attachment_mismatch', 'Fingerprint2 需使用匹配的 CoreS3 编程固件和浏览器内核。');
- profile.board = FINGERPRINT2_BOARD;
- profile.unitExample = unitExample;
+ 'browser_attachment_mismatch', '指纹附件需使用匹配的 CoreS3 编程固件和浏览器内核。');
+ Object.assign(profile,{board,unitExample});
} else if (unitExample === SERVOS8_ID) {
requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(SERVOS8_BOARD)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
@@ -570,12 +642,12 @@ export class PublicBrowserRuntime {
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
'browser_attachment_mismatch', 'Module LLM 需使用匹配的 CoreS3 编程固件和浏览器内核。');
profile.unitExample = unitExample;
- } else if (unitExample === AUDIO_MODULE_ID) {
- requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(AUDIO_MODULE_BOARD)
+ } else if ([AUDIO_MODULE_ID,PDM_UNIT_ID].includes(unitExample)) {
+ const board = unitExample === PDM_UNIT_ID ? PDM_UNIT_BOARD : AUDIO_MODULE_BOARD;
+ requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(board)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
- 'browser_attachment_mismatch', 'Audio Module 需使用匹配的 CoreS3 编程固件和浏览器内核。');
- profile.board = AUDIO_MODULE_BOARD;
- profile.unitExample = unitExample;
+ 'browser_attachment_mismatch', '音频附件需使用匹配的 CoreS3 编程固件和浏览器内核。');
+ Object.assign(profile,{board,unitExample});
} else if (env) {
requireValue(profile.deviceId === 'cores3' && this.availableProfiles?.includes(env)
&& firmwareInputSha256 === QRCODE_MODULE_FIRMWARE,
@@ -689,7 +761,17 @@ export class PublicBrowserRuntime {
if (networkFixture===TCP_SERVER_EXAMPLE_ID) worker.postMessage({op:'review-server'});
else if (networkFixture===EASY_TCP_SERVER_EXAMPLE_ID) worker.postMessage({op:'review-server',mode:'easy-tcp'});
else if (networkFixture===MODBUS_TCP_SERVER_EXAMPLE_ID) worker.postMessage({op:'review-server',mode:'modbus'});
- else if (usesExampleStation(networkFixture)) worker.postMessage({op:'review-tcp',mode:networkFixture});
+ else if (networkFixture===LABEL_PLUS_EXAMPLE_ID) {
+ const source=networkFixtureSource(networkFixture);
+ const asset=await loadVerifiedRuntimeAsset(source.url,{
+ signal:this.controller.signal,fetchImpl:this.fetchImpl,
+ expectedSha256:source.sha256,expectedBytes:source.bytes,maxBytes:source.bytes,
+ });
+ active();
+ const address=labelPlusEndpoint(new TextDecoder('utf-8',{fatal:true}).decode(asset.bytes));
+ requireValue(address, 'browser_attachment_mismatch', '官方 LabelPlus 例程缺少可用的虚拟对端。');
+ worker.postMessage({op:'review-tcp',mode:networkFixture,address});
+ } else if (usesExampleStation(networkFixture)) worker.postMessage({op:'review-tcp',mode:networkFixture});
if (arduinoRtc) worker.postMessage({op:'wifi',spec:ARDUINO_RTC_WIFI});
if (profile.camera) await this.queueInput({t:'camera-pattern',enabled:1});
requireValue((await this.ask('started', {op:'start',appDirect:false})).started, 'browser_boot_failed', '客体启动失败,请查看串口。'); active();
@@ -843,14 +925,23 @@ export class PublicBrowserRuntime {
const t = 'cap-radio-frame';
const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,frameHex:event.frameHex})});
return {accepted:reply.ok === true,delivery:'radio-packet'};
- } else if (event?.type === 'fingerprint2-input') {
- const {action} = event;
- requireValue(this.status === 'running' && this.profile.unitExample === FINGERPRINT2_ID
+ } else if (event?.type === 'finger-input' || event?.type === 'fingerprint2-input') {
+ const {type:t,action} = event;
+ const attachment = t === 'finger-input' ? FINGER_ID : FINGERPRINT2_ID;
+ requireValue(this.status === 'running' && this.profile.unitExample === attachment
&& ['sample-a','sample-b','release'].includes(action),
'invalid_fingerprint2_action', '请选择当前会话的合成指纹样本。');
- const t = event.type;
const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,action})});
return {accepted:reply.ok === true,delivery:'uart-peer'};
+ } else if (event?.type === 'drive-module-sample') {
+ const {type:t,step,rpm,frequency} = event;
+ const uint16 = value=>Number.isInteger(value) && value >= 0 && value <= 65535;
+ const valid = this.profile?.unitExample === 'dc-motor-module'
+ ? Number.isInteger(step) && step >= -32768 && step <= 32767 && rpm === undefined && frequency === undefined
+ : this.profile?.unitExample === 'fan-module' && step === undefined && uint16(rpm) && uint16(frequency);
+ requireValue(this.status === 'running' && valid, 'invalid_drive_sample', '请为当前 M-Bus 模块设置有效的反馈值。');
+ const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,step,rpm,frequency})});
+ return {accepted:reply.ok === true};
} else if (event?.type === 'usb-module-input') {
const {type:t,action,value} = event;
requireValue(this.status === 'running' && isUsbModuleInput(this.profile.unitExample,action,value),
@@ -883,6 +974,21 @@ export class PublicBrowserRuntime {
'invalid_cores3_sensor_sample', '请选择本例程的板载传感器采样。');
const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,sensor,sample})});
return {accepted:reply.ok === true};
+ } else if (event?.type === 'uart-example-sample') {
+ const {type:t,sample} = event;
+ const isEcg = this.profile.unitExample === ECG_MODULE_ID;
+ const validSample = isEcg ? ['sample-a','sample-b'].includes(sample)
+ : this.profile.unitExample === ASR_UNIT_ID && ['hello','up'].includes(sample);
+ requireValue(this.status === 'running' && validSample, isEcg ? 'invalid_ecg_sample' : 'invalid_asr_sample',
+ isEcg ? '请选择 ECG Module 的采样。' : '请选择已连接的 ASR Unit 的命令样本。');
+ const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,sample})});
+ return {accepted:reply.ok === true};
+ } else if (event?.type === 'weight-unit-sample') {
+ const {type:t,raw} = event;
+ requireValue(this.status === 'running' && this.profile.unitExample === 'weight-unit' && isWeightSample(raw),
+ 'invalid_weight_sample', '请在 Weight Unit 例程中输入有符号 24 位 ADC 整数。');
+ const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,raw})});
+ return {accepted:reply.ok === true};
} else if (event?.type === 'dof-sample') {
const {sample} = event;
requireValue(this.status === 'running' && dofBoard(this.profile.unitExample) && ['a','b'].includes(sample),
@@ -905,6 +1011,31 @@ export class PublicBrowserRuntime {
const t = 'hall-magnet';
const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,action})});
return {accepted:reply.ok === true};
+ } else if (event?.type === 'instrument-sample') {
+ const {sample} = event;
+ requireValue(this.status === 'running' && instrumentSamplesAvailable(this.profile.unitExample)
+ && ['a','b'].includes(sample), 'invalid_instrument_sample', '请选择采样 A 或 B。');
+ const t = event.type;
+ const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,sample})});
+ return {accepted:reply.ok === true};
+ } else if (event?.type === 'rs232-line') {
+ const {line} = event;
+ requireValue(this.status === 'running' && this.profile.unitExample === 'rs232-module'
+ && typeof line === 'string' && /^[ -~]{1,64}$/.test(line),
+ 'invalid_rs232_line', '请输入 1 到 64 个可打印 ASCII 字符。');
+ const t = event.type;
+ const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,line})});
+ return {accepted:reply.ok === true};
+ } else if (event?.type === 'nbiot-mqtt-message' || event?.type === 'mqtt-unit-message') {
+ const {message} = event;
+ const attachment = serialMqttAttachment(this.profile.unitExample);
+ requireValue(this.status === 'running' && attachment?.event === event.type
+ && typeof message === 'string' && /^[ -~]{1,64}$/.test(message)
+ && (event.type !== 'mqtt-unit-message' || !message.includes('"')),
+ 'invalid_serial_mqtt_message', '请输入此 MQTT 例程接受的 1 到 64 个可打印 ASCII 字符。');
+ const t = event.type;
+ const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,message})});
+ return {accepted:reply.ok === true};
} else if (event?.type === 'rui3-payload') {
const {payload} = event;
requireValue(this.status === 'running' && this.profile.unitExample === RUI3_MODULE_ID
@@ -961,6 +1092,12 @@ export class PublicBrowserRuntime {
const t = 'cardkb-key';
const reply = await this.ask(t,{op:'text',data:JSON.stringify({t,key})});
return {accepted:reply.ok === true};
+ } else if (event?.type === 'review-http-data') {
+ const {type,payload} = event;
+ requireValue(this.receipt.networkFixture === LABEL_PLUS_EXAMPLE_ID && typeof payload === 'string'
+ && /^[A-Za-z0-9 -]{1,32}$/.test(payload), 'invalid_http_fixture_data', '请输入 1 到 32 个字母、数字、空格或连字符。');
+ const reply = await this.ask(type,{op:type,data:payload});
+ return {accepted:reply.ok === true};
} else if (event?.type === 'review-server-send') {
const {payload} = event;
const fixture=this.receipt.networkFixture;
diff --git a/platform/web/public-display-unit-examples.js b/platform/web/public-display-unit-examples.js
new file mode 100644
index 000000000..67c0ae576
--- /dev/null
+++ b/platform/web/public-display-unit-examples.js
@@ -0,0 +1,64 @@
+const root = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
+
+const displays = {
+ glass: {
+ name:'GLASS', path:'unit/glass/cores3_glass_example.py', width:128, height:64, bytes:1067,
+ sha256:'da89f78e176ccfb18c181fd45d747f27e074627fb507e0b21d3d07ebcc3de3ee',
+ },
+ glass2: {
+ name:'GLASS2', path:'unit/glass2/cores3_glass2_example.py', width:128, height:64, bytes:1075,
+ sha256:'7ddc3c43ca010b15e4ba4ba030666e95a02d4c95469ca6e633f1075ed9bc46cf',
+ },
+ 'mini-oled': {
+ name:'MiniOLED', path:'unit/minioled/cores3_minioled_example.py', width:72, height:40, bytes:1086,
+ sha256:'e7dbcdba44e6bfbd1b4ae2e126d99082e75f815f8a7018aa4594acbb8887593d',
+ },
+ 'lcd-unit': {
+ name:'LCD', path:'unit/lcd/cores3_lcd_example.py', width:135, height:240, bytes:1038, format:'rgb565le',
+ sha256:'1e8ab0e965823995a84c440b743c1c7fa2bc2fca82e597d3a7b498c67012dbc6',
+ },
+ oled: {
+ name:'OLED', path:'unit/oled/cores3_oled_example.py', width:64, height:128, bytes:1044,
+ sha256:'551dae9fc2e919894c87e830749cc79524edbbe3bfbd4f3a44b5af23110abc03',
+ },
+};
+
+export function displayUnitExample(id) {
+ const row = Object.hasOwn(displays, id) ? displays[id] : null;
+ return row && {...row, attachment:id, board:`m5stack-cores3+${id}`, url:root+row.path};
+}
+
+export function hasDisplayUnitFrame(display, state) {
+ if (state?.width !== display.width || state.height !== display.height) return false;
+ const pixels = display.width * display.height;
+ if (display.format === 'rgb565le') {
+ const frame = state['frame-rgb565le'];
+ return typeof frame === 'string' && frame.length === pixels * 4 && /^[0-9a-f]+$/.test(frame);
+ }
+ return Array.isArray(state.frame) && state.frame.length === pixels / 8 &&
+ state.frame.every(byte => Number.isInteger(byte) && byte >= 0 && byte <= 255);
+}
+
+export function drawDisplayUnitFrame(canvas, {width,height,frame,'frame-rgb565le':rgb565le}) {
+ canvas.width = width;
+ canvas.height = height;
+ const ctx = canvas.getContext('2d');
+ const image = ctx.createImageData(width,height);
+ for (let pixel=0; pixel> 11) * 255 / 31;
+ image.data[rgb+1] = ((color >> 5) & 63) * 255 / 63;
+ image.data[rgb+2] = (color & 31) * 255 / 31;
+ } else {
+ const level = frame[pixel>>3] & (1 << (pixel&7)) ? 255 : 0;
+ image.data[rgb] = image.data[rgb+1] = image.data[rgb+2] = level;
+ }
+ image.data[rgb+3] = 255;
+ }
+ ctx.putImageData(image,0,0);
+}
diff --git a/platform/web/public-drive-module-examples.js b/platform/web/public-drive-module-examples.js
new file mode 100644
index 000000000..8ae39fe04
--- /dev/null
+++ b/platform/web/public-drive-module-examples.js
@@ -0,0 +1,22 @@
+const root = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/module/';
+
+const examples = {
+ "dc-motor-module": {
+ "name": "DC Motor Module",
+ "file": "dc_motor/cores3_dc_motor_module_speed_control.py",
+ "sha256": "00f1c645f961dc11d0194d45661a4cd90a02e32c4167256973ef65e14384e43d",
+ "bytes": 2494
+ },
+ "fan-module": {
+ "name": "Fan Module",
+ "file": "fan/fan_cores3_example.py",
+ "sha256": "4b0c58fa15d372b542e96ed6afc387d8641a950b6031b31deec9d3fa3c7573ae",
+ "bytes": 1899
+ }
+};
+
+export function driveModuleExample(id) {
+ if (!Object.hasOwn(examples,id)) return null;
+ const example=examples[id];
+ return {...example,attachment:id,board:`m5stack-cores3+${id}`,url:root+example.file};
+}
diff --git a/platform/web/public-fingerprint2-examples.js b/platform/web/public-fingerprint2-examples.js
index 7d21d47c6..8509fff39 100644
--- a/platform/web/public-fingerprint2-examples.js
+++ b/platform/web/public-fingerprint2-examples.js
@@ -1,8 +1,15 @@
export const FINGERPRINT2_ID = 'fingerprint2';
export const FINGERPRINT2_BOARD = 'm5stack-cores3+fingerprint2';
+export const FINGER_ID = 'finger-unit';
+export const FINGER_BOARD = 'm5stack-cores3+finger-unit';
const source = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/unit/fingerprint2/';
const unit = { attachment:FINGERPRINT2_ID, board:FINGERPRINT2_BOARD };
const examples = new Map([
+ [FINGER_ID, {
+ attachment:FINGER_ID, board:FINGER_BOARD, name:'CoreS3 Finger Unit',
+ url:new URL('../finger/cores3_finger_example.py',source).href, bytes:4448,
+ sha256:'96d8c1726b262057c56e77977e9b8607fa30b072bc7e8c3fa078f52b0084a4ac',
+ }],
['fingerprint2-basic', {
...unit, name:'Fingerprint2 基础', url:source+'m5cores3_fp2_basic_example.py', bytes:9422,
sha256:'57407fa13b60d2d97eb0cf8fc5c78b78275089c81a62971636d773623b7d1919',
diff --git a/platform/web/public-instrument-examples.js b/platform/web/public-instrument-examples.js
new file mode 100644
index 000000000..63dc8eb2e
--- /dev/null
+++ b/platform/web/public-instrument-examples.js
@@ -0,0 +1,24 @@
+const source='https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
+const examples=Object.freeze({
+ 'module-16340': {
+ name:'CoreS3 16340 Battery Module', path:'module/ina226/base16340_cores3_example.py',
+ bytes:1755, sha256:'fcdb7e833ad790d1543109ec1895a6075fc22b93b050cafb72dc4810c7c742d0',
+ },
+ 'pps-module': {
+ name:'CoreS3 PPS Module', path:'module/pps/cores3_pps_example.py',
+ bytes:1744, sha256:'6e132f2292354735b701d323d70c426bb6173a07da996aa4951881e16e7957d5',
+ },
+ 'rs232-module': {
+ name:'CoreS3 RS232 Receive', path:'module/rs232/cores3_rs232_rx_example.py',
+ bytes:990, sha256:'642c92bd17a646553739a7a7d88ac749692b1dad85143c47c6579c7d722601c6',
+ },
+});
+
+export function instrumentExample(id) {
+ const row=Object.hasOwn(examples,id)?examples[id]:null;
+ return row&&{...row,attachment:id,board:'m5stack-cores3+'+id,url:source+row.path};
+}
+
+export function instrumentSamplesAvailable(id) {
+ return id==='module-16340'||id==='pps-module';
+}
diff --git a/platform/web/public-module-radio-examples.js b/platform/web/public-module-radio-examples.js
index c2073766f..fe8ceff2c 100644
--- a/platform/web/public-module-radio-examples.js
+++ b/platform/web/public-module-radio-examples.js
@@ -21,6 +21,26 @@ const examples = {
"bytes": 3159,
"sha256": "c3fa10646051d60b8adace8e436c3c32bbb8035d26acbe8466a6960b0b1e58e0"
},
+ "lora868-sx1276-module-tx": {
+ "name": "LoRa868 Module (SX1276)",
+ "attachment": "lora868-sx1276-module",
+ "board": "m5stack-cores3+lora868-sx1276",
+ "protocol": "sx1276",
+ "role": "tx",
+ "path": "module/lora/cores3_lora868_tx_example.py",
+ "bytes": 1565,
+ "sha256": "bba0bfcdadcaf75c75a210b08ab79b1638eb8b4146da0b48e8481c9d37a2f367"
+ },
+ "lora868-sx1276-module-rx": {
+ "name": "LoRa868 Module (SX1276)",
+ "attachment": "lora868-sx1276-module",
+ "board": "m5stack-cores3+lora868-sx1276",
+ "protocol": "sx1276",
+ "role": "rx",
+ "path": "module/lora/cores3_lora868_rx_example.py",
+ "bytes": 1765,
+ "sha256": "b684aa46a6fe79c6dd56ce565ec969bee3d0029ae6f4eebcf17f5e56f2998779"
+ },
"lora868-v12-module-tx": {
"name": "LoRa868 V1.2 Module",
"attachment": "lora868-v12-module",
diff --git a/platform/web/public-mqtt-unit-examples.js b/platform/web/public-mqtt-unit-examples.js
new file mode 100644
index 000000000..910a8c9dd
--- /dev/null
+++ b/platform/web/public-mqtt-unit-examples.js
@@ -0,0 +1,33 @@
+import { nbiotBoard } from './public-nbiot-examples.js';
+
+const root = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
+const examples = {
+ "mqtt-unit": {
+ "name": "MQTT Unit",
+ "attachment": "mqtt-unit",
+ "path": "unit/mqtt/mqtt_demo.py",
+ "bytes": 990,
+ "sha256": "7e059096364a1fb95c972bab9de65545c836e67f58c5ba1888e845d324fabe21"
+ },
+ "mqttpoe-unit": {
+ "name": "MQTTPoE Unit",
+ "attachment": "mqttpoe-unit",
+ "path": "unit/mqtt_poe/mqttpoe_demo.py",
+ "bytes": 1029,
+ "sha256": "96ba871c3497c187ca706da47feec49dc6118fb2c8e67ffb529359727fcf7814"
+ }
+};
+
+export function serialMqttAttachment(attachment) {
+ const board = nbiotBoard(attachment);
+ if (board) return {board, topic:'testtopic/a', event:'nbiot-mqtt-message'};
+ if (Object.hasOwn(examples,attachment)) {
+ return {board:`m5stack-cores3+${attachment}`, topic:'SubTopic', event:'mqtt-unit-message'};
+ }
+ return null;
+}
+
+export function mqttUnitExample(id) {
+ const row = Object.hasOwn(examples,id) ? examples[id] : null;
+ return row && {...row, board:serialMqttAttachment(id).board, url:root + row.path};
+}
diff --git a/platform/web/public-nbiot-examples.js b/platform/web/public-nbiot-examples.js
new file mode 100644
index 000000000..48bbb0b51
--- /dev/null
+++ b/platform/web/public-nbiot-examples.js
@@ -0,0 +1,24 @@
+const source = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
+const examples = Object.freeze({
+ 'sim7020-unit-mqtt': {
+ name:'NB-IoT Unit MQTT', path:'unit/nbiot/cores3_unit_nbiot_mqtt_example.py', attachment:'sim7020',
+ bytes:1623, sha256:'dc099dba538981e3595843e3ba06fc63aac2df65d3567a0c2b72fbfda6c6965b',
+ },
+ 'sim7020-module-mqtt': {
+ name:'NB-IoT Module MQTT', path:'module/nbiot/cores3_module_nbiot_mqtt_example.py', attachment:'sim7020',
+ bytes:1715, sha256:'dec736bdef287892f4d7c73b173a8bd766abd9b9937e2558ec18b9accf5dc75a',
+ },
+ 'sim7028-unit-mqtt': {
+ name:'NB-IoT2 Unit MQTT', path:'unit/nbiot2/cores3_unit_nbiot2_mqtt_example.py', attachment:'sim7028',
+ bytes:1643, sha256:'b3da8d5d14a5a4e4b8a8ffd2ae6b3b190b621d87df2ea0baad8c3028eaaaf61e',
+ },
+});
+
+export function nbiotBoard(attachment) {
+ return ['sim7020','sim7028'].includes(attachment) ? 'm5stack-cores3+' + attachment : null;
+}
+
+export function nbiotExample(id) {
+ const row = Object.hasOwn(examples,id) ? examples[id] : null;
+ return row && {...row,board:nbiotBoard(row.attachment),url:source + row.path};
+}
diff --git a/platform/web/public-network-fixtures.js b/platform/web/public-network-fixtures.js
index c02867946..43050ff0e 100644
--- a/platform/web/public-network-fixtures.js
+++ b/platform/web/public-network-fixtures.js
@@ -5,6 +5,7 @@ export const MODBUS_TCP_SERVER_EXAMPLE_ID = 'modbus-tcp-server';
export const TCP_SERVER_EXAMPLE_ID = 'tcp-server';
export const EASY_TCP_SERVER_EXAMPLE_ID = 'easy-tcp-server';
const EASY_TCP_CLIENT_EXAMPLE_ID = 'easy-tcp-client';
+export const LABEL_PLUS_EXAMPLE_ID = 'label-plus';
export const MQTT_BASIC_EXAMPLE_ID = 'mqtt-basic';
export const ARDUINO_RTC_EXAMPLE_ID = 'arduino-rtc';
export const ARDUINO_RTC_FIRMWARE = 'cf450835c9b8d88f815272158040afee79f0d88cf32b1f46add9bd783b8ab00d';
@@ -25,15 +26,26 @@ const examples = new Map([
bytes:2936,sha256:'76b52aec85fd69291178449a1a1b069b877acbfbd3915c772fdba5fa4c2ea379'}],
[TCP_SERVER_EXAMPLE_ID,{name:'TCP Server',url:officialSource+'software/tcp/cores3_tcp_server_example.py',
bytes:3141,sha256:'66852604195ea59f24ccc9c5dc33df549a444d9e52dc47e29ad2ba7c98636992'}],
+ [LABEL_PLUS_EXAMPLE_ID,{name:'LabelPlus HTTP',url:officialSource+'widgets/labelplus/cores3_labelplus_example.py',
+ bytes:1283,sha256:'013a27a4c1ac9a693049c42856c650ee49a6bdabd7e668efef524e6197577fb4'}],
[MQTT_BASIC_EXAMPLE_ID,{name:'MQTT Client',url:officialSource+'software/mqtt/cores3_mqtt_basic_example.py',
bytes:4600,sha256:'0242384b10d48a2aa5fcc8a863945f4a4b71c3f90a7be482e12b91bcba91afc2'}],
]);
export function networkFixtureSource(id) { return examples.get(id) || null; }
+export function labelPlusEndpoint(source) {
+ const addresses = [...source.matchAll(/["']http:\/\/([0-9]+(?:\.[0-9]+){3}):8000\/data["']/g)];
+ if (addresses.length !== 1) return null;
+ const address = addresses[0][1].split('.').map(Number);
+ const [first,second] = address;
+ if (address.some(part=>!Number.isInteger(part) || part < 0 || part > 255)
+ || !(first===10 || first===172 && second>=16 && second<=31 || first===192 && second===168)) return null;
+ return address;
+}
export function usesTextTcpPeer(id) {
return id===TCP_SERVER_EXAMPLE_ID || id===EASY_TCP_SERVER_EXAMPLE_ID;
}
export function usesExampleStation(id) {
- return [TCP_CLIENT_EXAMPLE_ID, TCP_SERVER_EXAMPLE_ID, MQTT_BASIC_EXAMPLE_ID,
+ return [TCP_CLIENT_EXAMPLE_ID, TCP_SERVER_EXAMPLE_ID, MQTT_BASIC_EXAMPLE_ID, LABEL_PLUS_EXAMPLE_ID,
MODBUS_TCP_CLIENT_EXAMPLE_ID, MODBUS_TCP_SERVER_EXAMPLE_ID, EASY_TCP_CLIENT_EXAMPLE_ID, EASY_TCP_SERVER_EXAMPLE_ID].includes(id);
}
diff --git a/platform/web/public-oled-unit-examples.js b/platform/web/public-oled-unit-examples.js
deleted file mode 100644
index a1737301b..000000000
--- a/platform/web/public-oled-unit-examples.js
+++ /dev/null
@@ -1,39 +0,0 @@
-const root = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
-
-const displays = {
- glass: {
- name:'GLASS', path:'unit/glass/cores3_glass_example.py', width:128, height:64, bytes:1067,
- sha256:'da89f78e176ccfb18c181fd45d747f27e074627fb507e0b21d3d07ebcc3de3ee',
- },
- glass2: {
- name:'GLASS2', path:'unit/glass2/cores3_glass2_example.py', width:128, height:64, bytes:1075,
- sha256:'7ddc3c43ca010b15e4ba4ba030666e95a02d4c95469ca6e633f1075ed9bc46cf',
- },
- 'mini-oled': {
- name:'MiniOLED', path:'unit/minioled/cores3_minioled_example.py', width:72, height:40, bytes:1086,
- sha256:'e7dbcdba44e6bfbd1b4ae2e126d99082e75f815f8a7018aa4594acbb8887593d',
- },
- oled: {
- name:'OLED', path:'unit/oled/cores3_oled_example.py', width:64, height:128, bytes:1044,
- sha256:'551dae9fc2e919894c87e830749cc79524edbbe3bfbd4f3a44b5af23110abc03',
- },
-};
-
-export function oledUnitExample(id) {
- const row = Object.hasOwn(displays, id) ? displays[id] : null;
- return row && {...row, attachment:id, board:`m5stack-cores3+${id}`, url:root+row.path};
-}
-
-export function drawOledUnitFrame(canvas, {width,height,frame}) {
- canvas.width = width;
- canvas.height = height;
- const ctx = canvas.getContext('2d');
- const image = ctx.createImageData(width,height);
- for (let pixel=0; pixel>3] & (1 << (pixel&7)) ? 255 : 0;
- const rgb = pixel*4;
- image.data[rgb] = image.data[rgb+1] = image.data[rgb+2] = level;
- image.data[rgb+3] = 255;
- }
- ctx.putImageData(image,0,0);
-}
diff --git a/platform/web/public-port-a-examples.js b/platform/web/public-port-a-examples.js
index 394872024..722b209d2 100644
--- a/platform/web/public-port-a-examples.js
+++ b/platform/web/public-port-a-examples.js
@@ -1,6 +1,20 @@
const root = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
const examples = {
+ "bldc-driver": {
+ "name": "BLDC Driver",
+ "attachment": "bldc-driver",
+ "path": "unit/bldc_driver/cores3_bldc_driver_example.py",
+ "bytes": 1629,
+ "sha256": "341a61ad46fae8340fa434773bc56444ceebfbe336d57bef73f11b8bb5134952"
+ },
+ "hbridge": {
+ "name": "HBridge",
+ "attachment": "hbridge",
+ "path": "unit/hbridge/cores3_hbridge_motor_control.py",
+ "bytes": 1671,
+ "sha256": "3bbfeaafddbdd150924b3149266d0a02370a6a2fc172840715019a13f013da85"
+ },
"byteswitch": {
"name": "ByteSwitch",
"attachment": "byteswitch",
diff --git a/platform/web/public-port-b-examples.js b/platform/web/public-port-b-examples.js
index d46063d3f..6cde193e7 100644
--- a/platform/web/public-port-b-examples.js
+++ b/platform/web/public-port-b-examples.js
@@ -30,6 +30,13 @@ const examples = {
"adc": true,
"output": "使能 GPIO9"
},
+ "rf433t-unit": {
+ "name": "RF433T",
+ "file": "rf433t/cores3_rf433t_send_example.py",
+ "sha256": "57b0534d1d4b31f9b524607b43b739dbb44f23accd62cc63286844adffa7c35c",
+ "bytes": 1559,
+ "rmt": true
+ },
"flashlight-unit": {
"name": "FlashLight",
"file": "flashlight/cores3_flashlight_example.py",
diff --git a/platform/web/public-serial-sensor-examples.js b/platform/web/public-serial-sensor-examples.js
new file mode 100644
index 000000000..105fd5309
--- /dev/null
+++ b/platform/web/public-serial-sensor-examples.js
@@ -0,0 +1,28 @@
+const root = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
+const sources = {
+ 'uhf-rfid-unit': {
+ name:'UHF-RFID Unit', path:'unit/uhf_rfid/cores3_uhf_rfid_example.py', bytes:1018,
+ sha256:'f775b33324253d7c2fca66be4ee9a35858f048836553b9395d98185b2acea879',
+ },
+ 'weight-unit': {
+ name:'Weight Unit', path:'unit/weight/weight_cores3_example.py', bytes:1107,
+ sha256:'250424223330169696c47a3a11063d9b0aab8cf31794e7880c071b70a30f9cf4',
+ },
+ 'zigbee-unit': {
+ name:'Zigbee Unit', path:'unit/zigbee/cores3_zigbee_tx_example.py', bytes:1150, uart:1,
+ sha256:'338745add8d306ea0b1d3a0222b59bc9df40c8ef51627d52c4073fa794905cef',
+ },
+ 'zigbee-module': {
+ name:'Zigbee Module', path:'module/zigbee/cores3_zigbee_tx_example.py', bytes:1257, uart:2,
+ sha256:'2760cb81e375bb6bd4064b624568833d6fc291af861413c70b1f9fd1c0af7b1b',
+ },
+};
+
+export function serialSensorExample(id) {
+ const row = Object.hasOwn(sources,id) ? sources[id] : null;
+ return row && {...row,attachment:id,board:`m5stack-cores3+${id}`,url:root+row.path};
+}
+
+export function isWeightSample(raw) {
+ return Number.isInteger(raw) && raw >= -8388608 && raw <= 8388607;
+}
diff --git a/platform/web/public-uart-unit-examples.js b/platform/web/public-uart-unit-examples.js
new file mode 100644
index 000000000..105f248c8
--- /dev/null
+++ b/platform/web/public-uart-unit-examples.js
@@ -0,0 +1,21 @@
+export const ASR_UNIT_ID = 'asr-unit';
+export const ECG_MODULE_ID = 'ecg-module';
+const base = 'https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/examples/';
+const sources = new Map([
+ ['laser-tx',['Laser TX Unit','unit/laser/lasertx_cores3_example.py',1211,
+ 'b444e9e21d98b97b7033b619a93f32bdd0352a36b28ffee75abffb102543be6d']],
+ ['midi-unit',['MIDI Unit','unit/midi/midi_cores3_example.py',1232,
+ '2e32830e35e28637e1a1544b766a3fa1a7d5588482795cc939bf7c3a26e39cf3']],
+ ['synth-unit',['Synth Unit','unit/synth/synth_cores3_example.py',923,
+ '34fa01475a2d6885b75f60135dd6d55d59d0fe7457cc6042050929cd763e0818']],
+ [ASR_UNIT_ID,['ASR Unit','unit/asr/asr_cores3_example.py',2017,
+ '0fa39f33b6e300c569ed9c35fc8085738c0412b88a3e2fc8e88276693da2f944']],
+ [ECG_MODULE_ID,['ECG Module','module/ecg/cores3_ecg_module_base_example.py',3415,
+ '69f251d984242f07c2d2360e31186ff0116a2d21052d6d7b608b34ca1f216705']],
+].map(([attachment,[name,path,bytes,sha256]]) => [attachment,Object.freeze({
+ name, attachment, board:'m5stack-cores3+'+attachment, url:base+path, bytes, sha256,
+})]));
+
+export function uartUnitExample(id) {
+ return sources.get(id) || null;
+}
diff --git a/platform/web/public.js b/platform/web/public.js
index 92302d78d..45423c232 100644
--- a/platform/web/public.js
+++ b/platform/web/public.js
@@ -4,24 +4,30 @@ import {composeUIFlowWorkbenchFirmware,loadUIFlowWorkbenchProfiles,getUIFlowWork
import {openQemuPeerPair,newQemuPeerCode} from './public-qemu-peer-pair.js';
import {capGpsExample} from './public-cap-gps-examples.js';
import {GNSS_EXAMPLE_ID,supportsQemuGnssWorkbench} from './public-qemu-gnss-example.js';
-import {MODBUS_TCP_SERVER_EXAMPLE_ID,NETWORK_STATION_PREP,networkFixtureSource,usesExampleStation,usesTextTcpPeer} from './public-network-fixtures.js';
+import {MODBUS_TCP_SERVER_EXAMPLE_ID,LABEL_PLUS_EXAMPLE_ID,NETWORK_STATION_PREP,networkFixtureSource,usesExampleStation,usesTextTcpPeer} from './public-network-fixtures.js';
import {QRCODE_MODULE_ID,QRCODE_MODULE_BOARD,QRCODE_MODULE_FIRMWARE,qrcodeModuleExample} from './public-qrcode-module.js';
-import {FINGERPRINT2_ID,fingerprint2Example} from './public-fingerprint2-examples.js';
+import {FINGER_ID,FINGERPRINT2_ID,fingerprint2Example} from './public-fingerprint2-examples.js';
import {SERVOS8_ID,servos8Example} from './public-8servos-examples.js';
import {portAUnitExample} from './public-port-a-examples.js';
import {HALL_EFFECT_ID,SSR_GPIO_ATTACHMENT,gpioUnitExample} from './public-gpio-unit-examples.js';
+import {driveModuleExample} from './public-drive-module-examples.js';
import {usbModuleExample} from './public-usb-module-examples.js';
import {portBUnitExample} from './public-port-b-examples.js';
import {pwmUnitExample} from './public-pwm-unit-examples.js';
import {THERMAL_ID, thermalExample} from './public-thermal-example.js';
+import {ASR_UNIT_ID, ECG_MODULE_ID, uartUnitExample} from './public-uart-unit-examples.js';
import {cores3SensorExample} from './public-cores3-sensor-examples.js';
-import {drawOledUnitFrame, oledUnitExample} from './public-oled-unit-examples.js';
+import {drawDisplayUnitFrame, displayUnitExample} from './public-display-unit-examples.js';
+import {serialSensorExample} from './public-serial-sensor-examples.js';
import {dofBoard,dofExample} from './public-dof-examples.js';
import {moduleRadioExample,moduleRadioAttachment} from './public-module-radio-examples.js';
+import {instrumentExample,instrumentSamplesAvailable} from './public-instrument-examples.js';
+import {nbiotExample} from './public-nbiot-examples.js';
+import {mqttUnitExample,serialMqttAttachment} from './public-mqtt-unit-examples.js';
import {RUI3_MODULE_ID,rui3ModuleExample} from './public-rui3-module-example.js';
import {MINI_SCALES_ID,miniScalesExample} from './public-mini-scales.js';
import {MODULE_LLM_EXAMPLE_ID,moduleLlmExample} from './public-module-llm-example.js';
-import {AUDIO_MODULE_ID,audioModuleExample} from './public-audio-module.js';
+import {AUDIO_MODULE_ID,PDM_UNIT_ID,audioModuleExample} from './public-audio-module.js';
import {envBoard,envExample} from './public-env-examples.js';
import {facesModuleExample} from './public-faces-module.js';
import {MODBUS_RTU_FIRMWARE,modbusRtuExample} from './public-modbus-rtu.js';
@@ -160,7 +166,7 @@ function availableDualKmeterSource(profile, workbench) {
return dualKmeterExampleSource(getQemuBrowserProfile('cores3',state.qemuProfiles),workbench,state.config.browser_dual_kmeter_example);
}
function documentedAttachmentExample(id) {
- return portAUnitExample(id) || moduleRadioExample(id) || usbModuleExample(id) || oledUnitExample(id) || pwmUnitExample(id) || portBUnitExample(id) || dofExample(id) || thermalExample(id) || cores3SensorExample(id) || audioModuleExample(id) || gpioUnitExample(id) || rui3ModuleExample(id) || capGpsExample(id) || moduleLlmExample(id) || fingerprint2Example(id) || miniScalesExample(id) || servos8Example(id) || envExample(id) || facesModuleExample(id) || qrcodeModuleExample(id);
+ return mqttUnitExample(id) || nbiotExample(id) || instrumentExample(id) || uartUnitExample(id) || portAUnitExample(id) || moduleRadioExample(id) || driveModuleExample(id) || usbModuleExample(id) || displayUnitExample(id) || pwmUnitExample(id) || portBUnitExample(id) || serialSensorExample(id) || dofExample(id) || thermalExample(id) || cores3SensorExample(id) || audioModuleExample(id) || gpioUnitExample(id) || rui3ModuleExample(id) || capGpsExample(id) || moduleLlmExample(id) || fingerprint2Example(id) || miniScalesExample(id) || servos8Example(id) || envExample(id) || facesModuleExample(id) || qrcodeModuleExample(id);
}
function availableAttachmentSource(profile, workbench, id) {
const example=documentedAttachmentExample(id);
@@ -416,7 +422,7 @@ function updateBrowserUnitExample(run) {
$(id).disabled=facesDisabled;
$(id).setAttribute('aria-pressed',String(!!(faces&&run.facesButtons?.[button])));
}
- const fingerprint=live&&kind===FINGERPRINT2_ID;
+ const fingerprint=live&&[FINGER_ID,FINGERPRINT2_ID].includes(kind);
const fingerprintReady=fingerprint&&controller.status==='running'&&!run.fingerprintPending;
$('browserFingerprintPanel').hidden=!fingerprint;
$('browserFingerprintA').disabled=$('browserFingerprintB').disabled=$('browserFingerprintRelease').disabled=!fingerprintReady;
@@ -432,6 +438,26 @@ function updateBrowserUnitExample(run) {
$('browserHallPanel').hidden=!hall;
$('browserHallPresent').disabled=$('browserHallRemove').disabled=!hall||controller.status!=='running'||!!run?.hallPending;
$('browserHallStatus').textContent=hall?run.hallStatus||'':'';
+ const driveModule=live&&driveModuleExample(kind);
+ const driveState=driveModule&&reading?.kind===kind?reading:null;
+ const motor=driveModule&&kind==='dc-motor-module';
+ $('browserDriveModulePanel').hidden=!driveModule;
+ $('browserDriveEncoderControls').hidden=!motor;
+ $('browserDriveFanControls').hidden=!driveModule||!!motor;
+ $('browserDriveApply').disabled=!driveModule||controller.status!=='running'||!!run?.drivePending;
+ $('browserDriveModuleState').textContent=!driveState?'':motor
+ ? `通道 1 · 速度命令 ${driveState['motor-1-command']} · 计数 ${driveState['encoder-1-count']}`
+ : `风扇 ${driveState.enabled?'开启':'关闭'} · PWM ${driveState['pwm-duty-percent']}% · ${driveState['tach-rpm']} RPM`;
+ if(driveModule){
+ for(const id of ['browserDriveEncoderStep','browserDriveFanRpm','browserDriveFanFrequency']){
+ const input=$(id);
+ if(input.dataset.sessionId!==controller.sessionId){
+ input.dataset.sessionId=controller.sessionId;
+ input.value=input.defaultValue;
+ }
+ }
+ }
+ $('browserDriveModuleStatus').textContent=driveModule?run.driveStatus||'':'';
const usbModule=live&&usbModuleExample(kind);
const moduleState=usbModule&&reading?.kind===kind?reading:null;
const moduleAvailable=usbModule&&controller.status==='running'&&!run.usbModulePending;
@@ -449,6 +475,25 @@ function updateBrowserUnitExample(run) {
? `GPIO 输入 ${moduleState['gpio-in']} · 输出 ${moduleState['gpio-out']}`
: moduleState.configured?'USB 设备已就绪':moduleState.connected?'等待来宾配置 USB 设备':'USB 设备未连接';
$('browserUsbModuleStatus').textContent=usbModule?run.usbModuleStatus||'':'';
+ const serialSensor=live&&serialSensorExample(kind);
+ const weight=serialSensor&&kind==='weight-unit';
+ $('browserSerialSensorPanel').hidden=!serialSensor;
+ $('browserWeightInput').hidden=!weight;
+ $('browserWeightApply').disabled=!weight||controller.status!=='running'||!!run.weightPending;
+ $('browserWeightStatus').textContent=weight?run.weightStatus||'':'';
+ if(serialSensor){
+ const sensorState=reading?.kind===kind?reading:null;
+ const payload=bytes=>String.fromCharCode(...bytes);
+ if(kind==='uhf-rfid-unit') {
+ $('browserSerialSensorState').textContent=sensorState?.inventories
+ ? `标签扫描 ${sensorState.inventories} · 读 ${sensorState.reads} · 写 ${sensorState.writes}`
+ : '等待标签扫描';
+ } else $('browserSerialSensorState').textContent=weight
+ ? (sensorState?.['last-transferred']!=null?`来宾已读取 ADC ${sensorState['last-transferred']}`:'等待 ADC 读数')
+ : sensorState?.configured
+ ? `UART${sensorState.uart} · 单播 ${sensorState.directed} ${payload(sensorState['last-directed'])} · 广播 ${sensorState.broadcasts} ${payload(sensorState['last-broadcast'])}`
+ : '等待来宾配置 Zigbee';
+ }
const portB=live&&portBUnitExample(kind);
const portBState=portB&&reading?.kind===kind?reading:null;
const key=portB&&kind==='key-unit';
@@ -464,6 +509,7 @@ function updateBrowserUnitExample(run) {
const keyColor=led?.length===3?led.map(value=>value.toString(16).padStart(2,'0')).join(''):'';
$('browserPortBUnitState').textContent=!portBState?''
:key?`GPIO8 · ${portBState.pressed?'已按下':'已松开'}${keyColor ? ` · RGB #${keyColor}` : ''}`
+ :portB.rmt?`GPIO9 · ${portBState.frames} 帧 · ${portBState.payload.map(value=>value.toString(16).padStart(2,'0')).join(' ')}`
:portBAdc?`ADC ${portBState['adc-raw']} / 4095${portB.output
? ` · ${portB.output} ${portBState['output-high']?'高电平':'低电平'}` : ''}`
:`GPIO9 · ${portBState['output-high']?'高电平':'低电平'} · 上次脉冲 ${((portBState['last-high-us']??0)/1000).toFixed(1)} ms`;
@@ -477,14 +523,14 @@ function updateBrowserUnitExample(run) {
$('browserPwmUnitState').textContent=pwm&&frequency!=null
? `GPIO ${pwm.pin} · ${frequency.toFixed(1)} Hz · ${high.toFixed(1)} μs${burst!=null?` · ${burst.toFixed(1)} ms`:''}`
: pwm?'等待 PWM 信号':'';
- const oled=live&&oledUnitExample(kind);
- $('browserOledPanel').hidden=!oled;
- if(oled){
- $('browserOledTitle').textContent=oled.name;
+ const displayUnit=live&&displayUnitExample(kind);
+ $('browserOledPanel').hidden=!displayUnit;
+ if(displayUnit){
+ $('browserOledTitle').textContent=displayUnit.name;
const canvas=$('browserOledCanvas');
canvas.hidden=reading?.kind!==kind;
if(!canvas.hidden&&run.oledFrame!==reading){
- drawOledUnitFrame(canvas,reading);
+ drawDisplayUnitFrame(canvas,reading);
run.oledFrame=reading;
}
}
@@ -494,6 +540,21 @@ function updateBrowserUnitExample(run) {
$('browserThermalLeft').disabled=$('browserThermalRight').disabled=!thermal||controller.status!=='running'||!!run.thermalPending;
$('browserThermalStatus').textContent=!thermal?'':run.thermalError
|| (thermalState?.subpages ? `I²C 已读取 ${thermalState.subpages} 个子页` : '等待来宾读取图像');
+ const uartUnit = live && uartUnitExample(kind);
+ const uartState = uartUnit && reading?.kind === kind ? reading : null;
+ const asr = uartUnit && kind === ASR_UNIT_ID;
+ const ecg = uartUnit && kind === ECG_MODULE_ID;
+ $('browserUartUnitPanel').hidden = !uartUnit;
+ $('browserAsrUnitControls').hidden = !asr;
+ $('browserAsrUnitHello').disabled = $('browserAsrUnitUp').disabled = !asr || controller.status !== 'running' || !!run.uartSamplePending;
+ $('browserAsrUnitError').textContent = asr ? run.uartSampleError || '' : '';
+ $('browserEcgModuleControls').hidden = !ecg;
+ $('browserEcgModuleA').disabled = $('browserEcgModuleB').disabled = !ecg || controller.status !== 'running' || !!run.uartSamplePending;
+ $('browserEcgModuleStatus').textContent = ecg ? run.uartSampleError || '' : '';
+ $('browserUartUnitState').textContent = uartState
+ ? 'TX ' + uartState['tx-bytes'] + ' B · RX ' + uartState['rx-bytes'] + ' B' +
+ (uartState['tx-tail-hex'] ? ' · ' + uartState['tx-tail-hex'] : '')
+ : uartUnit ? '等待来宾 UART 数据' : '';
const cores3Sensor=live&&cores3SensorExample(kind);
const sampling=live&&(!!dofBoard(kind)||!!cores3Sensor);
$('browserDofPanel').hidden=!sampling;
@@ -502,19 +563,45 @@ function updateBrowserUnitExample(run) {
$('browserDofA').disabled=$('browserDofB').disabled=!sampling||controller.status!=='running'||!!run?.dofPending;
$('browserDofStatus').textContent=sampling?run.dofStatus||'':'';
const portAUnit=live&&portAUnitExample(kind);
+ const portAInput=portAUnit?.inputLabel;
const unitValue=$('browserPortAUnitValue');
- $('browserPortAUnitPanel').hidden=!portAUnit;
- if(portAUnit&&unitValue.dataset.unit!==kind){
+ $('browserPortAUnitPanel').hidden=!portAInput;
+ if(portAInput&&unitValue.dataset.unit!==kind){
unitValue.dataset.unit=kind;
unitValue.min=portAUnit.minimum;
unitValue.max=portAUnit.maximum;
unitValue.value=portAUnit.defaultValue;
$('browserPortAUnitLabel').textContent=portAUnit.inputLabel;
- } else if(!portAUnit){
+ } else if(!portAInput){
delete unitValue.dataset.unit;
}
- unitValue.disabled=$('browserPortAUnitApply').disabled=!portAUnit||controller.status!=='running'||!!run?.portAUnitPending;
- $('browserPortAUnitStatus').textContent=portAUnit?run.portAUnitStatus||'':'';
+ unitValue.disabled=$('browserPortAUnitApply').disabled=!portAInput||controller.status!=='running'||!!run?.portAUnitPending;
+ $('browserPortAUnitStatus').textContent=portAInput?run.portAUnitStatus||'':'';
+ const instrument=live&&instrumentSamplesAvailable(kind);
+ const instrumentReady=instrument&&controller.status==='running'&&!run.instrumentPending;
+ $('browserInstrumentPanel').hidden=!instrument;
+ $('browserInstrumentSampleA').disabled=$('browserInstrumentSampleB').disabled=!instrumentReady;
+ $('browserInstrumentStatus').textContent=instrument?run.instrumentStatus||'':'';
+ const rs232=live&&kind==='rs232-module';
+ $('browserRs232Panel').hidden=!rs232;
+ $('browserRs232Send').disabled=!rs232||controller.status!=='running'||!!run.rs232Pending;
+ const rs232Line=$('browserRs232Line');
+ if(rs232&&rs232Line.dataset.sessionId!==controller.sessionId){
+ rs232Line.dataset.sessionId=controller.sessionId;
+ rs232Line.value='';
+ }
+ $('browserRs232Status').textContent=rs232?run.rs232Status||'':'';
+ const nbiot=live&&serialMqttAttachment(kind);
+ const subscribed=nbiot&&reading?.kind===kind&&reading.listening;
+ $('browserNbiotPanel').hidden=!nbiot;
+ if(nbiot)$('browserNbiotTopicLabel').textContent=`发布到 ${nbiot.topic}`;
+ const nbiotMessage=$('browserNbiotMessage');
+ if(nbiot&&nbiotMessage.dataset.sessionId!==controller.sessionId){
+ nbiotMessage.dataset.sessionId=controller.sessionId;
+ nbiotMessage.value='';
+ }
+ $('browserNbiotSend').disabled=!subscribed||controller.status!=='running'||!!run?.nbiotPending;
+ $('browserNbiotStatus').textContent=nbiot?run.nbiotStatus||(subscribed?'客体已订阅。':'等待客体订阅。'):'';
const rui3=live&&kind===RUI3_MODULE_ID;
const rui3Listening=rui3&&reading?.kind===RUI3_MODULE_ID&&reading.listening;
const payload=$('browserRui3Payload');
@@ -559,7 +646,7 @@ function updateBrowserUnitExample(run) {
$('browserEnvHumidity').value=$('browserEnvHumidity').defaultValue;
}
$('browserEnvStatus').textContent=env?run.envStatus||'':'';
- panel.hidden=!live||qrcode||!!faces||!!env||!!modbusRtuExample(kind)||usb||scale||fingerprint||moduleLlm||usbModule||oled||pwm||portB||thermal||sampling||portAUnit||kind===AUDIO_MODULE_ID||!!moduleRadioAttachment(kind);
+ panel.hidden=!live||qrcode||!!faces||!!env||!!modbusRtuExample(kind)||usb||scale||fingerprint||moduleLlm||usbModule||driveModule||displayUnit||pwm||portB||serialSensor||thermal||uartUnit||sampling||portAUnit||[AUDIO_MODULE_ID,PDM_UNIT_ID].includes(kind)||!!moduleRadioAttachment(kind);
panel.dataset.kind=live?kind:'';
$('browserExampleDistanceControl').hidden=!live||kind!=='ultrasonic-i2c';
input.disabled=!reading||controller.status!=='running'||!!run?.unitDistancePending;
@@ -749,11 +836,15 @@ function updatePythonControls(currentStatus=state.run?.controller?.status || sta
const replace=pythonBusy&&run.python.canReplace===true&&run.pythonPhase==='running';
const fixtureId=receipt?.networkFixture;
const modbusTcp=fixtureId===MODBUS_TCP_SERVER_EXAMPLE_ID;
- const tcpPeer=active(run)&&run.kind==='browser'&&(usesTextTcpPeer(fixtureId)||modbusTcp);
+ const httpData=fixtureId===LABEL_PLUS_EXAMPLE_ID;
+ const tcpPeer=active(run)&&run.kind==='browser'&&(usesTextTcpPeer(fixtureId)||modbusTcp||httpData);
const tcpInput=$('browserTcpPeerText');
const peerReady=tcpPeer&&pythonBusy&&run.pythonPhase==='running'&&!run.tcpPeerPending;
$('browserTcpPeerPanel').hidden=!tcpPeer;
$('browserTcpPeerTextLabel').hidden=tcpInput.hidden=$('browserTcpPeerSend').hidden=modbusTcp;
+ $('browserTcpPeerTextLabel').textContent=httpData?'虚拟 HTTP 响应数据':'虚拟 TCP 客户端';
+ tcpInput.maxLength=httpData?32:64;
+ $('browserTcpPeerSend').textContent=httpData?'设置数据':'发送';
$('browserTcpPeerSend').disabled=!peerReady||modbusTcp;
$('browserModbusTcpRead').hidden=$('browserModbusTcpWrite').hidden=!modbusTcp;
$('browserModbusTcpRead').disabled=$('browserModbusTcpWrite').disabled=!peerReady||!modbusTcp;
@@ -881,7 +972,7 @@ async function runPython() {
}
function browserAudioExample() {
const profile = browserProfile(state.selected?.id);
- const moduleAudio = source()==='reference'&&reference()?.moduleSource?.attachment===AUDIO_MODULE_ID;
+ const moduleAudio = source()==='reference'&&[AUDIO_MODULE_ID,PDM_UNIT_ID].includes(reference()?.moduleSource?.attachment);
if ((moduleAudio || profile?.referenceSha256 || profile?.speaker) && lane() === 'browser') return 'speaker';
if (state.config.browser_cores3_audio !== true || state.selected?.id !== 'cores3' || lane() !== 'browser') return null;
if (source() === 'reference' && $('referenceExample').value === 'uiflow' && reference()?.sha256 === CORES3_MIC_FIRMWARE_SHA) return 'mic';
@@ -1091,22 +1182,32 @@ function renderDetails() {
: ref?.moduleSource
? (capGpsExample(ref.moduleSource.attachment)?'运行官方例程后,点击地点 A 或 B,查看来宾屏幕的坐标和时间。'
:ref.moduleSource.attachment===MODULE_LLM_EXAMPLE_ID?'运行原语音助手例程后挂接模块,再发送模拟结果。'
- :ref.moduleSource.attachment===FINGERPRINT2_ID?'运行官方例程后使用来宾屏幕选择操作,在提示时放置或移开合成样本。'
+ :[FINGER_ID,FINGERPRINT2_ID].includes(ref.moduleSource.attachment)?'运行官方例程后使用来宾屏幕选择操作,在提示时放置或移开合成样本。'
:ref.moduleSource.attachment===SERVOS8_ID?'运行官方例程后,在工作台查看 I²C 控制的舵机角度或 RGB 颜色。'
:ref.moduleSource.attachment===HALL_EFFECT_ID?'运行官方例程后,放置或移开模拟磁铁,查看来宾画面的颜色变化。'
:ref.moduleSource.attachment===SSR_GPIO_ATTACHMENT?'运行官方例程后,在工作台查看 Port B 的 GPIO 输出。'
+ :driveModuleExample(ref.moduleSource.attachment)?'运行原例程后设置 M-Bus 反馈,查看来宾显示。'
:usbModuleExample(ref.moduleSource.attachment)?'运行例程后,设置 GPIO 输入或连接虚拟 USB 设备。'
+ :portBUnitExample(ref.moduleSource.attachment)?.rmt?'运行原例程后按电源键,查看 Port B 的 RMT 输出。'
:portBUnitExample(ref.moduleSource.attachment)?'运行例程后操作可用的 Port B 输入,查看来宾读数或输出。'
:pwmUnitExample(ref.moduleSource.attachment)?'运行官方例程,查看 Unit 引脚的 PWM 输出。'
- :oledUnitExample(ref.moduleSource.attachment)?'运行官方例程后,在工作台查看通过 I²C 绘制的 Unit 画面。'
+ :displayUnitExample(ref.moduleSource.attachment)?'运行官方例程后,在工作台查看通过 I²C 绘制的 Unit 画面。'
:thermalExample(ref.moduleSource.attachment)?'运行官方例程并切换模拟热源位置。'
+ :ref.moduleSource.attachment===ASR_UNIT_ID?'运行官方例程,发送模拟的 ASR 命令。'
+ :ref.moduleSource.attachment===ECG_MODULE_ID?'运行官方例程后发送采样 A 或 B,查看波形和数值。'
+ :uartUnitExample(ref.moduleSource.attachment)?'运行官方例程,在工作台查看来宾 UART 数据。'
:cores3SensorExample(ref.moduleSource.attachment)?'运行官方例程并切换板载传感器采样。'
+ :serialSensorExample(ref.moduleSource.attachment)?'运行官方例程并查看已连接附件的读写结果。'
:dofBoard(ref.moduleSource.attachment)?'运行官方例程后选择采样 A 或 B,查看来宾的传感器读数。'
:moduleRadioAttachment(ref.moduleSource.attachment)?'在两个标签页运行同一模块的发送端与接收端,使用相同配对码连接。'
- :portAUnitExample(ref.moduleSource.attachment)?'运行官方例程后调整附件输入,查看来宾画面。'
+ :portAUnitExample(ref.moduleSource.attachment)?.inputLabel?'运行官方例程后调整附件输入,查看来宾画面。'
+ :portAUnitExample(ref.moduleSource.attachment)?'运行官方例程,查看来宾的速度显示。'
+ :instrumentSamplesAvailable(ref.moduleSource.attachment)?'选择虚拟采样,查看来宾画面读数。'
+ :ref.moduleSource.attachment==='rs232-module'?'从 RS232 发送一行,查看来宾串口输出。'
+ :serialMqttAttachment(ref.moduleSource.attachment)?'运行官方例程,待客体订阅后发布消息。'
:ref.moduleSource.attachment===RUI3_MODULE_ID?'运行官方例程并触摸来宾屏幕。模块开始监听后,发送一条模拟消息。'
:ref.moduleSource.attachment===MINI_SCALES_ID?'启动后载入并运行官方例程,再调整模拟 ADC 读数。'
- :ref.moduleSource.attachment===AUDIO_MODULE_ID?'启动时打开声音,载入并运行官方例程。录音例程可先导入麦克风 WAV。'
+ :[AUDIO_MODULE_ID,PDM_UNIT_ID].includes(ref.moduleSource.attachment)?'启动时打开声音,载入并运行官方例程。录音例程可先导入麦克风 WAV。'
:envBoard(ref.moduleSource.attachment)?'启动后载入并运行官方例程,再调整温度和湿度。'
:ref.moduleSource.attachment?'启动后载入并运行官方例程,再使用 FACES 模块控件。'
:'启动后载入并运行官方例程,再向模块呈现扫码结果。连续和脉冲模式使用电源键触发。')
@@ -2439,6 +2540,23 @@ for(const [id,action] of [['browserHallPresent','present'],['browserHallRemove',
}
});
}
+$('browserDriveApply').addEventListener('click',async()=>{
+ const run=state.run;
+ if(!active(run)||$('browserDriveApply').disabled)return;
+ run.drivePending=true;
+ updateBrowserUnitExample(run);
+ try {
+ const sample=run.controller.profile.unitExample==='dc-motor-module'
+ ? {step:$('browserDriveEncoderStep').valueAsNumber}
+ : {rpm:$('browserDriveFanRpm').valueAsNumber,frequency:$('browserDriveFanFrequency').valueAsNumber};
+ const {accepted}=await run.controller.input({type:'drive-module-sample',...sample});
+ run.driveStatus=accepted?'已设置反馈':'无法设置反馈';
+ } catch(cause) { run.driveStatus=cause.message; }
+ finally {
+ run.drivePending=false;
+ if(active(run))updateBrowserUnitExample(run);
+ }
+});
for (const [id,action,value] of [
['browserUsbModuleApply','gpio'],['browserUsbModuleConnect','attach'],['browserUsbModuleDisconnect','detach'],
['browserUsbModuleLeft','mouse','left'],['browserUsbModuleRight','mouse','right'],
@@ -2493,6 +2611,40 @@ for (const [id,scene] of [['browserThermalLeft','left'],['browserThermalRight','
}
});
}
+for (const [id, sample] of [
+ ['browserAsrUnitHello', 'hello'], ['browserAsrUnitUp', 'up'],
+ ['browserEcgModuleA', 'sample-a'], ['browserEcgModuleB', 'sample-b'],
+]) {
+ $(id).addEventListener('click', async () => {
+ const run = state.run;
+ if (!active(run) || $(id).disabled) return;
+ run.uartSamplePending = true;
+ run.uartSampleError = '';
+ updateBrowserUnitExample(run);
+ try {
+ const {accepted} = await run.controller.input({type:'uart-example-sample', sample});
+ if (!accepted) run.uartSampleError = '无法发送命令';
+ } catch (cause) { run.uartSampleError = cause.message; }
+ finally {
+ run.uartSamplePending = false;
+ if (active(run)) updateBrowserUnitExample(run);
+ }
+ });
+}
+$('browserWeightApply').addEventListener('click',async()=>{
+ const run=state.run;
+ if(!active(run)||$('browserWeightApply').disabled)return;
+ run.weightPending=true;
+ updateBrowserUnitExample(run);
+ try {
+ const {accepted}=await run.controller.input({type:'weight-unit-sample',raw:$('browserWeightRaw').valueAsNumber});
+ run.weightStatus=accepted?'已设置 ADC 输入':'无法设置 ADC 输入';
+ } catch(cause) { run.weightStatus=cause.message; }
+ finally {
+ run.weightPending=false;
+ if(active(run))updateBrowserUnitExample(run);
+ }
+});
for(const [id,sample] of [['browserDofA','a'],['browserDofB','b']]){
$(id).addEventListener('click',async()=>{
const run=state.run;
@@ -2527,6 +2679,56 @@ $('browserPortAUnitPanel').addEventListener('submit',async(event)=>{
if(active(run))updateBrowserUnitExample(run);
}
});
+for(const [id,sample] of [['browserInstrumentSampleA','a'],['browserInstrumentSampleB','b']]){
+ $(id).addEventListener('click',async()=>{
+ const run=state.run;
+ if(!active(run)||$(id).disabled)return;
+ run.instrumentPending=true;
+ updateBrowserUnitExample(run);
+ try {
+ const {accepted}=await run.controller.input({type:'instrument-sample',sample});
+ run.instrumentStatus=accepted?`已设置采样 ${sample.toUpperCase()}`:'无法设置采样';
+ } catch(cause) { run.instrumentStatus=cause.message; }
+ finally {
+ run.instrumentPending=false;
+ if(active(run))updateBrowserUnitExample(run);
+ }
+ });
+}
+$('browserRs232Panel').addEventListener('submit',async(event)=>{
+ event.preventDefault();
+ const run=state.run;
+ if(!active(run)||$('browserRs232Send').disabled)return;
+ const line=$('browserRs232Line').value;
+ run.rs232Pending=true;
+ updateBrowserUnitExample(run);
+ try {
+ const {accepted}=await run.controller.input({type:'rs232-line',line});
+ run.rs232Status=accepted?'已排队发送。':'暂时无法发送。';
+ } catch(cause) { run.rs232Status=cause.message; }
+ finally {
+ run.rs232Pending=false;
+ if(active(run))updateBrowserUnitExample(run);
+ }
+});
+$('browserNbiotPanel').addEventListener('submit',async(event)=>{
+ event.preventDefault();
+ const run=state.run;
+ if(!active(run)||$('browserNbiotSend').disabled)return;
+ const attachment=serialMqttAttachment(run.controller.profile?.unitExample);
+ if(!attachment)return;
+ const message=$('browserNbiotMessage').value;
+ run.nbiotPending=true;
+ updateBrowserUnitExample(run);
+ try {
+ const {accepted}=await run.controller.input({type:attachment.event,message});
+ run.nbiotStatus=accepted?'已发布到本地对端。':'对端未接受消息。';
+ } catch(cause) { run.nbiotStatus=cause.message; }
+ finally {
+ run.nbiotPending=false;
+ if(active(run))updateBrowserUnitExample(run);
+ }
+});
$('browserRui3Send').addEventListener('click',async()=>{
const run=state.run;
if(!active(run)||$('browserRui3Send').disabled)return;
@@ -2584,7 +2786,8 @@ for(const [id,action] of [['browserFingerprintA','sample-a'],['browserFingerprin
run.fingerprintPending=true;
updateBrowserUnitExample(run);
try{
- const {accepted}=await run.controller.input({type:'fingerprint2-input',action});
+ const type=run.controller.profile.unitExample===FINGER_ID?'finger-input':'fingerprint2-input';
+ const {accepted}=await run.controller.input({type,action});
run.fingerprintStatus=accepted?$(id).textContent:'输入未送达。';
}catch(cause){
run.fingerprintStatus=cause.message;
@@ -2676,8 +2879,12 @@ for (const [id,payload] of [
run.tcpPeerPending=true;
updatePythonControls();
try{
- const {accepted}=await run.controller.input({type:'review-server-send',payload:payload??$('browserTcpPeerText').value});
- run.tcpPeerStatus=accepted?'数据已进入虚拟客户端的发送队列。':'上一条消息尚未完成。';
+ const http=run.controller.receipt.networkFixture===LABEL_PLUS_EXAMPLE_ID;
+ const type=http?'review-http-data':'review-server-send';
+ const {accepted}=await run.controller.input({type,payload:payload??$('browserTcpPeerText').value});
+ run.tcpPeerStatus=http
+ ? (accepted?'下次请求将返回已设置的数据。':'无法设置响应数据。')
+ : (accepted?'数据已进入虚拟客户端的发送队列。':'上一条消息尚未完成。');
}catch(cause){
run.tcpPeerStatus=cause.message;
}finally{
diff --git a/platform/web/uiflow-workbench-resources.json b/platform/web/uiflow-workbench-resources.json
index c9d9a0b62..a7470ba18 100644
--- a/platform/web/uiflow-workbench-resources.json
+++ b/platform/web/uiflow-workbench-resources.json
@@ -25,6 +25,18 @@
"guestPath": "/flash/res/img/default.png",
"distribution": "fetch-only"
},
+ {
+ "id": "cores3-imageplus-default-png",
+ "deviceId": "cores3",
+ "firmwareSha256": "b9fe8334023c1b1f95e7c51b3a63724e621a6789812083848ed3ea7eaa332d49",
+ "exampleSha256": "62761a141904aa6b1a176a2f5439b7263f1d310534c15632550530ea26d6e689",
+ "sourcePackage": "m5stack/uiflow-micropython@a61a29409f09f1f4bebae05e15c4bd6dcc4956b6:m5stack/fs/user/res/img",
+ "url": "https://raw.githubusercontent.com/m5stack/uiflow-micropython/a61a29409f09f1f4bebae05e15c4bd6dcc4956b6/m5stack/fs/user/res/img/default.png",
+ "bytes": 1012,
+ "sha256": "a4ba28e1a06c072f0cc7cbc219e01b1aaa77a5df3a481206612b6c5d46de554b",
+ "guestPath": "/flash/res/img/default.png",
+ "distribution": "fetch-only"
+ },
{
"id": "cores3-m5ui-image-uiflow-jpg",
"deviceId": "cores3",
diff --git a/platform/web/vendor/esp32sim/UPSTREAM.md b/platform/web/vendor/esp32sim/UPSTREAM.md
index 6d8efa195..a8958f65e 100644
--- a/platform/web/vendor/esp32sim/UPSTREAM.md
+++ b/platform/web/vendor/esp32sim/UPSTREAM.md
@@ -1,7 +1,7 @@
# esp32sim browser execution glue
The ES modules and MIT license in this directory come from the
-[M5Stack esp32sim fork](https://github.com/m5agent/esp32sim/tree/d9b9e92bfc924aa2ac10ea540f516a3893fa96c8).
+[M5Stack esp32sim fork](https://github.com/m5agent/esp32sim/tree/d1c930adffaa8d94d03856eb0276df17da668002).
The browser runtime extends the
[backend completion milestone](https://github.com/m5agent/esp32sim/tree/m5-milestone-backend-complete-20261201).
It includes PaperMono and PaperColor timed PM1 input and PaperColor SPI SD.
diff --git a/platform/web/vendor/esp32sim/source.json b/platform/web/vendor/esp32sim/source.json
index be70917e1..2b9596d40 100644
--- a/platform/web/vendor/esp32sim/source.json
+++ b/platform/web/vendor/esp32sim/source.json
@@ -2,14 +2,14 @@
"schema_version": 1,
"repository": "https://github.com/m5agent/esp32sim",
"upstream": "https://github.com/mikroverk/esp32sim",
- "commit": "d9b9e92bfc924aa2ac10ea540f516a3893fa96c8",
+ "commit": "d1c930adffaa8d94d03856eb0276df17da668002",
"license": "MIT",
"scope": "WASM worker, pacing and block JIT glue only; no firmware or ROM",
"files": {
"worker.js": {
"source_path": "web/wasm/worker.js",
- "sha256": "b626f3c51b156b2a0f3f4ccc80ffa736e9f7dc313f4b5b65885db5a06ec9d656",
- "bytes": 23697
+ "sha256": "715d1dd55eddd89b3f5de36cc8b1b42689fab42f12db958437bdf250c8686925",
+ "bytes": 26015
},
"jit.mjs": {
"source_path": "web/wasm/jit.mjs",
diff --git a/platform/web/vendor/esp32sim/worker.js b/platform/web/vendor/esp32sim/worker.js
index 478cfde15..d7a302979 100644
--- a/platform/web/vendor/esp32sim/worker.js
+++ b/platform/web/vendor/esp32sim/worker.js
@@ -30,6 +30,17 @@ const reviewEndpoints = {
'easy-tcp-client': {address:[192,168,8,196],port:8000},
'mqtt-basic': {address:[192,0,2,20],port:1883,name:'broker.emqx.io'},
};
+function reviewEndpoint(mode, address) {
+ if (mode !== 'label-plus') {
+ return Object.hasOwn(reviewEndpoints, mode) ? reviewEndpoints[mode] : null;
+ }
+ if (!Array.isArray(address) || address.length !== 4
+ || !address.every(part => Number.isInteger(part) && part >= 0 && part <= 255)) return null;
+ const [first, second] = address;
+ if (!(first === 10 || first === 172 && second >= 16 && second <= 31
+ || first === 192 && second === 168)) return null;
+ return {address,port:8000};
+}
const emptyBytes = new Uint8Array();
let reviewTcp = null;
function reviewEvent(kind,id,arg=0,bytes=emptyBytes) {
@@ -49,10 +60,29 @@ function* reviewRecords() {
}
}
+function respondReviewHttp(flow, bytes, data) {
+ if (flow.replied || flow.pending.length + bytes.length > 4096) throw new Error('invalid request length');
+ const pending = new Uint8Array(flow.pending.length + bytes.length);
+ pending.set(flow.pending);
+ pending.set(bytes, flow.pending.length);
+ flow.pending = pending;
+ const raw = dec.decode(pending);
+ const end = raw.indexOf('\r\n\r\n');
+ if (end === -1) return null;
+ const requestLine = raw.slice(0, raw.indexOf('\r\n'));
+ if (!/^GET \/data HTTP\/1\.[01]$/.test(requestLine) || end + 4 !== raw.length) {
+ throw new Error('unexpected HTTP request');
+ }
+ flow.replied = true;
+ const body = JSON.stringify({ data });
+ return enc.encode('HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n'
+ + 'Connection: close\r\nContent-Length: ' + body.length + '\r\n\r\n' + body);
+}
+
function drainReviewTcp() {
if (!reviewTcp) return;
const flows = reviewTcp.flows;
- const endpoint = reviewEndpoints[reviewTcp.mode];
+ const {endpoint}=reviewTcp;
for(const {op,port,id,bytes,size} of reviewRecords()){
if(op===1){
if(port!==endpoint.port||size!==4||flows.size>=8||!endpoint.address.every((part,i)=>part===bytes[i])){
@@ -64,6 +94,25 @@ function drainReviewTcp() {
reviewEvent(1,id,4096);
}
}else if(op===2&&flows.has(id)){
+ if (reviewTcp.mode === 'label-plus') {
+ try {
+ const response = respondReviewHttp(flows.get(id), bytes, reviewTcp.httpData);
+ if (response && reviewEvent(3,id,0,response) !== response.length) {
+ throw new Error('restricted HTTP response is full');
+ }
+ reviewEvent(6,id,size);
+ if (response) {
+ reviewTcp.exchanges++;
+ reviewTcp.last = reviewTcp.httpData;
+ reviewEvent(4,id);
+ }
+ } catch {
+ reviewTcp.denied++;
+ flows.delete(id);
+ reviewEvent(5,id);
+ }
+ continue;
+ }
if(reviewTcp.mode==='mqtt-basic'){
try{
const {responses,close}=serveReviewMqtt(flows.get(id),bytes,reviewTcp);
@@ -374,15 +423,22 @@ onmessage = async (ev) => {
}
else if (m.op === 'review-tcp') {
const mode=m.mode||'tcp-client';
- if (!Object.hasOwn(reviewEndpoints,mode)||!wasm.esp32sim_nat_relay || withBytes(enc.encode('ssid=M5ExampleNet'),(p,n)=>wasm.esp32sim_wifi(emu,p,n)) !== 0
+ const endpoint=reviewEndpoint(mode,m.address);
+ if (!endpoint||!wasm.esp32sim_nat_relay || withBytes(enc.encode('ssid=M5ExampleNet'),(p,n)=>wasm.esp32sim_wifi(emu,p,n)) !== 0
|| wasm.esp32sim_nat_relay(emu,3) !== 0) {
setupError ||= 'restricted TCP fixture is unavailable';
} else {
reviewServer=null;
- reviewTcp={mode,flows:new Map(),connects:0,exchanges:0,handshakes:0,subscriptions:0,denied:0,last:null,
+ reviewTcp={mode,endpoint,flows:new Map(),connects:0,exchanges:0,handshakes:0,subscriptions:0,denied:0,last:null,httpData:'M5-A',
modbus:mode==='modbus-tcp-client'?newModbusRegisters():null};
}
}
+ else if (m.op === 'review-http-data') {
+ const accepted = reviewTcp?.mode === 'label-plus'
+ && typeof m.data === 'string' && /^[A-Za-z0-9 -]{1,32}$/.test(m.data);
+ if (accepted) reviewTcp.httpData = m.data;
+ postMessage({text:JSON.stringify({t:'review-http-data',ok:accepted})});
+ }
else if (m.op === 'review-tcp-state') {
const value=reviewTcp&&{connects:reviewTcp.connects,exchanges:reviewTcp.exchanges,
handshakes:reviewTcp.handshakes,subscriptions:reviewTcp.subscriptions,denied:reviewTcp.denied,last:reviewTcp.last};