divoom 0.1.42

Rust API for controlling divoom devices, like pixoo.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
use crate::dto::*;
use clap::{Args, Parser, Subcommand};

#[cfg(feature = "animation-builder")]
use crate::animation::*;

#[derive(Parser, Debug)]
#[clap(rename_all = "kebab-case")]
pub enum DivoomDeviceCommand {
    #[clap(subcommand, about = "Channel related APIs")]
    Channel(DivoomDeviceChannelCommand),

    #[clap(subcommand, about = "System/device related APIs")]
    System(DivoomDeviceSystemCommand),

    #[clap(subcommand, about = "APIs to launch some tools")]
    Tool(DivoomDeviceToolCommand),

    #[clap(subcommand, about = "Animation related APIs")]
    Animation(DivoomDeviceAnimationCommand),

    #[clap(subcommand, about = "Batch related APIs")]
    Batch(DivoomDeviceBatchCommand),

    #[clap(about = "Sending raw request")]
    Raw {
        #[clap(
            help = "Raw request body. Should be a valid JSON payload. Please refer to divoom's official API doc to check the format."
        )]
        request: String,
    },
}

#[derive(Subcommand, Debug)]
#[clap(rename_all = "kebab-case")]
pub enum DivoomDeviceChannelCommand {
    #[clap(about = "Set current channel")]
    Set {
        #[clap(help = "Channel type. It can be clock, cloud, visualizer and customPage.")]
        channel_type: DivoomChannelType,
    },

    #[clap(about = "Set current channel to clock")]
    SetClock {
        #[clap(help = "Clock id.")]
        clock_id: i32,
    },

    #[clap(about = "Set current channel to cloud channel")]
    SetCloudChannel {
        #[clap(help = "Cloud channel type. It can be gallery, fav and artist.")]
        channel_type: DivoomCloudChannelType,
    },

    #[clap(about = "Set current channel to custom page")]
    SetCustomPage {
        #[clap(help = "Custom page index. Can be 0-2.")]
        page_index: i32,
    },

    #[clap(about = "Set current channel to visualizer")]
    SetVisualizer {
        #[clap(help = "Visualizer index. Starting from 0.")]
        visualizer_index: i32,
    },
}

#[derive(Subcommand, Debug)]
pub enum DivoomDeviceSystemCommand {
    #[clap(about = "Set device brightness")]
    SetBrightness {
        #[clap(help = "Brightness (0-100)")]
        brightness: i32,
    },

    #[clap(about = "Set device time by UTC timestamp")]
    SetTime {
        #[clap(help = "Unix timestamp in UTC (in seconds)")]
        utc: u64,
    },

    #[clap(about = "Set device high light mode")]
    SetHighLightMode {
        #[clap(help = "High light mode. Can be on or off")]
        mode: DivoomDeviceHighLightMode,
    },

    #[clap(about = "Set device hour mode")]
    SetHourMode {
        #[clap(help = "Hour mode. Can be 12h or 24h")]
        mode: DivoomDeviceHourMode,
    },

    #[clap(about = "Set device mirror mode")]
    SetMirrorMode {
        #[clap(help = "Mirror mode. Can be on or off")]
        mode: DivoomDeviceMirrorMode,
    },

    #[clap(about = "Set device rotation angle")]
    SetRotationAngle {
        #[clap(help = "Screen rotation angle. Can be 0, 90, 180 and 270")]
        mode: DivoomDeviceRotationAngle,
    },

    #[clap(about = "Set device screen power state")]
    SetScreenPowerState {
        #[clap(help = "Screen power state, can be on or off")]
        power_state: DivoomDeviceScreenPowerState,
    },

    #[clap(about = "Set device temperature unit")]
    SetTemperatureUnit {
        #[clap(help = "Screen power state, can be c or f")]
        unit: DivoomDeviceTemperatureUnit,
    },

    #[clap(about = "Set device time zone")]
    SetTimeZone {
        #[clap(help = "Name of time zone")]
        time_zone: String,
    },

    #[clap(about = "Set device weather area")]
    SetWeatherArea {
        #[clap(allow_hyphen_values = true, help = "longitude")]
        longitude: String,

        #[clap(allow_hyphen_values = true, help = "latitude")]
        latitude: String,
    },

    #[clap(about = "Set device white balance")]
    SetWhiteBalance {
        #[clap(help = "Red, 0-255")]
        r: i32,

        #[clap(help = "Green, 0-255")]
        g: i32,

        #[clap(help = "Blue, 0-255")]
        b: i32,
    },
}

#[derive(Subcommand, Debug)]
pub enum DivoomDeviceToolCommand {
    #[clap(about = "Countdown tool")]
    Countdown {
        #[clap(help = "Action, can be start, stop")]
        action: DivoomToolCountdownAction,

        #[clap(value_parser, default_value_t = 0, help = "Number of minutes, 0-59")]
        minute: i32,

        #[clap(value_parser, default_value_t = 0, help = "Number of seconds, 0-59")]
        second: i32,
    },

    #[clap(about = "Noise tool")]
    Noise {
        #[clap(help = "Action, can be start, stop")]
        action: DivoomToolNoiseAction,
    },

    #[clap(about = "Scoreboard tool")]
    Scoreboard {
        #[clap(help = "Score of blue team")]
        blue_score: i32,

        #[clap(help = "Score of red team")]
        red_score: i32,
    },

    #[clap(about = "Stopwatch tool")]
    Stopwatch {
        #[clap(help = "Action, can be start, stop, reset")]
        action: DivoomToolStopwatchAction,
    },

    #[clap(about = "Play buzzer")]
    Buzzer {
        #[clap(default_value = "1000", help = "Total time to play in milliseconds")]
        play_total_time: i32,

        #[clap(
            short,
            default_value = "50",
            help = "Time to play in every buzz cycle in milliseconds"
        )]
        active_time_in_cycle: i32,

        #[clap(
            short,
            default_value = "100",
            help = "Time to off after every buzz in milliseconds"
        )]
        off_time_in_cycle: i32,
    },
}

#[derive(Subcommand, Debug)]
pub enum DivoomDeviceAnimationCommand {
    #[clap(subcommand, about = "Play GIF from Internet")]
    Gif(DivoomDeviceGifAnimationCommand),

    #[clap(subcommand, about = "Create image animation")]
    Image(DivoomDeviceImageAnimationCommand),

    #[clap(subcommand, about = "Create text animation")]
    Text(DivoomDeviceTextAnimationCommand),
}

#[derive(Subcommand, Debug)]
pub enum DivoomDeviceGifAnimationCommand {
    #[clap(about = "Play gif file. Only supports 16x16, 32x32, 64x64 gifs")]
    Play(DivoomDevicePlayGifAnimationCommandArgs),
}

#[derive(Args, Debug)]
pub struct DivoomDevicePlayGifAnimationCommandArgs {
    #[clap(
        long,
        help = "Specify a local file on *pixoo device*. Only supports 16x16, 32x32, 64x64 gifs"
    )]
    pub file: Option<String>,

    #[clap(
        long,
        help = "Specify a local folder on *pixoo device*. Only supports 16x16, 32x32, 64x64 gifs"
    )]
    pub folder: Option<String>,

    #[clap(
        long,
        help = "Specify a URL from Internet. Only supports 16x16, 32x32, 64x64 gifs"
    )]
    pub url: Option<String>,
}

#[derive(Subcommand, Debug)]
pub enum DivoomDeviceImageAnimationCommand {
    #[clap(about = "Reset next animation id")]
    ResetId,

    #[cfg(feature = "animation-builder")]
    #[clap(
        about = "Render gif as animation. This is different from \"gif play\" command, which is provided directly by Divoom device. This command will create a regular animation and render the specified file, then send to the device to play."
    )]
    RenderGif {
        #[clap(help = "Gif file path")]
        file_path: String,

        #[clap(
            default_value = "64",
            help = "Animation size in pixels. Only 16 and 32 and 64 are allowed."
        )]
        size: u32,

        #[clap(
            short,
            long = "speed",
            default_value = "100",
            help = "Animation play speed in milliseconds"
        )]
        speed_in_ms: u64,

        #[clap(
            short,
            long = "fit",
            default_value = "center",
            help = "Animation fit mode. Can be center, stretch, fitX and fitY"
        )]
        fit: DivoomDrawFitMode,

        #[clap(
            short,
            long = "rotate",
            default_value = "0.0",
            help = "Animation rotate angle"
        )]
        rotation: f32,

        #[clap(
            short,
            long = "opacity",
            default_value = "1.0",
            help = "Animation opacity"
        )]
        opacity: f32,
    },

    #[cfg(feature = "animation-builder")]
    #[clap(
        about = "Render file as animation. This is different from \"gif play\" command, which is provided directly by Divoom device. This command will create a regular animation and render the specified files one at a time, then send to the device to play."
    )]
    RenderFiles {
        #[clap(help = "File glob")]
        file_pattern: String,

        #[clap(
            default_value = "64",
            help = "Animation size in pixels. Only 16 and 32 and 64 are allowed."
        )]
        size: u32,

        #[clap(
            short,
            long = "speed",
            default_value = "100",
            help = "Animation play speed in milliseconds"
        )]
        speed_in_ms: u64,

        #[clap(
            short,
            long = "fit",
            default_value = "center",
            help = "Animation fit mode. Can be center, stretch, fitX and fitY"
        )]
        fit: DivoomDrawFitMode,

        #[clap(
            short,
            long = "rotate",
            default_value = "0.0",
            help = "Animation rotate angle"
        )]
        rotation: f32,

        #[clap(
            short,
            long = "opacity",
            default_value = "1.0",
            help = "Animation opacity"
        )]
        opacity: f32,

        #[clap(long = "random", help = "Render in random order")]
        random: bool,

        #[clap(
            short,
            long = "prefetch",
            value_parser,
            default_value_t = 10,
            help = "Number of gifs to prefetch to memory."
        )]
        prefetch_count: usize,
    },

    #[cfg(feature = "animation-builder")]
    #[clap(
        about = "Render animation template. This is different from \"gif play\" command, which is provided directly by Divoom device. This command will create a regular animation and render the specified template, then send to the device to play."
    )]
    RenderTemplate {
        #[clap(help = "Template name")]
        template_name: String,

        #[clap(
            short,
            long,
            default_value = "{}",
            help = "Template parameters. We use a string to string json dictionary as the format. E.g. {\"foo\":\"bar\"}"
        )]
        parameters: String,

        #[clap(
            short,
            long,
            default_value = "{}",
            help = "Per frame template parameters. We use a 0-indexed int to string to string json dictionary as the format. E.g. {0:{\"foo\":\"bar\"},1:{\"foo\":\"bar2\"}}"
        )]
        per_frame_parameters: String,
    },
}

#[derive(Subcommand, Debug)]
pub enum DivoomDeviceTextAnimationCommand {
    #[clap(about = "Clear all text area")]
    Clear,

    #[clap(about = "Send text animation.")]
    Set(DivoomDeviceTextAnimationCommandArgs),
}

#[derive(Args, Debug)]
pub struct DivoomDeviceTextAnimationCommandArgs {
    #[clap(help = "Text id to create/update. Must be <= 20.")]
    pub text_id: i32,

    #[clap(short, default_value = "0", help = "Start position x.")]
    pub x: i32,

    #[clap(short, default_value = "0", help = "Start position y.")]
    pub y: i32,

    #[clap(
        short = 'd',
        default_value = "left",
        help = "Scroll direction, can be left, right."
    )]
    pub scroll_direction: DivoomTextAnimationScrollDirection,

    #[clap(
        short,
        default_value = "0",
        help = "0-7: font id in app. Divoom only has 8 fonts."
    )]
    pub font_index: i32,

    #[clap(
        short = 'w',
        long = "width",
        default_value = "16",
        help = "Text size. Must be >= 16 and <= 64."
    )]
    pub text_width: i32,

    #[clap(
        short = 's',
        long = "speed",
        default_value = "100",
        help = "Speed of each animation step (scroll) in milliseconds."
    )]
    pub speed_in_ms: i32,

    #[clap(help = "Text data")]
    pub text_string: String,

    #[clap(short, default_value = "255", help = "Font color, red.")]
    pub r: u8,

    #[clap(short, default_value = "255", help = "Font color, green.")]
    pub g: u8,

    #[clap(short, default_value = "255", help = "Font color, blue.")]
    pub b: u8,

    #[clap(
        short = 'a',
        default_value = "middle",
        help = "Text align. Can be left, middle, right."
    )]
    pub align: DivoomTextAnimationAlign,
}

impl DivoomDeviceTextAnimationCommandArgs {
    pub fn as_animation(&self) -> DivoomTextAnimation {
        DivoomTextAnimation {
            text_id: self.text_id,
            x: self.x,
            y: self.y,
            scroll_direction: self.scroll_direction,
            font_index: self.font_index,
            text_width: self.text_width,
            speed_in_ms: self.speed_in_ms,
            text_string: self.text_string.to_string(),
            color: rgb::RGB8::new(self.r, self.g, self.b),
            align: self.align,
        }
    }
}

#[derive(Subcommand, Debug)]
pub enum DivoomDeviceBatchCommand {
    #[clap(about = "Run commands from a URL")]
    RunUrl {
        #[clap(help = "URL to the command list file")]
        command_url: String,
    },
}