@ikalogic/at1000 0.1.29 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/{at1000-LlkehOWj.d.cts → at1000-Bk6ohZKf.d.cts} +4 -4
  2. package/build/{at1000-C4BduTvM.d.mts.map → at1000-Bk6ohZKf.d.cts.map} +1 -1
  3. package/build/{at1000-6jr4Cfl3.mjs → at1000-DIRngXI2.mjs} +2 -2
  4. package/build/{at1000-6jr4Cfl3.mjs.map → at1000-DIRngXI2.mjs.map} +1 -1
  5. package/build/{at1000-C4BduTvM.d.mts → at1000-DQqmFBek.d.mts} +4 -4
  6. package/build/{at1000-LlkehOWj.d.cts.map → at1000-DQqmFBek.d.mts.map} +1 -1
  7. package/build/{at1000-ARKCVfb6.cjs → at1000-HauTVNei.cjs} +2 -2
  8. package/build/{at1000-ARKCVfb6.cjs.map → at1000-HauTVNei.cjs.map} +1 -1
  9. package/build/browser.cjs +1 -1
  10. package/build/browser.d.cts +1 -1
  11. package/build/browser.d.mts +1 -1
  12. package/build/browser.mjs +1 -1
  13. package/build/{gpio-B2EhZKM8.d.mts → gpio-B-XyukAb.d.mts} +2 -2
  14. package/build/{gpio-B2EhZKM8.d.mts.map → gpio-B-XyukAb.d.mts.map} +1 -1
  15. package/build/{gpio-C4wCa4wG.d.cts → gpio-bTPswI-R.d.cts} +2 -2
  16. package/build/{gpio-C4wCa4wG.d.cts.map → gpio-bTPswI-R.d.cts.map} +1 -1
  17. package/build/gpio.cjs +1 -1
  18. package/build/gpio.cjs.map +1 -1
  19. package/build/gpio.d.cts +1 -1
  20. package/build/gpio.d.mts +1 -1
  21. package/build/gpio.mjs +1 -1
  22. package/build/gpio.mjs.map +1 -1
  23. package/build/hmi.cjs +1 -1
  24. package/build/hmi.cjs.map +1 -1
  25. package/build/hmi.mjs +1 -1
  26. package/build/hmi.mjs.map +1 -1
  27. package/build/{management-ra61-qUr.d.mts → management-C7zHgMy1.d.cts} +3 -1
  28. package/build/management-C7zHgMy1.d.cts.map +1 -0
  29. package/build/{management-wQgti8p7.d.cts → management-dm4RL8mB.d.mts} +3 -1
  30. package/build/management-dm4RL8mB.d.mts.map +1 -0
  31. package/build/management.cjs +1 -1
  32. package/build/management.cjs.map +1 -1
  33. package/build/management.d.cts +1 -1
  34. package/build/management.d.mts +1 -1
  35. package/build/management.mjs +1 -1
  36. package/build/management.mjs.map +1 -1
  37. package/build/node.cjs +1 -1
  38. package/build/node.cjs.map +1 -1
  39. package/build/node.d.cts +1 -1
  40. package/build/node.d.mts +1 -1
  41. package/build/node.mjs +1 -1
  42. package/build/node.mjs.map +1 -1
  43. package/build/{power-Bi9cbP8g.d.mts → power-DMyzYMHJ.d.mts} +2 -2
  44. package/build/{power-Bi9cbP8g.d.mts.map → power-DMyzYMHJ.d.mts.map} +1 -1
  45. package/build/{power-Dv21KxFx.d.cts → power-Q-ksHbdP.d.cts} +2 -2
  46. package/build/{power-Dv21KxFx.d.cts.map → power-Q-ksHbdP.d.cts.map} +1 -1
  47. package/build/power.d.cts +1 -1
  48. package/build/power.d.mts +1 -1
  49. package/package.json +1 -1
  50. package/build/management-ra61-qUr.d.mts.map +0 -1
  51. package/build/management-wQgti8p7.d.cts.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { o as ComApi } from "./com-lqsVrnqO.cjs";
2
- import { n as Information, r as ManagementApi } from "./management-wQgti8p7.cjs";
3
- import { s as GpioApi } from "./gpio-C4wCa4wG.cjs";
2
+ import { n as Information, r as ManagementApi } from "./management-C7zHgMy1.cjs";
3
+ import { s as GpioApi } from "./gpio-bTPswI-R.cjs";
4
4
  import { r as HmiApi } from "./hmi-DkO4bd8B.cjs";
5
- import { i as PowerApi } from "./power-Dv21KxFx.cjs";
5
+ import { i as PowerApi } from "./power-Q-ksHbdP.cjs";
6
6
  import { n as RelaysApi } from "./relays-C-vNqDM-.cjs";
7
7
 
8
8
  //#region src/at1000.d.ts
@@ -47,4 +47,4 @@ declare class AT1000Base {
47
47
  }
48
48
  //#endregion
49
49
  export { AT1000Base as t };
50
- //# sourceMappingURL=at1000-LlkehOWj.d.cts.map
50
+ //# sourceMappingURL=at1000-Bk6ohZKf.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"at1000-C4BduTvM.d.mts","names":[],"sources":["../src/at1000.ts"],"mappings":";;;;;;;;;cAkBa,UAAA;EAAA;;;EAAA,SAIK,IAAA;EAUK;;;EAAA,SANL,IAAA,EAAM,WAAA;EAAA,QAEd,KAAA;EAwBgB;;;EAAA,SApBR,GAAA,EAAK,MAAA;EA+EwB;;;EAAA,SA3E7B,GAAA,EAAK,MAAA;EAVL;;;EAAA,SAcA,IAAA,EAAM,OAAA;EARD;;;EAAA,SAYL,UAAA,EAAY,aAAA;EAJN;;;EAAA,SAQN,KAAA,EAAO,QAAA;EAAA;;;EAAA,SAIP,MAAA,EAAQ,SAAA;cAEZ,IAAA,UAAc,IAAA,EAAM,WAAA;EAiD1B,KAAA,CAAA,GAAK,OAAA;EAAA,OAQG,MAAA,GAAgB,IAAA,aAAe,OAAA,CAAQ,UAAA;AAAA"}
1
+ {"version":3,"file":"at1000-Bk6ohZKf.d.cts","names":[],"sources":["../src/at1000.ts"],"mappings":";;;;;;;;;cAkBa,UAAA;EAAA;;;EAAA,SAIK,IAAA;EAUK;;;EAAA,SANL,IAAA,EAAM,WAAA;EAAA,QAEd,KAAA;EAwBgB;;;EAAA,SApBR,GAAA,EAAK,MAAA;EA+EwB;;;EAAA,SA3E7B,GAAA,EAAK,MAAA;EAVL;;;EAAA,SAcA,IAAA,EAAM,OAAA;EARD;;;EAAA,SAYL,UAAA,EAAY,aAAA;EAJN;;;EAAA,SAQN,KAAA,EAAO,QAAA;EAAA;;;EAAA,SAIP,MAAA,EAAQ,SAAA;cAEZ,IAAA,UAAc,IAAA,EAAM,WAAA;EAiD1B,KAAA,CAAA,GAAK,OAAA;EAAA,OAQG,MAAA,GAAgB,IAAA,aAAe,OAAA,CAAQ,UAAA;AAAA"}
@@ -1,3 +1,3 @@
1
- import{ComApi as e}from"./com.mjs";import{GpioApi as t}from"./gpio.mjs";import{HmiApi as n}from"./hmi.mjs";import{ManagementApi as r}from"./management.mjs";import{PowerApi as i}from"./power.mjs";import{RelaysApi as a}from"./relays.mjs";import{up as o}from"up-fetch";var s=`0.1.29`;function c(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}var l=class s{host;info;fetch;com;hmi;gpio;management;power;relays;constructor(s,l){this.host=s,this.info=l,this.fetch=o(fetch,()=>({baseUrl:`http://${c(this.host)}/v0`,timeout:1e3,parseRejected:async(e,t)=>{let n,r=e.headers.get(`content-type`);try{n=r?.includes(`application/json`)?await e.json():await e.text()}catch{n=`Failed to parse response body`}if(typeof n==`object`&&[`code`,`message`,`suggestion`,`path`].every(e=>e in n)){let e=n.suggestion.replace(/\n/g,`
1
+ import{ComApi as e}from"./com.mjs";import{GpioApi as t}from"./gpio.mjs";import{HmiApi as n}from"./hmi.mjs";import{ManagementApi as r}from"./management.mjs";import{PowerApi as i}from"./power.mjs";import{RelaysApi as a}from"./relays.mjs";import{up as o}from"up-fetch";var s=`0.1.30`;function c(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}var l=class s{host;info;fetch;com;hmi;gpio;management;power;relays;constructor(s,l){this.host=s,this.info=l,this.fetch=o(fetch,()=>({baseUrl:`http://${c(this.host)}/v0`,timeout:1e3,parseRejected:async(e,t)=>{let n,r=e.headers.get(`content-type`);try{n=r?.includes(`application/json`)?await e.json():await e.text()}catch{n=`Failed to parse response body`}if(typeof n==`object`&&[`code`,`message`,`suggestion`,`path`].every(e=>e in n)){let e=n.suggestion.replace(/\n/g,`
2
2
  `);throw Error(`${n.message} (${n.code})\n Suggestion: ${e}\n Path: ${n.path}`)}throw Error(`API request to ${t.method} ${e.url} failed with status ${e.status}: ${typeof n==`string`?n:JSON.stringify(n)}`)}})),this.com=new e(this.fetch),this.hmi=new n(this.fetch),this.gpio=new t(this.fetch,this.info),this.management=new r(this.fetch),this.power=new i(this.fetch,this.info),this.relays=new a(this.fetch)}async reset(){await this.com.reset(),await this.hmi.reset(),await this.gpio.reset(),await this.power.reset(),await this.relays.reset()}static create=async e=>new s(e,await new r(o(fetch,()=>({baseUrl:`http://${c(e)}/v0`,timeout:1e3}))).info())};export{s as n,l as t};
3
- //# sourceMappingURL=at1000-6jr4Cfl3.mjs.map
3
+ //# sourceMappingURL=at1000-DIRngXI2.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"at1000-6jr4Cfl3.mjs","names":[],"sources":["../package.json","../src/at1000.ts"],"sourcesContent":["","import { up, type UpFetch } from 'up-fetch';\n\nimport { ComApi } from './api/com';\nimport { GpioApi } from './api/gpio';\nimport { HmiApi } from './api/hmi';\nimport { type Information, ManagementApi } from './api/management';\nimport { PowerApi } from './api/power';\nimport { RelaysApi } from './api/relays';\n\n/** Wraps IPv6 literal addresses in brackets for use in URLs (RFC 3986). */\nfunction format_host_for_url(host: string): string {\n if (host.includes(':') && !host.startsWith('[')) {\n return `[${host}]`;\n }\n return host;\n}\n\n/** @hideconstructor */\nexport class AT1000Base {\n /**\n * IP address or hostname of the AT1000 device\n */\n public readonly host: string;\n /**\n * Device information\n */\n public readonly info: Information;\n\n private fetch: UpFetch;\n /**\n * COM API\n */\n public readonly com: ComApi;\n /**\n * HMI API\n */\n public readonly hmi: HmiApi;\n /**\n * GPIO API\n */\n public readonly gpio: GpioApi;\n /**\n * Management API\n */\n public readonly management: ManagementApi;\n /**\n * Power management API\n */\n public readonly power: PowerApi;\n /**\n * Relays API\n */\n public readonly relays: RelaysApi;\n\n constructor(host: string, info: Information) {\n this.host = host;\n this.info = info;\n\n this.fetch = up(\n fetch,\n () => ({\n baseUrl: `http://${format_host_for_url(this.host)}/v0`,\n timeout: 1000,\n parseRejected: async (response, request) => {\n let errorData: any;\n const contentType = response.headers.get('content-type');\n try {\n if (contentType?.includes('application/json')) {\n errorData = await response.json();\n } else {\n errorData = await response.text();\n }\n } catch {\n errorData = 'Failed to parse response body';\n }\n\n if (\n typeof errorData === 'object'\n && ['code', 'message', 'suggestion', 'path'].every((key) => key in errorData)\n ) {\n const formattedSuggestion = errorData.suggestion.replace(/\\n/g, '\\n ');\n throw new Error(\n `${errorData.message} (${errorData.code})\\n Suggestion: ${formattedSuggestion}\\n Path: ${errorData.path}`,\n );\n }\n\n throw new Error(\n `API request to ${request.method} ${response.url} failed with status ${response.status}: ${\n typeof errorData === 'string' ? errorData : JSON.stringify(errorData)\n }`,\n );\n },\n }),\n );\n\n this.com = new ComApi(this.fetch);\n this.hmi = new HmiApi(this.fetch);\n this.gpio = new GpioApi(this.fetch, this.info);\n this.management = new ManagementApi(this.fetch);\n this.power = new PowerApi(this.fetch, this.info);\n this.relays = new RelaysApi(this.fetch);\n }\n\n async reset() {\n await this.com.reset();\n await this.hmi.reset();\n await this.gpio.reset();\n await this.power.reset();\n await this.relays.reset();\n }\n\n public static create = async (host: string): Promise<AT1000Base> => {\n // Create a temporary client to fetch device info\n const management = new ManagementApi(\n up(fetch, () => ({ baseUrl: `http://${format_host_for_url(host)}/v0`, timeout: 1000 })),\n );\n const info = await management.info();\n\n return new AT1000Base(host, info);\n };\n}\n"],"mappings":"yRCUA,SAAS,EAAoB,EAAsB,CAIjD,OAHI,EAAK,SAAS,IAAI,EAAI,CAAC,EAAK,WAAW,IAAI,CACtC,IAAI,EAAK,GAEX,EAIT,IAAa,EAAb,MAAa,CAAW,CAItB,KAIA,KAEA,MAIA,IAIA,IAIA,KAIA,WAIA,MAIA,OAEA,YAAY,EAAc,EAAmB,CAC3C,KAAK,KAAO,EACZ,KAAK,KAAO,EAEZ,KAAK,MAAQ,EACX,WACO,CACL,QAAS,UAAU,EAAoB,KAAK,KAAK,CAAC,KAClD,QAAS,IACT,cAAe,MAAO,EAAU,IAAY,CAC1C,IAAI,EACE,EAAc,EAAS,QAAQ,IAAI,eAAe,CACxD,GAAI,CACF,AAGE,EAHE,GAAa,SAAS,mBAAmB,CAC/B,MAAM,EAAS,MAAM,CAErB,MAAM,EAAS,MAAM,MAE7B,CACN,EAAY,gCAGd,GACE,OAAO,GAAc,UAClB,CAAC,OAAQ,UAAW,aAAc,OAAO,CAAC,MAAO,GAAQ,KAAO,EAAU,CAC7E,CACA,IAAM,EAAsB,EAAU,WAAW,QAAQ,MAAO;kBAAqB,CACrF,MAAU,MACR,GAAG,EAAU,QAAQ,IAAI,EAAU,KAAK,qBAAqB,EAAoB,cAAc,EAAU,OAC1G,CAGH,MAAU,MACR,kBAAkB,EAAQ,OAAO,GAAG,EAAS,IAAI,sBAAsB,EAAS,OAAO,IACrF,OAAO,GAAc,SAAW,EAAY,KAAK,UAAU,EAAU,GAExE,EAEJ,EACF,CAED,KAAK,IAAM,IAAI,EAAO,KAAK,MAAM,CACjC,KAAK,IAAM,IAAI,EAAO,KAAK,MAAM,CACjC,KAAK,KAAO,IAAI,EAAQ,KAAK,MAAO,KAAK,KAAK,CAC9C,KAAK,WAAa,IAAI,EAAc,KAAK,MAAM,CAC/C,KAAK,MAAQ,IAAI,EAAS,KAAK,MAAO,KAAK,KAAK,CAChD,KAAK,OAAS,IAAI,EAAU,KAAK,MAAM,CAGzC,MAAM,OAAQ,CACZ,MAAM,KAAK,IAAI,OAAO,CACtB,MAAM,KAAK,IAAI,OAAO,CACtB,MAAM,KAAK,KAAK,OAAO,CACvB,MAAM,KAAK,MAAM,OAAO,CACxB,MAAM,KAAK,OAAO,OAAO,CAG3B,OAAc,OAAS,KAAO,IAOrB,IAAI,EAAW,EAFT,MAHM,IAAI,EACrB,EAAG,WAAc,CAAE,QAAS,UAAU,EAAoB,EAAK,CAAC,KAAM,QAAS,IAAM,EAAE,CACxF,CAC6B,MAAM,CAEH"}
1
+ {"version":3,"file":"at1000-DIRngXI2.mjs","names":[],"sources":["../package.json","../src/at1000.ts"],"sourcesContent":["","import { up, type UpFetch } from 'up-fetch';\n\nimport { ComApi } from './api/com';\nimport { GpioApi } from './api/gpio';\nimport { HmiApi } from './api/hmi';\nimport { type Information, ManagementApi } from './api/management';\nimport { PowerApi } from './api/power';\nimport { RelaysApi } from './api/relays';\n\n/** Wraps IPv6 literal addresses in brackets for use in URLs (RFC 3986). */\nfunction format_host_for_url(host: string): string {\n if (host.includes(':') && !host.startsWith('[')) {\n return `[${host}]`;\n }\n return host;\n}\n\n/** @hideconstructor */\nexport class AT1000Base {\n /**\n * IP address or hostname of the AT1000 device\n */\n public readonly host: string;\n /**\n * Device information\n */\n public readonly info: Information;\n\n private fetch: UpFetch;\n /**\n * COM API\n */\n public readonly com: ComApi;\n /**\n * HMI API\n */\n public readonly hmi: HmiApi;\n /**\n * GPIO API\n */\n public readonly gpio: GpioApi;\n /**\n * Management API\n */\n public readonly management: ManagementApi;\n /**\n * Power management API\n */\n public readonly power: PowerApi;\n /**\n * Relays API\n */\n public readonly relays: RelaysApi;\n\n constructor(host: string, info: Information) {\n this.host = host;\n this.info = info;\n\n this.fetch = up(\n fetch,\n () => ({\n baseUrl: `http://${format_host_for_url(this.host)}/v0`,\n timeout: 1000,\n parseRejected: async (response, request) => {\n let errorData: any;\n const contentType = response.headers.get('content-type');\n try {\n if (contentType?.includes('application/json')) {\n errorData = await response.json();\n } else {\n errorData = await response.text();\n }\n } catch {\n errorData = 'Failed to parse response body';\n }\n\n if (\n typeof errorData === 'object'\n && ['code', 'message', 'suggestion', 'path'].every((key) => key in errorData)\n ) {\n const formattedSuggestion = errorData.suggestion.replace(/\\n/g, '\\n ');\n throw new Error(\n `${errorData.message} (${errorData.code})\\n Suggestion: ${formattedSuggestion}\\n Path: ${errorData.path}`,\n );\n }\n\n throw new Error(\n `API request to ${request.method} ${response.url} failed with status ${response.status}: ${\n typeof errorData === 'string' ? errorData : JSON.stringify(errorData)\n }`,\n );\n },\n }),\n );\n\n this.com = new ComApi(this.fetch);\n this.hmi = new HmiApi(this.fetch);\n this.gpio = new GpioApi(this.fetch, this.info);\n this.management = new ManagementApi(this.fetch);\n this.power = new PowerApi(this.fetch, this.info);\n this.relays = new RelaysApi(this.fetch);\n }\n\n async reset() {\n await this.com.reset();\n await this.hmi.reset();\n await this.gpio.reset();\n await this.power.reset();\n await this.relays.reset();\n }\n\n public static create = async (host: string): Promise<AT1000Base> => {\n // Create a temporary client to fetch device info\n const management = new ManagementApi(\n up(fetch, () => ({ baseUrl: `http://${format_host_for_url(host)}/v0`, timeout: 1000 })),\n );\n const info = await management.info();\n\n return new AT1000Base(host, info);\n };\n}\n"],"mappings":"yRCUA,SAAS,EAAoB,EAAsB,CAIjD,OAHI,EAAK,SAAS,IAAI,EAAI,CAAC,EAAK,WAAW,IAAI,CACtC,IAAI,EAAK,GAEX,EAIT,IAAa,EAAb,MAAa,CAAW,CAItB,KAIA,KAEA,MAIA,IAIA,IAIA,KAIA,WAIA,MAIA,OAEA,YAAY,EAAc,EAAmB,CAC3C,KAAK,KAAO,EACZ,KAAK,KAAO,EAEZ,KAAK,MAAQ,EACX,WACO,CACL,QAAS,UAAU,EAAoB,KAAK,KAAK,CAAC,KAClD,QAAS,IACT,cAAe,MAAO,EAAU,IAAY,CAC1C,IAAI,EACE,EAAc,EAAS,QAAQ,IAAI,eAAe,CACxD,GAAI,CACF,AAGE,EAHE,GAAa,SAAS,mBAAmB,CAC/B,MAAM,EAAS,MAAM,CAErB,MAAM,EAAS,MAAM,MAE7B,CACN,EAAY,gCAGd,GACE,OAAO,GAAc,UAClB,CAAC,OAAQ,UAAW,aAAc,OAAO,CAAC,MAAO,GAAQ,KAAO,EAAU,CAC7E,CACA,IAAM,EAAsB,EAAU,WAAW,QAAQ,MAAO;kBAAqB,CACrF,MAAU,MACR,GAAG,EAAU,QAAQ,IAAI,EAAU,KAAK,qBAAqB,EAAoB,cAAc,EAAU,OAC1G,CAGH,MAAU,MACR,kBAAkB,EAAQ,OAAO,GAAG,EAAS,IAAI,sBAAsB,EAAS,OAAO,IACrF,OAAO,GAAc,SAAW,EAAY,KAAK,UAAU,EAAU,GAExE,EAEJ,EACF,CAED,KAAK,IAAM,IAAI,EAAO,KAAK,MAAM,CACjC,KAAK,IAAM,IAAI,EAAO,KAAK,MAAM,CACjC,KAAK,KAAO,IAAI,EAAQ,KAAK,MAAO,KAAK,KAAK,CAC9C,KAAK,WAAa,IAAI,EAAc,KAAK,MAAM,CAC/C,KAAK,MAAQ,IAAI,EAAS,KAAK,MAAO,KAAK,KAAK,CAChD,KAAK,OAAS,IAAI,EAAU,KAAK,MAAM,CAGzC,MAAM,OAAQ,CACZ,MAAM,KAAK,IAAI,OAAO,CACtB,MAAM,KAAK,IAAI,OAAO,CACtB,MAAM,KAAK,KAAK,OAAO,CACvB,MAAM,KAAK,MAAM,OAAO,CACxB,MAAM,KAAK,OAAO,OAAO,CAG3B,OAAc,OAAS,KAAO,IAOrB,IAAI,EAAW,EAFT,MAHM,IAAI,EACrB,EAAG,WAAc,CAAE,QAAS,UAAU,EAAoB,EAAK,CAAC,KAAM,QAAS,IAAM,EAAE,CACxF,CAC6B,MAAM,CAEH"}
@@ -1,8 +1,8 @@
1
1
  import { o as ComApi } from "./com-BKy7zoOg.mjs";
2
- import { n as Information, r as ManagementApi } from "./management-ra61-qUr.mjs";
3
- import { s as GpioApi } from "./gpio-B2EhZKM8.mjs";
2
+ import { n as Information, r as ManagementApi } from "./management-dm4RL8mB.mjs";
3
+ import { s as GpioApi } from "./gpio-B-XyukAb.mjs";
4
4
  import { r as HmiApi } from "./hmi-BdkiKYEE.mjs";
5
- import { i as PowerApi } from "./power-Bi9cbP8g.mjs";
5
+ import { i as PowerApi } from "./power-DMyzYMHJ.mjs";
6
6
  import { n as RelaysApi } from "./relays-CbyqFtJP.mjs";
7
7
 
8
8
  //#region src/at1000.d.ts
@@ -47,4 +47,4 @@ declare class AT1000Base {
47
47
  }
48
48
  //#endregion
49
49
  export { AT1000Base as t };
50
- //# sourceMappingURL=at1000-C4BduTvM.d.mts.map
50
+ //# sourceMappingURL=at1000-DQqmFBek.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"at1000-LlkehOWj.d.cts","names":[],"sources":["../src/at1000.ts"],"mappings":";;;;;;;;;cAkBa,UAAA;EAAA;;;EAAA,SAIK,IAAA;EAUK;;;EAAA,SANL,IAAA,EAAM,WAAA;EAAA,QAEd,KAAA;EAwBgB;;;EAAA,SApBR,GAAA,EAAK,MAAA;EA+EwB;;;EAAA,SA3E7B,GAAA,EAAK,MAAA;EAVL;;;EAAA,SAcA,IAAA,EAAM,OAAA;EARD;;;EAAA,SAYL,UAAA,EAAY,aAAA;EAJN;;;EAAA,SAQN,KAAA,EAAO,QAAA;EAAA;;;EAAA,SAIP,MAAA,EAAQ,SAAA;cAEZ,IAAA,UAAc,IAAA,EAAM,WAAA;EAiD1B,KAAA,CAAA,GAAK,OAAA;EAAA,OAQG,MAAA,GAAgB,IAAA,aAAe,OAAA,CAAQ,UAAA;AAAA"}
1
+ {"version":3,"file":"at1000-DQqmFBek.d.mts","names":[],"sources":["../src/at1000.ts"],"mappings":";;;;;;;;;cAkBa,UAAA;EAAA;;;EAAA,SAIK,IAAA;EAUK;;;EAAA,SANL,IAAA,EAAM,WAAA;EAAA,QAEd,KAAA;EAwBgB;;;EAAA,SApBR,GAAA,EAAK,MAAA;EA+EwB;;;EAAA,SA3E7B,GAAA,EAAK,MAAA;EAVL;;;EAAA,SAcA,IAAA,EAAM,OAAA;EARD;;;EAAA,SAYL,UAAA,EAAY,aAAA;EAJN;;;EAAA,SAQN,KAAA,EAAO,QAAA;EAAA;;;EAAA,SAIP,MAAA,EAAQ,SAAA;cAEZ,IAAA,UAAc,IAAA,EAAM,WAAA;EAiD1B,KAAA,CAAA,GAAK,OAAA;EAAA,OAQG,MAAA,GAAgB,IAAA,aAAe,OAAA,CAAQ,UAAA;AAAA"}
@@ -1,3 +1,3 @@
1
- require(`./chunk-Bmb41Sf3.cjs`);const e=require(`./com.cjs`),t=require(`./gpio.cjs`),n=require(`./hmi.cjs`),r=require(`./management.cjs`),i=require(`./power.cjs`),a=require(`./relays.cjs`);let o=require(`up-fetch`);var s=`0.1.29`;function c(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}var l=class s{host;info;fetch;com;hmi;gpio;management;power;relays;constructor(s,l){this.host=s,this.info=l,this.fetch=(0,o.up)(fetch,()=>({baseUrl:`http://${c(this.host)}/v0`,timeout:1e3,parseRejected:async(e,t)=>{let n,r=e.headers.get(`content-type`);try{n=r?.includes(`application/json`)?await e.json():await e.text()}catch{n=`Failed to parse response body`}if(typeof n==`object`&&[`code`,`message`,`suggestion`,`path`].every(e=>e in n)){let e=n.suggestion.replace(/\n/g,`
1
+ require(`./chunk-Bmb41Sf3.cjs`);const e=require(`./com.cjs`),t=require(`./gpio.cjs`),n=require(`./hmi.cjs`),r=require(`./management.cjs`),i=require(`./power.cjs`),a=require(`./relays.cjs`);let o=require(`up-fetch`);var s=`0.1.30`;function c(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}var l=class s{host;info;fetch;com;hmi;gpio;management;power;relays;constructor(s,l){this.host=s,this.info=l,this.fetch=(0,o.up)(fetch,()=>({baseUrl:`http://${c(this.host)}/v0`,timeout:1e3,parseRejected:async(e,t)=>{let n,r=e.headers.get(`content-type`);try{n=r?.includes(`application/json`)?await e.json():await e.text()}catch{n=`Failed to parse response body`}if(typeof n==`object`&&[`code`,`message`,`suggestion`,`path`].every(e=>e in n)){let e=n.suggestion.replace(/\n/g,`
2
2
  `);throw Error(`${n.message} (${n.code})\n Suggestion: ${e}\n Path: ${n.path}`)}throw Error(`API request to ${t.method} ${e.url} failed with status ${e.status}: ${typeof n==`string`?n:JSON.stringify(n)}`)}})),this.com=new e.ComApi(this.fetch),this.hmi=new n.HmiApi(this.fetch),this.gpio=new t.GpioApi(this.fetch,this.info),this.management=new r.ManagementApi(this.fetch),this.power=new i.PowerApi(this.fetch,this.info),this.relays=new a.RelaysApi(this.fetch)}async reset(){await this.com.reset(),await this.hmi.reset(),await this.gpio.reset(),await this.power.reset(),await this.relays.reset()}static create=async e=>new s(e,await new r.ManagementApi((0,o.up)(fetch,()=>({baseUrl:`http://${c(e)}/v0`,timeout:1e3}))).info())};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
3
- //# sourceMappingURL=at1000-ARKCVfb6.cjs.map
3
+ //# sourceMappingURL=at1000-HauTVNei.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"at1000-ARKCVfb6.cjs","names":["ComApi","HmiApi","GpioApi","ManagementApi","PowerApi","RelaysApi"],"sources":["../package.json","../src/at1000.ts"],"sourcesContent":["","import { up, type UpFetch } from 'up-fetch';\n\nimport { ComApi } from './api/com';\nimport { GpioApi } from './api/gpio';\nimport { HmiApi } from './api/hmi';\nimport { type Information, ManagementApi } from './api/management';\nimport { PowerApi } from './api/power';\nimport { RelaysApi } from './api/relays';\n\n/** Wraps IPv6 literal addresses in brackets for use in URLs (RFC 3986). */\nfunction format_host_for_url(host: string): string {\n if (host.includes(':') && !host.startsWith('[')) {\n return `[${host}]`;\n }\n return host;\n}\n\n/** @hideconstructor */\nexport class AT1000Base {\n /**\n * IP address or hostname of the AT1000 device\n */\n public readonly host: string;\n /**\n * Device information\n */\n public readonly info: Information;\n\n private fetch: UpFetch;\n /**\n * COM API\n */\n public readonly com: ComApi;\n /**\n * HMI API\n */\n public readonly hmi: HmiApi;\n /**\n * GPIO API\n */\n public readonly gpio: GpioApi;\n /**\n * Management API\n */\n public readonly management: ManagementApi;\n /**\n * Power management API\n */\n public readonly power: PowerApi;\n /**\n * Relays API\n */\n public readonly relays: RelaysApi;\n\n constructor(host: string, info: Information) {\n this.host = host;\n this.info = info;\n\n this.fetch = up(\n fetch,\n () => ({\n baseUrl: `http://${format_host_for_url(this.host)}/v0`,\n timeout: 1000,\n parseRejected: async (response, request) => {\n let errorData: any;\n const contentType = response.headers.get('content-type');\n try {\n if (contentType?.includes('application/json')) {\n errorData = await response.json();\n } else {\n errorData = await response.text();\n }\n } catch {\n errorData = 'Failed to parse response body';\n }\n\n if (\n typeof errorData === 'object'\n && ['code', 'message', 'suggestion', 'path'].every((key) => key in errorData)\n ) {\n const formattedSuggestion = errorData.suggestion.replace(/\\n/g, '\\n ');\n throw new Error(\n `${errorData.message} (${errorData.code})\\n Suggestion: ${formattedSuggestion}\\n Path: ${errorData.path}`,\n );\n }\n\n throw new Error(\n `API request to ${request.method} ${response.url} failed with status ${response.status}: ${\n typeof errorData === 'string' ? errorData : JSON.stringify(errorData)\n }`,\n );\n },\n }),\n );\n\n this.com = new ComApi(this.fetch);\n this.hmi = new HmiApi(this.fetch);\n this.gpio = new GpioApi(this.fetch, this.info);\n this.management = new ManagementApi(this.fetch);\n this.power = new PowerApi(this.fetch, this.info);\n this.relays = new RelaysApi(this.fetch);\n }\n\n async reset() {\n await this.com.reset();\n await this.hmi.reset();\n await this.gpio.reset();\n await this.power.reset();\n await this.relays.reset();\n }\n\n public static create = async (host: string): Promise<AT1000Base> => {\n // Create a temporary client to fetch device info\n const management = new ManagementApi(\n up(fetch, () => ({ baseUrl: `http://${format_host_for_url(host)}/v0`, timeout: 1000 })),\n );\n const info = await management.info();\n\n return new AT1000Base(host, info);\n };\n}\n"],"mappings":"sOCUA,SAAS,EAAoB,EAAsB,CAIjD,OAHI,EAAK,SAAS,IAAI,EAAI,CAAC,EAAK,WAAW,IAAI,CACtC,IAAI,EAAK,GAEX,EAIT,IAAa,EAAb,MAAa,CAAW,CAItB,KAIA,KAEA,MAIA,IAIA,IAIA,KAIA,WAIA,MAIA,OAEA,YAAY,EAAc,EAAmB,CAC3C,KAAK,KAAO,EACZ,KAAK,KAAO,EAEZ,KAAK,OAAA,EAAA,EAAA,IACH,WACO,CACL,QAAS,UAAU,EAAoB,KAAK,KAAK,CAAC,KAClD,QAAS,IACT,cAAe,MAAO,EAAU,IAAY,CAC1C,IAAI,EACE,EAAc,EAAS,QAAQ,IAAI,eAAe,CACxD,GAAI,CACF,AAGE,EAHE,GAAa,SAAS,mBAAmB,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sources":["../package.json","../src/at1000.ts"],"sourcesContent":["","import { up, type UpFetch } from 'up-fetch';\n\nimport { ComApi } from './api/com';\nimport { GpioApi } from './api/gpio';\nimport { HmiApi } from './api/hmi';\nimport { type Information, ManagementApi } from './api/management';\nimport { PowerApi } from './api/power';\nimport { RelaysApi } from './api/relays';\n\n/** Wraps IPv6 literal addresses in brackets for use in URLs (RFC 3986). */\nfunction format_host_for_url(host: string): string {\n if (host.includes(':') && !host.startsWith('[')) {\n return `[${host}]`;\n }\n return host;\n}\n\n/** @hideconstructor */\nexport class AT1000Base {\n /**\n * IP address or hostname of the AT1000 device\n */\n public readonly host: string;\n /**\n * Device information\n */\n public readonly info: Information;\n\n private fetch: UpFetch;\n /**\n * COM API\n */\n public readonly com: ComApi;\n /**\n * HMI API\n */\n public readonly hmi: HmiApi;\n /**\n * GPIO API\n */\n public readonly gpio: GpioApi;\n /**\n * Management API\n */\n public readonly management: ManagementApi;\n /**\n * Power management API\n */\n public readonly power: PowerApi;\n /**\n * Relays API\n */\n public readonly relays: RelaysApi;\n\n constructor(host: string, info: Information) {\n this.host = host;\n this.info = info;\n\n this.fetch = up(\n fetch,\n () => ({\n baseUrl: `http://${format_host_for_url(this.host)}/v0`,\n timeout: 1000,\n parseRejected: async (response, request) => {\n let errorData: any;\n const contentType = response.headers.get('content-type');\n try {\n if (contentType?.includes('application/json')) {\n errorData = await response.json();\n } else {\n errorData = await response.text();\n }\n } catch {\n errorData = 'Failed to parse response body';\n }\n\n if (\n typeof errorData === 'object'\n && ['code', 'message', 'suggestion', 'path'].every((key) => key in errorData)\n ) {\n const formattedSuggestion = errorData.suggestion.replace(/\\n/g, '\\n ');\n throw new Error(\n `${errorData.message} (${errorData.code})\\n Suggestion: ${formattedSuggestion}\\n Path: ${errorData.path}`,\n );\n }\n\n throw new Error(\n `API request to ${request.method} ${response.url} failed with status ${response.status}: ${\n typeof errorData === 'string' ? errorData : JSON.stringify(errorData)\n }`,\n );\n },\n }),\n );\n\n this.com = new ComApi(this.fetch);\n this.hmi = new HmiApi(this.fetch);\n this.gpio = new GpioApi(this.fetch, this.info);\n this.management = new ManagementApi(this.fetch);\n this.power = new PowerApi(this.fetch, this.info);\n this.relays = new RelaysApi(this.fetch);\n }\n\n async reset() {\n await this.com.reset();\n await this.hmi.reset();\n await this.gpio.reset();\n await this.power.reset();\n await this.relays.reset();\n }\n\n public static create = async (host: string): Promise<AT1000Base> => {\n // Create a temporary client to fetch device info\n const management = new ManagementApi(\n up(fetch, () => ({ baseUrl: `http://${format_host_for_url(host)}/v0`, timeout: 1000 })),\n );\n const info = await management.info();\n\n return new AT1000Base(host, info);\n };\n}\n"],"mappings":"sOCUA,SAAS,EAAoB,EAAsB,CAIjD,OAHI,EAAK,SAAS,IAAI,EAAI,CAAC,EAAK,WAAW,IAAI,CACtC,IAAI,EAAK,GAEX,EAIT,IAAa,EAAb,MAAa,CAAW,CAItB,KAIA,KAEA,MAIA,IAIA,IAIA,KAIA,WAIA,MAIA,OAEA,YAAY,EAAc,EAAmB,CAC3C,KAAK,KAAO,EACZ,KAAK,KAAO,EAEZ,KAAK,OAAA,EAAA,EAAA,IACH,WACO,CACL,QAAS,UAAU,EAAoB,KAAK,KAAK,CAAC,KAClD,QAAS,IACT,cAAe,MAAO,EAAU,IAAY,CAC1C,IAAI,EACE,EAAc,EAAS,QAAQ,IAAI,eAAe,CACxD,GAAI,CACF,AAGE,EAHE,GAAa,SAAS,mBAAmB,CAC/B,MAAM,EAAS,MAAM,CAErB,MAAM,EAAS,MAAM,MAE7B,CACN,EAAY,gCAGd,GACE,OAAO,GAAc,UAClB,CAAC,OAAQ,UAAW,aAAc,OAAO,CAAC,MAAO,GAAQ,KAAO,EAAU,CAC7E,CACA,IAAM,EAAsB,EAAU,WAAW,QAAQ,MAAO;kBAAqB,CACrF,MAAU,MACR,GAAG,EAAU,QAAQ,IAAI,EAAU,KAAK,qBAAqB,EAAoB,cAAc,EAAU,OAC1G,CAGH,MAAU,MACR,kBAAkB,EAAQ,OAAO,GAAG,EAAS,IAAI,sBAAsB,EAAS,OAAO,IACrF,OAAO,GAAc,SAAW,EAAY,KAAK,UAAU,EAAU,GAExE,EAEJ,EACF,CAED,KAAK,IAAM,IAAIA,EAAAA,OAAO,KAAK,MAAM,CACjC,KAAK,IAAM,IAAIC,EAAAA,OAAO,KAAK,MAAM,CACjC,KAAK,KAAO,IAAIC,EAAAA,QAAQ,KAAK,MAAO,KAAK,KAAK,CAC9C,KAAK,WAAa,IAAIC,EAAAA,cAAc,KAAK,MAAM,CAC/C,KAAK,MAAQ,IAAIC,EAAAA,SAAS,KAAK,MAAO,KAAK,KAAK,CAChD,KAAK,OAAS,IAAIC,EAAAA,UAAU,KAAK,MAAM,CAGzC,MAAM,OAAQ,CACZ,MAAM,KAAK,IAAI,OAAO,CACtB,MAAM,KAAK,IAAI,OAAO,CACtB,MAAM,KAAK,KAAK,OAAO,CACvB,MAAM,KAAK,MAAM,OAAO,CACxB,MAAM,KAAK,OAAO,OAAO,CAG3B,OAAc,OAAS,KAAO,IAOrB,IAAI,EAAW,EAFT,MAHM,IAAIF,EAAAA,eAAAA,EAAAA,EAAAA,IAClB,WAAc,CAAE,QAAS,UAAU,EAAoB,EAAK,CAAC,KAAM,QAAS,IAAM,EAAE,CACxF,CAC6B,MAAM,CAEH"}
package/build/browser.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./at1000-ARKCVfb6.cjs`);require(`./common-PXzrB8CC.cjs`);var t=class extends e.t{static apiVersion=e.n};exports.AT1000=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./at1000-HauTVNei.cjs`);require(`./common-PXzrB8CC.cjs`);var t=class extends e.t{static apiVersion=e.n};exports.AT1000=t;
2
2
  //# sourceMappingURL=browser.cjs.map
@@ -1,4 +1,4 @@
1
- import { t as AT1000Base } from "./at1000-LlkehOWj.cjs";
1
+ import { t as AT1000Base } from "./at1000-Bk6ohZKf.cjs";
2
2
 
3
3
  //#region src/browser.d.ts
4
4
  /** @hideconstructor */
@@ -1,4 +1,4 @@
1
- import { t as AT1000Base } from "./at1000-C4BduTvM.mjs";
1
+ import { t as AT1000Base } from "./at1000-DQqmFBek.mjs";
2
2
 
3
3
  //#region src/browser.d.ts
4
4
  /** @hideconstructor */
package/build/browser.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{n as e,t}from"./at1000-6jr4Cfl3.mjs";import"./common-DzTRbz1N.mjs";var n=class extends t{static apiVersion=e};export{n as AT1000};
1
+ import{n as e,t}from"./at1000-DIRngXI2.mjs";import"./common-DzTRbz1N.mjs";var n=class extends t{static apiVersion=e};export{n as AT1000};
2
2
  //# sourceMappingURL=browser.mjs.map
@@ -1,5 +1,5 @@
1
1
  import { t as AnalogOutputLevel } from "./common-Cc9ZDx5b.mjs";
2
- import { n as Information } from "./management-ra61-qUr.mjs";
2
+ import { n as Information } from "./management-dm4RL8mB.mjs";
3
3
  import { UpFetch } from "up-fetch";
4
4
  import * as v from "valibot";
5
5
 
@@ -355,4 +355,4 @@ declare class AnalogIO {
355
355
  }
356
356
  //#endregion
357
357
  export { DigitalInputConfiguration as a, OpenDrainConfiguration as c, PartialDigitalOutputConfiguration as d, PartialOpenDrainConfiguration as f, DigitalIO as i, PartialAnalogOutputConfiguration as l, AnalogInputConfiguration as n, DigitalOutputConfiguration as o, SyncConfiguration as p, AnalogOutputConfiguration as r, GpioApi as s, AnalogIO as t, PartialDigitalInputConfiguration as u };
358
- //# sourceMappingURL=gpio-B2EhZKM8.d.mts.map
358
+ //# sourceMappingURL=gpio-B-XyukAb.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gpio-B2EhZKM8.d.mts","names":[],"sources":["../src/api/gpio.ts"],"mappings":";;;;;;cASM,wBAAA,EAAwB,CAAA,CAAA,YAAA;EAAA;;;cAIxB,yBAAA,EAAyB,CAAA,CAAA,YAAA;EAAA;;;;cAKzB,yBAAA,EAAyB,CAAA,C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,CAAM,KAAA,WAAgB,OAAA;AAAA"}
@@ -1,5 +1,5 @@
1
1
  import { t as AnalogOutputLevel } from "./common-DWQyDOs5.cjs";
2
- import { n as Information } from "./management-wQgti8p7.cjs";
2
+ import { n as Information } from "./management-C7zHgMy1.cjs";
3
3
  import { UpFetch } from "up-fetch";
4
4
  import * as v from "valibot";
5
5
 
@@ -355,4 +355,4 @@ declare class AnalogIO {
355
355
  }
356
356
  //#endregion
357
357
  export { DigitalInputConfiguration as a, OpenDrainConfiguration as c, PartialDigitalOutputConfiguration as d, PartialOpenDrainConfiguration as f, DigitalIO as i, PartialAnalogOutputConfiguration as l, AnalogInputConfiguration as n, DigitalOutputConfiguration as o, SyncConfiguration as p, AnalogOutputConfiguration as r, GpioApi as s, AnalogIO as t, PartialDigitalInputConfiguration as u };
358
- //# sourceMappingURL=gpio-C4wCa4wG.d.cts.map
358
+ //# sourceMappingURL=gpio-bTPswI-R.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gpio-C4wCa4wG.d.cts","names":[],"sources":["../src/api/gpio.ts"],"mappings":";;;;;;cASM,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;;;;;;KAOhB,wBAAA,GAA2B,CAAA,CAAE,WAAA,QAAmB,wBAAA;AAAA,KAChD,yBAAA,GAA4B,CAAA,CAAE,WAAA,QAAmB,yBAAA;AAAA,KACjD,yBAAA,GAA4B,CAAA,CAAE,WAAA,QAAmB,yBAAA;AAAA,KACjD,0BAAA,GAA6B,CAAA,CAAE,WAAA,QAAmB,0BAAA;AAAA,KAClD,sBAAA,GAAyB,CAAA,CAAE,WAAA,QAAmB,sBAAA;AAAA,cAEpD,g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pC,IAAA,CAAA,GAAQ,OAAA,CAAQ,iBAAA;EAhF4C;;;AAC9D;;;;EA8FE,OAAA,CAAA,GAAW,OAAA,CAAQ,iBAAA;AAAA;;cAUR,SAAA;EAAA,iBACkB,KAAA;EAAA,SAAgC,EAAA;cAAhC,KAAA,EAAO,OAAA,EAAyB,EAAA;;;;;;EAO7D,eAAA,CAAgB,MAAA,EAAQ,gCAAA,GAAmC,OAAA,CAAQ,yBAAA;;;;;;EAgBnE,gBAAA,CAAiB,MAAA,EAAQ,iCAAA,GAAoC,OAAA,CAAQ,0BAAA;;;;;EAwB/D,IAAA,CAAA,GAAQ,OAAA;;;;;;EASR,KAAA,CAAM,KAAA,qBAA0B,OAAA;;;;;;EActC,oBAAA,CAAqB,MAAA,EAAQ,6BAAA,GAAgC,OAAA,CAAQ,sBAAA;AAAA;;cAa1D,QAAA;EAAA,iBACkB,KAAA;EAAA,SAAgC,EAAA;cAAhC,KAAA,EAAO,OAAA,EAAyB,EAAA;EA3LzB;;;;;EAkMpC,eAAA,CAAA,GAAmB,OAAA,CAAQ,wBAAA;;;;;;EAa3B,gBAAA,CAAiB,KAAA,EAAO,iBAAA,GAAoB,OAAA,CAAQ,yBAAA;;;;;EAe9C,IAAA,CAAA,GAAQ,OAAA;;;;;;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-Bmb41Sf3.cjs`),t=require(`./common-PXzrB8CC.cjs`);let n=require(`valibot`);n=e.t(n);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 p=class{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 m(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 h(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})}},m=class{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:{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})}},h=class{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=h,exports.DigitalIO=m,exports.GpioApi=p;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./common-PXzrB8CC.cjs`);let n=require(`valibot`);n=e.t(n);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 p=class{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 m(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 h(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})}},m=class{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})}},h=class{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=h,exports.DigitalIO=m,exports.GpioApi=p;
2
2
  //# sourceMappingURL=gpio.cjs.map
@@ -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: { 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":"gLAQA,MAAM,EAAaA,EAAE,SAAS,CAAC,UAAW,OAAO,CAAE,sBAAsB,CACnE,EAA2BA,EAAE,OAAO,CACxC,KAAMA,EAAE,QAAQ,SAAS,CACzB,UAAWA,EAAE,QAAQ,QAAQ,CAC9B,CAAC,CACI,EAA4BA,EAAE,OAAO,CACzC,KAAMA,EAAE,QAAQ,SAAS,CACzB,UAAWA,EAAE,QAAQ,SAAS,CAC9B,MAAOA,EAAE,SAASC,EAAAA,EAAkB,CACrC,CAAC,CACI,EAA4BD,EAAE,OAAO,CACzC,KAAM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,EAAE,MAQhF,MAAM,MAAM,EAA2C,CACrD,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,QAAO,CACf,OAAQ,EACT,CAAC,EACC,MAQL,qBAAqB,EAAwE,CAC3F,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAMA,EAAE,MACN,EACA,CAAE,GAAG,EAAQ,KAAM,UAAW,UAAW,aAAc,CACxD,CACD,OAAQ,EACT,CAAC,GAKO,EAAb,KAAsB,CACpB,YAAY,EAAiC,EAA4B,CAA5C,KAAA,MAAA,EAAgC,KAAA,GAAA,EAO7D,iBAAqD,CACnD,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,CAAE,KAAM,SAAU,UAAW,QAAS,CAC5C,OAAQ,EACT,CAAC,CAQJ,iBAAiB,EAA8D,CAC7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAMA,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,SAAU,CAC/C,CACD,OAAQ,EACT,CAAC,CAOJ,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,EAAa,CAAC,EAAE,MAQ/E,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,QAAO,CACf,OAAQ,EACT,CAAC,EACC"}
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":"gLAQA,MAAM,EAAaA,EAAE,SAAS,CAAC,UAAW,OAAO,CAAE,sBAAsB,CACnE,EAA2BA,EAAE,OAAO,CACxC,KAAMA,EAAE,QAAQ,SAAS,CACzB,UAAWA,EAAE,QAAQ,QAAQ,CAC9B,CAAC,CACI,EAA4BA,EAAE,OAAO,CACzC,KAAMA,EAAE,QAAQ,SAAS,CACzB,UAAWA,EAAE,QAAQ,SAAS,CAC9B,MAAOA,EAAE,SAASC,EAAAA,EAAkB,CACrC,CAAC,CACI,EAA4BD,EAAE,OAAO,CACzC,KAAMA,EAAE,QAAQ,UAAU,CAC1B,UAAWA,EAAE,QAAQ,QAAQ,CAC7B,IAAKE,EAAAA,EACL,IAAKA,EAAAA,EACN,C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ACR,KAAMA,EAAE,MAAM,EAAc,CAAE,QAAO,CAAC,CACtC,OAAQ,EACT,CAAC,EACC,MAQL,qBAAqB,EAAwE,CAC3F,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAMA,EAAE,MACN,EACA,CAAE,GAAG,EAAQ,KAAM,UAAW,UAAW,aAAc,CACxD,CACD,OAAQ,EACT,CAAC,GAKO,EAAb,KAAsB,CACpB,YAAY,EAAiC,EAA4B,CAA5C,KAAA,MAAA,EAAgC,KAAA,GAAA,EAO7D,iBAAqD,CACnD,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,CAAE,KAAM,SAAU,UAAW,QAAS,CAC5C,OAAQ,EACT,CAAC,CAQJ,iBAAiB,EAA8D,CAC7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAMA,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,SAAU,CAC/C,CACD,OAAQ,EACT,CAAC,CAOJ,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,EAAa,CAAC,EAAE,MAQ/E,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,QAAO,CACf,OAAQ,EACT,CAAC,EACC"}
package/build/gpio.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as AnalogOutputLevel } from "./common-DWQyDOs5.cjs";
2
- import { a as DigitalInputConfiguration, c as OpenDrainConfiguration, d as PartialDigitalOutputConfiguration, f as PartialOpenDrainConfiguration, i as DigitalIO, l as PartialAnalogOutputConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as SyncConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialDigitalInputConfiguration } from "./gpio-C4wCa4wG.cjs";
2
+ import { a as DigitalInputConfiguration, c as OpenDrainConfiguration, d as PartialDigitalOutputConfiguration, f as PartialOpenDrainConfiguration, i as DigitalIO, l as PartialAnalogOutputConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as SyncConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialDigitalInputConfiguration } from "./gpio-bTPswI-R.cjs";
3
3
  export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration };
package/build/gpio.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as AnalogOutputLevel } from "./common-Cc9ZDx5b.mjs";
2
- import { a as DigitalInputConfiguration, c as OpenDrainConfiguration, d as PartialDigitalOutputConfiguration, f as PartialOpenDrainConfiguration, i as DigitalIO, l as PartialAnalogOutputConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as SyncConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialDigitalInputConfiguration } from "./gpio-B2EhZKM8.mjs";
2
+ import { a as DigitalInputConfiguration, c as OpenDrainConfiguration, d as PartialDigitalOutputConfiguration, f as PartialOpenDrainConfiguration, i as DigitalIO, l as PartialAnalogOutputConfiguration, n as AnalogInputConfiguration, o as DigitalOutputConfiguration, p as SyncConfiguration, r as AnalogOutputConfiguration, s as GpioApi, t as AnalogIO, u as PartialDigitalInputConfiguration } from "./gpio-B-XyukAb.mjs";
3
3
  export { AnalogIO, AnalogInputConfiguration, AnalogOutputConfiguration, AnalogOutputLevel, DigitalIO, DigitalInputConfiguration, DigitalOutputConfiguration, GpioApi, OpenDrainConfiguration, PartialAnalogOutputConfiguration, PartialDigitalInputConfiguration, PartialDigitalOutputConfiguration, PartialOpenDrainConfiguration, SyncConfiguration };
package/build/gpio.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{n as e,r as t,t as n}from"./common-DzTRbz1N.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 m=class{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 h(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 g(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})}},h=class{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:{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})}},g=class{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{g as AnalogIO,h as DigitalIO,m as GpioApi};
1
+ import{n as e,r as t,t as n}from"./common-DzTRbz1N.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 m=class{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 h(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 g(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})}},h=class{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})}},g=class{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{g as AnalogIO,h as DigitalIO,m as GpioApi};
2
2
  //# sourceMappingURL=gpio.mjs.map
@@ -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: { 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,OAAO,CAAE,sBAAsB,CACnE,EAA2B,EAAE,OAAO,CACxC,KAAM,EAAE,QAAQ,SAAS,CACzB,UAAW,EAAE,QAAQ,QAAQ,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K,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,EAAc,CAAC,EAAE,MAQhF,MAAM,MAAM,EAA2C,CACrD,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,QAAO,CACf,OAAQ,EACT,CAAC,EACC,MAQL,qBAAqB,EAAwE,CAC3F,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,EAAE,MACN,EACA,CAAE,GAAG,EAAQ,KAAM,UAAW,UAAW,aAAc,CACxD,CACD,OAAQ,EACT,CAAC,GAKO,EAAb,KAAsB,CACpB,YAAY,EAAiC,EAA4B,CAA5C,KAAA,MAAA,EAAgC,KAAA,GAAA,EAO7D,iBAAqD,CACnD,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,CAAE,KAAM,SAAU,UAAW,QAAS,CAC5C,OAAQ,EACT,CAAC,CAQJ,iBAAiB,EAA8D,CAC7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,SAAU,CAC/C,CACD,OAAQ,EACT,CAAC,CAOJ,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,EAAa,CAAC,EAAE,MAQ/E,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,QAAO,CACf,OAAQ,EACT,CAAC,EACC"}
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,OAAO,CAAE,sBAAsB,CACnE,EAA2B,EAAE,OAAO,CACxC,KAAM,EAAE,QAAQ,SAAS,CACzB,UAAW,EAAE,QAAQ,QAAQ,CAC9B,CAAC,CACI,EAA4B,EAAE,OAAO,CACzC,KAAM,EAAE,QAAQ,SAAS,CACzB,UAAW,EAAE,QAAQ,SAAS,CAC9B,MAAO,EAAE,SAAS,EAAkB,CACrC,CAAC,CACI,EAA4B,EAAE,OAAO,CACzC,KAAM,EAAE,QAAQ,UAAU,CAC1B,UAAW,EAAE,QAAQ,QAAQ,CAC7B,IAAK,EACL,IAAK,EACN,CAAC,CACI,EA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MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,EAAE,MACN,EACA,CAAE,GAAG,EAAQ,KAAM,UAAW,UAAW,aAAc,CACxD,CACD,OAAQ,EACT,CAAC,GAKO,EAAb,KAAsB,CACpB,YAAY,EAAiC,EAA4B,CAA5C,KAAA,MAAA,EAAgC,KAAA,GAAA,EAO7D,iBAAqD,CACnD,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,CAAE,KAAM,SAAU,UAAW,QAAS,CAC5C,OAAQ,EACT,CAAC,CAQJ,iBAAiB,EAA8D,CAC7E,OAAO,KAAK,MAAM,SAAS,KAAK,GAAG,SAAU,CAC3C,OAAQ,QACR,KAAM,EAAE,MACN,EACA,CAAE,QAAO,KAAM,SAAU,UAAW,SAAU,CAC/C,CACD,OAAQ,EACT,CAAC,CAOJ,MAAM,MAAwB,CAC5B,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CAAE,OAAQ,EAAa,CAAC,EAAE,MAQ/E,MAAM,MAAM,EAAgC,CAC1C,OAAQ,MAAM,KAAK,MAAM,SAAS,KAAK,GAAG,QAAS,CACjD,OAAQ,MACR,KAAM,CAAE,QAAO,CACf,OAAQ,EACT,CAAC,EACC"}
package/build/hmi.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`valibot`);t=e.t(t);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{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{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{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{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||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-Bmb41Sf3.cjs`);let t=require(`valibot`);t=e.t(t);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{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{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{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{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;
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\nconst 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()));\nconst 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>;\nconst progress = v.object({ progress: progressValue });\nexport type Progress = v.InferOutput<typeof progress>;\n\nconst 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\nconst 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/** @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 ? 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":"6IAGA,MAAM,EAAaA,EAAE,KAAKA,EAAE,QAAQ,CAAEA,EAAE,UAAU,KAAK,CAAC,CAGlD,EAAOA,EAAE,OAAO,CAAE,KAAM,EAAY,CAAC,CAGrC,EAAmBA,EAAE,SAASA,EAAE,KAAKA,EAAE,QAAQ,CAAEA,EAAE,OAAO,EAAE,CAAEA,EAAE,UAAU,CAAC,CAAC,CAC5E,EAAQA,EAAE,OAAO,CACrB,KAAM,EACN,SAAU,EACV,WAAY,EACb,CAAC,CAGI,EAAgBA,EAAE,KAAKA,EAAE,QAAQ,CAAEA,EAAE,SAAS,EAAE,CAAEA,EAAE,SAAS,IAAI,CAAC,CAElE,EAAWA,EAAE,OAAO,CAAE,SAAU,EAAe,CAAC,CAGhD,EAAwBA,EAAE,OAAO,CACrC,SAAUA,EAAE,SACV,CAAC,UAAW,UAAW,UAAW,iBAAkB,iBAClD,iBAAiB,CACpB,CACD,OAAQA,EAAE,KAAKA,EAAE,QAAQ,CAAEA,EAAE,SAAS,EAAE,CAAEA,EAAE,SAAS,IAAI,CAAC,CAC3D,CAAC,CAGI,EAAoBA,EAAE,OAAO,CACjC,eAAgBA,EAAE,SAAS,CAC3B,YAAaA,EAAE,SAAS,CACxB,eAAgBA,EAAE,QAAQ,CAC3B,CAAC,CACgBA,EAAE,KAAK,EAAmB,CAAC,cAAc,CAAC,CAI5D,IAAa,EAAb,KAAoB,CAClB,YAAY,EAAiC,CAAhB,KAAA,MAAA,EAK7B,OAAuB,CACrB,OAAO,KAAK,MAAM,aAAc,CAAE,OAAQ,OAAQ,kBAAqB,GAAI,CA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,MAAM,KAAK,YAAY,EAAE,eAAe,EAAI,EAOnF,MAAM,WAAW,EAAgD,CAC/D,MAAM,KAAK,YAAY,CACvB,IAAI,EAAQ,EAEN,EAAW,KAAK,IAAI,IAAK,GAAc,KAAO,GAAG,CAEjD,EAAY,KAAK,KAAK,CAC5B,KAAO,IAAa,KAAK,KAAK,CAAG,EAAY,GAAmB,CAC9D,IAAM,EAAY,MAAM,KAAK,YAAY,CAGzC,GAFA,GAAS,EAAU,eAEf,EAAU,gBAAkB,KAAK,IAAI,EAAM,EAAI,EACjD,MAAO,CAAE,eAAgB,EAAU,eAAgB,eAAgB,KAAK,KAAK,EAAM,CAAE,CAEvF,MAAM,IAAI,QAAS,GAAY,WAAW,EAAS,EAAS,CAAC,CAG/D,OAAO"}
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\nconst 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()));\nconst 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>;\nconst progress = v.object({ progress: progressValue });\nexport type Progress = v.InferOutput<typeof progress>;\n\nconst 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\nconst 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/** @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":"6IAGA,MAAM,EAAaA,EAAE,KAAKA,EAAE,QAAQ,CAAEA,EAAE,UAAU,KAAK,CAAC,CAGlD,EAAOA,EAAE,OAAO,CAAE,KAAM,EAAY,CAAC,CAGrC,EAAmBA,EAAE,SAASA,EAAE,KAAKA,EAAE,QAAQ,CAAEA,EAAE,OAAO,EAAE,CAAEA,EAAE,UAAU,CAAC,CAAC,CAC5E,EAAQA,EAAE,OAAO,CACrB,KAAM,EACN,SAAU,EACV,WAAY,EACb,CAAC,CAGI,EAAgBA,EAAE,KAAKA,EAAE,QAAQ,CAAEA,EAAE,SAAS,EAAE,CAAEA,EAAE,SAAS,IAAI,CAAC,CAElE,EAAWA,EAAE,OA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ACR,KAAMA,EAAE,MAAM,EAAU,CAAE,SAAU,EAAM,CAAoB,CAC9D,OAAQ,EACT,CAAC,CAMJ,OAAuB,CACrB,OAAO,KAAK,MAAM,oBAAqB,CAAE,OAAQ,OAAQ,kBAAqB,GAAI,CAAC,GAK1E,EAAb,KAAmB,CACjB,YAAY,EAAiC,CAAhB,KAAA,MAAA,EAO7B,MAAM,KAAK,EAA+D,CACxE,OAAO,KAAK,MAAM,oBAAqB,CACrC,OAAQ,OACR,KAAMA,EAAE,MAAM,EAAuB,EAAO,CAC5C,OAAQ,EACT,CAAC,GAKO,EAAb,KAAkB,CAChB,YAAY,EAAiC,CAAhB,KAAA,MAAA,EAE7B,eAAmB,KAAK,MAAM,2BAA4B,CAAE,OAAQ,EAAmB,CAAC,CAExF,eAAiB,UAAa,MAAM,KAAK,YAAY,EAAE,YACvD,eAAiB,SAAY,KAAK,KAAK,MAAM,KAAK,YAAY,EAAE,eAAe,EAAI,EAOnF,MAAM,WAAW,EAAgD,CAC/D,MAAM,KAAK,YAAY,CACvB,IAAI,EAAQ,EAEN,EAAW,KAAK,IAAI,IAAK,GAAc,KAAO,GAAG,CAEjD,EAAY,KAAK,KAAK,CAC5B,KAAO,IAAe,IAAA,IAAY,KAAK,KAAK,CAAG,EAAY,GAAmB,CAC5E,IAAM,EAAY,MAAM,KAAK,YAAY,CAGzC,GAFA,GAAS,EAAU,eAEf,EAAU,gBAAkB,KAAK,IAAI,EAAM,EAAI,EACjD,MAAO,CAAE,eAAgB,EAAU,eAAgB,eAAgB,KAAK,KAAK,EAAM,CAAE,CAEvF,MAAM,IAAI,QAAS,GAAY,WAAW,EAAS,EAAS,CAAC,CAG/D,OAAO"}
package/build/hmi.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import*as e from"valibot";const t=e.pipe(e.string(),e.maxLength(1024)),n=e.object({text:t}),r=e.optional(e.pipe(e.string(),e.length(7),e.hexColor())),i=e.object({text:r,progress:r,background:r}),a=e.pipe(e.number(),e.minValue(0),e.maxValue(100)),o=e.object({progress:a}),s=e.object({sound_id:e.picklist([`success`,`warning`,`failure`,`notification_1`,`notification_2`,`imperial_march`]),volume:e.pipe(e.number(),e.minValue(0),e.maxValue(100))}),c=e.object({button_pressed:e.boolean(),button_held:e.boolean(),rotation_delta:e.number()});e.omit(c,[`button_held`]);var l=class{constructor(e){this.fetch=e}reset(){return this.fetch(`/hmi/reset`,{method:`POST`,parseResponse:()=>{}})}screen(){return new u(this.fetch)}audio(){return new d(this.fetch)}knob(){return new f(this.fetch)}},u=class{constructor(e){this.fetch=e}async print(t){return(await this.fetch(`/hmi/screen/text`,{method:`POST`,body:e.parse(n,{text:t}),schema:n})).text}colors(t){return this.fetch(`/hmi/screen/colors`,{method:`PATCH`,body:e.parse(i,t),schema:i})}async progress(t){return t==0?await this.fetch(`/hmi/screen/progress`,{method:`DELETE`,parseResponse:()=>({progress:0})}):this.fetch(`/hmi/screen/progress`,{method:`PUT`,body:e.parse(o,{progress:t}),schema:o})}clear(){return this.fetch(`/hmi/screen/clear`,{method:`POST`,parseResponse:()=>{}})}},d=class{constructor(e){this.fetch=e}async play(t){return this.fetch(`/hmi/speaker/play`,{method:`POST`,body:e.parse(s,t),schema:s})}},f=class{constructor(e){this.fetch=e}read_event=()=>this.fetch(`/hmi/knob/get_knob_event`,{schema:c});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||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}};export{d as Audio,l as HmiApi,f as Knob,u as Screen};
1
+ import*as e from"valibot";const t=e.pipe(e.string(),e.maxLength(1024)),n=e.object({text:t}),r=e.optional(e.pipe(e.string(),e.length(7),e.hexColor())),i=e.object({text:r,progress:r,background:r}),a=e.pipe(e.number(),e.minValue(0),e.maxValue(100)),o=e.object({progress:a}),s=e.object({sound_id:e.picklist([`success`,`warning`,`failure`,`notification_1`,`notification_2`,`imperial_march`]),volume:e.pipe(e.number(),e.minValue(0),e.maxValue(100))}),c=e.object({button_pressed:e.boolean(),button_held:e.boolean(),rotation_delta:e.number()});e.omit(c,[`button_held`]);var l=class{constructor(e){this.fetch=e}reset(){return this.fetch(`/hmi/reset`,{method:`POST`,parseResponse:()=>{}})}screen(){return new u(this.fetch)}audio(){return new d(this.fetch)}knob(){return new f(this.fetch)}},u=class{constructor(e){this.fetch=e}async print(t){return(await this.fetch(`/hmi/screen/text`,{method:`POST`,body:e.parse(n,{text:t}),schema:n})).text}colors(t){return this.fetch(`/hmi/screen/colors`,{method:`PATCH`,body:e.parse(i,t),schema:i})}async progress(t){return t==0?await this.fetch(`/hmi/screen/progress`,{method:`DELETE`,parseResponse:()=>({progress:0})}):this.fetch(`/hmi/screen/progress`,{method:`PUT`,body:e.parse(o,{progress:t}),schema:o})}clear(){return this.fetch(`/hmi/screen/clear`,{method:`POST`,parseResponse:()=>{}})}},d=class{constructor(e){this.fetch=e}async play(t){return this.fetch(`/hmi/speaker/play`,{method:`POST`,body:e.parse(s,t),schema:s})}},f=class{constructor(e){this.fetch=e}read_event=()=>this.fetch(`/hmi/knob/get_knob_event`,{schema:c});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}};export{d as Audio,l as HmiApi,f as Knob,u as Screen};
2
2
  //# sourceMappingURL=hmi.mjs.map
package/build/hmi.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hmi.mjs","names":[],"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\nconst 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()));\nconst 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>;\nconst progress = v.object({ progress: progressValue });\nexport type Progress = v.InferOutput<typeof progress>;\n\nconst 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\nconst 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/** @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 ? 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":"0BAGA,MAAM,EAAa,EAAE,KAAK,EAAE,QAAQ,CAAE,EAAE,UAAU,KAAK,CAAC,CAGlD,EAAO,EAAE,OAAO,CAAE,KAAM,EAAY,CAAC,CAGrC,EAAmB,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAE,EAAE,OAAO,EAAE,CAAE,EAAE,UAAU,CAAC,CAAC,CAC5E,EAAQ,EAAE,OAAO,CACrB,KAAM,EACN,SAAU,EACV,WAAY,EACb,CAAC,CAGI,EAAgB,EAAE,KAAK,EAAE,QAAQ,CAAE,EAAE,SAAS,EAAE,CAAE,EAAE,SAAS,IAAI,CAAC,CAElE,EAAW,EAAE,OAAO,CAAE,SAAU,EAAe,CAAC,CAGhD,EAAwB,EAAE,OAAO,CACrC,SAAU,EAAE,SACV,CAAC,UAAW,UAAW,UAAW,iBAAkB,iBAClD,iBAAiB,CACpB,CACD,OAAQ,EAAE,KAAK,EAAE,QAAQ,CAAE,EAAE,SAAS,EAAE,CAAE,EAAE,SAAS,IAAI,CAAC,CAC3D,CAAC,CAGI,EAAoB,EAAE,OAAO,CACjC,eAAgB,EAAE,SAAS,CAC3B,YAAa,EAAE,SAAS,CACxB,eAAgB,EAAE,QAAQ,CAC3B,CAAC,CACgB,EAAE,KAAK,EAAmB,CAAC,cAAc,CAAC,CAI5D,IAAa,EAAb,KAAoB,CAClB,YAAY,EAAiC,CAAhB,KAAA,MAAA,EAK7B,OAAuB,CACrB,OAAO,KAAK,MAAM,aAAc,CAAE,OAAQ,O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,SAAY,KAAK,KAAK,MAAM,KAAK,YAAY,EAAE,eAAe,EAAI,EAOnF,MAAM,WAAW,EAAgD,CAC/D,MAAM,KAAK,YAAY,CACvB,IAAI,EAAQ,EAEN,EAAW,KAAK,IAAI,IAAK,GAAc,KAAO,GAAG,CAEjD,EAAY,KAAK,KAAK,CAC5B,KAAO,IAAa,KAAK,KAAK,CAAG,EAAY,GAAmB,CAC9D,IAAM,EAAY,MAAM,KAAK,YAAY,CAGzC,GAFA,GAAS,EAAU,eAEf,EAAU,gBAAkB,KAAK,IAAI,EAAM,EAAI,EACjD,MAAO,CAAE,eAAgB,EAAU,eAAgB,eAAgB,KAAK,KAAK,EAAM,CAAE,CAEvF,MAAM,IAAI,QAAS,GAAY,WAAW,EAAS,EAAS,CAAC,CAG/D,OAAO"}
1
+ {"version":3,"file":"hmi.mjs","names":[],"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\nconst 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()));\nconst 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>;\nconst progress = v.object({ progress: progressValue });\nexport type Progress = v.InferOutput<typeof progress>;\n\nconst 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\nconst 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/** @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":"0BAGA,MAAM,EAAa,EAAE,KAAK,EAAE,QAAQ,CAAE,EAAE,UAAU,KAAK,CAAC,CAGlD,EAAO,EAAE,OAAO,CAAE,KAAM,EAAY,CAAC,CAGrC,EAAmB,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAE,EAAE,OAAO,EAAE,CAAE,EAAE,UAAU,CAAC,CAAC,CAC5E,EAAQ,EAAE,OAAO,CACrB,KAAM,EACN,SAAU,EACV,WAAY,EACb,CAAC,CAGI,EAAgB,EAAE,KAAK,EAAE,QAAQ,CAAE,EAAE,SAAS,EAAE,CAAE,EAAE,SAAS,IAAI,CAAC,CAElE,EAAW,EAAE,OA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,MAAM,EAAU,CAAE,SAAU,EAAM,CAAoB,CAC9D,OAAQ,EACT,CAAC,CAMJ,OAAuB,CACrB,OAAO,KAAK,MAAM,oBAAqB,CAAE,OAAQ,OAAQ,kBAAqB,GAAI,CAAC,GAK1E,EAAb,KAAmB,CACjB,YAAY,EAAiC,CAAhB,KAAA,MAAA,EAO7B,MAAM,KAAK,EAA+D,CACxE,OAAO,KAAK,MAAM,oBAAqB,CACrC,OAAQ,OACR,KAAM,EAAE,MAAM,EAAuB,EAAO,CAC5C,OAAQ,EACT,CAAC,GAKO,EAAb,KAAkB,CAChB,YAAY,EAAiC,CAAhB,KAAA,MAAA,EAE7B,eAAmB,KAAK,MAAM,2BAA4B,CAAE,OAAQ,EAAmB,CAAC,CAExF,eAAiB,UAAa,MAAM,KAAK,YAAY,EAAE,YACvD,eAAiB,SAAY,KAAK,KAAK,MAAM,KAAK,YAAY,EAAE,eAAe,EAAI,EAOnF,MAAM,WAAW,EAAgD,CAC/D,MAAM,KAAK,YAAY,CACvB,IAAI,EAAQ,EAEN,EAAW,KAAK,IAAI,IAAK,GAAc,KAAO,GAAG,CAEjD,EAAY,KAAK,KAAK,CAC5B,KAAO,IAAe,IAAA,IAAY,KAAK,KAAK,CAAG,EAAY,GAAmB,CAC5E,IAAM,EAAY,MAAM,KAAK,YAAY,CAGzC,GAFA,GAAS,EAAU,eAEf,EAAU,gBAAkB,KAAK,IAAI,EAAM,EAAI,EACjD,MAAO,CAAE,eAAgB,EAAU,eAAgB,eAAgB,KAAK,KAAK,EAAM,CAAE,CAEvF,MAAM,IAAI,QAAS,GAAY,WAAW,EAAS,EAAS,CAAC,CAG/D,OAAO"}
@@ -12,6 +12,7 @@ declare enum CommunicationInterfaceType {
12
12
  }
13
13
  declare const info: v.ObjectSchema<{
14
14
  readonly model: v.StringSchema<undefined>;
15
+ readonly hostname: v.StringSchema<undefined>;
15
16
  readonly serial_number: v.StringSchema<undefined>;
16
17
  readonly firmware_version: v.StringSchema<undefined>;
17
18
  readonly firmware_commit: v.StringSchema<undefined>;
@@ -121,6 +122,7 @@ declare class ManagementApi {
121
122
  */
122
123
  info(): Promise<{
123
124
  model: string;
125
+ hostname: string;
124
126
  serial_number: string;
125
127
  firmware_version: string;
126
128
  firmware_commit: string;
@@ -280,4 +282,4 @@ declare class ManagementApi {
280
282
  }
281
283
  //#endregion
282
284
  export { UpdateResponse as a, RebootResponse as i, Information as n, UpdateStatus as o, ManagementApi as r, CommunicationInterfaceType as t };
283
- //# sourceMappingURL=management-ra61-qUr.d.mts.map
285
+ //# sourceMappingURL=management-C7zHgMy1.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"management-C7zHgMy1.d.cts","names":[],"sources":["../src/api/management.ts"],"mappings":";;;;aAGY,0BAAA;EACV,GAAA;EACA,KAAA;EACA,KAAA;EACA,GAAA;EACA,GAAA;EACA,IAAA;AAAA;AAAA,cA+EI,IAAA,EAAI,CAAA,CAAA,YAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAWE,WAAA,GAAc,CAAA,CAAE,WAAA,QAAmB,IAAA;AAAA,cAEzC,OAAA,EAAO,CAAA,CAAA,YAAA;EAAA;;;;;KAMR,OAAA,GAAU,CAAA,CAAE,WAAA,QAAmB,OAAA;AAAA,cAE9B,aAAA,EAAa,CAAA,CAAA,YAAA;EAAA;;;KACd,aAAA,GAAgB,CAAA,CAAE,WAAA,QAAmB,aAAA;AAAA,cAEpC,cAAA,EAAc,CAAA,CAAA,YAAA;EAAA;;;KACR,cAAA,GAAiB,CAAA,CAAE,WAAA,QAAmB,cAAA;AAAA,cAE5C,YAAA,EAAY,CAAA,CAAA,YAAA;EAAA;;;;;KAMN,YAAA,GAAe,CAAA,CAAE,WAAA,QAAmB,YAAA;AAAA,cAE1C,cAAA,EAAc,CAAA,CAAA,YAAA;EAAA,kBAAoC,CAAA,CAAA,YAAA;AAAA;AAAA,KAC5C,cAAA,GAAiB,CAAA,CAAE,WAAA,QAAmB,cAAA;;cAGrC,aAAA;EAAA,iBACkB,KAAA;cAAA,KAAA,EAAO,OAAA;;;;;EAMpC,IAAA,CAAA,GAAI,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQE,QAAA,CAAA,GAAY,OAAA,CAAQ,IAAA;;;;;;;;EAc1B,WAAA,CAAY,QAAA,EAAU,IAAA,GAAO,OAAA;;;;;EAY7B,WAAA,CAAA,GAAW,OAAA;;;;;;;;;;EAQX,aAAA,CAAc,UAAA,EAAY,aAAA,GAAa,OAAA;;;;;;;;;;;EAavC,aAAA,CAAc,SAAA,UAAmB,IAAA,EAAM,OAAA,GAAO,OAAA;;;;;;;;;;EAY9C,UAAA,CAAW,SAAA,WAAiB,OAAA;;;;;EAQ5B,WAAA,CAAY,SAAA,WAAiB,OAAA;;;;;EAQ7B,aAAA,CAAc,SAAA,WAAiB,OAAA;;;;;;;EAU/B,aAAA,CAAc,IAAA,EAAM,IAAA,EAAM,QAAA,YAAyB,OAAA;;;;;;;;EAenD,aAAA,CAAA,GAAa,OAAA;;;;;;;;;;EAQb,MAAA,CAAA,GAAM,OAAA"}
@@ -12,6 +12,7 @@ declare enum CommunicationInterfaceType {
12
12
  }
13
13
  declare const info: v.ObjectSchema<{
14
14
  readonly model: v.StringSchema<undefined>;
15
+ readonly hostname: v.StringSchema<undefined>;
15
16
  readonly serial_number: v.StringSchema<undefined>;
16
17
  readonly firmware_version: v.StringSchema<undefined>;
17
18
  readonly firmware_commit: v.StringSchema<undefined>;
@@ -121,6 +122,7 @@ declare class ManagementApi {
121
122
  */
122
123
  info(): Promise<{
123
124
  model: string;
125
+ hostname: string;
124
126
  serial_number: string;
125
127
  firmware_version: string;
126
128
  firmware_commit: string;
@@ -280,4 +282,4 @@ declare class ManagementApi {
280
282
  }
281
283
  //#endregion
282
284
  export { UpdateResponse as a, RebootResponse as i, Information as n, UpdateStatus as o, ManagementApi as r, CommunicationInterfaceType as t };
283
- //# sourceMappingURL=management-wQgti8p7.d.cts.map
285
+ //# sourceMappingURL=management-dm4RL8mB.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"management-dm4RL8mB.d.mts","names":[],"sources":["../src/api/management.ts"],"mappings":";;;;aAGY,0BAAA;EACV,GAAA;EACA,KAAA;EACA,KAAA;EACA,GAAA;EACA,GAAA;EACA,IAAA;AAAA;AAAA,cA+EI,IAAA,EAAI,CAAA,CAAA,YAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAWE,WAAA,GAAc,CAAA,CAAE,WAAA,QAAmB,IAAA;AAAA,cAEzC,OAAA,EAAO,CAAA,CAAA,YAAA;EAAA;;;;;KAMR,OAAA,GAAU,CAAA,CAAE,WAAA,QAAmB,OAAA;AAAA,cAE9B,aAAA,EAAa,CAAA,CAAA,YAAA;EAAA;;;KACd,aAAA,GAAgB,CAAA,CAAE,WAAA,QAAmB,aAAA;AAAA,cAEpC,cAAA,EAAc,CAAA,CAAA,YAAA;EAAA;;;KACR,cAAA,GAAiB,CAAA,CAAE,WAAA,QAAmB,cAAA;AAAA,cAE5C,YAAA,EAAY,CAAA,CAAA,YAAA;EAAA;;;;;KAMN,YAAA,GAAe,CAAA,CAAE,WAAA,QAAmB,YAAA;AAAA,cAE1C,cAAA,EAAc,CAAA,CAAA,YAAA;EAAA,kBAAoC,CAAA,CAAA,YAAA;AAAA;AAAA,KAC5C,cAAA,GAAiB,CAAA,CAAE,WAAA,QAAmB,cAAA;;cAGrC,aAAA;EAAA,iBACkB,KAAA;cAAA,KAAA,EAAO,OAAA;;;;;EAMpC,IAAA,CAAA,GAAI,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQE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