awtrix-ts 1.1.0 → 1.1.2
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 +33 -33
- package/package.json +3 -4
- package/dist/api.d.ts +0 -83
- package/dist/api.js +0 -146
- package/dist/demo.d.ts +0 -1
- package/dist/demo.js +0 -75
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# awtrix-ts
|
|
1
|
+
# awtrix-ts [](https://badge.fury.io/js/awtrix-ts)
|
|
2
2
|
|
|
3
3
|
TS wrapper for Awtrix API.
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ The `Awtrix` class provides a TypeScript interface for interacting with the Awtr
|
|
|
9
9
|
### Usage
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
import { Awtrix } from '
|
|
12
|
+
import { Awtrix } from 'awtrix-ts';
|
|
13
13
|
|
|
14
14
|
const awtrix = new Awtrix(new URL('http://your-awtrix-device-ip'));
|
|
15
15
|
|
|
@@ -24,8 +24,8 @@ await awtrix.notify({ text: 'Hello World!' }); // Send a notification
|
|
|
24
24
|
Turn the device on or off.
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
await
|
|
28
|
-
await
|
|
27
|
+
await awtrix.power(true); // Turn on
|
|
28
|
+
await awtrix.power(false); // Turn off
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
#### reboot()
|
|
@@ -33,7 +33,7 @@ await clock.power(false); // Turn off
|
|
|
33
33
|
Reboot the device.
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
|
-
await
|
|
36
|
+
await awtrix.reboot();
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
#### sleep(time: number)
|
|
@@ -41,7 +41,7 @@ await clock.reboot();
|
|
|
41
41
|
Put the device to sleep for a specified time (in seconds).
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
|
-
await
|
|
44
|
+
await awtrix.sleep(5); // Sleep for 5 seconds
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
#### settings(settings: Settings)
|
|
@@ -49,7 +49,7 @@ await clock.sleep(5); // Sleep for 5 seconds
|
|
|
49
49
|
Update device settings.
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
await
|
|
52
|
+
await awtrix.settings({
|
|
53
53
|
automaticAppSwitching: false,
|
|
54
54
|
globalTextColor: [0, 255, 0],
|
|
55
55
|
// ...other settings
|
|
@@ -61,7 +61,7 @@ await clock.settings({
|
|
|
61
61
|
Resets the device settings back to default.
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
|
-
await
|
|
64
|
+
await awtrix.resetDefaultSettings();
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
#### erase()
|
|
@@ -69,7 +69,7 @@ await clock.resetDefaultSettings();
|
|
|
69
69
|
Factory resets the device. Does not modify WiFi settings.
|
|
70
70
|
|
|
71
71
|
```typescript
|
|
72
|
-
await
|
|
72
|
+
await awtrix.erase();
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
#### screen()
|
|
@@ -77,7 +77,7 @@ await clock.erase();
|
|
|
77
77
|
Get the current screen content.
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
|
-
const screen = await
|
|
80
|
+
const screen = await awtrix.screen();
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
#### stats()
|
|
@@ -85,7 +85,7 @@ const screen = await clock.screen();
|
|
|
85
85
|
Retrieve device statistics.
|
|
86
86
|
|
|
87
87
|
```typescript
|
|
88
|
-
console.log(await
|
|
88
|
+
console.log(await awtrix.stats());
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
#### effects()
|
|
@@ -93,7 +93,7 @@ console.log(await clock.stats());
|
|
|
93
93
|
List available effects.
|
|
94
94
|
|
|
95
95
|
```typescript
|
|
96
|
-
const effects = await
|
|
96
|
+
const effects = await awtrix.effects();
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
#### transitions()
|
|
@@ -101,7 +101,7 @@ const effects = await clock.effects();
|
|
|
101
101
|
List available transitions.
|
|
102
102
|
|
|
103
103
|
```typescript
|
|
104
|
-
const transitions = await
|
|
104
|
+
const transitions = await awtrix.transitions();
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
#### loop()
|
|
@@ -109,7 +109,7 @@ const transitions = await clock.transitions();
|
|
|
109
109
|
Get the app loop configuration.
|
|
110
110
|
|
|
111
111
|
```typescript
|
|
112
|
-
console.log(await
|
|
112
|
+
console.log(await awtrix.loop());
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
#### playMelody(rtttl: string)
|
|
@@ -117,7 +117,7 @@ console.log(await clock.loop());
|
|
|
117
117
|
Play a melody using RTTTL format.
|
|
118
118
|
|
|
119
119
|
```typescript
|
|
120
|
-
await
|
|
120
|
+
await awtrix.playMelody('d=4,o=5,b=140:c6,e6,g6');
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
#### playMelodyFile(name: string)
|
|
@@ -125,7 +125,7 @@ await clock.playMelody('d=4,o=5,b=140:c6,e6,g6');
|
|
|
125
125
|
Play a melody file by name.
|
|
126
126
|
|
|
127
127
|
```typescript
|
|
128
|
-
await
|
|
128
|
+
await awtrix.playMelodyFile('melody.mp3');
|
|
129
129
|
```
|
|
130
130
|
|
|
131
131
|
#### setIndicator(indicator: IndicatorPayload)
|
|
@@ -133,9 +133,9 @@ await clock.playMelodyFile('melody.mp3');
|
|
|
133
133
|
Set an indicator LED.
|
|
134
134
|
|
|
135
135
|
```typescript
|
|
136
|
-
await
|
|
136
|
+
await awtrix.setIndicator({
|
|
137
137
|
color: [255, 0, 0],
|
|
138
|
-
position:
|
|
138
|
+
position: awtrix.Indicators.UpperRight,
|
|
139
139
|
// blink: 500,
|
|
140
140
|
// fade: 1000,
|
|
141
141
|
});
|
|
@@ -146,7 +146,7 @@ await clock.setIndicator({
|
|
|
146
146
|
Clear an indicator LED.
|
|
147
147
|
|
|
148
148
|
```typescript
|
|
149
|
-
await
|
|
149
|
+
await awtrix.clearIndicator(awtrix.Indicators.UpperRight);
|
|
150
150
|
```
|
|
151
151
|
|
|
152
152
|
#### moodlight(setting: MoodlightColor | MoodlightKelvin)
|
|
@@ -154,7 +154,7 @@ await clock.clearIndicator(clock.Indicators.UpperRight);
|
|
|
154
154
|
Set moodlight color or temperature.
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
|
-
await
|
|
157
|
+
await awtrix.moodlight({ r: 255, g: 255, b: 255 });
|
|
158
158
|
```
|
|
159
159
|
|
|
160
160
|
#### clearMoodlight()
|
|
@@ -162,7 +162,7 @@ await clock.moodlight({ r: 255, g: 255, b: 255 });
|
|
|
162
162
|
Turn off moodlight.
|
|
163
163
|
|
|
164
164
|
```typescript
|
|
165
|
-
await
|
|
165
|
+
await awtrix.clearMoodlight();
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
#### notify(notification: Interaction)
|
|
@@ -170,11 +170,11 @@ await clock.clearMoodlight();
|
|
|
170
170
|
Send a notification.
|
|
171
171
|
|
|
172
172
|
```typescript
|
|
173
|
-
await
|
|
173
|
+
await awtrix.notify({
|
|
174
174
|
text: 'Hello World!',
|
|
175
175
|
icon: '3049',
|
|
176
|
-
pushIcon:
|
|
177
|
-
effect:
|
|
176
|
+
pushIcon: awtrix.PushIcon.MoveOnce,
|
|
177
|
+
effect: awtrix.Effects.PlasmaCloud,
|
|
178
178
|
repeat: 5,
|
|
179
179
|
});
|
|
180
180
|
```
|
|
@@ -184,7 +184,7 @@ await clock.notify({
|
|
|
184
184
|
Dismiss the current notification.
|
|
185
185
|
|
|
186
186
|
```typescript
|
|
187
|
-
await
|
|
187
|
+
await awtrix.dismissNotification();
|
|
188
188
|
```
|
|
189
189
|
|
|
190
190
|
#### app(name: string, app: Interaction)
|
|
@@ -192,12 +192,12 @@ await clock.dismissNotification();
|
|
|
192
192
|
Send a custom app payload.
|
|
193
193
|
|
|
194
194
|
```typescript
|
|
195
|
-
await
|
|
195
|
+
await awtrix.app('demoApp', {
|
|
196
196
|
text: 'This is a custom app!',
|
|
197
197
|
icon: '1000',
|
|
198
198
|
repeat: 5,
|
|
199
199
|
duration: 3000,
|
|
200
|
-
effect:
|
|
200
|
+
effect: awtrix.Effects.TwinklingStars,
|
|
201
201
|
scrollSpeed: 150,
|
|
202
202
|
});
|
|
203
203
|
```
|
|
@@ -207,7 +207,7 @@ await clock.app('demoApp', {
|
|
|
207
207
|
Launch an app by name.
|
|
208
208
|
|
|
209
209
|
```typescript
|
|
210
|
-
await
|
|
210
|
+
await awtrix.launchApp('demoApp');
|
|
211
211
|
```
|
|
212
212
|
|
|
213
213
|
#### nextApp(), previousApp()
|
|
@@ -215,9 +215,9 @@ await clock.launchApp('demoApp');
|
|
|
215
215
|
Switch between apps.
|
|
216
216
|
|
|
217
217
|
```typescript
|
|
218
|
-
await
|
|
218
|
+
await awtrix.nextApp();
|
|
219
219
|
await setTimeout(2000);
|
|
220
|
-
await
|
|
220
|
+
await awtrix.previousApp();
|
|
221
221
|
```
|
|
222
222
|
|
|
223
223
|
#### Progress Bar Example
|
|
@@ -227,16 +227,16 @@ Display a progress bar using a custom app:
|
|
|
227
227
|
```typescript
|
|
228
228
|
for (let i = 0; i <= 100; i++) {
|
|
229
229
|
if (i % 5 === 0) {
|
|
230
|
-
await
|
|
230
|
+
await awtrix.app('Progress', {
|
|
231
231
|
text: `${i}%`,
|
|
232
232
|
progress: i,
|
|
233
233
|
duration: 1,
|
|
234
234
|
});
|
|
235
235
|
if (i === 0) {
|
|
236
|
-
await
|
|
236
|
+
await awtrix.launchApp('Progress');
|
|
237
237
|
}
|
|
238
238
|
if (i === 100) {
|
|
239
|
-
await
|
|
239
|
+
await awtrix.app('Progress', {
|
|
240
240
|
text: `Done!`,
|
|
241
241
|
color: [0, 255, 0],
|
|
242
242
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "awtrix-ts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "TypeScript API for Awtrix LED Matrix Display",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,13 +20,12 @@
|
|
|
20
20
|
"src/**/*.d.ts"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"build": "tsc"
|
|
24
|
-
"prepublishOnly": "npm run build"
|
|
23
|
+
"build": "tsc"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
26
|
+
"@types/node": "^25.0.3",
|
|
27
27
|
"eslint": "^9.39.2",
|
|
28
28
|
"eslint-config": "github:7digital/eslint-config",
|
|
29
|
-
"@types/node": "^25.0.3",
|
|
30
29
|
"typescript": "^5.9.3"
|
|
31
30
|
}
|
|
32
31
|
}
|
package/dist/api.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import * as interaction from './interaction.js';
|
|
2
|
-
import * as transitions from './transitions.js';
|
|
3
|
-
import * as indicators from './indicators.js';
|
|
4
|
-
import * as settings from './settings.js';
|
|
5
|
-
import * as stats from './stats.js';
|
|
6
|
-
import * as moodlight from './moodlight.js';
|
|
7
|
-
declare class Awtrix {
|
|
8
|
-
#private;
|
|
9
|
-
url: string;
|
|
10
|
-
Transitions: {
|
|
11
|
-
readonly Random: 0;
|
|
12
|
-
readonly Slide: 1;
|
|
13
|
-
readonly Dim: 2;
|
|
14
|
-
readonly Zoom: 3;
|
|
15
|
-
readonly Rotate: 4;
|
|
16
|
-
readonly Pixelate: 5;
|
|
17
|
-
readonly Curtain: 6;
|
|
18
|
-
readonly Ripple: 7;
|
|
19
|
-
readonly Blink: 8;
|
|
20
|
-
readonly Reload: 9;
|
|
21
|
-
readonly Fade: 10;
|
|
22
|
-
};
|
|
23
|
-
Indicators: {
|
|
24
|
-
readonly UpperRight: 1;
|
|
25
|
-
readonly CenterRight: 2;
|
|
26
|
-
readonly BottomRight: 3;
|
|
27
|
-
};
|
|
28
|
-
Effects: {
|
|
29
|
-
readonly BrickBreaker: "BrickBreaker";
|
|
30
|
-
readonly Checkerboard: "Checkerboard";
|
|
31
|
-
readonly Fireworks: "Fireworks";
|
|
32
|
-
readonly PingPong: "PingPong";
|
|
33
|
-
readonly Radar: "Radar";
|
|
34
|
-
readonly Ripple: "Ripple";
|
|
35
|
-
readonly Snake: "Snake";
|
|
36
|
-
readonly TwinklingStars: "TwinklingStars";
|
|
37
|
-
readonly TheaterChase: "TheaterChase";
|
|
38
|
-
readonly ColorWaves: "ColorWaves";
|
|
39
|
-
readonly SwirlOut: "SwirlOut";
|
|
40
|
-
readonly SwirlIn: "SwirlIn";
|
|
41
|
-
readonly LookingEyes: "LookingEyes";
|
|
42
|
-
readonly Matrix: "Matrix";
|
|
43
|
-
readonly Pacifica: "Pacifica";
|
|
44
|
-
readonly Plasma: "Plasma";
|
|
45
|
-
readonly PlasmaCloud: "PlasmaCloud";
|
|
46
|
-
readonly MovingLine: "MovingLine";
|
|
47
|
-
readonly Fade: "Fade";
|
|
48
|
-
};
|
|
49
|
-
PushIcon: {
|
|
50
|
-
readonly Static: 0;
|
|
51
|
-
readonly MoveOnce: 1;
|
|
52
|
-
readonly MoveRepeat: 2;
|
|
53
|
-
};
|
|
54
|
-
constructor(url: URL);
|
|
55
|
-
power(power: boolean): Promise<void>;
|
|
56
|
-
sleep(time: number): Promise<void>;
|
|
57
|
-
reboot(): Promise<void>;
|
|
58
|
-
settings(settings: settings.Settings): Promise<void>;
|
|
59
|
-
resetDefaultSettings(): Promise<void>;
|
|
60
|
-
erase(): Promise<void>;
|
|
61
|
-
screen(): Promise<string>;
|
|
62
|
-
stats(): Promise<stats.Stats>;
|
|
63
|
-
effects(): Promise<interaction.Effect[]>;
|
|
64
|
-
transitions(): Promise<transitions.Transitions[]>;
|
|
65
|
-
loop(): Promise<{
|
|
66
|
-
[app: string]: number;
|
|
67
|
-
}>;
|
|
68
|
-
playMelody(rtttl: string): Promise<void>;
|
|
69
|
-
playMelodyFile(name: string): Promise<void>;
|
|
70
|
-
setIndicator(indicator: indicators.IndicatorPayload): Promise<void>;
|
|
71
|
-
clearIndicator(indicator: indicators.Indicators): Promise<void>;
|
|
72
|
-
moodlight(setting: moodlight.MoodlightColor | moodlight.MoodlightKelvin): Promise<void>;
|
|
73
|
-
clearMoodlight(): Promise<void>;
|
|
74
|
-
notify(notification: interaction.Interaction): Promise<void>;
|
|
75
|
-
dismissNotification(): Promise<void>;
|
|
76
|
-
app(name: string, app: interaction.Interaction): Promise<void>;
|
|
77
|
-
launchApp(name: string): Promise<void>;
|
|
78
|
-
nextApp(): Promise<void>;
|
|
79
|
-
previousApp(): Promise<void>;
|
|
80
|
-
get(endpoint: string): Promise<any>;
|
|
81
|
-
post(endpoint: string, data?: object): Promise<void>;
|
|
82
|
-
}
|
|
83
|
-
export { Awtrix };
|
package/dist/api.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from 'node:timers/promises';
|
|
2
|
-
import * as interaction from './interaction.js';
|
|
3
|
-
import * as transitions from './transitions.js';
|
|
4
|
-
import * as indicators from './indicators.js';
|
|
5
|
-
class Awtrix {
|
|
6
|
-
#bootTime = 15 * 1000;
|
|
7
|
-
url;
|
|
8
|
-
Transitions = transitions.Transition;
|
|
9
|
-
Indicators = indicators.Indicator;
|
|
10
|
-
Effects = interaction.Effect;
|
|
11
|
-
PushIcon = interaction.PushIcon;
|
|
12
|
-
constructor(url) {
|
|
13
|
-
this.url = url.href + 'api';
|
|
14
|
-
}
|
|
15
|
-
async power(power) {
|
|
16
|
-
await this.post('power', { power });
|
|
17
|
-
}
|
|
18
|
-
async sleep(time) {
|
|
19
|
-
await Promise.all([
|
|
20
|
-
await this.post('sleep', { sleep: time }),
|
|
21
|
-
await setTimeout((time * 1000) + this.#bootTime)
|
|
22
|
-
]);
|
|
23
|
-
}
|
|
24
|
-
async reboot() {
|
|
25
|
-
await Promise.all([
|
|
26
|
-
await this.post('reboot'),
|
|
27
|
-
await setTimeout(this.#bootTime)
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
30
|
-
async settings(settings) {
|
|
31
|
-
await this.post('settings', {
|
|
32
|
-
ATIME: settings.appTime,
|
|
33
|
-
TEFF: settings.transitionEffect,
|
|
34
|
-
TSPEED: settings.transitionSpeed,
|
|
35
|
-
TCOL: settings.globalTextColor,
|
|
36
|
-
TMODE: settings.timeAppStyle,
|
|
37
|
-
CHCOL: settings.calendarHeaderColor,
|
|
38
|
-
CBCOL: settings.calendarBodyColor,
|
|
39
|
-
CTCOL: settings.calendarTextColor,
|
|
40
|
-
WD: settings.weekdayDisplay,
|
|
41
|
-
WDCA: settings.activeWeekdayColor,
|
|
42
|
-
WDCI: settings.inactiveWeekdayColor,
|
|
43
|
-
BRI: settings.matrixBrightness,
|
|
44
|
-
ABRI: settings.automaticBrightnessControl,
|
|
45
|
-
ATRANS: settings.automaticAppSwitching,
|
|
46
|
-
CCORRECTION: settings.colorCorrection,
|
|
47
|
-
CTEMP: settings.colorTemperature,
|
|
48
|
-
TFORMAT: settings.timeFormat,
|
|
49
|
-
DFORMAT: settings.dateFormat,
|
|
50
|
-
SOM: settings.startWeekOnMonday,
|
|
51
|
-
CEL: settings.celsiusTemperature,
|
|
52
|
-
BLOCKN: settings.blockNavigationKeys,
|
|
53
|
-
UPPERCASE: settings.uppercaseText,
|
|
54
|
-
TIME_COL: settings.timeAppTextColor,
|
|
55
|
-
DATE_COL: settings.dateAppTextColor,
|
|
56
|
-
TEMP_COL: settings.temperatureAppTextColor,
|
|
57
|
-
HUM_COL: settings.humidityAppTextColor,
|
|
58
|
-
BAT_COL: settings.batteryAppTextColor,
|
|
59
|
-
SSPEED: settings.scrollSpeedModification,
|
|
60
|
-
TIM: settings.enableTimeApp,
|
|
61
|
-
DAT: settings.enableDateApp,
|
|
62
|
-
HUM: settings.enableHumidityApp,
|
|
63
|
-
TEMP: settings.enableTemperatureApp,
|
|
64
|
-
BAT: settings.enableBatteryApp,
|
|
65
|
-
MATP: settings.matrixPower,
|
|
66
|
-
VOL: settings.volume,
|
|
67
|
-
OVERLAY: settings.globalEffectOverlay
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
async resetDefaultSettings() {
|
|
71
|
-
await this.post('resetSettings');
|
|
72
|
-
}
|
|
73
|
-
async erase() {
|
|
74
|
-
await this.post('erase');
|
|
75
|
-
}
|
|
76
|
-
async screen() {
|
|
77
|
-
return this.get('screen');
|
|
78
|
-
}
|
|
79
|
-
async stats() {
|
|
80
|
-
return this.get('stats');
|
|
81
|
-
}
|
|
82
|
-
async effects() {
|
|
83
|
-
return this.get('effects');
|
|
84
|
-
}
|
|
85
|
-
async transitions() {
|
|
86
|
-
return this.get('transitions');
|
|
87
|
-
}
|
|
88
|
-
async loop() {
|
|
89
|
-
return this.get('loop');
|
|
90
|
-
}
|
|
91
|
-
async playMelody(rtttl) {
|
|
92
|
-
await this.post('rtttl', { rtttl });
|
|
93
|
-
}
|
|
94
|
-
async playMelodyFile(name) {
|
|
95
|
-
await this.post('sound', { sound: name });
|
|
96
|
-
}
|
|
97
|
-
async setIndicator(indicator) {
|
|
98
|
-
await this.post('indicator' + indicator.position, {
|
|
99
|
-
color: indicator.color,
|
|
100
|
-
blink: indicator.blink,
|
|
101
|
-
fade: indicator.fade
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
async clearIndicator(indicator) {
|
|
105
|
-
await this.post('indicator' + indicator);
|
|
106
|
-
}
|
|
107
|
-
async moodlight(setting) {
|
|
108
|
-
await this.post('moodlight', setting);
|
|
109
|
-
}
|
|
110
|
-
async clearMoodlight() {
|
|
111
|
-
await this.post('moodlight');
|
|
112
|
-
}
|
|
113
|
-
async notify(notification) {
|
|
114
|
-
await this.post('notify', notification);
|
|
115
|
-
}
|
|
116
|
-
async dismissNotification() {
|
|
117
|
-
await this.post('notify/dismiss');
|
|
118
|
-
}
|
|
119
|
-
async app(name, app) {
|
|
120
|
-
await this.post(`custom?name=${name}`, app);
|
|
121
|
-
}
|
|
122
|
-
async launchApp(name) {
|
|
123
|
-
await this.post('switch', { name });
|
|
124
|
-
}
|
|
125
|
-
async nextApp() {
|
|
126
|
-
await this.post('nextapp');
|
|
127
|
-
}
|
|
128
|
-
async previousApp() {
|
|
129
|
-
await this.post('previousapp');
|
|
130
|
-
}
|
|
131
|
-
async get(endpoint) {
|
|
132
|
-
const response = await fetch(`${this.url}/${endpoint}`);
|
|
133
|
-
const data = await response.json();
|
|
134
|
-
return data;
|
|
135
|
-
}
|
|
136
|
-
async post(endpoint, data) {
|
|
137
|
-
await fetch(`${this.url}/${endpoint}`, {
|
|
138
|
-
method: 'POST',
|
|
139
|
-
headers: {
|
|
140
|
-
'Content-Type': 'application/json',
|
|
141
|
-
},
|
|
142
|
-
...(data ? { body: JSON.stringify(data) } : {}),
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
export { Awtrix };
|
package/dist/demo.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/demo.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from 'node:timers/promises';
|
|
2
|
-
import { Awtrix } from './api.js';
|
|
3
|
-
const clockUrl = 'http://SOME_IP_ADDRESS'; // Replace with your Awtrix clock IP address
|
|
4
|
-
const clock = new Awtrix(new URL(clockUrl));
|
|
5
|
-
// Get status
|
|
6
|
-
console.log(await clock.stats());
|
|
7
|
-
// Get app loop
|
|
8
|
-
console.log(await clock.loop());
|
|
9
|
-
// Power on/off
|
|
10
|
-
await clock.power(true);
|
|
11
|
-
await clock.power(false);
|
|
12
|
-
// Hibernate
|
|
13
|
-
await clock.sleep(5);
|
|
14
|
-
// Switch apps
|
|
15
|
-
await clock.nextApp();
|
|
16
|
-
await setTimeout(2000);
|
|
17
|
-
await clock.previousApp();
|
|
18
|
-
// Change settings
|
|
19
|
-
await clock.settings({
|
|
20
|
-
automaticAppSwitching: false,
|
|
21
|
-
globalTextColor: [0, 255, 0],
|
|
22
|
-
// ...other settings
|
|
23
|
-
});
|
|
24
|
-
// Set/clear indicators
|
|
25
|
-
await clock.setIndicator({
|
|
26
|
-
color: [255, 0, 0],
|
|
27
|
-
position: clock.Indicators.UpperRight,
|
|
28
|
-
// blink: 500, // blink every 500ms
|
|
29
|
-
// fade: 1000, // fade in duration 1000ms
|
|
30
|
-
});
|
|
31
|
-
await setTimeout(3000);
|
|
32
|
-
await clock.clearIndicator(clock.Indicators.UpperRight);
|
|
33
|
-
// Send a notification
|
|
34
|
-
await clock.notify({
|
|
35
|
-
text: 'Hello World!',
|
|
36
|
-
icon: '3049',
|
|
37
|
-
pushIcon: clock.PushIcon.MoveOnce,
|
|
38
|
-
effect: clock.Effects.PlasmaCloud,
|
|
39
|
-
repeat: 5
|
|
40
|
-
});
|
|
41
|
-
await setTimeout(10000);
|
|
42
|
-
// Dismiss a notification
|
|
43
|
-
await clock.dismissNotification();
|
|
44
|
-
// Create/update a custom app
|
|
45
|
-
await clock.app('demoApp', {
|
|
46
|
-
text: 'This is a custom app!',
|
|
47
|
-
icon: '1000',
|
|
48
|
-
repeat: 5,
|
|
49
|
-
duration: 3000,
|
|
50
|
-
effect: clock.Effects.TwinklingStars,
|
|
51
|
-
scrollSpeed: 150
|
|
52
|
-
});
|
|
53
|
-
// Launch the custom app
|
|
54
|
-
await clock.launchApp('demoApp');
|
|
55
|
-
await setTimeout(20000);
|
|
56
|
-
// Display progress bar
|
|
57
|
-
for (let i = 0; i <= 100; i++) {
|
|
58
|
-
if (i % 5 === 0) {
|
|
59
|
-
await clock.app('Progress', {
|
|
60
|
-
text: `${i}%`,
|
|
61
|
-
progress: i,
|
|
62
|
-
duration: 1,
|
|
63
|
-
});
|
|
64
|
-
if (i === 0) {
|
|
65
|
-
await clock.launchApp('Progress');
|
|
66
|
-
}
|
|
67
|
-
if (i === 100) {
|
|
68
|
-
await clock.app('Progress', {
|
|
69
|
-
text: `Done!`,
|
|
70
|
-
color: [0, 255, 0],
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
await setTimeout(500);
|
|
74
|
-
}
|
|
75
|
-
}
|