Skip to content

Commit 503fbdb

Browse files
committed
Merge branch 'public' of https://github.com/rmontrosecbw/moddable into Wiznet_W5500_Ethernet_support
* 'public' of https://github.com/rmontrosecbw/moddable: include manifest file of embedded:io/provider/MCP23X17 Add MCP23017 expander module to manifest add xsCallFunction* Moddable-OpenSource#1536 don't need to import UDP first try at 419 mDNS typings 419 mdns - first time xsbug & mcsim icons for macOS Tahoe xsbug & mcsim icons for macOS Tahoe xsbug & mcsim icons for macOS Tahoe The mbedtls include path in Espressif SDK version 5.5.x is $(IDF_PATH)/components/mbedtls/mbedtls/include/. This is correct in make.esp32.mk but was left out of nmake.esp32.mk Moddable-OpenSource#1534 Fix typo in controller fix default manifest for git repos Moddable-OpenSource#1532 option to use Map for txt record changes from TC53 discussion XS linker; fix byte code map of strings > 64 KB onReady isn't passed connection
2 parents 0f71821 + ec3d810 commit 503fbdb

File tree

30 files changed

+1269
-54
lines changed

30 files changed

+1269
-54
lines changed

contributed/conversationalAI/Controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class Controller extends Behavior {
136136
const service = assets.services[option.service];
137137
const voiceName = option.voiceName;
138138
const voice = service.voices.find(voice => voice.id == voiceName);
139-
persona.voiceName = voice ? voiceName : sercice.defaultVoice;
139+
persona.voiceName = voice ? voiceName : service.defaultVoice;
140140
}
141141
}
142142
}

documentation/xs/XS in C.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
-->
3737

3838
# XS in C
39-
Revised: July 2, 2025
39+
Revised: October 2, 2025
4040

4141
**See end of document for [copyright and license](#license)**
4242

@@ -797,6 +797,10 @@ This section describes the macros related to accessing properties of objects (or
797797
<td><code>xsCall0</code> ... <code>xsCall7, xsmcCall</code></td>
798798
<td>Calls the function referred to by a property of an instance</td>
799799
</tr>
800+
<tr>
801+
<td><code>xsCallFunction0</code> ... <code> xsCallFunction8</code></td>
802+
<td>Calls the function with the provided instance as <code>this</code></td>
803+
</tr>
800804
<tr>
801805
<td><code>xsNew0</code> ... <code>xsNew7, xsmcNew</code></td>
802806
<td>Calls the constructor referred to by a property of an instance</td>
@@ -1344,7 +1348,7 @@ this[0](2, 3)
13441348

13451349
##### In C:
13461350

1347-
```
1351+
```c
13481352
xsCall0(xsGlobal, xsID_foo);
13491353
xsCall1(xsThis, xsID("foo"), xsInteger(1));
13501354
xsCall2(xsThis, 0, xsInteger(2), xsInteger(3));
@@ -1385,6 +1389,43 @@ xsmcCall(xsResult, xsThis, 0, &xsVar(1), &xsVar(2), NULL);
13851389
13861390
***
13871391
1392+
#### xsCallFunction*
1393+
1394+
When you have a reference to a function, you can call the function with one of the `xsCallFunction*` macros (where `*` is `0` through `7`, representing the number of parameter slots passed). If the value is not a reference to a function, the `xsCall*` macro throws an exception.
1395+
1396+
**`xsSlot xsCallFunction0(xsSlot theFunction, xsSlot theThis)`**<BR>
1397+
**`xsSlot xsCallFunction1(xsSlot theFunction, xsSlot theThis, xsSlot theParam0)`**<BR>
1398+
**`xsSlot xsCallFunction2(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1)`**<BR>
1399+
**`xsSlot xsCallFunction3(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2)`**<BR>
1400+
**`xsSlot xsCallFunction4(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3)`**<BR>
1401+
**`xsSlot xsCallFunction5(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3, xsSlot theParam4)`**<BR>
1402+
**`xsSlot xsCallFunction6(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3, xsSlot theParam4, xsSlot theParam5)`**<BR>
1403+
**`xsSlot xsCallFunction7(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3, xsSlot theParam4, xsSlot theParam5, xsSlot theParam6)`**
1404+
1405+
| Arguments | Description |
1406+
| --- | :-- |
1407+
| `theFunction` | A reference to a function instance
1408+
| `theThis` | A reference to the instance that will be `this` when the function is called
1409+
| `theParam0` ... `theParam6` | The parameter slots to pass to the function
1410+
1411+
Returns the result slot of the function
1412+
1413+
##### In ECMAScript:
1414+
1415+
```javascript
1416+
foo.call()
1417+
foo.call(device, 12);
1418+
```
1419+
1420+
##### In C:
1421+
1422+
```c
1423+
xsCallFunction0(xsGet(xsGlobal, xsID_foo), xsGlobal);
1424+
xsCallFunction1(xsThis, xsID("foo"), xsGet(xsGlobal, xsID("device"), xsInteger(12));
1425+
```
1426+
1427+
***
1428+
13881429
<a id="xsnew"></a>
13891430
#### xsNew*
13901431
@@ -1841,7 +1882,7 @@ XS in C defines the following macros to throw specific exceptions.
18411882

18421883
##### In C:
18431884

1844-
```
1885+
```c
18451886
xpt2046 xpt = calloc(1, sizeof(xpt2046Record));
18461887
if (!xpt) xsUnknownError("out of memory");
18471888

examples/io/ble/client/temperaturemonitor/main.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import {GAPClient, GATTClient} from "embedded:io/bluetoothle/central"
2222

23-
const scan = new GAPClient({
23+
new GAPClient({
2424
services: [
2525
"1809" // temperature monitor
2626
],
@@ -41,20 +41,21 @@ function instantiateTemperatureMonitor(address) {
4141
new GATTClient({
4242
address,
4343
security: { // "just works" security configuration
44-
manInTheMiddle: false, /* default – false */
44+
authenticate: false, /* default – false */
4545
bond: false, /* default – false */
4646
display: false, /* or true – default false */
4747
keyboard: false, /* or true or "yes/no" – default false */
48+
lazy: true, /* default – true */
4849
},
4950
onError() {
5051
trace("connection error\n");
5152
},
52-
onPasskey(action, number) {
53+
onPasskey(action, data) {
5354
trace("** implement onPasskey as required by your security settings **\n");
54-
this.replyToPasskey(action, number);
55+
this.replyToPasskey(action, data);
5556
},
5657
onSecured(state) {
57-
trace(`onSecured: encrypted ${state.encrypted}, authenticated ${state.authenticated}, bonded ${state.bonded}\n`);
58+
trace(`onSecured: encrypted ${state.encrypted}, authenticated ${state.authenticated}, keySize ${state.keySize}, bonded ${state.bonded}\n`);
5859

5960
this.getPrimaryServices([ "1809"], (error, services) => {
6061
this.getCharacteristics(services[0], ["2a1c"], (error, characteristics) => {

examples/io/ble/server/heartratemonitor-server/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Timer from "timer";
1717

1818
const deviceName = "419 HRM";
1919

20-
let hrm = new GATTServer({
20+
new GATTServer({
2121
mtu: 128,
2222
services: [
2323
// Generic Access Service
@@ -95,7 +95,7 @@ let hrm = new GATTServer({
9595
}
9696
]
9797
},
98-
// Heart Rate notification frequency – custom service and characteristic
98+
// Heart Rate notification frequency – custom service and characteristic
9999
{
100100
uuid: "cfe6f7f2-16d2-4b7e-9253-a1d1c1577a35",
101101
characteristics: [
@@ -131,7 +131,7 @@ let hrm = new GATTServer({
131131
trace("disconnect!\n");
132132
Timer.clear(connection.heartRateTimer);
133133
},
134-
onReady(connection) {
134+
onReady() {
135135
trace("hrm onReady\n");
136136
this.startAdvertising({
137137
flags: 6,

examples/io/dnssd/main.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2025 Moddable Tech, Inc.
3+
*
4+
* This file is part of the Moddable SDK.
5+
*
6+
* This work is licensed under the
7+
* Creative Commons Attribution 4.0 International License.
8+
* To view a copy of this license, visit
9+
* <http://creativecommons.org/licenses/by/4.0>.
10+
* or send a letter to Creative Commons, PO Box 1866,
11+
* Mountain View, CA 94042, USA.
12+
*
13+
*/
14+
15+
import Timer from "timer";
16+
17+
const mdns = new (device.network.mdns.io)(device.network.mdns);
18+
19+
const claim = mdns.claim({
20+
host: "a-server",
21+
onReady() {
22+
trace(`a-server claimed\n`);
23+
},
24+
onError() {
25+
trace("couldn't claim a-server\n");
26+
}
27+
});
28+
29+
const ad = mdns.advertise({
30+
serviceType: "_http._tcp",
31+
instanceName: "419 Web Server",
32+
host: "a-server",
33+
port: 8080,
34+
txt: new Map([
35+
["home", "/index.html"]
36+
]),
37+
onError(error) {
38+
trace("advertise failed\n");
39+
}
40+
});
41+
ad.counter = 0;
42+
43+
Timer.repeat(() => {
44+
ad.updateTXT(new Map([
45+
["home", "/index.html"],
46+
["counter", (++ad.counter).toString()],
47+
]));
48+
}, 1000)
49+
50+
mdns.discover({
51+
serviceType: "_airplay._tcp",
52+
onFound(service) {
53+
trace(`Found: "${service.name}" on ${service.host} @ ${service.address}:${service.port}\n`);
54+
this.history ??= new Map;
55+
const txt = service.txt ?? new Map;
56+
this.history.set(service.host, txt);
57+
for (const [key, value] of txt)
58+
trace(` ${key}:${value}\n`);
59+
},
60+
onUpdate(service) {
61+
trace(`Update: ${service.name}\n`);
62+
63+
const previous = this.history.get(service.host);
64+
const txt = service.txt ?? new Map;
65+
this.history.set(service.host, txt);
66+
67+
for (const [key, value] of previous) {
68+
if (!txt.has(key))
69+
trace(` removed ${key}:${value}\n`);
70+
}
71+
for (const [key, value] of txt) {
72+
if (!previous.has(key))
73+
trace(` added ${key}:${value}\n`);
74+
}
75+
for (const [key, value] of txt) {
76+
if (previous.has(key) && (previous.get(key) !== txt.get(key)))
77+
trace(` changed ${key} from ${previous.get(key)} to ${txt.get(key)}\n`);
78+
}
79+
},
80+
onLost(service) {
81+
trace(`Lost: ${service.name}\n`);
82+
this.history.delete(service.host);
83+
},
84+
onError(error) {
85+
trace(`failed\n`);
86+
}
87+
});

examples/io/dnssd/manifest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"include": [
3+
"$(MODDABLE)/examples/manifest_base.json",
4+
"$(MODDABLE)/modules/io/manifest.json",
5+
"$(MODULES)/io/dnssd/manifest.json"
6+
],
7+
"modules": {
8+
"*": "./main"
9+
}
10+
}

examples/io/i2c/expander/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*/
1414

15-
import Expander from "embedded:io/provider/MCP23017";
15+
import Expander from "embedded:io/provider/MCP23X17";
1616

1717
const expander = new Expander({
1818
i2c: device.I2C.default,

examples/io/i2c/expander/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"include": [
33
"$(MODDABLE)/examples/manifest_base.json",
4-
"$(MODDABLE)/modules/io/manifest.json"
4+
"$(MODDABLE)/modules/io/manifest.json",
5+
"$(MODDABLE)/modules/io/expander/manifest.json"
56
],
67
"modules": {
78
"*": "./main"

modules/io/ble/client/esp32/bleclient.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ typedef struct {
453453
uint8_t isClose;
454454

455455
uint8_t secure;
456+
uint8_t lazy;
456457

457458
BLEGATTCharacteristicValue values;
458459
uint8_t onReadableInFlight;
@@ -511,7 +512,7 @@ void xs_gattclient_constructor(xsMachine *the)
511512
{
512513
ble_addr_t address;
513514
int mtu = 0;
514-
uint8_t secure = 0, manInTheMiddle = 0, bond = 0, display = 0, keyboard = 0;
515+
uint8_t secure = 0, authenticate = 0, bond = 0, display = 0, keyboard = 0, lazy = 0;
515516

516517
xsmcVars(2);
517518

@@ -540,8 +541,11 @@ void xs_gattclient_constructor(xsMachine *the)
540541
if (xsmcHas(xsArg(0), xsID_security)) {
541542
xsmcGet(xsVar(0), xsArg(0), xsID_security);
542543

543-
xsmcGet(xsVar(1), xsVar(0), xsID_manInTheMiddle);
544-
manInTheMiddle = xsmcTest(xsVar(1));
544+
xsmcGet(xsVar(1), xsVar(0), xsID_authenticate);
545+
authenticate = xsmcTest(xsVar(1));
546+
547+
xsmcGet(xsVar(1), xsVar(0), xsID_lazy);
548+
lazy = xsmcTest(xsVar(1));
545549

546550
xsmcGet(xsVar(1), xsVar(0), xsID_bond);
547551
bond = xsmcTest(xsVar(1));
@@ -561,8 +565,8 @@ void xs_gattclient_constructor(xsMachine *the)
561565
else
562566
keyboard = xsmcTest(xsVar(1));
563567

564-
if (manInTheMiddle && !(keyboard || display))
565-
xsUnknownError("manInTheMiddle requires keyboard and/or display");
568+
if (authenticate && !(keyboard || display))
569+
xsUnknownError("authenticate requires keyboard and/or display");
566570

567571
secure = 1;
568572
}
@@ -581,6 +585,7 @@ void xs_gattclient_constructor(xsMachine *the)
581585
gc->onPasskey = onPasskey;
582586
gc->mtu = (uint16_t)mtu;
583587
gc->secure = secure;
588+
gc->lazy = lazy;
584589

585590
xsmcSetHostData(xsThis, gc);
586591
xsSetHostHooks(xsThis, (xsHostHooks *)&xsGATTClientHooks);
@@ -596,7 +601,7 @@ void xs_gattclient_constructor(xsMachine *the)
596601
else
597602
ble_hs_cfg.sm_io_cap = display ? BLE_HS_IO_DISPLAY_ONLY : BLE_HS_IO_NO_INPUT_OUTPUT;
598603
ble_hs_cfg.sm_bonding = bond;
599-
ble_hs_cfg.sm_mitm = manInTheMiddle;
604+
ble_hs_cfg.sm_mitm = authenticate;
600605
}
601606
}
602607

@@ -835,7 +840,7 @@ static int onGATTMCUExchanged(uint16_t conn_handle, const struct ble_gatt_error
835840

836841
gattClientExecuted(gc, 0);
837842

838-
if (gc->secure)
843+
if (gc->secure && !gc->lazy)
839844
ble_gap_security_initiate(conn_handle);
840845

841846
return 0;
@@ -860,7 +865,7 @@ int onGATTConnectionEvent(struct ble_gap_event *event, void *arg)
860865
gc->mtu = ble_att_mtu(gc->conn_handle);
861866
gattClientExecuted(gc, 0);
862867

863-
if (gc->secure)
868+
if (gc->secure && !gc->lazy)
864869
ble_gap_security_initiate(gc->conn_handle);
865870
}
866871
break;

0 commit comments

Comments
 (0)