@ikalogic/at1000 0.2.2 → 0.4.0
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 +21 -0
- package/build/at1000-B3HgANSi.d.mts +109 -0
- package/build/at1000-B3HgANSi.d.mts.map +1 -0
- package/build/at1000-B_udjy0I.cjs +8 -0
- package/build/at1000-B_udjy0I.cjs.map +1 -0
- package/build/at1000-BjVj0Ujk.mjs +8 -0
- package/build/at1000-BjVj0Ujk.mjs.map +1 -0
- package/build/at1000-C6w5G8L4.d.cts +109 -0
- package/build/at1000-C6w5G8L4.d.cts.map +1 -0
- package/build/browser.cjs +1 -1
- package/build/browser.cjs.map +1 -1
- package/build/browser.d.cts +9 -2
- package/build/browser.d.cts.map +1 -1
- package/build/browser.d.mts +9 -2
- package/build/browser.d.mts.map +1 -1
- package/build/browser.mjs +1 -1
- package/build/browser.mjs.map +1 -1
- package/build/{com-CBhjFJPB.d.cts → com-BLw4CGid.d.cts} +61 -61
- package/build/{com-CBhjFJPB.d.cts.map → com-BLw4CGid.d.cts.map} +1 -1
- package/build/{com-CBhjFJPB.d.mts → com-BLw4CGid.d.mts} +61 -61
- package/build/{com-CBhjFJPB.d.mts.map → com-BLw4CGid.d.mts.map} +1 -1
- package/build/com.cjs +1 -1
- package/build/com.cjs.map +1 -1
- package/build/com.d.cts +2 -2
- package/build/com.d.mts +2 -2
- package/build/com.mjs +1 -1
- package/build/com.mjs.map +1 -1
- package/build/events-CBVQfojK.d.cts +359 -0
- package/build/events-CBVQfojK.d.cts.map +1 -0
- package/build/events-CBVQfojK.d.mts +359 -0
- package/build/events-CBVQfojK.d.mts.map +1 -0
- package/build/events.cjs +1 -0
- package/build/events.d.cts +2 -0
- package/build/events.d.mts +2 -0
- package/build/events.mjs +1 -0
- package/build/{gpio-DNrdX-QV.d.cts → gpio-BuvDysYa.d.cts} +65 -16
- package/build/gpio-BuvDysYa.d.cts.map +1 -0
- package/build/{gpio-DchxrXWK.d.mts → gpio-DgQHE5fr.d.mts} +65 -16
- package/build/gpio-DgQHE5fr.d.mts.map +1 -0
- package/build/gpio.cjs +1 -1
- package/build/gpio.cjs.map +1 -1
- package/build/gpio.d.cts +2 -2
- package/build/gpio.d.mts +2 -2
- package/build/gpio.mjs +1 -1
- package/build/gpio.mjs.map +1 -1
- package/build/{hmi-DszM-Hfp.d.cts → hmi-BrdqKB3o.d.cts} +17 -5
- package/build/hmi-BrdqKB3o.d.cts.map +1 -0
- package/build/{hmi-DszM-Hfp.d.mts → hmi-BrdqKB3o.d.mts} +17 -5
- package/build/hmi-BrdqKB3o.d.mts.map +1 -0
- package/build/hmi.cjs +1 -1
- package/build/hmi.cjs.map +1 -1
- package/build/hmi.d.cts +2 -2
- package/build/hmi.d.mts +2 -2
- package/build/hmi.mjs +1 -1
- package/build/hmi.mjs.map +1 -1
- package/build/management.cjs +1 -2
- package/build/management.d.cts +816 -2
- package/build/management.d.cts.map +1 -0
- package/build/management.d.mts +816 -2
- package/build/management.d.mts.map +1 -0
- package/build/management.mjs +1 -2
- package/build/node.cjs +1 -1
- package/build/node.cjs.map +1 -1
- package/build/node.d.cts +16 -3
- package/build/node.d.cts.map +1 -1
- package/build/node.d.mts +16 -3
- package/build/node.d.mts.map +1 -1
- package/build/node.mjs +1 -1
- package/build/node.mjs.map +1 -1
- package/build/package-Bcvmz2Lx.cjs +2 -0
- package/build/package-Bcvmz2Lx.cjs.map +1 -0
- package/build/package-CN49oc-F.mjs +2 -0
- package/build/package-CN49oc-F.mjs.map +1 -0
- package/build/{power-o75Gjpwf.d.cts → power-FmknBUz2.d.cts} +30 -30
- package/build/{power-CN_9o_NX.d.mts.map → power-FmknBUz2.d.cts.map} +1 -1
- package/build/{power-CN_9o_NX.d.mts → power-HWfK-Ybw.d.mts} +30 -30
- package/build/{power-o75Gjpwf.d.cts.map → power-HWfK-Ybw.d.mts.map} +1 -1
- package/build/power.cjs +1 -1
- package/build/power.cjs.map +1 -1
- package/build/power.d.cts +2 -2
- package/build/power.d.mts +2 -2
- package/build/power.mjs +1 -1
- package/build/power.mjs.map +1 -1
- package/build/{relays-BCn6rQN1.d.cts → relays-8EGNIK1T.d.cts} +5 -2
- package/build/relays-8EGNIK1T.d.cts.map +1 -0
- package/build/{relays-BCn6rQN1.d.mts → relays-8EGNIK1T.d.mts} +5 -2
- package/build/relays-8EGNIK1T.d.mts.map +1 -0
- package/build/relays.cjs +1 -1
- package/build/relays.cjs.map +1 -1
- package/build/relays.d.cts +2 -2
- package/build/relays.d.mts +2 -2
- package/build/relays.mjs +1 -1
- package/build/relays.mjs.map +1 -1
- package/build/session-D7TpUd6L.d.cts +44 -0
- package/build/session-D7TpUd6L.d.cts.map +1 -0
- package/build/session-D7TpUd6L.d.mts +44 -0
- package/build/session-D7TpUd6L.d.mts.map +1 -0
- package/build/session.cjs +1 -0
- package/build/session.d.cts +2 -0
- package/build/session.d.mts +2 -0
- package/build/session.mjs +1 -0
- package/package.json +22 -2
- package/build/at1000-BXtrf8Rt.d.cts +0 -50
- package/build/at1000-BXtrf8Rt.d.cts.map +0 -1
- package/build/at1000-BuI_g7jF.cjs +0 -3
- package/build/at1000-BuI_g7jF.cjs.map +0 -1
- package/build/at1000-DVDltAyk.mjs +0 -3
- package/build/at1000-DVDltAyk.mjs.map +0 -1
- package/build/at1000-D_rOUVFH.d.mts +0 -50
- package/build/at1000-D_rOUVFH.d.mts.map +0 -1
- package/build/gpio-DNrdX-QV.d.cts.map +0 -1
- package/build/gpio-DchxrXWK.d.mts.map +0 -1
- package/build/hmi-DszM-Hfp.d.cts.map +0 -1
- package/build/hmi-DszM-Hfp.d.mts.map +0 -1
- package/build/management-C0iQha23.d.cts +0 -512
- package/build/management-C0iQha23.d.cts.map +0 -1
- package/build/management-C0iQha23.d.mts +0 -512
- package/build/management-C0iQha23.d.mts.map +0 -1
- package/build/management.cjs.map +0 -1
- package/build/management.mjs.map +0 -1
- package/build/relays-BCn6rQN1.d.cts.map +0 -1
- package/build/relays-BCn6rQN1.d.mts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AnalogOutputLevel } from "./common-BY1vXz1l.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { Information } from "./management.mjs";
|
|
3
3
|
import { UpFetch } from "up-fetch";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
|
|
@@ -44,7 +44,7 @@ declare const partialAnalogOutputConfiguration: Omit<v.ObjectSchema<{
|
|
|
44
44
|
readonly mode: v.LiteralSchema<"analog", undefined>;
|
|
45
45
|
readonly direction: v.LiteralSchema<"output", undefined>;
|
|
46
46
|
readonly value: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 24, undefined>]>, undefined>;
|
|
47
|
-
}, undefined>, "~
|
|
47
|
+
}, undefined>, "~types" | "~run" | "~standard" | "entries"> & {
|
|
48
48
|
readonly entries: Omit<{
|
|
49
49
|
readonly mode: v.LiteralSchema<"analog", undefined>;
|
|
50
50
|
readonly direction: v.LiteralSchema<"output", undefined>;
|
|
@@ -57,7 +57,7 @@ declare const partialAnalogOutputConfiguration: Omit<v.ObjectSchema<{
|
|
|
57
57
|
}>;
|
|
58
58
|
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
59
59
|
value?: number | undefined;
|
|
60
|
-
}, v.NumberIssue | v.MinValueIssue<number, 0> | v.
|
|
60
|
+
}, v.NumberIssue | v.ObjectIssue | v.MinValueIssue<number, 0> | v.MaxValueIssue<number, 24>>;
|
|
61
61
|
readonly "~types"?: {
|
|
62
62
|
readonly input: {
|
|
63
63
|
value?: number | undefined;
|
|
@@ -65,7 +65,7 @@ declare const partialAnalogOutputConfiguration: Omit<v.ObjectSchema<{
|
|
|
65
65
|
readonly output: {
|
|
66
66
|
value?: number | undefined;
|
|
67
67
|
};
|
|
68
|
-
readonly issue: v.NumberIssue | v.MinValueIssue<number, 0> | v.
|
|
68
|
+
readonly issue: v.NumberIssue | v.ObjectIssue | v.MinValueIssue<number, 0> | v.MaxValueIssue<number, 24>;
|
|
69
69
|
} | undefined;
|
|
70
70
|
};
|
|
71
71
|
type PartialAnalogOutputConfiguration = v.InferOutput<typeof partialAnalogOutputConfiguration>;
|
|
@@ -74,7 +74,7 @@ declare const partialDigitalInputConfiguration: Omit<v.ObjectSchema<{
|
|
|
74
74
|
readonly direction: v.LiteralSchema<"input", undefined>;
|
|
75
75
|
readonly vil: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
76
76
|
readonly vih: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
77
|
-
}, undefined>, "~
|
|
77
|
+
}, undefined>, "~types" | "~run" | "~standard" | "entries"> & {
|
|
78
78
|
readonly entries: Omit<{
|
|
79
79
|
readonly mode: v.LiteralSchema<"digital", undefined>;
|
|
80
80
|
readonly direction: v.LiteralSchema<"input", undefined>;
|
|
@@ -113,7 +113,7 @@ declare const partialDigitalOutputConfiguration: Omit<Omit<v.ObjectSchema<{
|
|
|
113
113
|
readonly voh: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 24, undefined>]>;
|
|
114
114
|
readonly vil: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
115
115
|
readonly vih: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
116
|
-
}, undefined>, "~
|
|
116
|
+
}, undefined>, "~types" | "~run" | "~standard" | "entries"> & {
|
|
117
117
|
readonly entries: Omit<{
|
|
118
118
|
readonly mode: v.LiteralSchema<"digital", undefined>;
|
|
119
119
|
readonly direction: v.LiteralSchema<"output", undefined>;
|
|
@@ -142,7 +142,7 @@ declare const partialDigitalOutputConfiguration: Omit<Omit<v.ObjectSchema<{
|
|
|
142
142
|
vih: number;
|
|
143
143
|
vol: number;
|
|
144
144
|
voh: number;
|
|
145
|
-
}, v.NumberIssue | v.
|
|
145
|
+
}, v.BooleanIssue | v.NumberIssue | v.ObjectIssue | v.MinValueIssue<number, 0> | v.UnionIssue<v.BooleanIssue | v.NumberIssue> | v.MinValueIssue<number, -25> | v.MaxValueIssue<number, 25> | v.MaxValueIssue<number, 24>>;
|
|
146
146
|
readonly "~types"?: {
|
|
147
147
|
readonly input: {
|
|
148
148
|
value: number | boolean;
|
|
@@ -158,9 +158,9 @@ declare const partialDigitalOutputConfiguration: Omit<Omit<v.ObjectSchema<{
|
|
|
158
158
|
vol: number;
|
|
159
159
|
voh: number;
|
|
160
160
|
};
|
|
161
|
-
readonly issue: v.NumberIssue | v.
|
|
161
|
+
readonly issue: v.BooleanIssue | v.NumberIssue | v.ObjectIssue | v.MinValueIssue<number, 0> | v.UnionIssue<v.BooleanIssue | v.NumberIssue> | v.MinValueIssue<number, -25> | v.MaxValueIssue<number, 25> | v.MaxValueIssue<number, 24>;
|
|
162
162
|
} | undefined;
|
|
163
|
-
}, "~
|
|
163
|
+
}, "~types" | "~run" | "~standard" | "entries"> & {
|
|
164
164
|
readonly entries: {
|
|
165
165
|
readonly value: v.SchemaWithPipe<readonly [v.UnionSchema<[v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.ToBooleanAction<number | boolean>]>;
|
|
166
166
|
readonly vil: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>, undefined>;
|
|
@@ -187,7 +187,7 @@ declare const partialDigitalOutputConfiguration: Omit<Omit<v.ObjectSchema<{
|
|
|
187
187
|
vih?: number | undefined;
|
|
188
188
|
vol: number;
|
|
189
189
|
voh: number;
|
|
190
|
-
}, v.NumberIssue | v.
|
|
190
|
+
}, v.BooleanIssue | v.NumberIssue | v.ObjectIssue | v.MinValueIssue<number, 0> | v.UnionIssue<v.BooleanIssue | v.NumberIssue> | v.MinValueIssue<number, -25> | v.MaxValueIssue<number, 25> | v.MaxValueIssue<number, 24>>;
|
|
191
191
|
readonly "~types"?: {
|
|
192
192
|
readonly input: {
|
|
193
193
|
value: number | boolean;
|
|
@@ -203,7 +203,7 @@ declare const partialDigitalOutputConfiguration: Omit<Omit<v.ObjectSchema<{
|
|
|
203
203
|
vol: number;
|
|
204
204
|
voh: number;
|
|
205
205
|
};
|
|
206
|
-
readonly issue: v.NumberIssue | v.
|
|
206
|
+
readonly issue: v.BooleanIssue | v.NumberIssue | v.ObjectIssue | v.MinValueIssue<number, 0> | v.UnionIssue<v.BooleanIssue | v.NumberIssue> | v.MinValueIssue<number, -25> | v.MaxValueIssue<number, 25> | v.MaxValueIssue<number, 24>;
|
|
207
207
|
} | undefined;
|
|
208
208
|
};
|
|
209
209
|
type PartialDigitalOutputConfiguration = v.InferInput<typeof partialDigitalOutputConfiguration>;
|
|
@@ -213,7 +213,7 @@ declare const partialOpenDrainConfiguration: Omit<v.ObjectSchema<{
|
|
|
213
213
|
readonly value: v.SchemaWithPipe<readonly [v.UnionSchema<[v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.ToBooleanAction<number | boolean>]>;
|
|
214
214
|
readonly vil: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
215
215
|
readonly vih: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
216
|
-
}, undefined>, "~
|
|
216
|
+
}, undefined>, "~types" | "~run" | "~standard" | "entries"> & {
|
|
217
217
|
readonly entries: Omit<{
|
|
218
218
|
readonly mode: v.LiteralSchema<"digital", undefined>;
|
|
219
219
|
readonly direction: v.LiteralSchema<"open_drain", undefined>;
|
|
@@ -234,7 +234,7 @@ declare const partialOpenDrainConfiguration: Omit<v.ObjectSchema<{
|
|
|
234
234
|
value: boolean;
|
|
235
235
|
vil: number;
|
|
236
236
|
vih: number;
|
|
237
|
-
}, v.
|
|
237
|
+
}, v.BooleanIssue | v.NumberIssue | v.ObjectIssue | v.UnionIssue<v.BooleanIssue | v.NumberIssue> | v.MinValueIssue<number, -25> | v.MaxValueIssue<number, 25>>;
|
|
238
238
|
readonly "~types"?: {
|
|
239
239
|
readonly input: {
|
|
240
240
|
value: number | boolean;
|
|
@@ -246,14 +246,52 @@ declare const partialOpenDrainConfiguration: Omit<v.ObjectSchema<{
|
|
|
246
246
|
vil: number;
|
|
247
247
|
vih: number;
|
|
248
248
|
};
|
|
249
|
-
readonly issue: v.
|
|
249
|
+
readonly issue: v.BooleanIssue | v.NumberIssue | v.ObjectIssue | v.UnionIssue<v.BooleanIssue | v.NumberIssue> | v.MinValueIssue<number, -25> | v.MaxValueIssue<number, 25>;
|
|
250
250
|
} | undefined;
|
|
251
251
|
};
|
|
252
252
|
type PartialOpenDrainConfiguration = v.InferOutput<typeof partialOpenDrainConfiguration>;
|
|
253
|
+
declare const digitalState: v.ObjectSchema<{
|
|
254
|
+
readonly value: v.SchemaWithPipe<readonly [v.UnionSchema<[v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.ToBooleanAction<number | boolean>]>;
|
|
255
|
+
}, undefined>;
|
|
256
|
+
declare const analogState: v.ObjectSchema<{
|
|
257
|
+
readonly value: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
258
|
+
}, undefined>;
|
|
253
259
|
declare const syncConfiguration: v.ObjectSchema<{
|
|
254
260
|
readonly action: v.PicklistSchema<["release", "hold"], "Invalid sync action">;
|
|
255
261
|
}, undefined>;
|
|
256
262
|
type SyncConfiguration = v.InferOutput<typeof syncConfiguration>;
|
|
263
|
+
declare const syncState: v.ObjectSchema<{
|
|
264
|
+
readonly hold_state: v.PicklistSchema<["held", "released"], undefined>;
|
|
265
|
+
}, undefined>;
|
|
266
|
+
type SyncState = v.InferOutput<typeof syncState>;
|
|
267
|
+
declare const gpioConfiguration: v.UnionSchema<[v.ObjectSchema<{
|
|
268
|
+
readonly mode: v.LiteralSchema<"digital", undefined>;
|
|
269
|
+
readonly direction: v.LiteralSchema<"output", undefined>;
|
|
270
|
+
readonly value: v.SchemaWithPipe<readonly [v.UnionSchema<[v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.ToBooleanAction<number | boolean>]>;
|
|
271
|
+
readonly vol: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 24, undefined>]>;
|
|
272
|
+
readonly voh: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 24, undefined>]>;
|
|
273
|
+
readonly vil: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
274
|
+
readonly vih: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
275
|
+
}, undefined>, v.ObjectSchema<{
|
|
276
|
+
readonly mode: v.LiteralSchema<"digital", undefined>;
|
|
277
|
+
readonly direction: v.LiteralSchema<"open_drain", undefined>;
|
|
278
|
+
readonly value: v.SchemaWithPipe<readonly [v.UnionSchema<[v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, v.ToBooleanAction<number | boolean>]>;
|
|
279
|
+
readonly vil: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
280
|
+
readonly vih: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
281
|
+
}, undefined>, v.ObjectSchema<{
|
|
282
|
+
readonly mode: v.LiteralSchema<"digital", undefined>;
|
|
283
|
+
readonly direction: v.LiteralSchema<"input", undefined>;
|
|
284
|
+
readonly vil: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
285
|
+
readonly vih: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -25, undefined>, v.MaxValueAction<number, 25, undefined>]>;
|
|
286
|
+
}, undefined>, v.ObjectSchema<{
|
|
287
|
+
readonly mode: v.LiteralSchema<"analog", undefined>;
|
|
288
|
+
readonly direction: v.LiteralSchema<"output", undefined>;
|
|
289
|
+
readonly value: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 24, undefined>]>, undefined>;
|
|
290
|
+
}, undefined>, v.ObjectSchema<{
|
|
291
|
+
readonly mode: v.LiteralSchema<"analog", undefined>;
|
|
292
|
+
readonly direction: v.LiteralSchema<"input", undefined>;
|
|
293
|
+
}, undefined>], undefined>;
|
|
294
|
+
type GpioConfiguration = v.InferOutput<typeof gpioConfiguration>;
|
|
257
295
|
/** @hideconstructor */
|
|
258
296
|
declare class GpioApi {
|
|
259
297
|
private readonly fetch;
|
|
@@ -288,6 +326,17 @@ declare class GpioApi {
|
|
|
288
326
|
* @returns The applied sync state.
|
|
289
327
|
*/
|
|
290
328
|
release(): Promise<SyncConfiguration>;
|
|
329
|
+
/**
|
|
330
|
+
* Reads back the current configuration of a specific IO pin.
|
|
331
|
+
* @param io The IO pin id.
|
|
332
|
+
* @returns The pin's current configuration.
|
|
333
|
+
*/
|
|
334
|
+
read_config(io: number): Promise<GpioConfiguration>;
|
|
335
|
+
/**
|
|
336
|
+
* Reads the current hold state of all GPIO pins.
|
|
337
|
+
* @returns The current sync state.
|
|
338
|
+
*/
|
|
339
|
+
read_sync(): Promise<SyncState>;
|
|
291
340
|
}
|
|
292
341
|
/** @hideconstructor */
|
|
293
342
|
declare class DigitalIO {
|
|
@@ -354,5 +403,5 @@ declare class AnalogIO {
|
|
|
354
403
|
write(value: number): Promise<number>;
|
|
355
404
|
}
|
|
356
405
|
//#endregion
|
|
357
|
-
export { DigitalInputConfiguration as a,
|
|
358
|
-
//# sourceMappingURL=gpio-
|
|
406
|
+
export { openDrainConfiguration as C, gpioConfiguration as S, analogOutputConfiguration as _, DigitalInputConfiguration as a, digitalOutputConfiguration as b, GpioConfiguration as c, PartialDigitalInputConfiguration as d, PartialDigitalOutputConfiguration as f, analogInputConfiguration as g, SyncState as h, DigitalIO as i, OpenDrainConfiguration as l, SyncConfiguration as m, AnalogInputConfiguration as n, DigitalOutputConfiguration as o, PartialOpenDrainConfiguration as p, AnalogOutputConfiguration as r, GpioApi as s, AnalogIO as t, PartialAnalogOutputConfiguration as u, analogState as v, syncState as w, digitalState as x, digitalInputConfiguration as y };
|
|
407
|
+
//# sourceMappingURL=gpio-DgQHE5fr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpio-DgQHE5fr.d.mts","names":[],"sources":["../src/api/gpio.ts"],"mappings":";;;;;;cASa,wBAAA,EAAwB,CAAA,CAAA,YAAA;EAAA;;;cAIxB,yBAAA,EAAyB,CAAA,CAAA,YAAA;EAAA;;;;cAKzB,yBAAA,EAAyB,CAAA,CAAA,YAAA;EAAA;;;;;cAMzB,0BAAA,EAA0B,CAAA,CAAA,YAAA;EAAA;;;;;;;;cAS1B,sBAAA,EAAsB,CAAA,CAAA,YAAA;EAAA;;;;;;KAOvB,wBAAA,GAA2B,CAAA,CAAE,WAAW,QAAQ,wBAAA;AAAA,KAChD,yBAAA,GAA4B,CAAA,CAAE,WAAW,QAAQ,yBAAA;AAAA,KACjD,yBAAA,GAA4B,CAA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;;;EASR,KAAA,CAAM,KAAA,WAAgB,OAAA;AAAA"}
|
package/build/gpio.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunk-CMqjfN_6.cjs"),t=require("./common-BSabSaAU.cjs");let n=require("valibot");n=e.t(n,1);const r=n.picklist([`release`,`hold`],`Invalid sync action`),i=n.object({mode:n.literal(`analog`),direction:n.literal(`input`)}),a=n.object({mode:n.literal(`analog`),direction:n.literal(`output`),value:n.optional(t.n)}),o=n.object({mode:n.literal(`digital`),direction:n.literal(`input`),vil:t.t,vih:t.t}),s=n.object({mode:n.literal(`digital`),direction:n.literal(`output`),value:t.r,vol:t.n,voh:t.n,vil:t.t,vih:t.t}),c=n.object({mode:n.literal(`digital`),direction:n.literal(`open_drain`),value:t.r,vil:t.t,vih:t.t});n.omit(a,[`direction`,`mode`]),n.omit(o,[`direction`,`mode`]);const l=n.partial(n.omit(s,[`direction`,`mode`]),[`vih`,`vil`]);n.omit(c,[`direction`,`mode`]);const u=n.object({value:t.r}),d=n.object({value:t.t}),f=n.object({action:r});var
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunk-CMqjfN_6.cjs"),t=require("./common-BSabSaAU.cjs");let n=require("valibot");n=e.t(n,1);const r=n.picklist([`release`,`hold`],`Invalid sync action`),i=n.object({mode:n.literal(`analog`),direction:n.literal(`input`)}),a=n.object({mode:n.literal(`analog`),direction:n.literal(`output`),value:n.optional(t.n)}),o=n.object({mode:n.literal(`digital`),direction:n.literal(`input`),vil:t.t,vih:t.t}),s=n.object({mode:n.literal(`digital`),direction:n.literal(`output`),value:t.r,vol:t.n,voh:t.n,vil:t.t,vih:t.t}),c=n.object({mode:n.literal(`digital`),direction:n.literal(`open_drain`),value:t.r,vil:t.t,vih:t.t});n.omit(a,[`direction`,`mode`]),n.omit(o,[`direction`,`mode`]);const l=n.partial(n.omit(s,[`direction`,`mode`]),[`vih`,`vil`]);n.omit(c,[`direction`,`mode`]);const u=n.object({value:t.r}),d=n.object({value:t.t}),f=n.object({action:r}),p=n.object({hold_state:n.picklist([`held`,`released`])}),m=n.union([s,c,o,a,i]);var h=class{fetch;count;constructor(e,t){this.fetch=e,this.count=t.capabilities.io.count}reset(){return this.fetch(`/gpio/reset`,{method:`POST`,parseResponse:()=>{}})}digital(e){if(e<0||e>=this.count)throw Error(`Invalid GPIO pin ${e} (RESOURCE_NOT_FOUND)\n Suggestion: Use a pin number between 0 and ${this.count-1}\n Path: /gpio/${e}`);return new g(this.fetch,e)}analog(e){if(e<0||e>=this.count)throw Error(`Invalid GPIO pin ${e} (RESOURCE_NOT_FOUND)\n Suggestion: Use a pin number between 0 and ${this.count-1}\n Path: /gpio/${e}`);return new _(this.fetch,e)}hold(){return this.fetch(`/gpio/sync`,{method:`POST`,body:{action:`hold`},schema:f})}release(){return this.fetch(`/gpio/sync`,{method:`POST`,body:{action:`release`},schema:f})}read_config(e){if(e<0||e>=this.count)throw Error(`Invalid GPIO pin ${e} (RESOURCE_NOT_FOUND)\n Suggestion: Use a pin number between 0 and ${this.count-1}\n Path: /gpio/${e}/config`);return this.fetch(`/gpio/${e}/config`,{schema:m})}read_sync(){return this.fetch(`/gpio/sync`,{schema:p})}},g=class{fetch;id;constructor(e,t){this.fetch=e,this.id=t}configure_input(e){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:n.parse(o,{...e,mode:`digital`,direction:`input`}),schema:o})}configure_output(e){e=n.parse(l,e);let t={mode:`digital`,direction:`output`,value:e.value,vol:e.vol,voh:e.voh,vil:e.vil??e.vol+(e.voh-e.vol)/4,vih:e.vih??e.voh-(e.voh-e.vol)/4};return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:n.parse(s,t),schema:s})}async read(){return(await this.fetch(`/gpio/${this.id}/state`,{schema:u})).value}async write(e){return(await this.fetch(`/gpio/${this.id}/state`,{method:`PUT`,body:n.parse(u,{value:e}),schema:u})).value}configure_open_drain(e){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:n.parse(c,{...e,mode:`digital`,direction:`open_drain`}),schema:c})}},_=class{fetch;id;constructor(e,t){this.fetch=e,this.id=t}configure_input(){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:{mode:`analog`,direction:`input`},schema:i})}configure_output(e){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:n.parse(a,{value:e,mode:`analog`,direction:`output`}),schema:a})}async read(){return(await this.fetch(`/gpio/${this.id}/state`,{schema:d})).value}async write(e){return(await this.fetch(`/gpio/${this.id}/state`,{method:`PUT`,body:{value:e},schema:d})).value}};exports.AnalogIO=_,exports.DigitalIO=g,exports.GpioApi=h,exports.analogInputConfiguration=i,exports.analogOutputConfiguration=a,exports.analogState=d,exports.digitalInputConfiguration=o,exports.digitalOutputConfiguration=s,exports.digitalState=u,exports.gpioConfiguration=m,exports.openDrainConfiguration=c,exports.syncState=p;
|
|
2
2
|
//# sourceMappingURL=gpio.cjs.map
|
package/build/gpio.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gpio.cjs","names":["v","analogOutputLevel","analogLevel","digitalLevel"],"sources":["../src/api/gpio.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nimport { analogLevel, type AnalogOutputLevel, analogOutputLevel, digitalLevel } from './common';\nimport type { Information } from './management';\n\nexport type { AnalogOutputLevel };\n\nconst syncAction = v.picklist(['release', 'hold'], 'Invalid sync action');\nconst analogInputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('input'),\n});\nconst analogOutputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('output'),\n value: v.optional(analogOutputLevel),\n});\nconst digitalInputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('input'),\n vil: analogLevel,\n vih: analogLevel,\n});\nconst digitalOutputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('output'),\n value: digitalLevel,\n vol: analogOutputLevel,\n voh: analogOutputLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nconst openDrainConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('open_drain'),\n value: digitalLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport type AnalogInputConfiguration = v.InferOutput<typeof analogInputConfiguration>;\nexport type AnalogOutputConfiguration = v.InferOutput<typeof analogOutputConfiguration>;\nexport type DigitalInputConfiguration = v.InferOutput<typeof digitalInputConfiguration>;\nexport type DigitalOutputConfiguration = v.InferOutput<typeof digitalOutputConfiguration>;\nexport type OpenDrainConfiguration = v.InferOutput<typeof openDrainConfiguration>;\n\nconst partialAnalogOutputConfiguration = v.omit(analogOutputConfiguration, ['direction', 'mode']);\nexport type PartialAnalogOutputConfiguration = v.InferOutput<\n typeof partialAnalogOutputConfiguration\n>;\nconst partialDigitalInputConfiguration = v.omit(digitalInputConfiguration, ['direction', 'mode']);\nexport type PartialDigitalInputConfiguration = v.InferOutput<\n typeof partialDigitalInputConfiguration\n>;\nconst partialDigitalOutputConfiguration = v.partial(\n v.omit(digitalOutputConfiguration, ['direction', 'mode']),\n ['vih', 'vil'],\n);\nexport type PartialDigitalOutputConfiguration = v.InferInput<\n typeof partialDigitalOutputConfiguration\n>;\nconst partialOpenDrainConfiguration = v.omit(openDrainConfiguration, ['direction', 'mode']);\nexport type PartialOpenDrainConfiguration = v.InferOutput<typeof partialOpenDrainConfiguration>;\n\nconst digitalState = v.object({ value: digitalLevel });\nconst analogState = v.object({ value: analogLevel });\n\nconst syncConfiguration = v.object({ action: syncAction });\nexport type SyncConfiguration = v.InferOutput<typeof syncConfiguration>;\n\n/** @hideconstructor */\nexport class GpioApi {\n private count: number;\n\n constructor(private readonly fetch: UpFetch, info: Information) {\n this.count = info.capabilities.io.count;\n }\n\n /**\n * Resets all IO configurations to default.\n */\n reset(): Promise<void> {\n return this.fetch('/gpio/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access a specific digital IO pin by id.\n * @param io The IO pin id.\n * @returns The digital IO instance.\n */\n digital(io: number): DigitalIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new DigitalIO(this.fetch, io);\n }\n\n /**\n * Access a specific analog IO pin by id.\n * @param io The IO pin id.\n * @returns The analog IO instance.\n */\n analog(io: number): AnalogIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new AnalogIO(this.fetch, io);\n }\n\n /**\n * Holds the current state of all GPIO pins.\n * @returns The applied sync state.\n */\n hold(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'hold' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Releases control of the IO pins, allowing external control.\n *\n * This also sets the device as a slave.\n *\n * @returns The applied sync state.\n */\n release(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'release' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class DigitalIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configure the pin as a digital input.\n * @param config The digital input configuration.\n * @returns The applied configuration.\n */\n configure_input(config: PartialDigitalInputConfiguration): Promise<DigitalInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n digitalInputConfiguration,\n { ...config, mode: 'digital', direction: 'input' } satisfies DigitalInputConfiguration,\n ),\n schema: digitalInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as a digital output.\n * @param config The digital output configuration.\n * @returns The applied configuration.\n */\n configure_output(config: PartialDigitalOutputConfiguration): Promise<DigitalOutputConfiguration> {\n config = v.parse(partialDigitalOutputConfiguration, config);\n\n const fullConfig = {\n mode: 'digital' as const,\n direction: 'output' as const,\n value: config.value,\n vol: config.vol,\n voh: config.voh,\n vil: config.vil ?? config.vol + (config.voh - config.vol) / 4,\n vih: config.vih ?? config.voh - (config.voh - config.vol) / 4,\n };\n\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(digitalOutputConfiguration, fullConfig),\n schema: digitalOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: digitalState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: boolean | number): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: v.parse(digitalState, { value }),\n schema: digitalState,\n }))\n .value;\n }\n\n /**\n * Configure the pin as an open drain output.\n * @param config The open drain configuration.\n * @returns The applied configuration.\n */\n configure_open_drain(config: PartialOpenDrainConfiguration): Promise<OpenDrainConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n openDrainConfiguration,\n { ...config, mode: 'digital', direction: 'open_drain' } satisfies OpenDrainConfiguration,\n ),\n schema: openDrainConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class AnalogIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configures the pin as an analog input.\n * @returns The applied configuration.\n * @returns The applied configuration.\n */\n configure_input(): Promise<AnalogInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: { mode: 'analog', direction: 'input' } satisfies AnalogInputConfiguration,\n schema: analogInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as an analog output.\n * @param config The analog output configuration.\n * @returns The applied configuration.\n */\n configure_output(value: AnalogOutputLevel): Promise<AnalogOutputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n analogOutputConfiguration,\n { value, mode: 'analog', direction: 'output' } satisfies AnalogOutputConfiguration,\n ),\n schema: analogOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: analogState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: number): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: { value },\n schema: analogState,\n }))\n .value;\n }\n}\n"],"mappings":"kLAQA,MAAM,EAAaA,EAAE,SAAS,CAAC,UAAW,MAAM,EAAG,qBAAqB,EAClE,EAA2BA,EAAE,OAAO,CACxC,KAAMA,EAAE,QAAQ,QAAQ,EACxB,UAAWA,EAAE,QAAQ,OAAO,CAC9B,CAAC,EACK,EAA4BA,EAAE,OAAO,CACzC,KAAMA,EAAE,QAAQ,QAAQ,EACxB,UAAWA,EAAE,QAAQ,QAAQ,EAC7B,MAAOA,EAAE,SAASC,EAAAA,CAAiB,CACrC,CAAC,EACK,EAA4BD,EAAE,OAAO,CACzC,KAAMA,EAAE,QAAQ,SAAS,EACzB,UAAWA,EAAE,QAAQ,OAAO,EAC5B,IAAKE,EAAAA,EACL,IAAKA,EAAAA,CACP,CAAC,EACK,EAA6BF,EAAE,OAAO,CAC1C,KAAMA,EAAE,QAAQ,SAAS,EACzB,UAAWA,EAAE,QAAQ,QAAQ,EAC7B,MAAOG,EAAAA,EACP,IAAKF,EAAAA,EACL,IAAKA,EAAAA,EACL,IAAKC,EAAAA,EACL,IAAKA,EAAAA,CACP,CAAC,EACK,EAAyBF,EAAE,OAAO,CACtC,KAAMA,EAAE,QAAQ,SAAS,EACzB,UAAWA,EAAE,QAAQ,YAAY,EACjC,MAA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M,UAAW,UAAW,YAAa,CACxD,EACA,OAAQ,CACV,CAAC,CACH,CACF,EAGa,EAAb,KAAsB,CACS,MAAgC,GAA7D,YAAY,EAAiC,EAA4B,CAA5C,KAAA,MAAA,EAAgC,KAAA,GAAA,CAAa,CAO1E,iBAAqD,CACnD,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,CAAE,KAAM,SAAU,UAAW,OAAQ,EAC3C,OAAQ,CACV,CAAC,CACH,CAOA,iBAAiB,EAA8D,CAC7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAMA,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,QAAS,CAC/C,EACA,OAAQ,CACV,CAAC,CACH,CAMA,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,CAAY,CAAC,EAAA,CAAG,KAC/E,CAOA,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,OAAM,EACd,OAAQ,CACV,CAAC,EAAA,CACE,KACL,CACF"}
|
|
1
|
+
{"version":3,"file":"gpio.cjs","names":["v","analogOutputLevel","analogLevel","digitalLevel"],"sources":["../src/api/gpio.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nimport { analogLevel, type AnalogOutputLevel, analogOutputLevel, digitalLevel } from './common';\nimport type { Information } from './management';\n\nexport type { AnalogOutputLevel };\n\nconst syncAction = v.picklist(['release', 'hold'], 'Invalid sync action');\nexport const analogInputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('input'),\n});\nexport const analogOutputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('output'),\n value: v.optional(analogOutputLevel),\n});\nexport const digitalInputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('input'),\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const digitalOutputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('output'),\n value: digitalLevel,\n vol: analogOutputLevel,\n voh: analogOutputLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const openDrainConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('open_drain'),\n value: digitalLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport type AnalogInputConfiguration = v.InferOutput<typeof analogInputConfiguration>;\nexport type AnalogOutputConfiguration = v.InferOutput<typeof analogOutputConfiguration>;\nexport type DigitalInputConfiguration = v.InferOutput<typeof digitalInputConfiguration>;\nexport type DigitalOutputConfiguration = v.InferOutput<typeof digitalOutputConfiguration>;\nexport type OpenDrainConfiguration = v.InferOutput<typeof openDrainConfiguration>;\n\nconst partialAnalogOutputConfiguration = v.omit(analogOutputConfiguration, ['direction', 'mode']);\nexport type PartialAnalogOutputConfiguration = v.InferOutput<\n typeof partialAnalogOutputConfiguration\n>;\nconst partialDigitalInputConfiguration = v.omit(digitalInputConfiguration, ['direction', 'mode']);\nexport type PartialDigitalInputConfiguration = v.InferOutput<\n typeof partialDigitalInputConfiguration\n>;\nconst partialDigitalOutputConfiguration = v.partial(\n v.omit(digitalOutputConfiguration, ['direction', 'mode']),\n ['vih', 'vil'],\n);\nexport type PartialDigitalOutputConfiguration = v.InferInput<\n typeof partialDigitalOutputConfiguration\n>;\nconst partialOpenDrainConfiguration = v.omit(openDrainConfiguration, ['direction', 'mode']);\nexport type PartialOpenDrainConfiguration = v.InferOutput<typeof partialOpenDrainConfiguration>;\n\nexport const digitalState = v.object({ value: digitalLevel });\nexport const analogState = v.object({ value: analogLevel });\n\nconst syncConfiguration = v.object({ action: syncAction });\nexport type SyncConfiguration = v.InferOutput<typeof syncConfiguration>;\n\nexport const syncState = v.object({ hold_state: v.picklist(['held', 'released']) });\nexport type SyncState = v.InferOutput<typeof syncState>;\n\nexport const gpioConfiguration = v.union([\n digitalOutputConfiguration,\n openDrainConfiguration,\n digitalInputConfiguration,\n analogOutputConfiguration,\n analogInputConfiguration,\n]);\nexport type GpioConfiguration = v.InferOutput<typeof gpioConfiguration>;\n\n/** @hideconstructor */\nexport class GpioApi {\n private count: number;\n\n constructor(private readonly fetch: UpFetch, info: Information) {\n this.count = info.capabilities.io.count;\n }\n\n /**\n * Resets all IO configurations to default.\n */\n reset(): Promise<void> {\n return this.fetch('/gpio/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access a specific digital IO pin by id.\n * @param io The IO pin id.\n * @returns The digital IO instance.\n */\n digital(io: number): DigitalIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new DigitalIO(this.fetch, io);\n }\n\n /**\n * Access a specific analog IO pin by id.\n * @param io The IO pin id.\n * @returns The analog IO instance.\n */\n analog(io: number): AnalogIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new AnalogIO(this.fetch, io);\n }\n\n /**\n * Holds the current state of all GPIO pins.\n * @returns The applied sync state.\n */\n hold(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'hold' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Releases control of the IO pins, allowing external control.\n *\n * This also sets the device as a slave.\n *\n * @returns The applied sync state.\n */\n release(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'release' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Reads back the current configuration of a specific IO pin.\n * @param io The IO pin id.\n * @returns The pin's current configuration.\n */\n read_config(io: number): Promise<GpioConfiguration> {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}/config`,\n );\n }\n\n return this.fetch(`/gpio/${io}/config`, { schema: gpioConfiguration });\n }\n\n /**\n * Reads the current hold state of all GPIO pins.\n * @returns The current sync state.\n */\n read_sync(): Promise<SyncState> {\n return this.fetch('/gpio/sync', { schema: syncState });\n }\n}\n\n/** @hideconstructor */\nexport class DigitalIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configure the pin as a digital input.\n * @param config The digital input configuration.\n * @returns The applied configuration.\n */\n configure_input(config: PartialDigitalInputConfiguration): Promise<DigitalInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n digitalInputConfiguration,\n { ...config, mode: 'digital', direction: 'input' } satisfies DigitalInputConfiguration,\n ),\n schema: digitalInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as a digital output.\n * @param config The digital output configuration.\n * @returns The applied configuration.\n */\n configure_output(config: PartialDigitalOutputConfiguration): Promise<DigitalOutputConfiguration> {\n config = v.parse(partialDigitalOutputConfiguration, config);\n\n const fullConfig = {\n mode: 'digital' as const,\n direction: 'output' as const,\n value: config.value,\n vol: config.vol,\n voh: config.voh,\n vil: config.vil ?? config.vol + (config.voh - config.vol) / 4,\n vih: config.vih ?? config.voh - (config.voh - config.vol) / 4,\n };\n\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(digitalOutputConfiguration, fullConfig),\n schema: digitalOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: digitalState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: boolean | number): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: v.parse(digitalState, { value }),\n schema: digitalState,\n }))\n .value;\n }\n\n /**\n * Configure the pin as an open drain output.\n * @param config The open drain configuration.\n * @returns The applied configuration.\n */\n configure_open_drain(config: PartialOpenDrainConfiguration): Promise<OpenDrainConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n openDrainConfiguration,\n { ...config, mode: 'digital', direction: 'open_drain' } satisfies OpenDrainConfiguration,\n ),\n schema: openDrainConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class AnalogIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configures the pin as an analog input.\n * @returns The applied configuration.\n * @returns The applied configuration.\n */\n configure_input(): Promise<AnalogInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: { mode: 'analog', direction: 'input' } satisfies AnalogInputConfiguration,\n schema: analogInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as an analog output.\n * @param config The analog output configuration.\n * @returns The applied configuration.\n */\n configure_output(value: AnalogOutputLevel): Promise<AnalogOutputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n analogOutputConfiguration,\n { value, mode: 'analog', direction: 'output' } satisfies AnalogOutputConfiguration,\n ),\n schema: analogOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: analogState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: number): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: { value },\n schema: analogState,\n }))\n .value;\n }\n}\n"],"mappings":"kLAQA,MAAM,EAAaA,EAAE,SAAS,CAAC,UAAW,MAA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MAAgC,GAA7D,YAAY,EAAiC,EAA4B,CAA5C,KAAA,MAAA,EAAgC,KAAA,GAAA,CAAa,CAO1E,iBAAqD,CACnD,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,CAAE,KAAM,SAAU,UAAW,OAAQ,EAC3C,OAAQ,CACV,CAAC,CACH,CAOA,iBAAiB,EAA8D,CAC7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAMA,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,QAAS,CAC/C,EACA,OAAQ,CACV,CAAC,CACH,CAMA,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,CAAY,CAAC,EAAA,CAAG,KAC/E,CAOA,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,OAAM,EACd,OAAQ,CACV,CAAC,EAAA,CACE,KACL,CACF"}
|
package/build/gpio.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { t as AnalogOutputLevel } from "./common-BY1vXz1l.cjs";
|
|
2
|
-
import { a as DigitalInputConfiguration, c as
|
|
3
|
-
export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, type AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration };
|
|
2
|
+
import { C as openDrainConfiguration, S as gpioConfiguration, _ as analogOutputConfiguration, a as DigitalInputConfiguration, b as digitalOutputConfiguration, c as GpioConfiguration, d as PartialDigitalInputConfiguration, f as PartialDigitalOutputConfiguration, g as analogInputConfiguration, h as SyncState, i as DigitalIO, l as OpenDrainConfiguration, m as SyncConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as PartialOpenDrainConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialAnalogOutputConfiguration, v as analogState, w as syncState, x as digitalState, y as digitalInputConfiguration } from "./gpio-BuvDysYa.cjs";
|
|
3
|
+
export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, type AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, GpioConfiguration, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration, SyncState, analogInputConfiguration, analogOutputConfiguration, analogState, digitalInputConfiguration, digitalOutputConfiguration, digitalState, gpioConfiguration, openDrainConfiguration, syncState };
|
package/build/gpio.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { t as AnalogOutputLevel } from "./common-BY1vXz1l.mjs";
|
|
2
|
-
import { a as DigitalInputConfiguration, c as
|
|
3
|
-
export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, type AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration };
|
|
2
|
+
import { C as openDrainConfiguration, S as gpioConfiguration, _ as analogOutputConfiguration, a as DigitalInputConfiguration, b as digitalOutputConfiguration, c as GpioConfiguration, d as PartialDigitalInputConfiguration, f as PartialDigitalOutputConfiguration, g as analogInputConfiguration, h as SyncState, i as DigitalIO, l as OpenDrainConfiguration, m as SyncConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as PartialOpenDrainConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialAnalogOutputConfiguration, v as analogState, w as syncState, x as digitalState, y as digitalInputConfiguration } from "./gpio-DgQHE5fr.mjs";
|
|
3
|
+
export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, type AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, GpioConfiguration, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration, SyncState, analogInputConfiguration, analogOutputConfiguration, analogState, digitalInputConfiguration, digitalOutputConfiguration, digitalState, gpioConfiguration, openDrainConfiguration, syncState };
|
package/build/gpio.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./common-Ce3FeF-Q.mjs";import*as r from"valibot";const i=r.picklist([`release`,`hold`],`Invalid sync action`),a=r.object({mode:r.literal(`analog`),direction:r.literal(`input`)}),o=r.object({mode:r.literal(`analog`),direction:r.literal(`output`),value:r.optional(e)}),s=r.object({mode:r.literal(`digital`),direction:r.literal(`input`),vil:n,vih:n}),c=r.object({mode:r.literal(`digital`),direction:r.literal(`output`),value:t,vol:e,voh:e,vil:n,vih:n}),l=r.object({mode:r.literal(`digital`),direction:r.literal(`open_drain`),value:t,vil:n,vih:n});r.omit(o,[`direction`,`mode`]),r.omit(s,[`direction`,`mode`]);const u=r.partial(r.omit(c,[`direction`,`mode`]),[`vih`,`vil`]);r.omit(l,[`direction`,`mode`]);const d=r.object({value:t}),f=r.object({value:n}),p=r.object({action:i});var
|
|
1
|
+
import{n as e,r as t,t as n}from"./common-Ce3FeF-Q.mjs";import*as r from"valibot";const i=r.picklist([`release`,`hold`],`Invalid sync action`),a=r.object({mode:r.literal(`analog`),direction:r.literal(`input`)}),o=r.object({mode:r.literal(`analog`),direction:r.literal(`output`),value:r.optional(e)}),s=r.object({mode:r.literal(`digital`),direction:r.literal(`input`),vil:n,vih:n}),c=r.object({mode:r.literal(`digital`),direction:r.literal(`output`),value:t,vol:e,voh:e,vil:n,vih:n}),l=r.object({mode:r.literal(`digital`),direction:r.literal(`open_drain`),value:t,vil:n,vih:n});r.omit(o,[`direction`,`mode`]),r.omit(s,[`direction`,`mode`]);const u=r.partial(r.omit(c,[`direction`,`mode`]),[`vih`,`vil`]);r.omit(l,[`direction`,`mode`]);const d=r.object({value:t}),f=r.object({value:n}),p=r.object({action:i}),m=r.object({hold_state:r.picklist([`held`,`released`])}),h=r.union([c,l,s,o,a]);var g=class{fetch;count;constructor(e,t){this.fetch=e,this.count=t.capabilities.io.count}reset(){return this.fetch(`/gpio/reset`,{method:`POST`,parseResponse:()=>{}})}digital(e){if(e<0||e>=this.count)throw Error(`Invalid GPIO pin ${e} (RESOURCE_NOT_FOUND)\n Suggestion: Use a pin number between 0 and ${this.count-1}\n Path: /gpio/${e}`);return new _(this.fetch,e)}analog(e){if(e<0||e>=this.count)throw Error(`Invalid GPIO pin ${e} (RESOURCE_NOT_FOUND)\n Suggestion: Use a pin number between 0 and ${this.count-1}\n Path: /gpio/${e}`);return new v(this.fetch,e)}hold(){return this.fetch(`/gpio/sync`,{method:`POST`,body:{action:`hold`},schema:p})}release(){return this.fetch(`/gpio/sync`,{method:`POST`,body:{action:`release`},schema:p})}read_config(e){if(e<0||e>=this.count)throw Error(`Invalid GPIO pin ${e} (RESOURCE_NOT_FOUND)\n Suggestion: Use a pin number between 0 and ${this.count-1}\n Path: /gpio/${e}/config`);return this.fetch(`/gpio/${e}/config`,{schema:h})}read_sync(){return this.fetch(`/gpio/sync`,{schema:m})}},_=class{fetch;id;constructor(e,t){this.fetch=e,this.id=t}configure_input(e){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:r.parse(s,{...e,mode:`digital`,direction:`input`}),schema:s})}configure_output(e){e=r.parse(u,e);let t={mode:`digital`,direction:`output`,value:e.value,vol:e.vol,voh:e.voh,vil:e.vil??e.vol+(e.voh-e.vol)/4,vih:e.vih??e.voh-(e.voh-e.vol)/4};return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:r.parse(c,t),schema:c})}async read(){return(await this.fetch(`/gpio/${this.id}/state`,{schema:d})).value}async write(e){return(await this.fetch(`/gpio/${this.id}/state`,{method:`PUT`,body:r.parse(d,{value:e}),schema:d})).value}configure_open_drain(e){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:r.parse(l,{...e,mode:`digital`,direction:`open_drain`}),schema:l})}},v=class{fetch;id;constructor(e,t){this.fetch=e,this.id=t}configure_input(){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:{mode:`analog`,direction:`input`},schema:a})}configure_output(e){return this.fetch(`/gpio/${this.id}/config`,{method:`PATCH`,body:r.parse(o,{value:e,mode:`analog`,direction:`output`}),schema:o})}async read(){return(await this.fetch(`/gpio/${this.id}/state`,{schema:f})).value}async write(e){return(await this.fetch(`/gpio/${this.id}/state`,{method:`PUT`,body:{value:e},schema:f})).value}};export{v as AnalogIO,_ as DigitalIO,g as GpioApi,a as analogInputConfiguration,o as analogOutputConfiguration,f as analogState,s as digitalInputConfiguration,c as digitalOutputConfiguration,d as digitalState,h as gpioConfiguration,l as openDrainConfiguration,m as syncState};
|
|
2
2
|
//# sourceMappingURL=gpio.mjs.map
|
package/build/gpio.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gpio.mjs","names":[],"sources":["../src/api/gpio.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nimport { analogLevel, type AnalogOutputLevel, analogOutputLevel, digitalLevel } from './common';\nimport type { Information } from './management';\n\nexport type { AnalogOutputLevel };\n\nconst syncAction = v.picklist(['release', 'hold'], 'Invalid sync action');\nconst analogInputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('input'),\n});\nconst analogOutputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('output'),\n value: v.optional(analogOutputLevel),\n});\nconst digitalInputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('input'),\n vil: analogLevel,\n vih: analogLevel,\n});\nconst digitalOutputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('output'),\n value: digitalLevel,\n vol: analogOutputLevel,\n voh: analogOutputLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nconst openDrainConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('open_drain'),\n value: digitalLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport type AnalogInputConfiguration = v.InferOutput<typeof analogInputConfiguration>;\nexport type AnalogOutputConfiguration = v.InferOutput<typeof analogOutputConfiguration>;\nexport type DigitalInputConfiguration = v.InferOutput<typeof digitalInputConfiguration>;\nexport type DigitalOutputConfiguration = v.InferOutput<typeof digitalOutputConfiguration>;\nexport type OpenDrainConfiguration = v.InferOutput<typeof openDrainConfiguration>;\n\nconst partialAnalogOutputConfiguration = v.omit(analogOutputConfiguration, ['direction', 'mode']);\nexport type PartialAnalogOutputConfiguration = v.InferOutput<\n typeof partialAnalogOutputConfiguration\n>;\nconst partialDigitalInputConfiguration = v.omit(digitalInputConfiguration, ['direction', 'mode']);\nexport type PartialDigitalInputConfiguration = v.InferOutput<\n typeof partialDigitalInputConfiguration\n>;\nconst partialDigitalOutputConfiguration = v.partial(\n v.omit(digitalOutputConfiguration, ['direction', 'mode']),\n ['vih', 'vil'],\n);\nexport type PartialDigitalOutputConfiguration = v.InferInput<\n typeof partialDigitalOutputConfiguration\n>;\nconst partialOpenDrainConfiguration = v.omit(openDrainConfiguration, ['direction', 'mode']);\nexport type PartialOpenDrainConfiguration = v.InferOutput<typeof partialOpenDrainConfiguration>;\n\nconst digitalState = v.object({ value: digitalLevel });\nconst analogState = v.object({ value: analogLevel });\n\nconst syncConfiguration = v.object({ action: syncAction });\nexport type SyncConfiguration = v.InferOutput<typeof syncConfiguration>;\n\n/** @hideconstructor */\nexport class GpioApi {\n private count: number;\n\n constructor(private readonly fetch: UpFetch, info: Information) {\n this.count = info.capabilities.io.count;\n }\n\n /**\n * Resets all IO configurations to default.\n */\n reset(): Promise<void> {\n return this.fetch('/gpio/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access a specific digital IO pin by id.\n * @param io The IO pin id.\n * @returns The digital IO instance.\n */\n digital(io: number): DigitalIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new DigitalIO(this.fetch, io);\n }\n\n /**\n * Access a specific analog IO pin by id.\n * @param io The IO pin id.\n * @returns The analog IO instance.\n */\n analog(io: number): AnalogIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new AnalogIO(this.fetch, io);\n }\n\n /**\n * Holds the current state of all GPIO pins.\n * @returns The applied sync state.\n */\n hold(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'hold' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Releases control of the IO pins, allowing external control.\n *\n * This also sets the device as a slave.\n *\n * @returns The applied sync state.\n */\n release(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'release' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class DigitalIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configure the pin as a digital input.\n * @param config The digital input configuration.\n * @returns The applied configuration.\n */\n configure_input(config: PartialDigitalInputConfiguration): Promise<DigitalInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n digitalInputConfiguration,\n { ...config, mode: 'digital', direction: 'input' } satisfies DigitalInputConfiguration,\n ),\n schema: digitalInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as a digital output.\n * @param config The digital output configuration.\n * @returns The applied configuration.\n */\n configure_output(config: PartialDigitalOutputConfiguration): Promise<DigitalOutputConfiguration> {\n config = v.parse(partialDigitalOutputConfiguration, config);\n\n const fullConfig = {\n mode: 'digital' as const,\n direction: 'output' as const,\n value: config.value,\n vol: config.vol,\n voh: config.voh,\n vil: config.vil ?? config.vol + (config.voh - config.vol) / 4,\n vih: config.vih ?? config.voh - (config.voh - config.vol) / 4,\n };\n\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(digitalOutputConfiguration, fullConfig),\n schema: digitalOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: digitalState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: boolean | number): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: v.parse(digitalState, { value }),\n schema: digitalState,\n }))\n .value;\n }\n\n /**\n * Configure the pin as an open drain output.\n * @param config The open drain configuration.\n * @returns The applied configuration.\n */\n configure_open_drain(config: PartialOpenDrainConfiguration): Promise<OpenDrainConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n openDrainConfiguration,\n { ...config, mode: 'digital', direction: 'open_drain' } satisfies OpenDrainConfiguration,\n ),\n schema: openDrainConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class AnalogIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configures the pin as an analog input.\n * @returns The applied configuration.\n * @returns The applied configuration.\n */\n configure_input(): Promise<AnalogInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: { mode: 'analog', direction: 'input' } satisfies AnalogInputConfiguration,\n schema: analogInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as an analog output.\n * @param config The analog output configuration.\n * @returns The applied configuration.\n */\n configure_output(value: AnalogOutputLevel): Promise<AnalogOutputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n analogOutputConfiguration,\n { value, mode: 'analog', direction: 'output' } satisfies AnalogOutputConfiguration,\n ),\n schema: analogOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: analogState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: number): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: { value },\n schema: analogState,\n }))\n .value;\n }\n}\n"],"mappings":"kFAQA,MAAM,EAAa,EAAE,SAAS,CAAC,UAAW,MAAM,EAAG,qBAAqB,EAClE,EAA2B,EAAE,OAAO,CACxC,KAAM,EAAE,QAAQ,QAAQ,EACxB,UAAW,EAAE,QAAQ,OAAO,CAC9B,CAAC,EACK,EAA4B,EAAE,OAAO,CACzC,KAAM,EAAE,QAAQ,QAAQ,EACxB,UAAW,EAAE,QAAQ,QAAQ,EAC7B,MAAO,EAAE,SAAS,CAAiB,CACrC,CAAC,EACK,EAA4B,EAAE,OAAO,CACzC,KAAM,EAAE,QAAQ,SAAS,EACzB,UAAW,EAAE,QAAQ,OAAO,EAC5B,IAAK,EACL,IAAK,CACP,CAAC,EACK,EAA6B,EAAE,OAAO,CAC1C,KAAM,EAAE,QAAQ,SAAS,EACzB,UAAW,EAAE,QAAQ,QAAQ,EAC7B,MAAO,EACP,IAAK,EACL,IAAK,EACL,IAAK,EACL,IAAK,CACP,CAAC,EACK,EAAyB,EAAE,OAAO,CACtC,KAAM,EAAE,QAAQ,SAAS,EACzB,UAAW,EAAE,QAAQ,YAAY,EACjC,MAAO,EACP,IAAK,EACL,IAA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CACS,MAAgC,GAA7D,YAAY,EAAiC,EAA4B,CAA5C,KAAA,MAAA,EAAgC,KAAA,GAAA,CAAa,CAO1E,iBAAqD,CACnD,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,CAAE,KAAM,SAAU,UAAW,OAAQ,EAC3C,OAAQ,CACV,CAAC,CACH,CAOA,iBAAiB,EAA8D,CAC7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,QAAS,CAC/C,EACA,OAAQ,CACV,CAAC,CACH,CAMA,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,CAAY,CAAC,EAAA,CAAG,KAC/E,CAOA,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,OAAM,EACd,OAAQ,CACV,CAAC,EAAA,CACE,KACL,CACF"}
|
|
1
|
+
{"version":3,"file":"gpio.mjs","names":[],"sources":["../src/api/gpio.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nimport { analogLevel, type AnalogOutputLevel, analogOutputLevel, digitalLevel } from './common';\nimport type { Information } from './management';\n\nexport type { AnalogOutputLevel };\n\nconst syncAction = v.picklist(['release', 'hold'], 'Invalid sync action');\nexport const analogInputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('input'),\n});\nexport const analogOutputConfiguration = v.object({\n mode: v.literal('analog'),\n direction: v.literal('output'),\n value: v.optional(analogOutputLevel),\n});\nexport const digitalInputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('input'),\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const digitalOutputConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('output'),\n value: digitalLevel,\n vol: analogOutputLevel,\n voh: analogOutputLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport const openDrainConfiguration = v.object({\n mode: v.literal('digital'),\n direction: v.literal('open_drain'),\n value: digitalLevel,\n vil: analogLevel,\n vih: analogLevel,\n});\nexport type AnalogInputConfiguration = v.InferOutput<typeof analogInputConfiguration>;\nexport type AnalogOutputConfiguration = v.InferOutput<typeof analogOutputConfiguration>;\nexport type DigitalInputConfiguration = v.InferOutput<typeof digitalInputConfiguration>;\nexport type DigitalOutputConfiguration = v.InferOutput<typeof digitalOutputConfiguration>;\nexport type OpenDrainConfiguration = v.InferOutput<typeof openDrainConfiguration>;\n\nconst partialAnalogOutputConfiguration = v.omit(analogOutputConfiguration, ['direction', 'mode']);\nexport type PartialAnalogOutputConfiguration = v.InferOutput<\n typeof partialAnalogOutputConfiguration\n>;\nconst partialDigitalInputConfiguration = v.omit(digitalInputConfiguration, ['direction', 'mode']);\nexport type PartialDigitalInputConfiguration = v.InferOutput<\n typeof partialDigitalInputConfiguration\n>;\nconst partialDigitalOutputConfiguration = v.partial(\n v.omit(digitalOutputConfiguration, ['direction', 'mode']),\n ['vih', 'vil'],\n);\nexport type PartialDigitalOutputConfiguration = v.InferInput<\n typeof partialDigitalOutputConfiguration\n>;\nconst partialOpenDrainConfiguration = v.omit(openDrainConfiguration, ['direction', 'mode']);\nexport type PartialOpenDrainConfiguration = v.InferOutput<typeof partialOpenDrainConfiguration>;\n\nexport const digitalState = v.object({ value: digitalLevel });\nexport const analogState = v.object({ value: analogLevel });\n\nconst syncConfiguration = v.object({ action: syncAction });\nexport type SyncConfiguration = v.InferOutput<typeof syncConfiguration>;\n\nexport const syncState = v.object({ hold_state: v.picklist(['held', 'released']) });\nexport type SyncState = v.InferOutput<typeof syncState>;\n\nexport const gpioConfiguration = v.union([\n digitalOutputConfiguration,\n openDrainConfiguration,\n digitalInputConfiguration,\n analogOutputConfiguration,\n analogInputConfiguration,\n]);\nexport type GpioConfiguration = v.InferOutput<typeof gpioConfiguration>;\n\n/** @hideconstructor */\nexport class GpioApi {\n private count: number;\n\n constructor(private readonly fetch: UpFetch, info: Information) {\n this.count = info.capabilities.io.count;\n }\n\n /**\n * Resets all IO configurations to default.\n */\n reset(): Promise<void> {\n return this.fetch('/gpio/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access a specific digital IO pin by id.\n * @param io The IO pin id.\n * @returns The digital IO instance.\n */\n digital(io: number): DigitalIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new DigitalIO(this.fetch, io);\n }\n\n /**\n * Access a specific analog IO pin by id.\n * @param io The IO pin id.\n * @returns The analog IO instance.\n */\n analog(io: number): AnalogIO {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}`,\n );\n }\n\n return new AnalogIO(this.fetch, io);\n }\n\n /**\n * Holds the current state of all GPIO pins.\n * @returns The applied sync state.\n */\n hold(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'hold' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Releases control of the IO pins, allowing external control.\n *\n * This also sets the device as a slave.\n *\n * @returns The applied sync state.\n */\n release(): Promise<SyncConfiguration> {\n return this.fetch('/gpio/sync', {\n method: 'POST',\n body: { action: 'release' } satisfies SyncConfiguration,\n schema: syncConfiguration,\n });\n }\n\n /**\n * Reads back the current configuration of a specific IO pin.\n * @param io The IO pin id.\n * @returns The pin's current configuration.\n */\n read_config(io: number): Promise<GpioConfiguration> {\n if (io < 0 || io >= this.count) {\n throw new Error(\n `Invalid GPIO pin ${io} (RESOURCE_NOT_FOUND)\\n Suggestion: Use a pin number between 0 and ${\n this.count - 1\n }\\n Path: /gpio/${io}/config`,\n );\n }\n\n return this.fetch(`/gpio/${io}/config`, { schema: gpioConfiguration });\n }\n\n /**\n * Reads the current hold state of all GPIO pins.\n * @returns The current sync state.\n */\n read_sync(): Promise<SyncState> {\n return this.fetch('/gpio/sync', { schema: syncState });\n }\n}\n\n/** @hideconstructor */\nexport class DigitalIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configure the pin as a digital input.\n * @param config The digital input configuration.\n * @returns The applied configuration.\n */\n configure_input(config: PartialDigitalInputConfiguration): Promise<DigitalInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n digitalInputConfiguration,\n { ...config, mode: 'digital', direction: 'input' } satisfies DigitalInputConfiguration,\n ),\n schema: digitalInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as a digital output.\n * @param config The digital output configuration.\n * @returns The applied configuration.\n */\n configure_output(config: PartialDigitalOutputConfiguration): Promise<DigitalOutputConfiguration> {\n config = v.parse(partialDigitalOutputConfiguration, config);\n\n const fullConfig = {\n mode: 'digital' as const,\n direction: 'output' as const,\n value: config.value,\n vol: config.vol,\n voh: config.voh,\n vil: config.vil ?? config.vol + (config.voh - config.vol) / 4,\n vih: config.vih ?? config.voh - (config.voh - config.vol) / 4,\n };\n\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(digitalOutputConfiguration, fullConfig),\n schema: digitalOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: digitalState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: boolean | number): Promise<boolean> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: v.parse(digitalState, { value }),\n schema: digitalState,\n }))\n .value;\n }\n\n /**\n * Configure the pin as an open drain output.\n * @param config The open drain configuration.\n * @returns The applied configuration.\n */\n configure_open_drain(config: PartialOpenDrainConfiguration): Promise<OpenDrainConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n openDrainConfiguration,\n { ...config, mode: 'digital', direction: 'open_drain' } satisfies OpenDrainConfiguration,\n ),\n schema: openDrainConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class AnalogIO {\n constructor(private readonly fetch: UpFetch, public readonly id: number) {}\n\n /**\n * Configures the pin as an analog input.\n * @returns The applied configuration.\n * @returns The applied configuration.\n */\n configure_input(): Promise<AnalogInputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: { mode: 'analog', direction: 'input' } satisfies AnalogInputConfiguration,\n schema: analogInputConfiguration,\n });\n }\n\n /**\n * Configures the pin as an analog output.\n * @param config The analog output configuration.\n * @returns The applied configuration.\n */\n configure_output(value: AnalogOutputLevel): Promise<AnalogOutputConfiguration> {\n return this.fetch(`/gpio/${this.id}/config`, {\n method: 'PATCH',\n body: v.parse(\n analogOutputConfiguration,\n { value, mode: 'analog', direction: 'output' } satisfies AnalogOutputConfiguration,\n ),\n schema: analogOutputConfiguration,\n });\n }\n\n /**\n * Reads the current state of the pin.\n * @returns The current state of the pin.\n */\n async read(): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, { schema: analogState })).value;\n }\n\n /**\n * Writes a value to the pin.\n * @param value The value to write.\n * @returns The written value.\n */\n async write(value: number): Promise<number> {\n return (await this.fetch(`/gpio/${this.id}/state`, {\n method: 'PUT',\n body: { value },\n schema: analogState,\n }))\n .value;\n }\n}\n"],"mappings":"kFAQA,MAAM,EAAa,EAAE,SAAS,CAAC,UAAW,MAAM,EAAG,qBAAqB,EAC3D,EAA2B,EAAE,OAAO,CAC/C,KAAM,EAAE,QAAQ,QAAQ,EACxB,UAAW,EAAE,QAAQ,OAAO,C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7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,QAAS,CAC/C,EACA,OAAQ,CACV,CAAC,CACH,CAMA,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,CAAY,CAAC,EAAA,CAAG,KAC/E,CAOA,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,OAAM,EACd,OAAQ,CACV,CAAC,EAAA,CACE,KACL,CACF"}
|
|
@@ -4,6 +4,9 @@ import * as v from "valibot";
|
|
|
4
4
|
//#region src/api/hmi.d.ts
|
|
5
5
|
declare const screenText: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1024, undefined>]>;
|
|
6
6
|
type ScreenText = v.InferOutput<typeof screenText>;
|
|
7
|
+
declare const text: v.ObjectSchema<{
|
|
8
|
+
readonly text: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1024, undefined>]>;
|
|
9
|
+
}, undefined>;
|
|
7
10
|
declare const color: v.ObjectSchema<{
|
|
8
11
|
readonly text: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.LengthAction<string, 7, undefined>, v.HexColorAction<string, undefined>]>, undefined>;
|
|
9
12
|
readonly progress: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.LengthAction<string, 7, undefined>, v.HexColorAction<string, undefined>]>, undefined>;
|
|
@@ -21,11 +24,16 @@ declare const playbackConfiguration: v.ObjectSchema<{
|
|
|
21
24
|
readonly volume: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
|
|
22
25
|
}, undefined>;
|
|
23
26
|
type PlaybackConfiguration = v.InferOutput<typeof playbackConfiguration>;
|
|
27
|
+
declare const internalKnobEvent: v.ObjectSchema<{
|
|
28
|
+
readonly button_pressed: v.BooleanSchema<undefined>;
|
|
29
|
+
readonly button_held: v.BooleanSchema<undefined>;
|
|
30
|
+
readonly rotation_delta: v.NumberSchema<undefined>;
|
|
31
|
+
}, undefined>;
|
|
24
32
|
declare const knobEvent: Omit<v.ObjectSchema<{
|
|
25
33
|
readonly button_pressed: v.BooleanSchema<undefined>;
|
|
26
34
|
readonly button_held: v.BooleanSchema<undefined>;
|
|
27
35
|
readonly rotation_delta: v.NumberSchema<undefined>;
|
|
28
|
-
}, undefined>, "~
|
|
36
|
+
}, undefined>, "~types" | "~run" | "~standard" | "entries"> & {
|
|
29
37
|
readonly entries: Omit<{
|
|
30
38
|
readonly button_pressed: v.BooleanSchema<undefined>;
|
|
31
39
|
readonly button_held: v.BooleanSchema<undefined>;
|
|
@@ -41,7 +49,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
41
49
|
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
42
50
|
button_pressed: boolean;
|
|
43
51
|
rotation_delta: number;
|
|
44
|
-
}, v.
|
|
52
|
+
}, v.BooleanIssue | v.NumberIssue | v.ObjectIssue>;
|
|
45
53
|
readonly "~types"?: {
|
|
46
54
|
readonly input: {
|
|
47
55
|
button_pressed: boolean;
|
|
@@ -51,7 +59,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
51
59
|
button_pressed: boolean;
|
|
52
60
|
rotation_delta: number;
|
|
53
61
|
};
|
|
54
|
-
readonly issue: v.
|
|
62
|
+
readonly issue: v.BooleanIssue | v.NumberIssue | v.ObjectIssue;
|
|
55
63
|
} | undefined;
|
|
56
64
|
};
|
|
57
65
|
type KnobEvent = v.InferOutput<typeof knobEvent>;
|
|
@@ -105,6 +113,10 @@ declare class Screen {
|
|
|
105
113
|
* Clears the screen.
|
|
106
114
|
*/
|
|
107
115
|
clear(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Clears the text on the screen.
|
|
118
|
+
*/
|
|
119
|
+
clear_text(): Promise<void>;
|
|
108
120
|
}
|
|
109
121
|
/** @hideconstructor */
|
|
110
122
|
declare class Audio {
|
|
@@ -136,5 +148,5 @@ declare class Knob {
|
|
|
136
148
|
wait_event(timeout_ms?: number): Promise<KnobEvent | null>;
|
|
137
149
|
}
|
|
138
150
|
//#endregion
|
|
139
|
-
export { KnobEvent as a, ProgressValue as c, Knob as i, Screen as l, Color as n, PlaybackConfiguration as o, HmiApi as r, Progress as s, Audio as t, ScreenText as u };
|
|
140
|
-
//# sourceMappingURL=hmi-
|
|
151
|
+
export { KnobEvent as a, ProgressValue as c, color as d, internalKnobEvent as f, text as h, Knob as i, Screen as l, progress as m, Color as n, PlaybackConfiguration as o, playbackConfiguration as p, HmiApi as r, Progress as s, Audio as t, ScreenText as u };
|
|
152
|
+
//# sourceMappingURL=hmi-BrdqKB3o.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmi-BrdqKB3o.d.cts","names":[],"sources":["../src/api/hmi.ts"],"mappings":";;;;cAGM,UAAA,EAAU,CAAA,CAAA,cAAA,WAAA,CAAA,CAAA,YAAA,aAAA,CAAA,CAAA,eAAA;AAAA,KACJ,UAAA,GAAa,CAAA,CAAE,WAAW,QAAQ,UAAA;AAAA,cAEjC,IAAA,EAAI,CAAA,CAAA,YAAA;EAAA;;cAIJ,KAAA,EAAK,CAAA,CAAA,YAAA;EAAA;;;;KAKN,KAAA,GAAQ,CAAA,CAAE,WAAW,QAAQ,KAAA;AAAA,cAEnC,aAAA,EAAa,CAAA,CAAA,cAAA,WAAA,CAAA,CAAA,YAAA,aAAA,CAAA,CAAA,cAAA,wBAAA,CAAA,CAAA,cAAA;AAAA,KACP,aAAA,GAAgB,CAAA,CAAE,WAAW,QAAQ,aAAA;AAAA,cACpC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Q,UAAA,CAAW,UAAA,YAAsB,OAAA,CAAQ,SAAA;AAAA"}
|
|
@@ -4,6 +4,9 @@ import * as v from "valibot";
|
|
|
4
4
|
//#region src/api/hmi.d.ts
|
|
5
5
|
declare const screenText: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1024, undefined>]>;
|
|
6
6
|
type ScreenText = v.InferOutput<typeof screenText>;
|
|
7
|
+
declare const text: v.ObjectSchema<{
|
|
8
|
+
readonly text: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1024, undefined>]>;
|
|
9
|
+
}, undefined>;
|
|
7
10
|
declare const color: v.ObjectSchema<{
|
|
8
11
|
readonly text: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.LengthAction<string, 7, undefined>, v.HexColorAction<string, undefined>]>, undefined>;
|
|
9
12
|
readonly progress: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.LengthAction<string, 7, undefined>, v.HexColorAction<string, undefined>]>, undefined>;
|
|
@@ -21,11 +24,16 @@ declare const playbackConfiguration: v.ObjectSchema<{
|
|
|
21
24
|
readonly volume: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
|
|
22
25
|
}, undefined>;
|
|
23
26
|
type PlaybackConfiguration = v.InferOutput<typeof playbackConfiguration>;
|
|
27
|
+
declare const internalKnobEvent: v.ObjectSchema<{
|
|
28
|
+
readonly button_pressed: v.BooleanSchema<undefined>;
|
|
29
|
+
readonly button_held: v.BooleanSchema<undefined>;
|
|
30
|
+
readonly rotation_delta: v.NumberSchema<undefined>;
|
|
31
|
+
}, undefined>;
|
|
24
32
|
declare const knobEvent: Omit<v.ObjectSchema<{
|
|
25
33
|
readonly button_pressed: v.BooleanSchema<undefined>;
|
|
26
34
|
readonly button_held: v.BooleanSchema<undefined>;
|
|
27
35
|
readonly rotation_delta: v.NumberSchema<undefined>;
|
|
28
|
-
}, undefined>, "~
|
|
36
|
+
}, undefined>, "~types" | "~run" | "~standard" | "entries"> & {
|
|
29
37
|
readonly entries: Omit<{
|
|
30
38
|
readonly button_pressed: v.BooleanSchema<undefined>;
|
|
31
39
|
readonly button_held: v.BooleanSchema<undefined>;
|
|
@@ -41,7 +49,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
41
49
|
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
42
50
|
button_pressed: boolean;
|
|
43
51
|
rotation_delta: number;
|
|
44
|
-
}, v.
|
|
52
|
+
}, v.BooleanIssue | v.NumberIssue | v.ObjectIssue>;
|
|
45
53
|
readonly "~types"?: {
|
|
46
54
|
readonly input: {
|
|
47
55
|
button_pressed: boolean;
|
|
@@ -51,7 +59,7 @@ declare const knobEvent: Omit<v.ObjectSchema<{
|
|
|
51
59
|
button_pressed: boolean;
|
|
52
60
|
rotation_delta: number;
|
|
53
61
|
};
|
|
54
|
-
readonly issue: v.
|
|
62
|
+
readonly issue: v.BooleanIssue | v.NumberIssue | v.ObjectIssue;
|
|
55
63
|
} | undefined;
|
|
56
64
|
};
|
|
57
65
|
type KnobEvent = v.InferOutput<typeof knobEvent>;
|
|
@@ -105,6 +113,10 @@ declare class Screen {
|
|
|
105
113
|
* Clears the screen.
|
|
106
114
|
*/
|
|
107
115
|
clear(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Clears the text on the screen.
|
|
118
|
+
*/
|
|
119
|
+
clear_text(): Promise<void>;
|
|
108
120
|
}
|
|
109
121
|
/** @hideconstructor */
|
|
110
122
|
declare class Audio {
|
|
@@ -136,5 +148,5 @@ declare class Knob {
|
|
|
136
148
|
wait_event(timeout_ms?: number): Promise<KnobEvent | null>;
|
|
137
149
|
}
|
|
138
150
|
//#endregion
|
|
139
|
-
export { KnobEvent as a, ProgressValue as c, Knob as i, Screen as l, Color as n, PlaybackConfiguration as o, HmiApi as r, Progress as s, Audio as t, ScreenText as u };
|
|
140
|
-
//# sourceMappingURL=hmi-
|
|
151
|
+
export { KnobEvent as a, ProgressValue as c, color as d, internalKnobEvent as f, text as h, Knob as i, Screen as l, progress as m, Color as n, PlaybackConfiguration as o, playbackConfiguration as p, HmiApi as r, Progress as s, Audio as t, ScreenText as u };
|
|
152
|
+
//# sourceMappingURL=hmi-BrdqKB3o.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmi-BrdqKB3o.d.mts","names":[],"sources":["../src/api/hmi.ts"],"mappings":";;;;cAGM,UAAA,EAAU,CAAA,CAAA,cAAA,WAAA,CAAA,CAAA,YAAA,aAAA,CAAA,CAAA,eAAA;AAAA,KACJ,UAAA,GAAa,CAAA,CAAE,WAAW,QAAQ,UAAA;AAAA,cAEjC,IAAA,EAAI,CAAA,CAAA,YAAA;EAAA;;cAIJ,KAAA,EAAK,CAAA,CAAA,YAAA;EAAA;;;;KAKN,KAAA,GAAQ,CAAA,CAAE,WAAW,QAAQ,KAAA;AAAA,cAEnC,aAAA,EAAa,CAAA,CAAA,cAAA,WAAA,CAAA,CAAA,YAAA,aAAA,CAAA,CAAA,cAAA,wBAAA,CAAA,CAAA,cAAA;AAAA,KACP,aAAA,GAAgB,CAAA,CAAE,WAAW,QAAQ,aAAA;AAAA,cACpC,QAAA,EAAQ,CAAA,CAAA,YAAA;EAAA;;KACT,QAAA,GAAW,CAAA,CAAE,WAAW,QAAQ,QAAA;AAAA,cAE/B,qBAAA,EAAqB,CAAA,CAAA,YAAA;EAAA;;;KAOtB,qBAAA,GAAwB,CAAA,CAAE,WAAW,QAAQ,qBAAA;AAAA,cAE5C,iBAAA,EAAiB,CAAA,CAAA,YAAA;EAAA;;;;cAKxB,SAAA,EAAS,IAAA,CAAA,CAAA,CAAA,YAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KACH,SAAA,GAAY,CAAA,CAAE,WAAW,QAAQ,SAAA;;cAGhC,MAAA;EAAA,iBACkB,KAAA;cAAA,KAAA,EAAO,OAAA;EA/BpB;;;EAoChB,KAAA,IAAS,OAAA;EApCO;;;;EA4ChB,MAAA,IAAU,MAAA;;;;;EAQV,KAAA,IAAS,KAAA;;;;;EAQT,IAAA,IAAQ,IAAA;AAAA;;cAMG,MAAA;EAAA,iBACkB,KAAA;cAAA,KAAA,EAAO,OAAA;;;;;;EAO9B,KAAA,CAAM,IAAA,EAAM,UAAA,GAAa,OAAA;;;;;;EAc/B,MAAA,CAAO,MAAA,EAAQ,KAAA,GAAQ,OAAA,CAAQ,KAAA;;;;;AAnFjC;EAgGQ,QAAA,CAAS,IAAA,EAAM,aAAA,GAAgB,OAAA,CAAQ,QAAA;;;;EAkB7C,KAAA,IAAS,OAAA;EAlH8B;;AAAK;EAyH5C,UAAA,IAAc,OAAA;AAAA;;cAMH,KAAA;EAAA,iBACkB,KAAA;cAAA,KAAA,EAAO,OAAA;EA9HnB;;;;;EAqIX,IAAA,CAAK,MAAA,EAAQ,qBAAA,GAAwB,OAAA,CAAQ,qBAAA;AAAA;;cAUxC,IAAA;EAAA,iBACkB,KAAA;cAAA,KAAA,EAAO,OAAA;EAEpC,UAAA,QAAU,OAAA;;;;;EAEV,cAAA,QAAc,OAAA;EACd,cAAA,QAAc,OAAA;EApJc;;;AAAgC;AAC9D;EA0JQ,UAAA,CAAW,UAAA,YAAsB,OAAA,CAAQ,SAAA;AAAA"}
|
package/build/hmi.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunk-CMqjfN_6.cjs");let t=require("valibot");t=e.t(t,1);const n=t.pipe(t.string(),t.maxLength(1024)),r=t.object({text:n}),i=t.optional(t.pipe(t.string(),t.length(7),t.hexColor())),a=t.object({text:i,progress:i,background:i}),o=t.pipe(t.number(),t.minValue(0),t.maxValue(100)),s=t.object({progress:o}),c=t.object({sound_id:t.picklist([`success`,`warning`,`failure`,`notification_1`,`notification_2`,`imperial_march`]),volume:t.pipe(t.number(),t.minValue(0),t.maxValue(100))}),l=t.object({button_pressed:t.boolean(),button_held:t.boolean(),rotation_delta:t.number()});t.omit(l,[`button_held`]);var u=class{fetch;constructor(e){this.fetch=e}reset(){return this.fetch(`/hmi/reset`,{method:`POST`,parseResponse:()=>{}})}screen(){return new d(this.fetch)}audio(){return new f(this.fetch)}knob(){return new p(this.fetch)}},d=class{fetch;constructor(e){this.fetch=e}async print(e){return(await this.fetch(`/hmi/screen/text`,{method:`POST`,body:t.parse(r,{text:e}),schema:r})).text}colors(e){return this.fetch(`/hmi/screen/colors`,{method:`PATCH`,body:t.parse(a,e),schema:a})}async progress(e){return e==0?await this.fetch(`/hmi/screen/progress`,{method:`DELETE`,parseResponse:()=>({progress:0})}):this.fetch(`/hmi/screen/progress`,{method:`PUT`,body:t.parse(s,{progress:e}),schema:s})}clear(){return this.fetch(`/hmi/screen/clear`,{method:`POST`,parseResponse:()=>{}})}},f=class{fetch;constructor(e){this.fetch=e}async play(e){return this.fetch(`/hmi/speaker/play`,{method:`POST`,body:t.parse(c,e),schema:c})}},p=class{fetch;constructor(e){this.fetch=e}read_event=()=>this.fetch(`/hmi/knob/get_knob_event`,{schema:l});is_button_held=async()=>(await this.read_event()).button_held;is_knob_turned=async()=>Math.abs((await this.read_event()).rotation_delta)>=4;async wait_event(e){await this.read_event();let t=0,n=Math.min(50,(e??500)/10),r=Date.now();for(;e===void 0||Date.now()-r<e;){let e=await this.read_event();if(t+=e.rotation_delta,e.button_pressed||Math.abs(t)>=4)return{button_pressed:e.button_pressed,rotation_delta:Math.sign(t)};await new Promise(e=>setTimeout(e,n))}return null}};exports.Audio=f,exports.HmiApi=u,exports.Knob=p,exports.Screen=d;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunk-CMqjfN_6.cjs");let t=require("valibot");t=e.t(t,1);const n=t.pipe(t.string(),t.maxLength(1024)),r=t.object({text:n}),i=t.optional(t.pipe(t.string(),t.length(7),t.hexColor())),a=t.object({text:i,progress:i,background:i}),o=t.pipe(t.number(),t.minValue(0),t.maxValue(100)),s=t.object({progress:o}),c=t.object({sound_id:t.picklist([`success`,`warning`,`failure`,`notification_1`,`notification_2`,`imperial_march`]),volume:t.pipe(t.number(),t.minValue(0),t.maxValue(100))}),l=t.object({button_pressed:t.boolean(),button_held:t.boolean(),rotation_delta:t.number()});t.omit(l,[`button_held`]);var u=class{fetch;constructor(e){this.fetch=e}reset(){return this.fetch(`/hmi/reset`,{method:`POST`,parseResponse:()=>{}})}screen(){return new d(this.fetch)}audio(){return new f(this.fetch)}knob(){return new p(this.fetch)}},d=class{fetch;constructor(e){this.fetch=e}async print(e){return(await this.fetch(`/hmi/screen/text`,{method:`POST`,body:t.parse(r,{text:e}),schema:r})).text}colors(e){return this.fetch(`/hmi/screen/colors`,{method:`PATCH`,body:t.parse(a,e),schema:a})}async progress(e){return e==0?await this.fetch(`/hmi/screen/progress`,{method:`DELETE`,parseResponse:()=>({progress:0})}):this.fetch(`/hmi/screen/progress`,{method:`PUT`,body:t.parse(s,{progress:e}),schema:s})}clear(){return this.fetch(`/hmi/screen/clear`,{method:`POST`,parseResponse:()=>{}})}clear_text(){return this.fetch(`/hmi/screen/text`,{method:`DELETE`,parseResponse:()=>{}})}},f=class{fetch;constructor(e){this.fetch=e}async play(e){return this.fetch(`/hmi/speaker/play`,{method:`POST`,body:t.parse(c,e),schema:c})}},p=class{fetch;constructor(e){this.fetch=e}read_event=()=>this.fetch(`/hmi/knob/get_knob_event`,{schema:l});is_button_held=async()=>(await this.read_event()).button_held;is_knob_turned=async()=>Math.abs((await this.read_event()).rotation_delta)>=4;async wait_event(e){await this.read_event();let t=0,n=Math.min(50,(e??500)/10),r=Date.now();for(;e===void 0||Date.now()-r<e;){let e=await this.read_event();if(t+=e.rotation_delta,e.button_pressed||Math.abs(t)>=4)return{button_pressed:e.button_pressed,rotation_delta:Math.sign(t)};await new Promise(e=>setTimeout(e,n))}return null}};exports.Audio=f,exports.HmiApi=u,exports.Knob=p,exports.Screen=d,exports.color=a,exports.internalKnobEvent=l,exports.playbackConfiguration=c,exports.progress=s,exports.text=r;
|
|
2
2
|
//# sourceMappingURL=hmi.cjs.map
|
package/build/hmi.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmi.cjs","names":["v"],"sources":["../src/api/hmi.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nconst screenText = v.pipe(v.string(), v.maxLength(1024));\nexport type ScreenText = v.InferOutput<typeof screenText>;\n\
|
|
1
|
+
{"version":3,"file":"hmi.cjs","names":["v"],"sources":["../src/api/hmi.ts"],"sourcesContent":["import type { UpFetch } from 'up-fetch';\nimport * as v from 'valibot';\n\nconst screenText = v.pipe(v.string(), v.maxLength(1024));\nexport type ScreenText = v.InferOutput<typeof screenText>;\n\nexport const text = v.object({ text: screenText });\ntype Text = v.InferOutput<typeof text>;\n\nconst optionalHexColor = v.optional(v.pipe(v.string(), v.length(7), v.hexColor()));\nexport const color = v.object({\n text: optionalHexColor,\n progress: optionalHexColor,\n background: optionalHexColor,\n});\nexport type Color = v.InferOutput<typeof color>;\n\nconst progressValue = v.pipe(v.number(), v.minValue(0), v.maxValue(100));\nexport type ProgressValue = v.InferOutput<typeof progressValue>;\nexport const progress = v.object({ progress: progressValue });\nexport type Progress = v.InferOutput<typeof progress>;\n\nexport const playbackConfiguration = v.object({\n sound_id: v.picklist(\n ['success', 'warning', 'failure', 'notification_1', 'notification_2',\n 'imperial_march'] as const,\n ),\n volume: v.pipe(v.number(), v.minValue(0), v.maxValue(100)),\n});\nexport type PlaybackConfiguration = v.InferOutput<typeof playbackConfiguration>;\n\nexport const internalKnobEvent = v.object({\n button_pressed: v.boolean(),\n button_held: v.boolean(),\n rotation_delta: v.number(),\n});\nconst knobEvent = v.omit(internalKnobEvent, ['button_held']);\nexport type KnobEvent = v.InferOutput<typeof knobEvent>;\n\n/** @hideconstructor */\nexport class HmiApi {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Resets the HMI.\n */\n reset(): Promise<void> {\n return this.fetch('/hmi/reset', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Access the screen API.\n * @returns The screen instance.\n */\n screen(): Screen {\n return new Screen(this.fetch);\n }\n\n /**\n * Access the audio API.\n * @returns The audio instance.\n */\n audio(): Audio {\n return new Audio(this.fetch);\n }\n\n /**\n * Access the knob API.\n * @returns The knob instance.\n */\n knob(): Knob {\n return new Knob(this.fetch);\n }\n}\n\n/** @hideconstructor */\nexport class Screen {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Prints text to the screen.\n * @param data The text to print.\n * @returns The printed text.\n */\n async print(data: ScreenText): Promise<string> {\n return (await this.fetch('/hmi/screen/text', {\n method: 'POST',\n body: v.parse(text, { text: data } satisfies Text),\n schema: text,\n }))\n .text;\n }\n\n /**\n * Sets the screen colors.\n * @param colors The colors to set.\n * @returns The updated colors.\n */\n colors(colors: Color): Promise<Color> {\n return this.fetch('/hmi/screen/colors', {\n method: 'PATCH',\n body: v.parse(color, colors satisfies Color),\n schema: color,\n });\n }\n\n /**\n * Sets the screen progress.\n * @param data The progress value to set.\n * @returns The updated progress.\n */\n async progress(data: ProgressValue): Promise<Progress> {\n if (data == 0) {\n return await this.fetch('/hmi/screen/progress', {\n method: 'DELETE',\n parseResponse: () => ({ progress: 0 }),\n });\n }\n\n return this.fetch('/hmi/screen/progress', {\n method: 'PUT',\n body: v.parse(progress, { progress: data } satisfies Progress),\n schema: progress,\n });\n }\n\n /**\n * Clears the screen.\n */\n clear(): Promise<void> {\n return this.fetch('/hmi/screen/clear', { method: 'POST', parseResponse: () => {} });\n }\n\n /**\n * Clears the text on the screen.\n */\n clear_text(): Promise<void> {\n return this.fetch('/hmi/screen/text', { method: 'DELETE', parseResponse: () => {} });\n }\n}\n\n/** @hideconstructor */\nexport class Audio {\n constructor(private readonly fetch: UpFetch) {}\n\n /**\n * Plays a sound.\n * @param config The configuration (sound_id, volume).\n * @returns The play configuration.\n */\n async play(config: PlaybackConfiguration): Promise<PlaybackConfiguration> {\n return this.fetch('/hmi/speaker/play', {\n method: 'POST',\n body: v.parse(playbackConfiguration, config),\n schema: playbackConfiguration,\n });\n }\n}\n\n/** @hideconstructor */\nexport class Knob {\n constructor(private readonly fetch: UpFetch) {}\n\n read_event = () => this.fetch('/hmi/knob/get_knob_event', { schema: internalKnobEvent });\n\n is_button_held = async () => (await this.read_event()).button_held;\n is_knob_turned = async () => Math.abs((await this.read_event()).rotation_delta) >= 4;\n\n /**\n * Waits for a knob event and returns it.\n * @param timeout_ms The timeout in milliseconds.\n * @returns The knob event or null if the timeout was reached.\n */\n async wait_event(timeout_ms?: number): Promise<KnobEvent | null> {\n await this.read_event(); // Discard any previous events\n let delta = 0;\n\n const interval = Math.min(50, (timeout_ms ?? 500) / 10);\n\n const startTime = Date.now();\n while (timeout_ms !== undefined ? Date.now() - startTime < timeout_ms : true) {\n const knobEvent = await this.read_event();\n delta += knobEvent.rotation_delta;\n\n if (knobEvent.button_pressed || Math.abs(delta) >= 4) {\n return { button_pressed: knobEvent.button_pressed, rotation_delta: Math.sign(delta) };\n }\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n\n return null;\n }\n}\n"],"mappings":"+IAGA,MAAM,EAAaA,EAAE,KAAKA,EAAE,OAAO,EAAGA,EAAE,UAAU,IAAI,CAAC,EAG1C,EAAOA,EAAE,OAAO,CAAE,KAAM,CAAW,CAAC,EAG3C,EAAmBA,EAAE,SAASA,EAAE,KAAKA,EAAE,OAAO,EAAGA,EAAE,OAAO,CAAC,EAAGA,EAAE,SAAS,CAAC,CAAC,EACpE,EAAQA,EAAE,OAAO,CAC5B,KAAM,EACN,SAAU,EACV,WAAY,CACd,CAAC,EAGK,EAAgBA,EAAE,KAAKA,EAAE,OAAO,EAAGA,EAAE,SAAS,CAAC,EAAGA,EAAE,SAAS,GA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