@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.
- package/CMakeLists.txt +3 -1
- package/cmake/mikrojs_bytecode.cmake +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/runtime/result/native-result.node-shim.js.map +1 -1
- package/dist/runtime/result/types.d.ts +5 -5
- package/dist/runtime/result/types.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/include/mikrojs/mikrojs.h +26 -2
- package/include/mikrojs/ota_env.h +8 -6
- package/include/mikrojs/ota_policy.h +16 -0
- package/include/mikrojs/private.h +13 -0
- package/include/mikrojs/utils.h +24 -0
- package/package.json +10 -10
- package/prebuilds/darwin-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-x64/mikrojs.napi.node +0 -0
- package/runtime/gpio/types.ts +116 -0
- package/runtime/i2c/types.ts +25 -31
- package/runtime/i2s/types.ts +23 -12
- package/runtime/internal.d.ts +1 -174
- package/runtime/kv/shared.ts +13 -11
- package/runtime/neopixel/types.ts +24 -6
- package/runtime/observable/native-observable.node-shim.ts +73 -37
- package/runtime/observable/native-operators.node-shim.ts +417 -0
- package/runtime/observable/observable.ts +76 -1
- package/runtime/observable/operators.ts +156 -89
- package/runtime/observable/types.ts +61 -6
- package/runtime/pwm/types.ts +31 -11
- package/runtime/result/native-result.node-shim.ts +1 -1
- package/runtime/result/types.ts +5 -5
- package/runtime/sleep/types.ts +10 -8
- package/runtime/spi/types.ts +16 -14
- package/runtime/uart/types.ts +27 -15
- package/src/gpio_claim.cpp +63 -0
- package/src/mik_abort.cpp +1 -2
- package/src/mik_console.cpp +192 -115
- package/src/mik_http_client.cpp +3 -14
- package/src/mik_inspect.cpp +86 -9
- package/src/mik_observable.cpp +1028 -80
- package/src/mik_ota_client.cpp +5 -2
- package/src/mik_ota_policy.cpp +65 -18
- package/src/mik_result.cpp +10 -9
- package/src/mikrojs.cpp +26 -13
- package/src/modules.cpp +17 -6
- package/src/timers.cpp +6 -2
- package/src/utils.cpp +106 -0
- package/runtime/i2c/i2c.ts +0 -35
- package/runtime/i2s/i2s.ts +0 -46
- package/runtime/neopixel/neopixel.ts +0 -38
- package/runtime/pin/pin.ts +0 -51
- package/runtime/pin/types.ts +0 -49
- package/runtime/pwm/pwm.ts +0 -32
- package/runtime/spi/spi.ts +0 -31
- package/runtime/uart/uart.ts +0 -52
package/runtime/pin/types.ts
DELETED
|
@@ -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>
|
package/runtime/pwm/pwm.ts
DELETED
|
@@ -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
|
-
}
|
package/runtime/spi/spi.ts
DELETED
|
@@ -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
|
-
}
|
package/runtime/uart/uart.ts
DELETED
|
@@ -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
|
-
}
|