ajazz_sdk/
info.rs

1use crate::{
2    protocol::codes,
3    images::{ImageFormat, ImageMirroring, ImageMode, ImageRotation},
4};
5
6/// Returns true for vendors IDs that are handled by the library
7pub const fn is_mirabox_vendor(vendor: u16) -> bool {
8    matches!(
9        vendor,
10        codes::VENDOR_ID_MIRABOX_V1 | codes::VENDOR_ID_MIRABOX_V2
11    )
12}
13
14/// Enum describing kinds of Ajazz devices
15#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
16pub enum Kind {
17    /// Ajazz AKP153
18    Akp153,
19    /// Ajazz AKP153E
20    Akp153E,
21    /// Ajazz AKP153R
22    Akp153R,
23    /// Ajazz AKP815
24    Akp815,
25    /// Ajazz AKP03
26    Akp03,
27    /// Ajazz AKP03E
28    Akp03E,
29    /// Ajazz AKP03R
30    Akp03R,
31    /// Ajazz AKP03R rev 2
32    Akp03RRev2,
33}
34
35impl Kind {
36    /// Creates [Kind] variant from Vendor ID and Product ID
37    pub const fn from_vid_pid(vid: u16, pid: u16) -> Option<Kind> {
38        match vid {
39            codes::VENDOR_ID_MIRABOX_V1 => match pid {
40                codes::PID_AJAZZ_AKP153 => Some(Kind::Akp153),
41                codes::PID_AJAZZ_AKP815 => Some(Kind::Akp815),
42                _ => None,
43            },
44
45            codes::VENDOR_ID_MIRABOX_V2 => match pid {
46                codes::PID_AJAZZ_AKP153E => Some(Kind::Akp153E),
47                codes::PID_AJAZZ_AKP153R => Some(Kind::Akp153R),
48                codes::PID_AJAZZ_AKP03 => Some(Kind::Akp03),
49                codes::PID_AJAZZ_AKP03E => Some(Kind::Akp03E),
50                codes::PID_AJAZZ_AKP03R => Some(Kind::Akp03R),
51                codes::PID_AJAZZ_AKP03R_REV2 => Some(Kind::Akp03RRev2),
52                _ => None,
53            },
54
55            _ => None,
56        }
57    }
58
59    /// Retrieves Product ID of the device
60    pub const fn product_id(&self) -> u16 {
61        match self {
62            Kind::Akp153 => codes::PID_AJAZZ_AKP153,
63            Kind::Akp153E => codes::PID_AJAZZ_AKP153E,
64            Kind::Akp153R => codes::PID_AJAZZ_AKP153R,
65            Kind::Akp815 => codes::PID_AJAZZ_AKP815,
66            Kind::Akp03 => codes::PID_AJAZZ_AKP03,
67            Kind::Akp03E => codes::PID_AJAZZ_AKP03E,
68            Kind::Akp03R => codes::PID_AJAZZ_AKP03R,
69            Kind::Akp03RRev2 => codes::PID_AJAZZ_AKP03R_REV2,
70        }
71    }
72
73    /// Retrieves Vendor ID
74    pub const fn vendor_id(&self) -> u16 {
75        match self {
76            Kind::Akp153 => codes::VENDOR_ID_MIRABOX_V1,
77            Kind::Akp153E => codes::VENDOR_ID_MIRABOX_V2,
78            Kind::Akp153R => codes::VENDOR_ID_MIRABOX_V2,
79            Kind::Akp815 => codes::VENDOR_ID_MIRABOX_V1,
80            Kind::Akp03 => codes::VENDOR_ID_MIRABOX_V2,
81            Kind::Akp03E => codes::VENDOR_ID_MIRABOX_V2,
82            Kind::Akp03R => codes::VENDOR_ID_MIRABOX_V2,
83            Kind::Akp03RRev2 => codes::VENDOR_ID_MIRABOX_V2,
84        }
85    }
86
87    /// Amount of keys the device has
88    pub const fn key_count(&self) -> u8 {
89        match self {
90            Kind::Akp153 | Kind::Akp153E | Kind::Akp153R => 15 + 3,
91            Kind::Akp815 => 15,
92            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2 => 6 + 3,
93        }
94    }
95
96    /// Amount of display keys the device has
97    pub const fn display_key_count(&self) -> u8 {
98        match self {
99            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2 => 6,
100            _ => self.key_count(),
101        }
102    }
103
104    /// Amount of button rows the device has
105    pub const fn row_count(&self) -> u8 {
106        match self {
107            Kind::Akp153 | Kind::Akp153E | Kind::Akp153R => 3,
108            Kind::Akp815 => 5,
109            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2 => 2,
110        }
111    }
112
113    /// Amount of button columns the device has
114    pub const fn column_count(&self) -> u8 {
115        match self {
116            Kind::Akp153 | Kind::Akp153E | Kind::Akp153R => 6,
117            Kind::Akp815 => 3,
118            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2 => 3,
119        }
120    }
121
122    /// Amount of encoders/knobs the device has
123    pub const fn encoder_count(&self) -> u8 {
124        match self {
125            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2 => 3,
126            _ => 0,
127        }
128    }
129
130    /// Size of the LCD strip on the device
131    pub const fn lcd_strip_size(&self) -> Option<(usize, usize)> {
132        match self {
133            Kind::Akp153 | Kind::Akp153E | Kind::Akp153R => Some((854, 480)),
134            Kind::Akp815 => Some((800, 480)),
135            _ => None,
136        }
137    }
138
139    /// Size of the boot logo on the device
140    pub const fn boot_logo_size(&self) -> Option<(usize, usize)> {
141        match self {
142            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2 => Some((320, 240)),
143            _ => self.lcd_strip_size(),
144        }
145    }
146
147    /// Key layout of the device kind as (rows, columns)
148    pub const fn key_layout(&self) -> (u8, u8) {
149        (self.row_count(), self.column_count())
150    }
151
152    /// Image format used by the device kind
153    pub const fn logo_image_format(&self) -> ImageFormat {
154        match self {
155            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2 => ImageFormat {
156                mode: ImageMode::JPEG,
157                size: (240, 320),
158                rotation: ImageRotation::Rot90,
159                mirror: ImageMirroring::None,
160            },
161
162            Kind::Akp153 | Kind::Akp153E | Kind::Akp153R => ImageFormat {
163                mode: ImageMode::JPEG,
164                size: (854, 480),
165                rotation: ImageRotation::Rot0,
166                mirror: ImageMirroring::None,
167            },
168
169            Kind::Akp815 => ImageFormat {
170                mode: ImageMode::JPEG,
171                size: (800, 480),
172                rotation: ImageRotation::Rot0,
173                mirror: ImageMirroring::None,
174            },
175        }
176    }
177
178    /// Image format used by the device kind
179    pub const fn key_image_format(&self) -> ImageFormat {
180        match self {
181            Kind::Akp153 | Kind::Akp153E | Kind::Akp153R => ImageFormat {
182                mode: ImageMode::JPEG,
183                size: (85, 85),
184                rotation: ImageRotation::Rot90,
185                mirror: ImageMirroring::Both,
186            },
187
188            Kind::Akp815 => ImageFormat {
189                mode: ImageMode::JPEG,
190                size: (100, 100),
191                rotation: ImageRotation::Rot180,
192                mirror: ImageMirroring::None,
193            },
194
195            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R => ImageFormat {
196                mode: ImageMode::JPEG,
197                size: (60, 60),
198                rotation: ImageRotation::Rot0,
199                mirror: ImageMirroring::None,
200            },
201
202            Kind::Akp03RRev2 => ImageFormat {
203                mode: ImageMode::JPEG,
204                size: (64, 64),
205                rotation: ImageRotation::Rot90,
206                mirror: ImageMirroring::None,
207            },
208        }
209    }
210
211    /// Returns true for devices with 512 byte packet length
212    pub const fn is_v1_api(&self) -> bool {
213        matches!(
214            self,
215            Kind::Akp153 | Kind::Akp153E | Kind::Akp153R | Kind::Akp815
216        )
217    }
218
219    /// Returns true for devices with 1024 byte packet length
220    pub const fn is_v2_api(&self) -> bool {
221        self.is_akp03()
222    }
223
224    /// Returns true for devices is Ajazz AKP03
225    pub const fn is_akp03(&self) -> bool {
226        matches!(
227            self,
228            Kind::Akp03 | Kind::Akp03E | Kind::Akp03R | Kind::Akp03RRev2
229        )
230    }
231}