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
use super::divoom_dto_common::*;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::collections::BTreeMap;
use std::fmt;
use std::str::FromStr;
/// Definition of image animations.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DivoomImageAnimation {
/// Id of the Animation to create/update. Returned by `get_next_animation_id()`.
pub id: i32,
/// Size of canvas. Only 16, 32, 64 are supported
pub size: i32,
/// The total number of frames in entire animation
pub frame_count: i32,
/// Animation play speed, in ms.
pub speed_in_ms: i32,
/// Offset to frame data map.
/// We use this format, because Divoom support only updating a single frame at a time, so we don't need to use vector and update all frames.
pub frames: BTreeMap<i32, DivoomImageAnimationFrameData>,
}
/// The data of this frame. It is a base64 encoded RGB data.
///
/// The decoded data format looks like below, which goes row by row and column by column, from left to right and top to down,
/// e.g.: (0, 0), (0, 1), (0, 2), ..., (1, 0), (1, 1), (1, 2), ..., (2, 0), (2, 1), (2, 2), ...
///
/// Hex data format looks like below:
/// ```text
/// RR GG BB RR GG BB RR GG BB ......
/// ```
pub type DivoomImageAnimationFrameData = String;
/// Type of the image animations file source.
#[derive(Debug, PartialOrd, PartialEq)]
pub enum DivoomFileAnimationSourceType {
LocalFile,
LocalFolder,
Url,
Raw(i32),
}
impl_divoom_dto_enum_traits!(DivoomFileAnimationSourceType, LocalFile: "file", LocalFolder: "folder", Url: "url");