@typecad/hal 1.0.0-alpha.6 → 1.0.0-alpha.7

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/dist/http.js ADDED
@@ -0,0 +1,104 @@
1
+ import { httpBegin, httpReset, httpSetHeader, httpSetTimeout, httpSetMaxBody, httpSetBody, httpSetInsecure, httpSetCaCert, httpSend, httpStatus, httpOk, httpBody, httpContentLength, httpResponseHeader, } from './emit.js';
2
+ export var HttpMethod;
3
+ (function (HttpMethod) {
4
+ HttpMethod[HttpMethod["GET"] = 0] = "GET";
5
+ HttpMethod[HttpMethod["POST"] = 1] = "POST";
6
+ HttpMethod[HttpMethod["PUT"] = 2] = "PUT";
7
+ HttpMethod[HttpMethod["DELETE"] = 3] = "DELETE";
8
+ HttpMethod[HttpMethod["HEAD"] = 4] = "HEAD";
9
+ HttpMethod[HttpMethod["PATCH"] = 5] = "PATCH";
10
+ })(HttpMethod || (HttpMethod = {}));
11
+ /**
12
+ * Fluent HTTP/S request builder, lowered to native ESP-IDF
13
+ * `esp_http_client` by framework-esp32 (TLS via esp-tls / mbedTLS bundle).
14
+ * Response fields are read from this object after send() — mirrors
15
+ * `await WiFi.connect(); WiFi.localIP()`.
16
+ *
17
+ * No `include()` calls here — ESP-IDF headers are framework-owned and added
18
+ * via forcedIncludes when the program uses http.* ops.
19
+ */
20
+ export class HttpRequest {
21
+ constructor(method, url) {
22
+ this._method = method;
23
+ this._url = url;
24
+ }
25
+ header(name, value) {
26
+ httpSetHeader(name, value);
27
+ return this;
28
+ }
29
+ timeout(ms) {
30
+ httpSetTimeout(ms);
31
+ return this;
32
+ }
33
+ maxBody(bytes) {
34
+ httpSetMaxBody(bytes);
35
+ return this;
36
+ }
37
+ body(data) {
38
+ httpSetBody(data, false);
39
+ return this;
40
+ }
41
+ jsonBody(json) {
42
+ httpSetBody(json, true);
43
+ return this;
44
+ }
45
+ /** Skip TLS certificate verification (development only). */
46
+ insecure() {
47
+ httpSetInsecure();
48
+ return this;
49
+ }
50
+ caCert(pem) {
51
+ httpSetCaCert(pem);
52
+ return this;
53
+ }
54
+ /** Blocking at top level; cooperatively awaitable inside async functions. */
55
+ send() {
56
+ httpBegin(this._method, this._url);
57
+ httpSend();
58
+ return Promise.resolve(false);
59
+ }
60
+ status() {
61
+ return httpStatus();
62
+ }
63
+ ok() {
64
+ return httpOk();
65
+ }
66
+ /** Response body as a C string (valid until the next request). */
67
+ text() {
68
+ return httpBody();
69
+ }
70
+ contentLength() {
71
+ return httpContentLength();
72
+ }
73
+ responseHeader(name) {
74
+ return httpResponseHeader(name);
75
+ }
76
+ }
77
+ export class HttpClass {
78
+ get(url) {
79
+ httpReset();
80
+ return new HttpRequest("GET", url);
81
+ }
82
+ post(url) {
83
+ httpReset();
84
+ return new HttpRequest("POST", url);
85
+ }
86
+ put(url) {
87
+ httpReset();
88
+ return new HttpRequest("PUT", url);
89
+ }
90
+ del(url) {
91
+ httpReset();
92
+ return new HttpRequest("DELETE", url);
93
+ }
94
+ head(url) {
95
+ httpReset();
96
+ return new HttpRequest("HEAD", url);
97
+ }
98
+ patch(url) {
99
+ httpReset();
100
+ return new HttpRequest("PATCH", url);
101
+ }
102
+ }
103
+ HttpClass.__instance_name = "Http";
104
+ export const Http = new HttpClass();
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export type { SPIBitOrder, SPIMode, SPISettings } from './types.js';
9
9
  export { include } from './include.js';
10
10
  export { board } from './board.js';
11
11
  export { callback } from './callback.js';
12
- export { rawCpp, boardResolve } from './emit.js';
12
+ export { rawCpp, rawCppExpr, boardResolve } from './emit.js';
13
13
  export { HIGH, LOW, OUTPUT, INPUT, INPUT_PULLUP, INPUT_PULLDOWN, OUTPUT_OPEN_DRAIN, ANALOG, LED_BUILTIN, LSBFIRST, MSBFIRST, WDTO_15MS, WDTO_30MS, WDTO_60MS, WDTO_120MS, WDTO_250MS, WDTO_500MS, WDTO_1S, WDTO_2S, WDTO_4S, WDTO_8S } from './constants.js';
14
14
  export { delay, millis, micros, delayMicroseconds, map, constrain, TimingClass, Timing } from './timing.js';
15
15
  export { freeHeap, setInterval, setTimeout, clearInterval, clearTimeout } from './timing.js';
@@ -35,3 +35,8 @@ export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
35
35
  export { FSClass, FS } from './fs.js';
36
36
  export { PowerClass, Power } from './power.js';
37
37
  export { AsyncClass, Async } from './async.js';
38
+ export { WiFiClass, WiFi, WiFiStatus, WiFiEncryption } from './wifi.js';
39
+ export { HttpClass, Http, HttpRequest, HttpMethod } from './http.js';
40
+ export { BleClass, Ble, BleServer, BleValueType, BlePerm, BleStatus, BleAdvertisingMode, GATT, } from './ble.js';
41
+ export type { GattCharacteristicDef, CharValue } from './ble.js';
42
+ export { RmtChannel } from './rmt.js';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { createPinGroup } from './types.js';
3
3
  export { include } from './include.js';
4
4
  export { board } from './board.js';
5
5
  export { callback } from './callback.js';
6
- export { rawCpp, boardResolve } from './emit.js';
6
+ export { rawCpp, rawCppExpr, boardResolve } from './emit.js';
7
7
  export { HIGH, LOW, OUTPUT, INPUT, INPUT_PULLUP, INPUT_PULLDOWN, OUTPUT_OPEN_DRAIN, ANALOG, LED_BUILTIN, LSBFIRST, MSBFIRST, WDTO_15MS, WDTO_30MS, WDTO_60MS, WDTO_120MS, WDTO_250MS, WDTO_500MS, WDTO_1S, WDTO_2S, WDTO_4S, WDTO_8S } from './constants.js';
8
8
  export { delay, millis, micros, delayMicroseconds, map, constrain, TimingClass, Timing } from './timing.js';
9
9
  export { freeHeap, setInterval, setTimeout, clearInterval, clearTimeout } from './timing.js';
@@ -28,3 +28,7 @@ export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
28
28
  export { FSClass, FS } from './fs.js';
29
29
  export { PowerClass, Power } from './power.js';
30
30
  export { AsyncClass, Async } from './async.js';
31
+ export { WiFiClass, WiFi, WiFiStatus, WiFiEncryption } from './wifi.js';
32
+ export { HttpClass, Http, HttpRequest, HttpMethod } from './http.js';
33
+ export { BleClass, Ble, BleServer, BleValueType, BlePerm, BleStatus, BleAdvertisingMode, GATT, } from './ble.js';
34
+ export { RmtChannel } from './rmt.js';
package/dist/power.d.ts CHANGED
@@ -8,6 +8,13 @@
8
8
  export declare class PowerClass {
9
9
  static readonly __instance_name = "Power";
10
10
  deepSleep(ms: number): void;
11
+ /** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
12
+ *
13
+ * Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the gpio-wakeup
14
+ * variant (RISC-V C3/C6) depending on the target. `pin` must be RTC-capable;
15
+ * the framework flags non-RTC pins at compile time. Wakeup resets the chip,
16
+ * so this call never returns. */
17
+ deepSleepPin(pin: number, level: 0 | 1): void;
11
18
  lightSleep(): void;
12
19
  setCpuFrequency(mhz: number): void;
13
20
  }
package/dist/power.js CHANGED
@@ -1,4 +1,4 @@
1
- import { powerDeepSleep, powerLightSleep, powerSetCpuFrequency } from './emit.js';
1
+ import { powerDeepSleep, powerLightSleep, powerSetCpuFrequency, powerDeepSleepPin } from './emit.js';
2
2
  /**
3
3
  * PowerClass provides control over MCU power states and clock frequencies.
4
4
  *
@@ -10,6 +10,15 @@ export class PowerClass {
10
10
  deepSleep(ms) {
11
11
  powerDeepSleep(ms);
12
12
  }
13
+ /** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
14
+ *
15
+ * Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the gpio-wakeup
16
+ * variant (RISC-V C3/C6) depending on the target. `pin` must be RTC-capable;
17
+ * the framework flags non-RTC pins at compile time. Wakeup resets the chip,
18
+ * so this call never returns. */
19
+ deepSleepPin(pin, level) {
20
+ powerDeepSleepPin(pin, level);
21
+ }
13
22
  lightSleep() {
14
23
  powerLightSleep();
15
24
  }
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Preferences — a persistent key/value store, lowered to native NVS
3
+ * (nvs_flash / nvs_open / nvs_set_* / nvs_get_*) by framework-esp32.
4
+ *
5
+ * No include() calls here — NVS headers are framework-owned and added via
6
+ * forcedIncludes when the program uses preferences.* ops. Method bodies pass
7
+ * parameters directly into semantic calls so the resolver can statically track
8
+ * every argument (matching the WiFi/HTTP HAL pattern).
9
+ */
1
10
  export declare class PreferencesClass {
2
11
  static readonly __instance_name = "Preferences";
3
12
  begin(name: string, readOnly?: boolean): void;
@@ -8,10 +17,10 @@ export declare class PreferencesClass {
8
17
  getInt(key: string, defaultValue?: number): number;
9
18
  putUInt(key: string, value: number): void;
10
19
  getUInt(key: string, defaultValue?: number): number;
11
- putFloat(key: string, value: number): void;
12
- getFloat(key: string, defaultValue?: number): number;
13
20
  putBool(key: string, value: boolean): void;
14
21
  getBool(key: string, defaultValue?: boolean): boolean;
22
+ putFloat(key: string, value: number): void;
23
+ getFloat(key: string, defaultValue?: number): number;
15
24
  putString(key: string, value: string): void;
16
25
  getString(key: string, defaultValue?: string): string;
17
26
  }
@@ -1,54 +1,55 @@
1
- import { rawCpp } from './emit.js';
1
+ import { preferencesBegin, preferencesEnd, preferencesClear, preferencesRemove, preferencesPutInt, preferencesGetInt, preferencesPutUInt, preferencesGetUInt, preferencesPutBool, preferencesGetBool, preferencesPutFloat, preferencesGetFloat, preferencesPutString, preferencesGetString, } from './emit.js';
2
+ /**
3
+ * Preferences — a persistent key/value store, lowered to native NVS
4
+ * (nvs_flash / nvs_open / nvs_set_* / nvs_get_*) by framework-esp32.
5
+ *
6
+ * No include() calls here — NVS headers are framework-owned and added via
7
+ * forcedIncludes when the program uses preferences.* ops. Method bodies pass
8
+ * parameters directly into semantic calls so the resolver can statically track
9
+ * every argument (matching the WiFi/HTTP HAL pattern).
10
+ */
2
11
  export class PreferencesClass {
3
- // NOTE: no __includes here. The transpiler emits singleton __includes on
4
- // every architecture with no filtering, and <Preferences.h> is ESP32-only —
5
- // adding it would break AVR builds. The class is ESP32-only by convention.
6
12
  begin(name, readOnly = false) {
7
- rawCpp(`Preferences.begin(${name}.c_str(), ${readOnly});`);
13
+ preferencesBegin(name, readOnly);
8
14
  }
9
15
  end() {
10
- rawCpp(`Preferences.end();`);
16
+ preferencesEnd();
11
17
  }
12
18
  clear() {
13
- rawCpp(`Preferences.clear();`);
19
+ preferencesClear();
14
20
  }
15
21
  remove(key) {
16
- rawCpp(`Preferences.remove(${key}.c_str());`);
22
+ preferencesRemove(key);
17
23
  }
18
24
  putInt(key, value) {
19
- rawCpp(`Preferences.putInt(${key}.c_str(), ${value});`);
25
+ preferencesPutInt(key, value);
20
26
  }
21
27
  getInt(key, defaultValue = 0) {
22
- rawCpp(`return Preferences.getInt(${key}.c_str(), ${defaultValue});`);
23
- return 0;
28
+ return preferencesGetInt(key, defaultValue);
24
29
  }
25
30
  putUInt(key, value) {
26
- rawCpp(`Preferences.putUInt(${key}.c_str(), ${value});`);
31
+ preferencesPutUInt(key, value);
27
32
  }
28
33
  getUInt(key, defaultValue = 0) {
29
- rawCpp(`return Preferences.getUInt(${key}.c_str(), ${defaultValue});`);
30
- return 0;
31
- }
32
- putFloat(key, value) {
33
- rawCpp(`Preferences.putFloat(${key}.c_str(), ${value});`);
34
- }
35
- getFloat(key, defaultValue = 0) {
36
- rawCpp(`return Preferences.getFloat(${key}.c_str(), ${defaultValue});`);
37
- return 0;
34
+ return preferencesGetUInt(key, defaultValue);
38
35
  }
39
36
  putBool(key, value) {
40
- rawCpp(`Preferences.putBool(${key}.c_str(), ${value});`);
37
+ preferencesPutBool(key, value);
41
38
  }
42
39
  getBool(key, defaultValue = false) {
43
- rawCpp(`return Preferences.getBool(${key}.c_str(), ${defaultValue});`);
44
- return 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);
45
47
  }
46
48
  putString(key, value) {
47
- rawCpp(`Preferences.putString(${key}.c_str(), ${value}.c_str());`);
49
+ preferencesPutString(key, value);
48
50
  }
49
51
  getString(key, defaultValue = "") {
50
- rawCpp(`return Preferences.getString(${key}.c_str(), ${defaultValue}.c_str());`);
51
- return "";
52
+ return preferencesGetString(key, defaultValue);
52
53
  }
53
54
  }
54
55
  PreferencesClass.__instance_name = "Preferences";
package/dist/rmt.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type { Pin } from './gpio.js';
2
+ /** Pin identifier accepted by RmtChannel: a Pin object, raw GPIO number, or port name. */
3
+ type RmtPin = Pin | number | string;
4
+ /**
5
+ * RMT transceiver channel bound to a GPIO pin. One channel per pin; TX and RX
6
+ * are independent roles on the same channel object.
7
+ *
8
+ * ```ts
9
+ * const led = new RmtChannel(LED);
10
+ * led.txInit({ resolutionHz: 10_000_000, bit0: [4, 9], bit1: [9, 4] });
11
+ * led.txWriteBytes([0, 16, 0]);
12
+ * led.txWaitDone();
13
+ * ```
14
+ */
15
+ export declare class RmtChannel {
16
+ private _pin;
17
+ constructor(pin: RmtPin);
18
+ /** Initialize the channel for TX. Idempotent per pin. Bit timings are fixed
19
+ * at init — ESP-IDF bakes them into the bytes-encoder and exposes no public
20
+ * mutation API. Tick units are 1/resolutionHz seconds.
21
+ *
22
+ * Args are positional scalars (not an opts object) because the transpiler's
23
+ * method-body renderer folds scalar params but not property accesses on an
24
+ * object param (opts.resolutionHz would render as a collapsed object + dead
25
+ * property access). Mirrors how I2CBus.begin(address) takes a scalar. */
26
+ txInit(resolutionHz: number, bit0Hi: number, bit0Lo: number, bit1Hi: number, bit1Lo: number, msbFirst?: boolean, queueDepth?: number): void;
27
+ /** Write bytes via the channel's bytes-encoder (timings fixed at txInit). */
28
+ txWriteBytes(bytes: number[] | Uint8Array): void;
29
+ /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
30
+ txWriteSymbols(symbols: [number, number][]): void;
31
+ /** Block until the queued TX completes. */
32
+ txWaitDone(timeoutMs?: number): void;
33
+ /** Tear down the TX channel and release its slot. */
34
+ txDeinit(): void;
35
+ /** Initialize the channel for RX. Idempotent per pin. */
36
+ rxInit(resolutionHz: number): void;
37
+ /** Register a callback-by-name invoked when an RX burst completes. */
38
+ rxOnReceived(handler: string): void;
39
+ /** Start receiving. */
40
+ rxStart(): void;
41
+ /** Stop receiving. */
42
+ rxStop(): void;
43
+ /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
44
+ rxRead(maxCount: number): number[];
45
+ /** Tear down the RX channel and release its slot. */
46
+ rxDeinit(): void;
47
+ }
48
+ export {};
package/dist/rmt.js ADDED
@@ -0,0 +1,81 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/hal — RMT (Remote Control Transceiver) ergonomic API
3
+ // ---------------------------------------------------------------------------
4
+ // Exposes RMT via a RmtChannel class, mirroring the I2CBus/I2CDevice pattern.
5
+ // The transpiler only resolves semantic calls made inside class-method bodies
6
+ // (free top-level calls emit verbatim), so every peripheral exposes its API
7
+ // through a class whose methods call the positional semantic primitives in
8
+ // emit.ts. The resolver collapses object literals, so HALOpIR fields must be
9
+ // scalars; these methods destructure `opts` at the call site before forwarding.
10
+ //
11
+ // Channel identity is the GPIO pin (like pwm.ts's LEDC channel-per-pin model).
12
+ import { rmtTxInit, rmtRxInit, rmtTxWriteBytes, rmtTxWriteSymbols, rmtTxWaitDone, rmtTxDeinit, rmtRxOnReceived, rmtRxStart, rmtRxStop, rmtRxRead, rmtRxDeinit, } from './emit.js';
13
+ /**
14
+ * RMT transceiver channel bound to a GPIO pin. One channel per pin; TX and RX
15
+ * are independent roles on the same channel object.
16
+ *
17
+ * ```ts
18
+ * const led = new RmtChannel(LED);
19
+ * led.txInit({ resolutionHz: 10_000_000, bit0: [4, 9], bit1: [9, 4] });
20
+ * led.txWriteBytes([0, 16, 0]);
21
+ * led.txWaitDone();
22
+ * ```
23
+ */
24
+ export class RmtChannel {
25
+ constructor(pin) {
26
+ this._pin = pin;
27
+ }
28
+ // ── TX ─────────────────────────────────────────────────────────────────────
29
+ /** Initialize the channel for TX. Idempotent per pin. Bit timings are fixed
30
+ * at init — ESP-IDF bakes them into the bytes-encoder and exposes no public
31
+ * mutation API. Tick units are 1/resolutionHz seconds.
32
+ *
33
+ * Args are positional scalars (not an opts object) because the transpiler's
34
+ * method-body renderer folds scalar params but not property accesses on an
35
+ * object param (opts.resolutionHz would render as a collapsed object + dead
36
+ * property access). Mirrors how I2CBus.begin(address) takes a scalar. */
37
+ txInit(resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst = false, queueDepth = 4) {
38
+ rmtTxInit(this._pin, resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst, queueDepth);
39
+ }
40
+ /** Write bytes via the channel's bytes-encoder (timings fixed at txInit). */
41
+ txWriteBytes(bytes) {
42
+ rmtTxWriteBytes(this._pin, bytes);
43
+ }
44
+ /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
45
+ txWriteSymbols(symbols) {
46
+ rmtTxWriteSymbols(this._pin, symbols);
47
+ }
48
+ /** Block until the queued TX completes. */
49
+ txWaitDone(timeoutMs) {
50
+ rmtTxWaitDone(this._pin, timeoutMs);
51
+ }
52
+ /** Tear down the TX channel and release its slot. */
53
+ txDeinit() {
54
+ rmtTxDeinit(this._pin);
55
+ }
56
+ // ── RX ─────────────────────────────────────────────────────────────────────
57
+ /** Initialize the channel for RX. Idempotent per pin. */
58
+ rxInit(resolutionHz) {
59
+ rmtRxInit(this._pin, resolutionHz);
60
+ }
61
+ /** Register a callback-by-name invoked when an RX burst completes. */
62
+ rxOnReceived(handler) {
63
+ rmtRxOnReceived(this._pin, handler);
64
+ }
65
+ /** Start receiving. */
66
+ rxStart() {
67
+ rmtRxStart(this._pin);
68
+ }
69
+ /** Stop receiving. */
70
+ rxStop() {
71
+ rmtRxStop(this._pin);
72
+ }
73
+ /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
74
+ rxRead(maxCount) {
75
+ return rmtRxRead(this._pin, maxCount);
76
+ }
77
+ /** Tear down the RX channel and release its slot. */
78
+ rxDeinit() {
79
+ rmtRxDeinit(this._pin);
80
+ }
81
+ }
package/dist/wifi.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ /** Normalized WiFi link status (mapped from esp_wifi events by the runtime shim). */
2
+ export declare enum WiFiStatus {
3
+ Idle = 0,
4
+ Connecting = 1,
5
+ Connected = 2,
6
+ ConnectFailed = 3,
7
+ Disconnected = 4
8
+ }
9
+ export declare enum WiFiEncryption {
10
+ Open = 0,
11
+ WEP = 1,
12
+ WPA = 2,
13
+ WPA2 = 3,
14
+ WPA3 = 4,
15
+ Enterprise = 5
16
+ }
17
+ /**
18
+ * WiFi radio / link control, lowered to native ESP-IDF (`esp_wifi` /
19
+ * `esp_netif` / `esp_event` / `nvs_flash`) by framework-esp32.
20
+ *
21
+ * No `include()` calls here — ESP-IDF headers are framework-owned and added
22
+ * via forcedIncludes when the program uses wifi.* ops (the Preferences
23
+ * lesson: HAL files must not carry platform headers). Frameworks without a
24
+ * wifi lowering reject these ops with a diagnostic.
25
+ */
26
+ export declare class WiFiClass {
27
+ static readonly __instance_name = "WiFi";
28
+ /** Blocking at top level; cooperatively awaitable inside async functions. */
29
+ connect(ssid: string, password?: string, timeoutMs?: number): Promise<boolean>;
30
+ /** Fire-and-forget STA begin; poll status() / untilConnected(). */
31
+ connectAsync(ssid: string, password?: string): void;
32
+ untilConnected(timeoutMs?: number): Promise<boolean>;
33
+ untilDisconnected(): Promise<void>;
34
+ disconnect(): void;
35
+ isConnected(): boolean;
36
+ status(): WiFiStatus;
37
+ localIP(): string;
38
+ rssi(): number;
39
+ macAddress(): string;
40
+ hostname(name: string): this;
41
+ staticIP(ip: string, gateway: string, subnet: string, dns?: string): this;
42
+ autoReconnect(enabled: boolean): this;
43
+ powerSave(mode: "default" | "none"): this;
44
+ /** Cap TX power in dBm (roughly 2–20). Safe to call before connect() —
45
+ * the value is applied after the radio starts. */
46
+ txPower(dbm: number): this;
47
+ saveCredentials(ssid: string, password: string): void;
48
+ connectSaved(timeoutMs?: number): boolean;
49
+ clearCredentials(): void;
50
+ onConnect(handler: () => void): void;
51
+ onDisconnect(handler: () => void): void;
52
+ onGotIP(handler: () => void): void;
53
+ startAP(ssid: string, password?: string): boolean;
54
+ apChannel(ch: number): this;
55
+ apHidden(hidden: boolean): this;
56
+ apMaxClients(n: number): this;
57
+ stopAP(): void;
58
+ apClientCount(): number;
59
+ apIP(): string;
60
+ scan(): number;
61
+ scanAsync(): Promise<void>;
62
+ scanCount(): number;
63
+ scanSSID(i: number): string;
64
+ scanRSSI(i: number): number;
65
+ scanEncryption(i: number): WiFiEncryption;
66
+ scanChannel(i: number): number;
67
+ }
68
+ export declare const WiFi: WiFiClass;
package/dist/wifi.js ADDED
@@ -0,0 +1,154 @@
1
+ import { wifiConnect, wifiConnectStart, wifiDisconnect, wifiStatus, wifiIsConnected, wifiLocalIp, wifiRssi, wifiMac, wifiSetHostname, wifiSetStaticIp, wifiSetAutoReconnect, wifiSetPowerSave, wifiSetTxPower, wifiOnEvent, wifiApStart, wifiApStop, wifiApClientCount, wifiApIp, wifiApSetChannel, wifiApSetHidden, wifiApSetMaxClients, wifiScan, wifiScanStart, wifiScanCount, wifiScanSsid, wifiScanRssi, wifiScanEncryption, wifiScanChannel, wifiSaveCredentials, wifiConnectSaved, wifiClearCredentials, wifiWaitConnected, wifiWaitDisconnected, } from './emit.js';
2
+ import { callback } from './callback.js';
3
+ /** Normalized WiFi link status (mapped from esp_wifi events by the runtime shim). */
4
+ export var WiFiStatus;
5
+ (function (WiFiStatus) {
6
+ WiFiStatus[WiFiStatus["Idle"] = 0] = "Idle";
7
+ WiFiStatus[WiFiStatus["Connecting"] = 1] = "Connecting";
8
+ WiFiStatus[WiFiStatus["Connected"] = 2] = "Connected";
9
+ WiFiStatus[WiFiStatus["ConnectFailed"] = 3] = "ConnectFailed";
10
+ WiFiStatus[WiFiStatus["Disconnected"] = 4] = "Disconnected";
11
+ })(WiFiStatus || (WiFiStatus = {}));
12
+ export var WiFiEncryption;
13
+ (function (WiFiEncryption) {
14
+ WiFiEncryption[WiFiEncryption["Open"] = 0] = "Open";
15
+ WiFiEncryption[WiFiEncryption["WEP"] = 1] = "WEP";
16
+ WiFiEncryption[WiFiEncryption["WPA"] = 2] = "WPA";
17
+ WiFiEncryption[WiFiEncryption["WPA2"] = 3] = "WPA2";
18
+ WiFiEncryption[WiFiEncryption["WPA3"] = 4] = "WPA3";
19
+ WiFiEncryption[WiFiEncryption["Enterprise"] = 5] = "Enterprise";
20
+ })(WiFiEncryption || (WiFiEncryption = {}));
21
+ /**
22
+ * WiFi radio / link control, lowered to native ESP-IDF (`esp_wifi` /
23
+ * `esp_netif` / `esp_event` / `nvs_flash`) by framework-esp32.
24
+ *
25
+ * No `include()` calls here — ESP-IDF headers are framework-owned and added
26
+ * via forcedIncludes when the program uses wifi.* ops (the Preferences
27
+ * lesson: HAL files must not carry platform headers). Frameworks without a
28
+ * wifi lowering reject these ops with a diagnostic.
29
+ */
30
+ export class WiFiClass {
31
+ /** Blocking at top level; cooperatively awaitable inside async functions. */
32
+ connect(ssid, password, timeoutMs = 15000) {
33
+ wifiConnect(ssid, password, timeoutMs);
34
+ return Promise.resolve(false);
35
+ }
36
+ /** Fire-and-forget STA begin; poll status() / untilConnected(). */
37
+ connectAsync(ssid, password) {
38
+ wifiConnectStart(ssid, password);
39
+ }
40
+ untilConnected(timeoutMs = 15000) {
41
+ wifiWaitConnected(timeoutMs);
42
+ return Promise.resolve(false);
43
+ }
44
+ untilDisconnected() {
45
+ wifiWaitDisconnected();
46
+ return Promise.resolve();
47
+ }
48
+ disconnect() {
49
+ wifiDisconnect();
50
+ }
51
+ isConnected() {
52
+ return wifiIsConnected();
53
+ }
54
+ status() {
55
+ return wifiStatus();
56
+ }
57
+ localIP() {
58
+ return wifiLocalIp();
59
+ }
60
+ rssi() {
61
+ return wifiRssi();
62
+ }
63
+ macAddress() {
64
+ return wifiMac();
65
+ }
66
+ hostname(name) {
67
+ wifiSetHostname(name);
68
+ return this;
69
+ }
70
+ staticIP(ip, gateway, subnet, dns) {
71
+ wifiSetStaticIp(ip, gateway, subnet, dns);
72
+ return this;
73
+ }
74
+ autoReconnect(enabled) {
75
+ wifiSetAutoReconnect(enabled);
76
+ return this;
77
+ }
78
+ powerSave(mode) {
79
+ wifiSetPowerSave(mode);
80
+ return this;
81
+ }
82
+ /** Cap TX power in dBm (roughly 2–20). Safe to call before connect() —
83
+ * the value is applied after the radio starts. */
84
+ txPower(dbm) {
85
+ wifiSetTxPower(dbm);
86
+ return this;
87
+ }
88
+ saveCredentials(ssid, password) {
89
+ wifiSaveCredentials(ssid, password);
90
+ }
91
+ connectSaved(timeoutMs = 15000) {
92
+ return wifiConnectSaved(timeoutMs);
93
+ }
94
+ clearCredentials() {
95
+ wifiClearCredentials();
96
+ }
97
+ onConnect(handler) {
98
+ wifiOnEvent("connect", callback(handler));
99
+ }
100
+ onDisconnect(handler) {
101
+ wifiOnEvent("disconnect", callback(handler));
102
+ }
103
+ onGotIP(handler) {
104
+ wifiOnEvent("got_ip", callback(handler));
105
+ }
106
+ startAP(ssid, password) {
107
+ return wifiApStart(ssid, password);
108
+ }
109
+ apChannel(ch) {
110
+ wifiApSetChannel(ch);
111
+ return this;
112
+ }
113
+ apHidden(hidden) {
114
+ wifiApSetHidden(hidden);
115
+ return this;
116
+ }
117
+ apMaxClients(n) {
118
+ wifiApSetMaxClients(n);
119
+ return this;
120
+ }
121
+ stopAP() {
122
+ wifiApStop();
123
+ }
124
+ apClientCount() {
125
+ return wifiApClientCount();
126
+ }
127
+ apIP() {
128
+ return wifiApIp();
129
+ }
130
+ scan() {
131
+ return wifiScan();
132
+ }
133
+ scanAsync() {
134
+ wifiScanStart();
135
+ return Promise.resolve();
136
+ }
137
+ scanCount() {
138
+ return wifiScanCount();
139
+ }
140
+ scanSSID(i) {
141
+ return wifiScanSsid(i);
142
+ }
143
+ scanRSSI(i) {
144
+ return wifiScanRssi(i);
145
+ }
146
+ scanEncryption(i) {
147
+ return wifiScanEncryption(i);
148
+ }
149
+ scanChannel(i) {
150
+ return wifiScanChannel(i);
151
+ }
152
+ }
153
+ WiFiClass.__instance_name = "WiFi";
154
+ export const WiFi = new WiFiClass();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typecad/hal",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.7",
4
4
  "description": "TypeCAD hardware abstraction layer — GPIO, I2C, SPI, UART as regular TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,9 +49,9 @@
49
49
  },
50
50
  "author": "typecad0",
51
51
  "devDependencies": {
52
- "@typecad/expect": "1.0.0-alpha.6",
53
- "@typecad/board-arduino-uno": "1.0.0-alpha.6",
54
- "@typecad/mcu-atmega328p": "1.0.0-alpha.6"
52
+ "@typecad/expect": "1.0.0-alpha.7",
53
+ "@typecad/board-arduino-uno": "1.0.0-alpha.7",
54
+ "@typecad/mcu-atmega328p": "1.0.0-alpha.7"
55
55
  },
56
56
  "sideEffects": false,
57
57
  "exports": {