@typecad/hal 1.0.0-alpha.14 → 1.0.0-alpha.16

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.
Files changed (121) hide show
  1. package/README.md +145 -87
  2. package/dist/adc-pin.d.ts +53 -0
  3. package/dist/adc-pin.js +69 -0
  4. package/dist/async.d.ts +3 -11
  5. package/dist/async.js +3 -15
  6. package/dist/ble.d.ts +42 -78
  7. package/dist/ble.js +79 -98
  8. package/dist/counter.d.ts +16 -0
  9. package/dist/counter.js +32 -0
  10. package/dist/dac-pin.d.ts +13 -0
  11. package/dist/dac-pin.js +21 -0
  12. package/dist/emit.d.ts +123 -196
  13. package/dist/emit.js +146 -208
  14. package/dist/fs.d.ts +12 -31
  15. package/dist/fs.js +30 -40
  16. package/dist/gpio-pin.d.ts +46 -0
  17. package/dist/gpio-pin.js +77 -0
  18. package/dist/gpio.d.ts +0 -103
  19. package/dist/gpio.js +16 -227
  20. package/dist/http.d.ts +38 -39
  21. package/dist/http.js +53 -78
  22. package/dist/i2c-target.d.ts +28 -0
  23. package/dist/i2c-target.js +52 -0
  24. package/dist/i2c.d.ts +5 -43
  25. package/dist/i2c.js +17 -130
  26. package/dist/index.d.ts +30 -42
  27. package/dist/index.js +27 -39
  28. package/dist/math.d.ts +0 -13
  29. package/dist/math.js +9 -13
  30. package/dist/mqtt.d.ts +15 -25
  31. package/dist/mqtt.js +32 -28
  32. package/dist/power.d.ts +9 -17
  33. package/dist/power.js +22 -20
  34. package/dist/preferences.d.ts +17 -25
  35. package/dist/preferences.js +54 -52
  36. package/dist/pulse.d.ts +4 -4
  37. package/dist/pulse.js +6 -2
  38. package/dist/pwm-pin.d.ts +24 -0
  39. package/dist/pwm-pin.js +38 -0
  40. package/dist/random.d.ts +0 -2
  41. package/dist/random.js +14 -20
  42. package/dist/sensor-catalog.generated.d.ts +997 -0
  43. package/dist/sensor-catalog.generated.js +764 -0
  44. package/dist/sensor.d.ts +46 -0
  45. package/dist/sensor.js +52 -0
  46. package/dist/shift-pin.d.ts +2 -0
  47. package/dist/shift-pin.js +13 -0
  48. package/dist/spi-target.d.ts +25 -0
  49. package/dist/spi-target.js +42 -0
  50. package/dist/spi.d.ts +8 -26
  51. package/dist/spi.js +15 -87
  52. package/dist/thread.d.ts +18 -0
  53. package/dist/thread.js +36 -0
  54. package/dist/time.d.ts +23 -0
  55. package/dist/time.js +43 -0
  56. package/dist/timing.d.ts +17 -7
  57. package/dist/timing.js +17 -7
  58. package/dist/types.d.ts +4 -34
  59. package/dist/types.js +5 -47
  60. package/dist/uart-port.d.ts +26 -0
  61. package/dist/uart-port.js +52 -0
  62. package/dist/uart.d.ts +0 -17
  63. package/dist/uart.js +10 -53
  64. package/dist/usb.d.ts +26 -0
  65. package/dist/usb.js +66 -0
  66. package/dist/watchdog.d.ts +12 -0
  67. package/dist/watchdog.js +28 -0
  68. package/dist/wifi.d.ts +88 -64
  69. package/dist/wifi.js +112 -126
  70. package/dist/zephyr-tokens.generated.d.ts +8 -0
  71. package/dist/zephyr-tokens.generated.js +73 -0
  72. package/package.json +6 -7
  73. package/src/adc-pin.ts +89 -0
  74. package/src/async.ts +3 -16
  75. package/src/ble.ts +84 -111
  76. package/src/counter.ts +40 -0
  77. package/src/dac-pin.ts +28 -0
  78. package/src/emit.ts +157 -238
  79. package/src/fs.ts +47 -54
  80. package/src/gpio-pin.ts +91 -0
  81. package/src/gpio.ts +49 -320
  82. package/src/http.ts +75 -95
  83. package/src/i2c-target.ts +63 -0
  84. package/src/i2c.ts +29 -167
  85. package/src/index.ts +32 -46
  86. package/src/math.ts +9 -14
  87. package/src/mqtt.ts +39 -31
  88. package/src/preferences.ts +52 -61
  89. package/src/pwm-pin.ts +54 -0
  90. package/src/random.ts +14 -21
  91. package/src/sensor-catalog.generated.ts +1238 -0
  92. package/src/sensor.ts +80 -0
  93. package/src/shift-pin.ts +16 -0
  94. package/src/spi-target.ts +53 -0
  95. package/src/spi.ts +27 -121
  96. package/src/thread.ts +44 -0
  97. package/src/time.ts +50 -0
  98. package/src/types.ts +14 -89
  99. package/src/uart-port.ts +64 -0
  100. package/src/usb.ts +82 -0
  101. package/src/watchdog.ts +35 -0
  102. package/src/wifi.ts +147 -179
  103. package/src/zephyr-tokens.generated.ts +77 -0
  104. package/src/adc.ts +0 -30
  105. package/src/capacitive.ts +0 -31
  106. package/src/constants.ts +0 -23
  107. package/src/dac.ts +0 -21
  108. package/src/eeprom.ts +0 -26
  109. package/src/interrupts.ts +0 -35
  110. package/src/mdns.ts +0 -50
  111. package/src/ota.ts +0 -44
  112. package/src/power.ts +0 -36
  113. package/src/pulse.ts +0 -63
  114. package/src/rmt.ts +0 -125
  115. package/src/shift.ts +0 -88
  116. package/src/temperature.ts +0 -20
  117. package/src/timer.ts +0 -58
  118. package/src/timing.ts +0 -67
  119. package/src/uart.ts +0 -77
  120. package/src/utils.ts +0 -17
  121. package/src/wdt.ts +0 -17
@@ -0,0 +1,77 @@
1
+ // ---------------------------------------------------------------------------
2
+ // GPIO — the thin Zephyr-shaped digital pin class
3
+ //
4
+ // One configured pin handle ≈ gpio_dt_spec + flags, mirroring Zephyr's verbs:
5
+ // construction carries the flag combination (GPIO.OUTPUT | GPIO.PULL_UP),
6
+ // set/get/toggle lower to gpio_pin_set_dt / get_dt / toggle_dt (logical
7
+ // levels — polarity comes from the board's DT node when the pin has a dtSpec),
8
+ // and the configure itself is emitted guarded-per-pin ahead of the first use,
9
+ // so construction flags apply exactly once. No mode strings, no shadow reads.
10
+ //
11
+ // Flag and interrupt tokens are Zephyr's names under the GPIO. namespace
12
+ // (GPIO_OUTPUT ↔ GPIO.OUTPUT, GPIO_INT_EDGE_FALLING ↔ GPIO.INT_EDGE_FALLING);
13
+ // the lowering maps token NAMES to macros, so any Zephyr doc greps both ways.
14
+ // ----------------------------------------------------------------------------
15
+ import { gpioWrite, gpioReadCfg, gpioToggle, gpioConfigure, interruptAttachFlags, interruptDetach } from './emit.js';
16
+ import { callback } from './callback.js';
17
+ export class GPIO {
18
+ /** Construct a configured pin. `flags` is a combination of the GPIO.*
19
+ * statics (the transpiler carries the token text; the values are for the
20
+ * editor only). The configure applies once, ahead of the first
21
+ * set/get/toggle/onInterrupt call. */
22
+ constructor(pin, flags) {
23
+ this._pin = typeof pin === 'number' ? pin : pin.number;
24
+ this._flags = flags;
25
+ }
26
+ /** Drive the pin (gpio_pin_set_dt / set_raw). Logical level: on a pin with
27
+ * a board dtSpec (LED, BUTTON), true means "active" — the DT node's
28
+ * GPIO_ACTIVE_LOW is honored. */
29
+ set(value) {
30
+ gpioConfigure(this._pin, this._flags);
31
+ gpioWrite(this._pin, value);
32
+ }
33
+ /** Read the pin (gpio_pin_get_dt / get_raw). Logical level. The guarded
34
+ * configure is FUSED into the read's lowering (one statement-expression),
35
+ * so the pin is correctly configured even when the call sits in a pure
36
+ * expression position (if-conditions, comparisons) where a method's
37
+ * leading side-effect ops would otherwise be dropped. */
38
+ get() {
39
+ return gpioReadCfg(this._pin, this._flags);
40
+ }
41
+ /** Toggle the pin (gpio_pin_toggle_dt — the driver's atomic toggle). */
42
+ toggle() {
43
+ gpioConfigure(this._pin, this._flags);
44
+ gpioToggle(this._pin);
45
+ }
46
+ /** Attach an interrupt (gpio_pin_interrupt_configure_dt +
47
+ * gpio_init_callback + gpio_add_callback). `intFlags` is one GPIO.INT_*
48
+ * token — Zephyr's names verbatim, covering the level modes the legacy
49
+ * onHigh/onLow strings could not express. */
50
+ onInterrupt(intFlags, handler) {
51
+ gpioConfigure(this._pin, this._flags);
52
+ interruptAttachFlags(this._pin, callback(handler), intFlags);
53
+ }
54
+ /** Detach the interrupt (disable + remove callback). */
55
+ offInterrupt() {
56
+ interruptDetach(this._pin);
57
+ }
58
+ }
59
+ // ── Config flags (gpio.h) ──────────────────────────────────────────────
60
+ GPIO.INPUT = 0x001;
61
+ GPIO.OUTPUT = 0x002;
62
+ /** Configure the output buffer's initial level atomically — no
63
+ * configure-then-write glitch window. */
64
+ GPIO.OUTPUT_INIT_LOW = 0x004;
65
+ GPIO.OUTPUT_INIT_HIGH = 0x008;
66
+ GPIO.PULL_UP = 0x010;
67
+ GPIO.PULL_DOWN = 0x020;
68
+ GPIO.OPEN_DRAIN = 0x040;
69
+ GPIO.OPEN_SOURCE = 0x080;
70
+ GPIO.DISCONNECTED = 0x100;
71
+ // ── Interrupt flags (GPIO_INT_* minus the prefix) ──────────────────────
72
+ GPIO.INT_DISABLE = 0x01;
73
+ GPIO.INT_EDGE_RISING = 0x02;
74
+ GPIO.INT_EDGE_FALLING = 0x04;
75
+ GPIO.INT_EDGE_BOTH = 0x08;
76
+ GPIO.INT_LEVEL_LOW = 0x10;
77
+ GPIO.INT_LEVEL_HIGH = 0x20;
package/dist/gpio.d.ts CHANGED
@@ -1,87 +1,3 @@
1
- export declare class OutputPin {
2
- private _pin;
3
- readonly number: number;
4
- readonly gpio: number;
5
- constructor(pin: number);
6
- high(): void;
7
- low(): void;
8
- toggle(): void;
9
- write(value: number | boolean): void;
10
- /**
11
- * Returns the level the program last drove onto this output pin.
12
- *
13
- * The transpiler tracks every write (high/low/write/toggle and the
14
- * asOutput initial value) and lowers this to a compile-time constant
15
- * when the state is statically known, or to a tracked shadow variable
16
- * the generated writes keep updated. No hardware pin read is performed —
17
- * reading back an OUTPUT-only pin is not portable (e.g. Zephyr), so this
18
- * reports software truth, not electrical truth.
19
- */
20
- read(): boolean;
21
- isHigh(): boolean;
22
- isLow(): boolean;
23
- pulse(durationMs: number): void;
24
- tone(frequency: number): ToneChain;
25
- toneFor(frequency: number, duration: number): void;
26
- noTone(): void;
27
- pwm(duty: number): void;
28
- getPwmFrequency(): number;
29
- getPwmResolution(): number;
30
- }
31
- export declare class InputPin {
32
- private _pin;
33
- readonly number: number;
34
- readonly gpio: number;
35
- constructor(pin: number);
36
- read(): boolean;
37
- isHigh(): boolean;
38
- isLow(): boolean;
39
- readAnalog(): number;
40
- readVoltage(): number;
41
- getAnalogResolution(): number;
42
- setAnalogReference(ref: string): void;
43
- onFalling(handler: () => void): void;
44
- onRising(handler: () => void): void;
45
- onChange(handler: () => void): void;
46
- offAll(): void;
47
- /** Alias matching the BasePin.offInterrupts() interface name. */
48
- offInterrupts(): void;
49
- /**
50
- * Wait for a RISING edge on this input pin.
51
- * Returns a Promise<void> that resolves when the pin transitions from LOW to HIGH.
52
- * The platform strategy controls whether this uses interrupts, polling, or a stub.
53
- *
54
- * @param timeout Optional timeout in milliseconds. If provided, the promise
55
- * rejects (or resolves with a false/error) after the timeout expires.
56
- */
57
- waitForRising(timeout?: number): Promise<void>;
58
- /**
59
- * Wait for a FALLING edge on this input pin.
60
- * Returns a Promise<void> that resolves when the pin transitions from HIGH to LOW.
61
- *
62
- * @param timeout Optional timeout in milliseconds. If provided, the promise
63
- * rejects (or resolves with a false/error) after the timeout expires.
64
- */
65
- waitForFalling(timeout?: number): Promise<void>;
66
- }
67
- export declare class ToneChain {
68
- private _pin;
69
- private _lastFreq;
70
- constructor(pin: number, frequency: number);
71
- for(duration: number): void;
72
- }
73
- /**
74
- * Represents a physical hardware pin before it has been configured for a specific mode.
75
- * Use `.asInput()` or `.asOutput()` to obtain a functional pin instance.
76
- *
77
- * Pins can be created two ways:
78
- * - `new Pin(number)` — legacy, using framework pin number (e.g. Arduino pin 13)
79
- * - `Pin.fromPort("PB5")` — preferred, using MCU datasheet port name
80
- *
81
- * When created via `fromPort()`, the pin carries its canonical port identity.
82
- * The transpiler resolves the port name to a framework pin number at compile time
83
- * using the MCU package's pin mapping (e.g. arduino-map.ts).
84
- */
85
1
  export declare class Pin {
86
2
  /** MCU port name (e.g. "PB5") — empty string for legacy numeric pins */
87
3
  private _port;
@@ -99,23 +15,4 @@ export declare class Pin {
99
15
  * are resolved at transpile time via the MCU package's pin mapping.
100
16
  */
101
17
  static fromPort(portName: string): Pin;
102
- asOutput(initial?: number | boolean): OutputPin;
103
- /** Alias for asOutput() — shorter fluent form. */
104
- output(initial?: number | boolean): OutputPin;
105
- asInput(): InputPin;
106
- asInputPullUp(): InputPin;
107
- asInputPullDown(): InputPin;
108
- inputPullUp(): InputPin;
109
- /** Alias for asInputPullDown() — shorter fluent form. */
110
- inputPullDown(): InputPin;
111
- read(): boolean;
112
- isHigh(): boolean;
113
- isLow(): boolean;
114
- write(value: number | boolean): void;
115
- high(): void;
116
- low(): void;
117
- toggle(): void;
118
- pwm(duty: number): void;
119
- tone(frequency: number): ToneChain;
120
- noTone(): void;
121
18
  }
package/dist/gpio.js CHANGED
@@ -1,157 +1,19 @@
1
- import { gpioWrite, gpioRead, gpioToggle, gpioSetMode, tonePlay, toneStop, adcRead, adcReadVoltage, adcSetReference, interruptAttach, interruptDetach, pwmWrite, rawCpp, boardResolve } from './emit.js';
2
- import { callback } from './callback.js';
3
- import { ADC } from './adc.js';
4
- export class OutputPin {
5
- constructor(pin) {
6
- this._pin = pin;
7
- this.number = pin;
8
- this.gpio = pin;
9
- }
10
- high() {
11
- gpioWrite(this._pin, 1);
12
- }
13
- low() {
14
- gpioWrite(this._pin, 0);
15
- }
16
- toggle() {
17
- gpioToggle(this._pin);
18
- }
19
- write(value) {
20
- gpioWrite(this._pin, value);
21
- }
22
- /**
23
- * Returns the level the program last drove onto this output pin.
24
- *
25
- * The transpiler tracks every write (high/low/write/toggle and the
26
- * asOutput initial value) and lowers this to a compile-time constant
27
- * when the state is statically known, or to a tracked shadow variable
28
- * the generated writes keep updated. No hardware pin read is performed —
29
- * reading back an OUTPUT-only pin is not portable (e.g. Zephyr), so this
30
- * reports software truth, not electrical truth.
31
- */
32
- read() {
33
- return gpioRead(this._pin);
34
- }
35
- isHigh() {
36
- return this.read();
37
- }
38
- isLow() {
39
- return !this.read();
40
- }
41
- pulse(durationMs) {
42
- gpioWrite(this._pin, 1);
43
- rawCpp(`delay(${durationMs});`);
44
- gpioWrite(this._pin, 0);
45
- }
46
- tone(frequency) {
47
- tonePlay(this._pin, frequency);
48
- return new ToneChain(this._pin, frequency);
49
- }
50
- toneFor(frequency, duration) {
51
- tonePlay(this._pin, frequency, duration);
52
- }
53
- noTone() {
54
- toneStop(this._pin);
55
- }
56
- pwm(duty) {
57
- pwmWrite(this._pin, duty);
58
- }
59
- getPwmFrequency() {
60
- return boardResolve("peripherals.pwm.maxFrequency");
61
- }
62
- getPwmResolution() {
63
- return boardResolve("peripherals.pwm.resolution");
64
- }
65
- }
66
- export class InputPin {
67
- constructor(pin) {
68
- this._pin = pin;
69
- this.number = pin;
70
- this.gpio = pin;
71
- }
72
- read() {
73
- return gpioRead(this._pin);
74
- }
75
- isHigh() {
76
- return this.read();
77
- }
78
- isLow() {
79
- return !this.read();
80
- }
81
- readAnalog() {
82
- return adcRead(this._pin);
83
- }
84
- readVoltage() {
85
- return adcReadVoltage(this._pin);
86
- }
87
- getAnalogResolution() {
88
- return boardResolve("peripherals.adc.0.resolution");
89
- }
90
- setAnalogReference(ref) {
91
- ADC._reference = ref;
92
- adcSetReference(ref);
93
- }
94
- onFalling(handler) {
95
- interruptAttach(this._pin, callback(handler), "FALLING");
96
- }
97
- onRising(handler) {
98
- interruptAttach(this._pin, callback(handler), "RISING");
99
- }
100
- onChange(handler) {
101
- interruptAttach(this._pin, callback(handler), "CHANGE");
102
- }
103
- offAll() {
104
- interruptDetach(this._pin);
105
- }
106
- /** Alias matching the BasePin.offInterrupts() interface name. */
107
- offInterrupts() {
108
- interruptDetach(this._pin);
109
- }
110
- /**
111
- * Wait for a RISING edge on this input pin.
112
- * Returns a Promise<void> that resolves when the pin transitions from LOW to HIGH.
113
- * The platform strategy controls whether this uses interrupts, polling, or a stub.
114
- *
115
- * @param timeout Optional timeout in milliseconds. If provided, the promise
116
- * rejects (or resolves with a false/error) after the timeout expires.
117
- */
118
- waitForRising(timeout) {
119
- rawCpp(`__cuttlefish_wait_pin_edge(${this._pin}, RISING, ${timeout ?? -1});`);
120
- return Promise.resolve();
121
- }
122
- /**
123
- * Wait for a FALLING edge on this input pin.
124
- * Returns a Promise<void> that resolves when the pin transitions from HIGH to LOW.
125
- *
126
- * @param timeout Optional timeout in milliseconds. If provided, the promise
127
- * rejects (or resolves with a false/error) after the timeout expires.
128
- */
129
- waitForFalling(timeout) {
130
- rawCpp(`__cuttlefish_wait_pin_edge(${this._pin}, FALLING, ${timeout ?? -1});`);
131
- return Promise.resolve();
132
- }
133
- }
134
- export class ToneChain {
135
- constructor(pin, frequency) {
136
- this._pin = pin;
137
- this._lastFreq = frequency;
138
- }
139
- for(duration) {
140
- tonePlay(this._pin, this._lastFreq, duration);
141
- }
142
- }
143
- /**
144
- * Represents a physical hardware pin before it has been configured for a specific mode.
145
- * Use `.asInput()` or `.asOutput()` to obtain a functional pin instance.
146
- *
147
- * Pins can be created two ways:
148
- * - `new Pin(number)` — legacy, using framework pin number (e.g. Arduino pin 13)
149
- * - `Pin.fromPort("PB5")` — preferred, using MCU datasheet port name
150
- *
151
- * When created via `fromPort()`, the pin carries its canonical port identity.
152
- * The transpiler resolves the port name to a framework pin number at compile time
153
- * using the MCU package's pin mapping (e.g. arduino-map.ts).
154
- */
1
+ // ---------------------------------------------------------------------------
2
+ // Pin the board-addressable pin identity (legacy GPIO classes removed)
3
+ //
4
+ // A Pin carries its canonical datasheet port name (Pin.fromPort("PB5")) and/or
5
+ // framework pin number; the transpiler resolves it via the MCU package's pin
6
+ // mapping. It is an ADDRESS, not a configured peripheral — configure pins by
7
+ // constructing the thin peripherals with them:
8
+ //
9
+ // new GPIO(PB5, GPIO.OUTPUT | GPIO.PULL_UP)
10
+ // new PWM(PA5, { periodNs: 20_000_000 })
11
+ // new ADC(A1)
12
+ //
13
+ // The former OutputPin/InputPin/ToneChain classes (and their as*/read/write/
14
+ // pwm methods) were removed with the legacy Arduino surface. Their thin
15
+ // replacements are gpio-pin.ts / pwm-pin.ts / adc-pin.ts.
16
+ // ---------------------------------------------------------------------------
155
17
  export class Pin {
156
18
  /** Legacy constructor — creates a Pin from a framework pin number */
157
19
  constructor(pin) {
@@ -173,77 +35,4 @@ export class Pin {
173
35
  p.port = portName;
174
36
  return p;
175
37
  }
176
- asOutput(initial) {
177
- gpioSetMode(this._pin, "OUTPUT");
178
- if (initial !== undefined) {
179
- gpioWrite(this._pin, initial);
180
- }
181
- // Returns `this` so the transpiler can suppress the C++ return emission
182
- // (it resolves `this` to the same instance and tracks the result as an
183
- // OutputPin via the method name). Returning `new OutputPin(this._pin)`
184
- // would leak the literal text into generated C++. The cast is required
185
- // because Pin and OutputPin are structurally distinct classes; the
186
- // transpiler handles the mode transition semantically.
187
- return this;
188
- }
189
- /** Alias for asOutput() — shorter fluent form. */
190
- output(initial) {
191
- gpioSetMode(this._pin, "OUTPUT");
192
- if (initial !== undefined) {
193
- gpioWrite(this._pin, initial);
194
- }
195
- return this;
196
- }
197
- asInput() {
198
- gpioSetMode(this._pin, "INPUT");
199
- return this;
200
- }
201
- asInputPullUp() {
202
- gpioSetMode(this._pin, "INPUT_PULLUP");
203
- return this;
204
- }
205
- asInputPullDown() {
206
- gpioSetMode(this._pin, "INPUT_PULLDOWN");
207
- return this;
208
- }
209
- inputPullUp() {
210
- gpioSetMode(this._pin, "INPUT_PULLUP");
211
- return this;
212
- }
213
- /** Alias for asInputPullDown() — shorter fluent form. */
214
- inputPullDown() {
215
- gpioSetMode(this._pin, "INPUT_PULLDOWN");
216
- return this;
217
- }
218
- read() {
219
- return gpioRead(this._pin);
220
- }
221
- isHigh() {
222
- return this.read();
223
- }
224
- isLow() {
225
- return !this.read();
226
- }
227
- write(value) {
228
- gpioWrite(this._pin, value);
229
- }
230
- high() {
231
- gpioWrite(this._pin, 1);
232
- }
233
- low() {
234
- gpioWrite(this._pin, 0);
235
- }
236
- toggle() {
237
- gpioToggle(this._pin);
238
- }
239
- pwm(duty) {
240
- pwmWrite(this._pin, duty);
241
- }
242
- tone(frequency) {
243
- tonePlay(this._pin, frequency);
244
- return new ToneChain(this._pin, frequency);
245
- }
246
- noTone() {
247
- toneStop(this._pin);
248
- }
249
38
  }
package/dist/http.d.ts CHANGED
@@ -1,48 +1,47 @@
1
- export declare enum HttpMethod {
2
- GET = 0,
3
- POST = 1,
4
- PUT = 2,
5
- DELETE = 3,
6
- HEAD = 4,
7
- PATCH = 5
1
+ /** Request construction facts beyond method + URL. */
2
+ export interface RequestOpts {
3
+ /** Response timeout in ms (default 10_000). */
4
+ timeoutMs?: number;
5
+ /** Request body (raw). */
6
+ body?: string;
7
+ /** The body is JSON — sets the JSON content type. */
8
+ json?: boolean;
9
+ /** Skip TLS certificate verification (development only). */
10
+ insecure?: boolean;
11
+ /** PEM of a trusted CA — enables verified TLS. */
12
+ caCert?: string;
8
13
  }
9
- /**
10
- * Fluent HTTP/S request builder, lowered to native ESP-IDF
11
- * `esp_http_client` by framework-esp32 (TLS via esp-tls / mbedTLS bundle).
12
- * Response fields are read from this object after send() — mirrors
13
- * `await WiFi.connect(); WiFi.localIP()`.
14
- *
15
- * No `include()` calls here — ESP-IDF headers are framework-owned and added
16
- * via forcedIncludes when the program uses http.* ops.
17
- */
18
- export declare class HttpRequest {
19
- private _method;
20
- private _url;
21
- constructor(method: string, url: string);
14
+ export declare class Request {
15
+ static readonly GET = "GET";
16
+ static readonly POST = "POST";
17
+ static readonly PUT = "PUT";
18
+ static readonly DELETE = "DELETE";
19
+ static readonly HEAD = "HEAD";
20
+ static readonly PATCH = "PATCH";
21
+ private readonly _method;
22
+ private readonly _url;
23
+ private readonly _timeoutMs;
24
+ private readonly _body;
25
+ private readonly _json;
26
+ private readonly _insecure;
27
+ private readonly _caCert;
28
+ constructor(method: string, url: string, opts?: RequestOpts);
29
+ /** Attach a request header. Chainable — one per header. */
22
30
  header(name: string, value: string): this;
23
- timeout(ms: number): this;
24
- maxBody(bytes: number): this;
25
- body(data: string): this;
26
- jsonBody(json: string): this;
27
- /** Skip TLS certificate verification (development only). */
28
- insecure(): this;
29
- caCert(pem: string): this;
30
- /** Blocking at top level; cooperatively awaitable inside async functions. */
31
- send(): Promise<boolean>;
31
+ /** Send the request (blocking). The construction facts lower into the
32
+ * shim first (timeout/body/TLS mode), then the request performs.
33
+ * Awaitable inside async functions — the async machinery splits the
34
+ * send into a background request + done-poll. */
35
+ send(): boolean;
36
+ /** Response status code (0 before a completed send). */
32
37
  status(): number;
38
+ /** True when the response status is 2xx. */
33
39
  ok(): boolean;
34
40
  /** Response body as a C string (valid until the next request). */
35
41
  text(): string;
42
+ /** Response Content-Length (0 when absent). */
36
43
  contentLength(): number;
44
+ /** One response header value ("" when absent; valid until the next
45
+ * request). */
37
46
  responseHeader(name: string): string;
38
47
  }
39
- export declare class HttpClass {
40
- static readonly __instance_name = "Http";
41
- get(url: string): HttpRequest;
42
- post(url: string): HttpRequest;
43
- put(url: string): HttpRequest;
44
- del(url: string): HttpRequest;
45
- head(url: string): HttpRequest;
46
- patch(url: string): HttpRequest;
47
- }
48
- export declare const Http: HttpClass;