@mikrojs/native 0.20.1 → 0.21.0-next.20260913195055

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 (56) hide show
  1. package/CMakeLists.txt +3 -1
  2. package/cmake/mikrojs_bytecode.cmake +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/runtime/result/native-result.node-shim.js.map +1 -1
  6. package/dist/runtime/result/types.d.ts +5 -5
  7. package/dist/runtime/result/types.d.ts.map +1 -1
  8. package/dist/types.d.ts +1 -1
  9. package/dist/types.d.ts.map +1 -1
  10. package/include/mikrojs/mikrojs.h +26 -2
  11. package/include/mikrojs/ota_env.h +8 -6
  12. package/include/mikrojs/ota_policy.h +16 -0
  13. package/include/mikrojs/private.h +13 -0
  14. package/include/mikrojs/utils.h +24 -0
  15. package/package.json +10 -10
  16. package/prebuilds/darwin-arm64/mikrojs.napi.node +0 -0
  17. package/prebuilds/linux-arm64/mikrojs.napi.node +0 -0
  18. package/prebuilds/linux-x64/mikrojs.napi.node +0 -0
  19. package/runtime/gpio/types.ts +116 -0
  20. package/runtime/i2c/types.ts +25 -31
  21. package/runtime/i2s/types.ts +23 -12
  22. package/runtime/internal.d.ts +1 -174
  23. package/runtime/kv/shared.ts +13 -11
  24. package/runtime/neopixel/types.ts +24 -6
  25. package/runtime/observable/native-observable.node-shim.ts +73 -37
  26. package/runtime/observable/native-operators.node-shim.ts +417 -0
  27. package/runtime/observable/observable.ts +76 -1
  28. package/runtime/observable/operators.ts +156 -89
  29. package/runtime/observable/types.ts +61 -6
  30. package/runtime/pwm/types.ts +31 -11
  31. package/runtime/result/native-result.node-shim.ts +1 -1
  32. package/runtime/result/types.ts +5 -5
  33. package/runtime/sleep/types.ts +10 -8
  34. package/runtime/spi/types.ts +16 -14
  35. package/runtime/uart/types.ts +27 -15
  36. package/src/gpio_claim.cpp +63 -0
  37. package/src/mik_abort.cpp +1 -2
  38. package/src/mik_console.cpp +192 -115
  39. package/src/mik_http_client.cpp +3 -14
  40. package/src/mik_inspect.cpp +86 -9
  41. package/src/mik_observable.cpp +1028 -80
  42. package/src/mik_ota_client.cpp +5 -2
  43. package/src/mik_ota_policy.cpp +65 -18
  44. package/src/mik_result.cpp +10 -9
  45. package/src/mikrojs.cpp +26 -13
  46. package/src/modules.cpp +17 -6
  47. package/src/timers.cpp +6 -2
  48. package/src/utils.cpp +106 -0
  49. package/runtime/i2c/i2c.ts +0 -35
  50. package/runtime/i2s/i2s.ts +0 -46
  51. package/runtime/neopixel/neopixel.ts +0 -38
  52. package/runtime/pin/pin.ts +0 -51
  53. package/runtime/pin/types.ts +0 -49
  54. package/runtime/pwm/pwm.ts +0 -32
  55. package/runtime/spi/spi.ts +0 -31
  56. package/runtime/uart/uart.ts +0 -52
@@ -1,49 +0,0 @@
1
- import type {Result} from '../result/types.js'
2
-
3
- export type PinMode = 'INPUT' | 'OUTPUT' | 'INPUT_PULLUP'
4
-
5
- /**
6
- * ADC attenuation setting, controls the measurable voltage range.
7
- * - `'0db'` — 0–750 mV
8
- * - `'2.5db'` — 0–1050 mV
9
- * - `'6db'` — 0–1300 mV
10
- * - `'11db'` — 0–2500 mV (default)
11
- */
12
- export type Attenuation = '0db' | '2.5db' | '6db' | '11db'
13
-
14
- export interface AnalogReadOptions {
15
- /** ADC attenuation. Defaults to `'11db'` (0–2500 mV range). */
16
- attenuation?: Attenuation
17
- }
18
-
19
- export type PinError =
20
- | {name: 'InvalidPin'; message: string}
21
- | {name: 'SetModeFailed'; message: string}
22
- | {name: 'WriteFailed'; message: string}
23
- | {name: 'AdcInitFailed'; message: string}
24
- | {name: 'AdcReadFailed'; message: string}
25
- | {name: 'InvalidAdcPin'}
26
-
27
- export declare function pinMode(pin: number, mode: PinMode): Result<void, PinError>
28
-
29
- export declare function digitalWrite(pin: number, value: 0 | 1): Result<void, PinError>
30
-
31
- export declare function digitalRead(pin: number): 0 | 1
32
-
33
- /**
34
- * Read the raw ADC value from a pin.
35
- * @returns A Result containing a 12-bit integer (0–4095) proportional to the input voltage, or a PinError.
36
- */
37
- export declare function analogRead(
38
- pin: number,
39
- options?: AnalogReadOptions,
40
- ): Result<number, PinError>
41
-
42
- /**
43
- * Read a calibrated voltage from a pin.
44
- * @returns A Result containing the input voltage in millivolts, or a PinError.
45
- */
46
- export declare function analogReadMillivolts(
47
- pin: number,
48
- options?: AnalogReadOptions,
49
- ): Result<number, PinError>
@@ -1,32 +0,0 @@
1
- import {ok} from 'mikro/result'
2
- import {Pwm as NativePwm} from 'native:mikro/pwm'
3
-
4
- import type {Result} from '../result/types.js'
5
- import type {PwmError, PwmOptions} from './types.js'
6
-
7
- export class Pwm {
8
- #native: InstanceType<typeof NativePwm>
9
-
10
- constructor(pin: number, options: PwmOptions) {
11
- this.#native = new NativePwm(pin, options.freq, options.duty ?? 0)
12
- }
13
-
14
- duty(value?: number): Result<number, PwmError> {
15
- return this.#native.duty(value)
16
- }
17
-
18
- freq(value?: number): Result<number, PwmError> {
19
- return this.#native.freq(value)
20
- }
21
-
22
- async fade(targetDuty: number, durationMs: number): Promise<Result<void, PwmError>> {
23
- const result = this.#native.fade(targetDuty, durationMs)
24
- if (!result.ok) return result
25
- await result.value
26
- return ok(undefined)
27
- }
28
-
29
- end(): Result<void, PwmError> {
30
- return this.#native.end()
31
- }
32
- }
@@ -1,31 +0,0 @@
1
- import * as native from 'native:mikro/spi'
2
-
3
- import type {Result} from '../result/types.js'
4
- import type {Spi as PlatformSpi, SpiError, SpiOptions} from './types.js'
5
-
6
- /**
7
- * @public
8
- */
9
- export class Spi implements PlatformSpi {
10
- #native: native.Spi
11
-
12
- constructor(hostNo: 1 | 2, options: SpiOptions) {
13
- this.#native = new native.Spi(hostNo, options)
14
- }
15
-
16
- begin(): Result<void, SpiError> {
17
- return this.#native.begin()
18
- }
19
-
20
- end(): Result<void, SpiError> {
21
- return this.#native.end()
22
- }
23
-
24
- transfer(data: Uint8Array): Result<Uint8Array, SpiError> {
25
- return this.#native.transfer(data)
26
- }
27
-
28
- write(data: Uint8Array): Result<void, SpiError> {
29
- return this.#native.write(data)
30
- }
31
- }
@@ -1,52 +0,0 @@
1
- import {ok} from 'mikro/result'
2
- import * as native from 'native:mikro/uart'
3
-
4
- import type {Result} from '../result/types.js'
5
- import type {
6
- UartBase,
7
- UartBaseOptions,
8
- UartError,
9
- UartRxOnlyOptions,
10
- UartTxOnlyOptions,
11
- UartTxRxOptions,
12
- } from './types.js'
13
-
14
- /**
15
- * @public
16
- */
17
- export class Uart implements UartBase {
18
- #native: native.Uart
19
-
20
- constructor(port: number, options: UartTxRxOptions)
21
- constructor(port: number, options: UartTxOnlyOptions)
22
- constructor(port: number, options: UartRxOnlyOptions)
23
- constructor(port: number, options: UartBaseOptions & {tx?: number; rx?: number}) {
24
- this.#native = new native.Uart(port, options)
25
- }
26
-
27
- begin(): Result<void, UartError> {
28
- return this.#native.begin()
29
- }
30
-
31
- end(): Result<void, UartError> {
32
- return this.#native.end()
33
- }
34
-
35
- write(data: Uint8Array): Result<void, UartError> {
36
- return this.#native.write(data)
37
- }
38
-
39
- read(): Result<AsyncIterable<Result<Uint8Array, UartError>>, UartError> {
40
- const result = this.#native.read()
41
- if (!result.ok) return result
42
- const nativeIter = result.value
43
- // Wrap the native iterator object (which has next/return) into a proper AsyncIterable.
44
- // Native yields Result items directly via mik__result_ok / mik__result_err_tag.
45
- const iterable: AsyncIterable<Result<Uint8Array, UartError>> = {
46
- [Symbol.asyncIterator]() {
47
- return nativeIter as AsyncIterator<Result<Uint8Array, UartError>>
48
- },
49
- }
50
- return ok(iterable)
51
- }
52
- }