@typecad/hal 1.0.0-alpha.13 → 1.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -87
- package/dist/adc-pin.d.ts +53 -0
- package/dist/adc-pin.js +69 -0
- package/dist/async.d.ts +3 -11
- package/dist/async.js +3 -15
- package/dist/ble.d.ts +42 -78
- package/dist/ble.js +79 -98
- package/dist/counter.d.ts +16 -0
- package/dist/counter.js +32 -0
- package/dist/dac-pin.d.ts +13 -0
- package/dist/dac-pin.js +21 -0
- package/dist/emit.d.ts +123 -196
- package/dist/emit.js +146 -208
- package/dist/fs.d.ts +12 -31
- package/dist/fs.js +30 -40
- package/dist/gpio-pin.d.ts +46 -0
- package/dist/gpio-pin.js +77 -0
- package/dist/gpio.d.ts +0 -103
- package/dist/gpio.js +16 -227
- package/dist/http.d.ts +38 -39
- package/dist/http.js +53 -78
- package/dist/i2c-target.d.ts +28 -0
- package/dist/i2c-target.js +52 -0
- package/dist/i2c.d.ts +5 -43
- package/dist/i2c.js +17 -130
- package/dist/index.d.ts +30 -42
- package/dist/index.js +27 -39
- package/dist/math.d.ts +0 -13
- package/dist/math.js +9 -13
- package/dist/mqtt.d.ts +15 -25
- package/dist/mqtt.js +32 -28
- package/dist/power.d.ts +9 -17
- package/dist/power.js +22 -20
- package/dist/preferences.d.ts +17 -25
- package/dist/preferences.js +54 -52
- package/dist/pulse.d.ts +4 -4
- package/dist/pulse.js +6 -2
- package/dist/pwm-pin.d.ts +24 -0
- package/dist/pwm-pin.js +38 -0
- package/dist/random.d.ts +0 -2
- package/dist/random.js +14 -20
- package/dist/sensor-catalog.generated.d.ts +997 -0
- package/dist/sensor-catalog.generated.js +764 -0
- package/dist/sensor.d.ts +46 -0
- package/dist/sensor.js +52 -0
- package/dist/shift-pin.d.ts +2 -0
- package/dist/shift-pin.js +13 -0
- package/dist/spi-target.d.ts +25 -0
- package/dist/spi-target.js +42 -0
- package/dist/spi.d.ts +8 -26
- package/dist/spi.js +15 -87
- package/dist/thread.d.ts +18 -0
- package/dist/thread.js +36 -0
- package/dist/time.d.ts +23 -0
- package/dist/time.js +43 -0
- package/dist/timing.d.ts +17 -7
- package/dist/timing.js +17 -7
- package/dist/types.d.ts +4 -34
- package/dist/types.js +5 -47
- package/dist/uart-port.d.ts +26 -0
- package/dist/uart-port.js +52 -0
- package/dist/uart.d.ts +0 -17
- package/dist/uart.js +10 -53
- package/dist/usb.d.ts +26 -0
- package/dist/usb.js +66 -0
- package/dist/watchdog.d.ts +12 -0
- package/dist/watchdog.js +28 -0
- package/dist/wifi.d.ts +88 -64
- package/dist/wifi.js +112 -126
- package/dist/zephyr-tokens.generated.d.ts +8 -0
- package/dist/zephyr-tokens.generated.js +73 -0
- package/package.json +7 -8
- package/src/adc-pin.ts +89 -0
- package/src/async.ts +3 -16
- package/src/ble.ts +84 -111
- package/src/counter.ts +40 -0
- package/src/dac-pin.ts +28 -0
- package/src/emit.ts +157 -238
- package/src/fs.ts +47 -54
- package/src/gpio-pin.ts +91 -0
- package/src/gpio.ts +49 -320
- package/src/http.ts +75 -95
- package/src/i2c-target.ts +63 -0
- package/src/i2c.ts +29 -167
- package/src/index.ts +32 -46
- package/src/math.ts +9 -14
- package/src/mqtt.ts +39 -31
- package/src/preferences.ts +52 -61
- package/src/pwm-pin.ts +54 -0
- package/src/random.ts +14 -21
- package/src/sensor-catalog.generated.ts +1238 -0
- package/src/sensor.ts +80 -0
- package/src/shift-pin.ts +16 -0
- package/src/spi-target.ts +53 -0
- package/src/spi.ts +27 -121
- package/src/thread.ts +44 -0
- package/src/time.ts +50 -0
- package/src/types.ts +14 -89
- package/src/uart-port.ts +64 -0
- package/src/usb.ts +82 -0
- package/src/watchdog.ts +35 -0
- package/src/wifi.ts +147 -179
- package/src/zephyr-tokens.generated.ts +77 -0
- package/src/adc.ts +0 -30
- package/src/capacitive.ts +0 -31
- package/src/constants.ts +0 -23
- package/src/dac.ts +0 -21
- package/src/eeprom.ts +0 -26
- package/src/interrupts.ts +0 -35
- package/src/mdns.ts +0 -50
- package/src/ota.ts +0 -44
- package/src/power.ts +0 -36
- package/src/pulse.ts +0 -63
- package/src/rmt.ts +0 -125
- package/src/shift.ts +0 -88
- package/src/temperature.ts +0 -20
- package/src/timer.ts +0 -58
- package/src/timing.ts +0 -67
- package/src/uart.ts +0 -77
- package/src/utils.ts +0 -17
- package/src/wdt.ts +0 -17
package/dist/math.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
between(low, high) { return 0; }
|
|
11
|
-
}
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Num — numeric conveniences over the strategy polyfill.
|
|
3
|
+
//
|
|
4
|
+
// The fluent map/constrain chains (Num.map(x).from(a,b).to(c,d)) were dropped
|
|
5
|
+
// with the free map()/constrain() functions in the Zephyr-first cleanup —
|
|
6
|
+
// the remap/clamp arithmetic is a three-line helper in user code, and no
|
|
7
|
+
// backend honors it natively. abs/min/max stay (bare-call polyfills exist on
|
|
8
|
+
// every framework).
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
12
10
|
export class NumClass {
|
|
13
11
|
// No __instance_name — Num methods must NOT be intercepted by the HAL
|
|
14
12
|
// resolver. They pass through as bare C++ calls (Num.abs(-7)), which the
|
|
@@ -19,8 +17,6 @@ export class NumClass {
|
|
|
19
17
|
abs(x) { return 0; }
|
|
20
18
|
min(a, b) { return 0; }
|
|
21
19
|
max(a, b) { return 0; }
|
|
22
|
-
constrain(value) { return new ConstrainChain(value); }
|
|
23
|
-
map(value) { return new MapChain(value); }
|
|
24
20
|
}
|
|
25
21
|
export const Num = new NumClass();
|
|
26
22
|
export function abs(x) { return 0; }
|
package/dist/mqtt.d.ts
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
connect(brokerUri: string, clientId: string): boolean;
|
|
15
|
-
/** Set a handler invoked for every received PUBLISH on a subscribed topic.
|
|
16
|
-
* The handler receives (topic, payload). */
|
|
1
|
+
export declare class Mqtt {
|
|
2
|
+
private readonly _uri;
|
|
3
|
+
private readonly _clientId;
|
|
4
|
+
/** Construct the client for a broker ("mqtt://broker.local" or
|
|
5
|
+
* "mqtts://..." for TLS). */
|
|
6
|
+
constructor(uri: string, opts: {
|
|
7
|
+
clientId: string;
|
|
8
|
+
});
|
|
9
|
+
/** Connect to the broker. Requires a network connection (WiFi) first.
|
|
10
|
+
* The Zephyr client completes the session in its poll thread — poll
|
|
11
|
+
* linked() afterwards. */
|
|
12
|
+
connect(): void;
|
|
13
|
+
/** Handler invoked for every received PUBLISH on a subscribed topic. */
|
|
17
14
|
onMessage(handler: (topic: string, payload: string) => void): void;
|
|
18
15
|
/** Subscribe to a topic filter (e.g. "sensors/#"). */
|
|
19
16
|
subscribe(topic: string): void;
|
|
20
17
|
/** Publish a message to a topic. */
|
|
21
18
|
publish(topic: string, data: string): void;
|
|
22
|
-
/** True
|
|
23
|
-
|
|
19
|
+
/** True while the broker session is up. */
|
|
20
|
+
linked(): boolean;
|
|
24
21
|
/** Disconnect from the broker and free the client. */
|
|
25
22
|
disconnect(): void;
|
|
26
23
|
}
|
|
27
|
-
export declare const MQTT: MqttClass;
|
|
28
|
-
export declare function mqttConnect(brokerUri: string, clientId: string): void;
|
|
29
|
-
export declare function mqttOnMessage(handler: string): void;
|
|
30
|
-
export declare function mqttSubscribe(topic: string): void;
|
|
31
|
-
export declare function mqttPublish(topic: string, data: string): void;
|
|
32
|
-
export declare function mqttConnected(): boolean;
|
|
33
|
-
export declare function mqttDisconnect(): void;
|
package/dist/mqtt.js
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Mqtt — the thin pub/sub client
|
|
3
|
+
//
|
|
4
|
+
// The broker URI and client id are CONSTRUCTION facts; the verbs map onto
|
|
5
|
+
// the Zephyr MQTT client (mqtt_connect / mqtt_publish / mqtt_subscribe,
|
|
6
|
+
// with a poll thread feeding mqtt_input/mqtt_live):
|
|
7
|
+
//
|
|
8
|
+
// connect() → establish the broker session (poll linked() after —
|
|
9
|
+
// the Zephyr client connects in its poll thread)
|
|
10
|
+
// onMessage(cb) → handler for every received PUBLISH on a subscribed
|
|
11
|
+
// topic — receives (topic, payload)
|
|
12
|
+
// subscribe(t) → subscribe to a topic filter ("sensors/#")
|
|
13
|
+
// publish(t, s) → publish a message
|
|
14
|
+
// linked() → the broker session is up
|
|
15
|
+
// disconnect() → disconnect and free the client
|
|
16
|
+
// ----------------------------------------------------------------------------
|
|
1
17
|
import { callback } from './callback.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* Requires a network connection (WiFi) before connect().
|
|
11
|
-
*/
|
|
12
|
-
export class MqttClass {
|
|
13
|
-
/** Connect to a broker URI (e.g. "mqtt://broker.local" or "mqtts://..."). */
|
|
14
|
-
connect(brokerUri, clientId) {
|
|
15
|
-
mqttConnect(brokerUri, clientId);
|
|
16
|
-
return true;
|
|
18
|
+
import { mqttConnect, mqttOnMessage, mqttSubscribe, mqttPublish, mqttConnected, mqttDisconnect, } from './emit.js';
|
|
19
|
+
export class Mqtt {
|
|
20
|
+
/** Construct the client for a broker ("mqtt://broker.local" or
|
|
21
|
+
* "mqtts://..." for TLS). */
|
|
22
|
+
constructor(uri, opts) {
|
|
23
|
+
this._uri = uri;
|
|
24
|
+
this._clientId = opts.clientId;
|
|
17
25
|
}
|
|
18
|
-
/**
|
|
19
|
-
* The
|
|
26
|
+
/** Connect to the broker. Requires a network connection (WiFi) first.
|
|
27
|
+
* The Zephyr client completes the session in its poll thread — poll
|
|
28
|
+
* linked() afterwards. */
|
|
29
|
+
connect() {
|
|
30
|
+
mqttConnect(this._uri, this._clientId);
|
|
31
|
+
}
|
|
32
|
+
/** Handler invoked for every received PUBLISH on a subscribed topic. */
|
|
20
33
|
onMessage(handler) {
|
|
21
34
|
mqttOnMessage(callback(handler));
|
|
22
35
|
}
|
|
@@ -28,8 +41,8 @@ export class MqttClass {
|
|
|
28
41
|
publish(topic, data) {
|
|
29
42
|
mqttPublish(topic, data);
|
|
30
43
|
}
|
|
31
|
-
/** True
|
|
32
|
-
|
|
44
|
+
/** True while the broker session is up. */
|
|
45
|
+
linked() {
|
|
33
46
|
return mqttConnected();
|
|
34
47
|
}
|
|
35
48
|
/** Disconnect from the broker and free the client. */
|
|
@@ -37,12 +50,3 @@ export class MqttClass {
|
|
|
37
50
|
mqttDisconnect();
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
|
-
MqttClass.__instance_name = "MQTT";
|
|
41
|
-
export const MQTT = new MqttClass();
|
|
42
|
-
// ── Semantic primitives (resolved to mqtt.* HAL ops by the transpiler) ──
|
|
43
|
-
export function mqttConnect(brokerUri, clientId) { }
|
|
44
|
-
export function mqttOnMessage(handler) { }
|
|
45
|
-
export function mqttSubscribe(topic) { }
|
|
46
|
-
export function mqttPublish(topic, data) { }
|
|
47
|
-
export function mqttConnected() { return false; }
|
|
48
|
-
export function mqttDisconnect() { }
|
package/dist/power.d.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* The arch guard (ESP32 family vs AVR) lives in the strategy, not here — it
|
|
5
|
-
* relies on the FQBN-derived architecture which is always available at
|
|
6
|
-
* transpile time, unlike `board("architecture")` which needs a board package.
|
|
7
|
-
*/
|
|
8
|
-
export declare class PowerClass {
|
|
9
|
-
static readonly __instance_name = "Power";
|
|
1
|
+
export declare class Power {
|
|
2
|
+
/** Enter deep sleep for `ms`. Wakeup resets the chip — this call never
|
|
3
|
+
* returns. */
|
|
10
4
|
deepSleep(ms: number): void;
|
|
11
5
|
/** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
deepSleepPin(pin: number, level: 0 | 1): void;
|
|
6
|
+
* Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the
|
|
7
|
+
* gpio-wakeup variant (RISC-V C3/C6) depending on the target. Wakeup
|
|
8
|
+
* resets the chip — this call never returns. */
|
|
9
|
+
deepSleepUntil(pin: number, level: 0 | 1): void;
|
|
10
|
+
/** Enter light sleep until any wake source (GPIO/timer). */
|
|
18
11
|
lightSleep(): void;
|
|
19
|
-
setCpuFrequency(mhz: number): void;
|
|
20
12
|
}
|
|
21
|
-
export declare const
|
|
13
|
+
export declare const PowerDefault: Power;
|
package/dist/power.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Power — the thin power-management verbs
|
|
3
|
+
//
|
|
4
|
+
// Power is stateless on Zephyr (sleep entry goes through the power-management
|
|
5
|
+
// policy / sys_pm), so the surface is bare verbs with no construction facts:
|
|
6
|
+
//
|
|
7
|
+
// deepSleep(ms) → deep sleep for ms (wake resets the chip)
|
|
8
|
+
// deepSleepUntil(pin, level) → deep sleep until the pin reaches level
|
|
9
|
+
// (RTC-capable pins only; the framework flags
|
|
10
|
+
// non-RTC pins at compile time; never returns)
|
|
11
|
+
// lightSleep() → light sleep until any wake source
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
import { powerDeepSleep, powerLightSleep, powerDeepSleepPin } from './emit.js';
|
|
14
|
+
export class Power {
|
|
15
|
+
/** Enter deep sleep for `ms`. Wakeup resets the chip — this call never
|
|
16
|
+
* returns. */
|
|
10
17
|
deepSleep(ms) {
|
|
11
18
|
powerDeepSleep(ms);
|
|
12
19
|
}
|
|
13
20
|
/** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
* so this call never returns. */
|
|
19
|
-
deepSleepPin(pin, level) {
|
|
21
|
+
* Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the
|
|
22
|
+
* gpio-wakeup variant (RISC-V C3/C6) depending on the target. Wakeup
|
|
23
|
+
* resets the chip — this call never returns. */
|
|
24
|
+
deepSleepUntil(pin, level) {
|
|
20
25
|
powerDeepSleepPin(pin, level);
|
|
21
26
|
}
|
|
27
|
+
/** Enter light sleep until any wake source (GPIO/timer). */
|
|
22
28
|
lightSleep() {
|
|
23
29
|
powerLightSleep();
|
|
24
30
|
}
|
|
25
|
-
setCpuFrequency(mhz) {
|
|
26
|
-
powerSetCpuFrequency(mhz);
|
|
27
|
-
}
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
export const Power = new PowerClass();
|
|
32
|
+
export const PowerDefault = new Power();
|
package/dist/preferences.d.ts
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
export declare class Store {
|
|
2
|
+
private readonly _ns;
|
|
3
|
+
/** Construct the store for a namespace ('app' → settings subtree tc/app/). */
|
|
4
|
+
constructor(ns: string);
|
|
5
|
+
setInt(key: string, value: number): void;
|
|
6
|
+
getInt(key: string, defaultValue: number): number;
|
|
7
|
+
setFloat(key: string, value: number): void;
|
|
8
|
+
getFloat(key: string, defaultValue: number): number;
|
|
9
|
+
setBool(key: string, value: boolean): void;
|
|
10
|
+
getBool(key: string, defaultValue: boolean): boolean;
|
|
11
|
+
setString(key: string, value: string): void;
|
|
12
|
+
/** Read a string back. The value lands in the shim's ring buffer — copy
|
|
13
|
+
* what you need before the next get on the same key. */
|
|
14
|
+
getString(key: string, defaultValue: string): string;
|
|
15
|
+
/** Delete one key (flash + cache). No-op when absent. */
|
|
15
16
|
remove(key: string): void;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
putUInt(key: string, value: number): void;
|
|
19
|
-
getUInt(key: string, defaultValue?: number): number;
|
|
20
|
-
putBool(key: string, value: boolean): void;
|
|
21
|
-
getBool(key: string, defaultValue?: boolean): boolean;
|
|
22
|
-
putFloat(key: string, value: number): void;
|
|
23
|
-
getFloat(key: string, defaultValue?: number): number;
|
|
24
|
-
putString(key: string, value: string): void;
|
|
25
|
-
getString(key: string, defaultValue?: string): string;
|
|
17
|
+
/** Delete every key under this store's namespace. */
|
|
18
|
+
clear(): void;
|
|
26
19
|
}
|
|
27
|
-
export declare const Preferences: PreferencesClass;
|
package/dist/preferences.js
CHANGED
|
@@ -1,56 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Store — the thin persistent key/value store
|
|
3
|
+
//
|
|
4
|
+
// The namespace is the CONSTRUCTION fact: `new Store('app')` rides every op
|
|
5
|
+
// as the settings subtree prefix (tc/app/<key> on Zephyr's settings/ZMS
|
|
6
|
+
// backend). There is no session to open or close — the backend loads once at
|
|
7
|
+
// boot and every verb maps 1:1 onto a settings write/read/delete:
|
|
8
|
+
//
|
|
9
|
+
// setInt/getInt, setFloat/getFloat, setBool/getBool,
|
|
10
|
+
// setString/getString — typed pairs; get takes a REQUIRED default (no
|
|
11
|
+
// hidden = 0 magic value)
|
|
12
|
+
// remove(key) → settings_delete
|
|
13
|
+
// clear() → delete every tc/<ns>/* key this app wrote
|
|
14
|
+
//
|
|
15
|
+
// Values survive re-flashing the application: they live in the board's
|
|
16
|
+
// storage partition, not the app image.
|
|
17
|
+
// ----------------------------------------------------------------------------
|
|
18
|
+
import { preferencesPutInt, preferencesGetInt, preferencesPutFloat, preferencesGetFloat, preferencesPutBool, preferencesGetBool, preferencesPutString, preferencesGetString, preferencesRemove, preferencesClear, } from './emit.js';
|
|
19
|
+
export class Store {
|
|
20
|
+
/** Construct the store for a namespace ('app' → settings subtree tc/app/). */
|
|
21
|
+
constructor(ns) {
|
|
22
|
+
this._ns = ns;
|
|
23
|
+
}
|
|
24
|
+
setInt(key, value) {
|
|
25
|
+
preferencesPutInt(this._ns, key, value);
|
|
26
|
+
}
|
|
27
|
+
getInt(key, defaultValue) {
|
|
28
|
+
return preferencesGetInt(this._ns, key, defaultValue);
|
|
29
|
+
}
|
|
30
|
+
setFloat(key, value) {
|
|
31
|
+
preferencesPutFloat(this._ns, key, value);
|
|
32
|
+
}
|
|
33
|
+
getFloat(key, defaultValue) {
|
|
34
|
+
return preferencesGetFloat(this._ns, key, defaultValue);
|
|
35
|
+
}
|
|
36
|
+
setBool(key, value) {
|
|
37
|
+
preferencesPutBool(this._ns, key, value);
|
|
38
|
+
}
|
|
39
|
+
getBool(key, defaultValue) {
|
|
40
|
+
return preferencesGetBool(this._ns, key, defaultValue);
|
|
41
|
+
}
|
|
42
|
+
setString(key, value) {
|
|
43
|
+
preferencesPutString(this._ns, key, value);
|
|
44
|
+
}
|
|
45
|
+
/** Read a string back. The value lands in the shim's ring buffer — copy
|
|
46
|
+
* what you need before the next get on the same key. */
|
|
47
|
+
getString(key, defaultValue) {
|
|
48
|
+
return preferencesGetString(this._ns, key, defaultValue);
|
|
49
|
+
}
|
|
50
|
+
/** Delete one key (flash + cache). No-op when absent. */
|
|
21
51
|
remove(key) {
|
|
22
|
-
preferencesRemove(key);
|
|
23
|
-
}
|
|
24
|
-
putInt(key, value) {
|
|
25
|
-
preferencesPutInt(key, value);
|
|
26
|
-
}
|
|
27
|
-
getInt(key, defaultValue = 0) {
|
|
28
|
-
return preferencesGetInt(key, defaultValue);
|
|
29
|
-
}
|
|
30
|
-
putUInt(key, value) {
|
|
31
|
-
preferencesPutUInt(key, value);
|
|
32
|
-
}
|
|
33
|
-
getUInt(key, defaultValue = 0) {
|
|
34
|
-
return preferencesGetUInt(key, defaultValue);
|
|
52
|
+
preferencesRemove(this._ns, key);
|
|
35
53
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
getBool(key, defaultValue = false) {
|
|
40
|
-
return preferencesGetBool(key, defaultValue);
|
|
41
|
-
}
|
|
42
|
-
putFloat(key, value) {
|
|
43
|
-
preferencesPutFloat(key, value);
|
|
44
|
-
}
|
|
45
|
-
getFloat(key, defaultValue = 0) {
|
|
46
|
-
return preferencesGetFloat(key, defaultValue);
|
|
47
|
-
}
|
|
48
|
-
putString(key, value) {
|
|
49
|
-
preferencesPutString(key, value);
|
|
50
|
-
}
|
|
51
|
-
getString(key, defaultValue = "") {
|
|
52
|
-
return preferencesGetString(key, defaultValue);
|
|
54
|
+
/** Delete every key under this store's namespace. */
|
|
55
|
+
clear() {
|
|
56
|
+
preferencesClear(this._ns);
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
|
-
PreferencesClass.__instance_name = "Preferences";
|
|
56
|
-
export const Preferences = new PreferencesClass();
|
package/dist/pulse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Pin
|
|
1
|
+
import type { Pin } from './gpio.js';
|
|
2
2
|
export declare function pulseIn(pin: number, value: number, timeout?: number): number;
|
|
3
3
|
export declare function pulseInLong(pin: number, value: number, timeout?: number): number;
|
|
4
4
|
export declare class Pulse {
|
|
@@ -6,14 +6,14 @@ export declare class Pulse {
|
|
|
6
6
|
* Functional entrypoint for measuring pulses.
|
|
7
7
|
* @example Pulse.on(D7).high()
|
|
8
8
|
*/
|
|
9
|
-
static on(pin: Pin |
|
|
9
|
+
static on(pin: Pin | number): PulseMeasurement;
|
|
10
10
|
/** Measure long pulses using high-precision 64-bit timers. */
|
|
11
|
-
static long(pin: Pin |
|
|
11
|
+
static long(pin: Pin | number, value: number): number;
|
|
12
12
|
}
|
|
13
13
|
declare class PulseMeasurement {
|
|
14
14
|
private _pin;
|
|
15
15
|
private _timeout;
|
|
16
|
-
constructor(pin: Pin |
|
|
16
|
+
constructor(pin: Pin | number);
|
|
17
17
|
/** Set the maximum wait time for a pulse (in microseconds). */
|
|
18
18
|
timeout(us: number): this;
|
|
19
19
|
/** Measures the next HIGH pulse duration in microseconds. */
|
package/dist/pulse.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { rawCpp } from './emit.js';
|
|
2
|
+
/** Pin-or-number to the resolver's identifier form (type-level only). */
|
|
3
|
+
function pinNum(pin) {
|
|
4
|
+
return (typeof pin === 'number' ? pin : pin.number);
|
|
5
|
+
}
|
|
2
6
|
export function pulseIn(pin, value, timeout) {
|
|
3
7
|
if (timeout !== undefined) {
|
|
4
8
|
rawCpp(`return pulseIn(${pin}, ${value}, ${timeout});`);
|
|
@@ -27,13 +31,13 @@ export class Pulse {
|
|
|
27
31
|
}
|
|
28
32
|
/** Measure long pulses using high-precision 64-bit timers. */
|
|
29
33
|
static long(pin, value) {
|
|
30
|
-
rawCpp(`return pulseInLong(${pin
|
|
34
|
+
rawCpp(`return pulseInLong(${pinNum(pin)}, ${value});`);
|
|
31
35
|
return 0;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
class PulseMeasurement {
|
|
35
39
|
constructor(pin) {
|
|
36
|
-
this._pin = pin
|
|
40
|
+
this._pin = pinNum(pin);
|
|
37
41
|
}
|
|
38
42
|
/** Set the maximum wait time for a pulse (in microseconds). */
|
|
39
43
|
timeout(us) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Pin } from './gpio.js';
|
|
2
|
+
export declare class PWM {
|
|
3
|
+
private readonly _pin;
|
|
4
|
+
private readonly _periodNs;
|
|
5
|
+
private readonly _controller;
|
|
6
|
+
private readonly _channel;
|
|
7
|
+
/** Construct a PWM channel. `periodNs` is required — the channel's period
|
|
8
|
+
* in nanoseconds (50 Hz servo = 20_000_000; 1 kHz LED dimming = 1_000_000).
|
|
9
|
+
* `controller`/`channel` override the routing when the board's facts do
|
|
10
|
+
* not map this pin. */
|
|
11
|
+
constructor(pin: number | Pin, opts: {
|
|
12
|
+
periodNs: number;
|
|
13
|
+
controller?: string;
|
|
14
|
+
channel?: number;
|
|
15
|
+
});
|
|
16
|
+
/** Set the pulse width in nanoseconds (pwm_set_pulse_dt). */
|
|
17
|
+
setPulse(pulseNs: number): void;
|
|
18
|
+
/** Set the duty cycle as a fraction 0.0–1.0. Sugar: lowers to one
|
|
19
|
+
* pwm_set_pulse_dt with pulse = duty × the constructed period. */
|
|
20
|
+
setDuty(duty: number): void;
|
|
21
|
+
/** Change the period at runtime (pwm_set_dt). Zephyr 4.4 has no period-only
|
|
22
|
+
* setter, so the pulse resets to idle — follow with setPulse/setDuty. */
|
|
23
|
+
setPeriod(periodNs: number): void;
|
|
24
|
+
}
|
package/dist/pwm-pin.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// PWM — the thin Zephyr-shaped PWM channel
|
|
3
|
+
//
|
|
4
|
+
// The period is a CONSTRUCTION fact (Zephyr's model — the period lives with
|
|
5
|
+
// the channel, not with each write): `new PWM(PA5, { periodNs: 20_000_000 })`.
|
|
6
|
+
// The first use applies the construction period (pwm_set_dt with an idle
|
|
7
|
+
// pulse — Zephyr 4.4 has no period-only setter), then setPulse lowers to
|
|
8
|
+
// pwm_set_pulse_dt verbatim. setDuty(0.0–1.0) is sugar that lowers to
|
|
9
|
+
// exactly one pwm_set_pulse_dt against the known period — no 0–255 scaling
|
|
10
|
+
// anywhere. Nanoseconds throughout.
|
|
11
|
+
// ----------------------------------------------------------------------------
|
|
12
|
+
import { pwmSetPulse, pwmSetDuty, pwmSetPeriod } from './emit.js';
|
|
13
|
+
export class PWM {
|
|
14
|
+
/** Construct a PWM channel. `periodNs` is required — the channel's period
|
|
15
|
+
* in nanoseconds (50 Hz servo = 20_000_000; 1 kHz LED dimming = 1_000_000).
|
|
16
|
+
* `controller`/`channel` override the routing when the board's facts do
|
|
17
|
+
* not map this pin. */
|
|
18
|
+
constructor(pin, opts) {
|
|
19
|
+
this._pin = typeof pin === 'number' ? pin : pin.number;
|
|
20
|
+
this._periodNs = opts.periodNs;
|
|
21
|
+
this._controller = opts?.controller ?? '';
|
|
22
|
+
this._channel = opts?.channel ?? -1;
|
|
23
|
+
}
|
|
24
|
+
/** Set the pulse width in nanoseconds (pwm_set_pulse_dt). */
|
|
25
|
+
setPulse(pulseNs) {
|
|
26
|
+
pwmSetPulse(this._pin, this._periodNs, pulseNs, this._controller, this._channel);
|
|
27
|
+
}
|
|
28
|
+
/** Set the duty cycle as a fraction 0.0–1.0. Sugar: lowers to one
|
|
29
|
+
* pwm_set_pulse_dt with pulse = duty × the constructed period. */
|
|
30
|
+
setDuty(duty) {
|
|
31
|
+
pwmSetDuty(this._pin, this._periodNs, duty, this._controller, this._channel);
|
|
32
|
+
}
|
|
33
|
+
/** Change the period at runtime (pwm_set_dt). Zephyr 4.4 has no period-only
|
|
34
|
+
* setter, so the pulse resets to idle — follow with setPulse/setDuty. */
|
|
35
|
+
setPeriod(periodNs) {
|
|
36
|
+
pwmSetPeriod(this._pin, periodNs, this._controller, this._channel);
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/random.d.ts
CHANGED
package/dist/random.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Random — the thin PRNG surface
|
|
3
|
+
//
|
|
4
|
+
// The Random namespace methods (seed/upTo/between/int) are intercepted by the
|
|
5
|
+
// transpiler's namespace-method resolver and lowered to the random.* HAL op
|
|
6
|
+
// family (random.seed / random.range / random.int), which each framework lowers
|
|
7
|
+
// to its platform PRNG (Zephyr: a userspace xorshift32 seeded from
|
|
8
|
+
// sys_rand_get). The bodies below are inert runtime stubs for host-side
|
|
9
|
+
// type-checking only — never emitted.
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
4
11
|
export class Random {
|
|
5
12
|
/** Seeds the PRNG with a starting value. */
|
|
6
|
-
static seed(val) {
|
|
7
|
-
rawCpp(`randomSeed(${val});`);
|
|
8
|
-
}
|
|
13
|
+
static seed(val) { }
|
|
9
14
|
/** Returns a random number in range [0, max-1]. */
|
|
10
|
-
static upTo(max) {
|
|
11
|
-
rawCpp(`return random(${max});`);
|
|
12
|
-
return 0;
|
|
13
|
-
}
|
|
15
|
+
static upTo(max) { return 0; }
|
|
14
16
|
/** Returns a random number in range [min, max-1]. */
|
|
15
|
-
static between(min, max) {
|
|
16
|
-
rawCpp(`return random(${min}, ${max});`);
|
|
17
|
-
return 0;
|
|
18
|
-
}
|
|
17
|
+
static between(min, max) { return 0; }
|
|
19
18
|
/** Returns a random non-negative 31-bit integer [0, 2147483646]. */
|
|
20
|
-
static int() {
|
|
21
|
-
// Arduino random(max) returns [0, max-1]; 2147483647 = INT_MAX gives a
|
|
22
|
-
// non-negative 31-bit range (sign bit always 0).
|
|
23
|
-
rawCpp(`return random(2147483647);`);
|
|
24
|
-
return 0;
|
|
25
|
-
}
|
|
19
|
+
static int() { return 0; }
|
|
26
20
|
}
|