awtrix-ts 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -246,7 +246,29 @@ for (let i = 0; i <= 100; i++) {
246
246
  }
247
247
  ```
248
248
 
249
+ #### Draw Pixels
250
+
251
+ Draw shapes on the display:
252
+
253
+ ```typescript
254
+ await clock.notify({
255
+ draw: [
256
+ new clock.draw.Pixel(0, 0, [255, 0, 0]),
257
+ new clock.draw.Line(0, 1, 15, 1, [0, 255, 0]),
258
+ new clock.draw.Rectangle(2, 2, 12, 6, [0, 0, 255]),
259
+ new clock.draw.FilledRectangle(3, 3, 10, 4, [255, 255, 0]),
260
+ new clock.draw.Circle(8, 1, 3, [0, 255, 255]),
261
+ new clock.draw.FilledCircle(8, 3, 2, [255, 0, 255]),
262
+ new clock.draw.Text(0, 1, 'AWTRIX', [255, 255, 255]),
263
+ ],
264
+ });
265
+ ```
266
+
249
267
  ### Other
250
268
 
251
269
  - All API calls are asynchronous and return Promises.
252
270
  - The class exposes enums for transitions, indicators, and effects for convenience.
271
+
272
+ ```
273
+
274
+ ```
package/dist/draw.d.ts ADDED
@@ -0,0 +1,132 @@
1
+ export declare class Pixel {
2
+ x: number;
3
+ y: number;
4
+ color: string | number[];
5
+ constructor(x: number, y: number, color: string | number[]);
6
+ }
7
+ export declare class Line {
8
+ x0: number;
9
+ y0: number;
10
+ x1: number;
11
+ y1: number;
12
+ color: string | number[];
13
+ constructor(x0: number, y0: number, x1: number, y1: number, color: string | number[]);
14
+ }
15
+ export declare class Rectangle {
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ color: string | number[];
21
+ constructor(x: number, y: number, width: number, height: number, color: string | number[]);
22
+ }
23
+ export declare class FilledRectangle {
24
+ x: number;
25
+ y: number;
26
+ width: number;
27
+ height: number;
28
+ color: string | number[];
29
+ constructor(x: number, y: number, width: number, height: number, color: string | number[]);
30
+ }
31
+ export declare class Circle {
32
+ x: number;
33
+ y: number;
34
+ radius: number;
35
+ color: string | number[];
36
+ constructor(x: number, y: number, radius: number, color: string | number[]);
37
+ }
38
+ export declare class FilledCircle {
39
+ x: number;
40
+ y: number;
41
+ radius: number;
42
+ color: string | number[];
43
+ constructor(x: number, y: number, radius: number, color: string | number[]);
44
+ }
45
+ export declare class Text {
46
+ x: number;
47
+ y: number;
48
+ text: string;
49
+ color: string | number[];
50
+ constructor(x: number, y: number, text: string, color: string | number[]);
51
+ }
52
+ export declare class Bitmap {
53
+ x: number;
54
+ y: number;
55
+ width: number;
56
+ height: number;
57
+ bitmap: (string | number[])[];
58
+ constructor(x: number, y: number, width: number, height: number, bitmap: (string | number[])[]);
59
+ }
60
+ export declare const map: (item: Pixel | Line | Rectangle | FilledRectangle | Circle | FilledCircle | Text | Bitmap) => Pixel | Line | Rectangle | FilledRectangle | Circle | FilledCircle | Text | Bitmap | {
61
+ dp: (string | number | number[])[];
62
+ dl?: undefined;
63
+ dr?: undefined;
64
+ fr?: undefined;
65
+ dc?: undefined;
66
+ dfc?: undefined;
67
+ dt?: undefined;
68
+ db?: undefined;
69
+ } | {
70
+ dl: (string | number | number[])[];
71
+ dp?: undefined;
72
+ dr?: undefined;
73
+ fr?: undefined;
74
+ dc?: undefined;
75
+ dfc?: undefined;
76
+ dt?: undefined;
77
+ db?: undefined;
78
+ } | {
79
+ dr: (string | number | number[])[];
80
+ dp?: undefined;
81
+ dl?: undefined;
82
+ fr?: undefined;
83
+ dc?: undefined;
84
+ dfc?: undefined;
85
+ dt?: undefined;
86
+ db?: undefined;
87
+ } | {
88
+ fr: (string | number | number[])[];
89
+ dp?: undefined;
90
+ dl?: undefined;
91
+ dr?: undefined;
92
+ dc?: undefined;
93
+ dfc?: undefined;
94
+ dt?: undefined;
95
+ db?: undefined;
96
+ } | {
97
+ dc: (string | number | number[])[];
98
+ dp?: undefined;
99
+ dl?: undefined;
100
+ dr?: undefined;
101
+ fr?: undefined;
102
+ dfc?: undefined;
103
+ dt?: undefined;
104
+ db?: undefined;
105
+ } | {
106
+ dfc: (string | number | number[])[];
107
+ dp?: undefined;
108
+ dl?: undefined;
109
+ dr?: undefined;
110
+ fr?: undefined;
111
+ dc?: undefined;
112
+ dt?: undefined;
113
+ db?: undefined;
114
+ } | {
115
+ dt: (string | number | number[])[];
116
+ dp?: undefined;
117
+ dl?: undefined;
118
+ dr?: undefined;
119
+ fr?: undefined;
120
+ dc?: undefined;
121
+ dfc?: undefined;
122
+ db?: undefined;
123
+ } | {
124
+ db: (number | (string | number[])[])[];
125
+ dp?: undefined;
126
+ dl?: undefined;
127
+ dr?: undefined;
128
+ fr?: undefined;
129
+ dc?: undefined;
130
+ dfc?: undefined;
131
+ dt?: undefined;
132
+ };
package/dist/draw.js ADDED
@@ -0,0 +1,147 @@
1
+ export class Pixel {
2
+ x;
3
+ y;
4
+ color;
5
+ constructor(x, y, color) {
6
+ this.x = x;
7
+ this.y = y;
8
+ this.color = color;
9
+ }
10
+ }
11
+ export class Line {
12
+ x0;
13
+ y0;
14
+ x1;
15
+ y1;
16
+ color;
17
+ constructor(x0, y0, x1, y1, color) {
18
+ this.x0 = x0;
19
+ this.y0 = y0;
20
+ this.x1 = x1;
21
+ this.y1 = y1;
22
+ this.color = color;
23
+ }
24
+ }
25
+ export class Rectangle {
26
+ x;
27
+ y;
28
+ width;
29
+ height;
30
+ color;
31
+ constructor(x, y, width, height, color) {
32
+ this.x = x;
33
+ this.y = y;
34
+ this.width = width;
35
+ this.height = height;
36
+ this.color = color;
37
+ }
38
+ }
39
+ export class FilledRectangle {
40
+ x;
41
+ y;
42
+ width;
43
+ height;
44
+ color;
45
+ constructor(x, y, width, height, color) {
46
+ this.x = x;
47
+ this.y = y;
48
+ this.width = width;
49
+ this.height = height;
50
+ this.color = color;
51
+ }
52
+ }
53
+ export class Circle {
54
+ x;
55
+ y;
56
+ radius;
57
+ color;
58
+ constructor(x, y, radius, color) {
59
+ this.x = x;
60
+ this.y = y;
61
+ this.radius = radius;
62
+ this.color = color;
63
+ }
64
+ }
65
+ export class FilledCircle {
66
+ x;
67
+ y;
68
+ radius;
69
+ color;
70
+ constructor(x, y, radius, color) {
71
+ this.x = x;
72
+ this.y = y;
73
+ this.radius = radius;
74
+ this.color = color;
75
+ }
76
+ }
77
+ export class Text {
78
+ x;
79
+ y;
80
+ text;
81
+ color;
82
+ constructor(x, y, text, color) {
83
+ this.x = x;
84
+ this.y = y;
85
+ this.text = text;
86
+ this.color = color;
87
+ }
88
+ }
89
+ export class Bitmap {
90
+ x;
91
+ y;
92
+ width;
93
+ height;
94
+ bitmap;
95
+ constructor(x, y, width, height, bitmap) {
96
+ this.x = x;
97
+ this.y = y;
98
+ this.width = width;
99
+ this.height = height;
100
+ this.bitmap = bitmap;
101
+ }
102
+ }
103
+ export const map = (item) => {
104
+ switch (item.constructor) {
105
+ case Pixel:
106
+ const p = item;
107
+ return {
108
+ dp: [p.x, p.y, p.color]
109
+ };
110
+ case Line:
111
+ const l = item;
112
+ return {
113
+ dl: [l.x0, l.y0, l.x1, l.y1, l.color]
114
+ };
115
+ case Rectangle:
116
+ const r = item;
117
+ return {
118
+ dr: [r.x, r.y, r.width, r.height, r.color]
119
+ };
120
+ case FilledRectangle:
121
+ const fr = item;
122
+ return {
123
+ fr: [fr.x, fr.y, fr.width, fr.height, fr.color]
124
+ };
125
+ case Circle:
126
+ const c = item;
127
+ return {
128
+ dc: [c.x, c.y, c.radius, c.color]
129
+ };
130
+ case FilledCircle:
131
+ const fc = item;
132
+ return {
133
+ dfc: [fc.x, fc.y, fc.radius, fc.color]
134
+ };
135
+ case Text:
136
+ const t = item;
137
+ return {
138
+ dt: [t.x, t.y, t.text, t.color]
139
+ };
140
+ case Bitmap:
141
+ const b = item;
142
+ return {
143
+ db: [b.x, b.y, b.width, b.height, b.bitmap]
144
+ };
145
+ }
146
+ return item;
147
+ };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as interaction from './interaction.js';
2
+ import * as draw from './draw.js';
2
3
  import * as transitions from './transitions.js';
3
4
  import * as indicators from './indicators.js';
4
5
  import * as settings from './settings.js';
@@ -51,6 +52,7 @@ declare class Awtrix {
51
52
  readonly MoveOnce: 1;
52
53
  readonly MoveRepeat: 2;
53
54
  };
55
+ draw: typeof draw;
54
56
  constructor(url: URL);
55
57
  power(power: boolean): Promise<void>;
56
58
  sleep(time: number): Promise<void>;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { setTimeout } from 'node:timers/promises';
2
2
  import * as interaction from './interaction.js';
3
+ import * as draw from './draw.js';
3
4
  import * as transitions from './transitions.js';
4
5
  import * as indicators from './indicators.js';
5
6
  class Awtrix {
@@ -9,6 +10,7 @@ class Awtrix {
9
10
  Indicators = indicators.Indicator;
10
11
  Effects = interaction.Effect;
11
12
  PushIcon = interaction.PushIcon;
13
+ draw = draw;
12
14
  constructor(url) {
13
15
  this.url = url.href + 'api';
14
16
  }
@@ -111,7 +113,10 @@ class Awtrix {
111
113
  await this.post('moodlight');
112
114
  }
113
115
  async notify(notification) {
114
- await this.post('notify', notification);
116
+ await this.post('notify', {
117
+ ...notification,
118
+ draw: notification.draw?.map(item => draw.map(item)),
119
+ });
115
120
  }
116
121
  async dismissNotification() {
117
122
  await this.post('notify/dismiss');
@@ -1,4 +1,5 @@
1
- export interface Interaction {
1
+ import * as draw from './draw.js';
2
+ export interface InteractionPayload {
2
3
  text?: string;
3
4
  textCase?: number;
4
5
  topText?: boolean;
@@ -26,7 +27,7 @@ export interface Interaction {
26
27
  progressC?: string | number[];
27
28
  progressBC?: string | number[];
28
29
  pos?: number;
29
- draw?: object[];
30
+ draw?: DrawCommand[];
30
31
  lifetime?: number;
31
32
  lifetimeMode?: number;
32
33
  stack?: boolean;
@@ -39,6 +40,9 @@ export interface Interaction {
39
40
  save?: boolean;
40
41
  overlay?: string;
41
42
  }
43
+ export interface Interaction extends Omit<InteractionPayload, 'draw'> {
44
+ draw?: Array<draw.Pixel | draw.Line | draw.Rectangle | draw.FilledRectangle | draw.Circle | draw.FilledCircle | draw.Text | draw.Bitmap>;
45
+ }
42
46
  declare const PushIcon: {
43
47
  readonly Static: 0;
44
48
  readonly MoveOnce: 1;
@@ -67,4 +71,21 @@ declare const Effect: {
67
71
  readonly Fade: "Fade";
68
72
  };
69
73
  type Effect = typeof Effect[keyof typeof Effect];
74
+ export type DrawCommand = {
75
+ dp: [number, number, string | number[]];
76
+ } | {
77
+ dl: [number, number, number, number, string | number[]];
78
+ } | {
79
+ dr: [number, number, number, number, string | number[]];
80
+ } | {
81
+ df: [number, number, number, number, string | number[]];
82
+ } | {
83
+ dc: [number, number, number, string | number[]];
84
+ } | {
85
+ dfc: [number, number, number, string | number[]];
86
+ } | {
87
+ dt: [number, number, string, string | number[]];
88
+ } | {
89
+ db: [number, number, number, number, (string | number[])[]];
90
+ };
70
91
  export { PushIcon, Effect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awtrix-ts",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "description": "TypeScript API for Awtrix LED Matrix Display",
5
5
  "repository": {
6
6
  "type": "git",