1#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum AlsGain {
6 Gain1x,
8 Gain2x,
10 Gain4x,
12 Gain8x,
14 Gain48x,
16 Gain96x,
18}
19
20impl Default for AlsGain {
22 fn default() -> Self {
23 AlsGain::Gain1x
24 }
25}
26
27impl AlsGain {
28 pub fn value(&self) -> u8 {
30 const BIT_OFFSET: u8 = 2;
31 match *self {
32 AlsGain::Gain1x => 0 << BIT_OFFSET,
33 AlsGain::Gain2x => 1 << BIT_OFFSET,
34 AlsGain::Gain4x => 2 << BIT_OFFSET,
35 AlsGain::Gain8x => 3 << BIT_OFFSET,
36 AlsGain::Gain48x => 6 << BIT_OFFSET,
37 AlsGain::Gain96x => 7 << BIT_OFFSET,
38 }
39 }
40
41 pub fn lux_compute_value(&self) -> f32 {
43 match *self {
44 AlsGain::Gain1x => 1.0,
45 AlsGain::Gain2x => 2.0,
46 AlsGain::Gain4x => 4.0,
47 AlsGain::Gain8x => 8.0,
48 AlsGain::Gain48x => 48.0,
49 AlsGain::Gain96x => 96.0,
50 }
51 }
52}
53
54#[derive(Debug, Clone, Copy, PartialEq)]
56pub enum LedPulse {
57 Pulse30,
59 Pulse40,
61 Pulse50,
63 Pulse60,
65 Pulse70,
67 Pulse80,
69 Pulse90,
71 Pulse100,
73}
74
75impl Default for LedPulse {
76 fn default() -> Self {
77 LedPulse::Pulse60
78 }
79}
80
81impl LedPulse {
83 pub fn value(&self) -> u8 {
85 const BIT_OFFSET: u8 = 5;
86 match *self {
87 LedPulse::Pulse30 => 0 << BIT_OFFSET,
88 LedPulse::Pulse40 => 1 << BIT_OFFSET,
89 LedPulse::Pulse50 => 2 << BIT_OFFSET,
90 LedPulse::Pulse60 => 3 << BIT_OFFSET,
91 LedPulse::Pulse70 => 4 << BIT_OFFSET,
92 LedPulse::Pulse80 => 5 << BIT_OFFSET,
93 LedPulse::Pulse90 => 6 << BIT_OFFSET,
94 LedPulse::Pulse100 => 7 << BIT_OFFSET,
95 }
96 }
97}
98
99#[derive(Debug, Clone, Copy, PartialEq)]
101pub enum LedDutyCycle {
102 _25,
104 _50,
106 _75,
108 _100,
110}
111
112impl Default for LedDutyCycle {
113 fn default() -> Self {
114 LedDutyCycle::_100
115 }
116}
117
118impl LedDutyCycle {
119 pub fn value(&self) -> u8 {
121 const BIT_OFFSET: u8 = 3;
122 match *self {
123 LedDutyCycle::_25 => 0 << BIT_OFFSET,
124 LedDutyCycle::_50 => 1 << BIT_OFFSET,
125 LedDutyCycle::_75 => 2 << BIT_OFFSET,
126 LedDutyCycle::_100 => 3 << BIT_OFFSET,
127 }
128 }
129}
130
131#[derive(Debug, Clone, Copy, PartialEq)]
133pub enum LedCurrent {
134 _5mA,
136 _10mA,
138 _20mA,
140 _50mA,
142 _100mA,
144}
145
146impl Default for LedCurrent {
147 fn default() -> Self {
148 LedCurrent::_100mA
149 }
150}
151
152impl LedCurrent {
153 pub fn value(&self) -> u8 {
155 match *self {
156 LedCurrent::_5mA => 0,
157 LedCurrent::_10mA => 1,
158 LedCurrent::_20mA => 2,
159 LedCurrent::_50mA => 3,
160 LedCurrent::_100mA => 7,
161 }
162 }
163}
164
165#[derive(Debug, Clone, Copy, PartialEq)]
167pub enum PsMeasRate {
168 _50ms,
170 _70ms,
172 _100ms,
174 _200ms,
176 _500ms,
178 _1000ms,
180 _2000ms,
182 _10ms,
184}
185
186impl Default for PsMeasRate {
187 fn default() -> Self {
188 PsMeasRate::_100ms
189 }
190}
191
192impl PsMeasRate {
193 pub fn value(&self) -> u8 {
195 match *self {
196 PsMeasRate::_10ms => 8,
197 PsMeasRate::_50ms => 0,
198 PsMeasRate::_70ms => 1,
199 PsMeasRate::_100ms => 2,
200 PsMeasRate::_200ms => 3,
201 PsMeasRate::_500ms => 4,
202 PsMeasRate::_1000ms => 5,
203 PsMeasRate::_2000ms => 6,
204 }
205 }
206}
207
208#[derive(Debug, Clone, Copy, PartialEq)]
210pub enum AlsMeasRate {
211 _50ms,
213 _100ms,
215 _200ms,
217 _500ms,
219 _1000ms,
221 _2000ms,
223}
224
225impl Default for AlsMeasRate {
226 fn default() -> Self {
227 AlsMeasRate::_500ms
228 }
229}
230
231impl AlsMeasRate {
232 pub fn value(&self) -> u8 {
234 match *self {
235 AlsMeasRate::_50ms => 0,
236 AlsMeasRate::_100ms => 1,
237 AlsMeasRate::_200ms => 2,
238 AlsMeasRate::_500ms => 3,
239 AlsMeasRate::_1000ms => 4,
240 AlsMeasRate::_2000ms => 7,
241 }
242 }
243}
244
245#[derive(Debug, Clone, Copy, PartialEq)]
247pub enum AlsIntTime {
248 _50ms,
250 _100ms,
252 _150ms,
254 _200ms,
256 _250ms,
258 _300ms,
260 _350ms,
262 _400ms,
264}
265
266impl Default for AlsIntTime {
267 fn default() -> Self {
268 AlsIntTime::_100ms
269 }
270}
271
272impl AlsIntTime {
273 pub fn value(&self) -> u8 {
275 match *self {
276 AlsIntTime::_100ms => 0,
277 AlsIntTime::_50ms => 1,
278 AlsIntTime::_200ms => 2,
279 AlsIntTime::_400ms => 3,
280 AlsIntTime::_150ms => 4,
281 AlsIntTime::_250ms => 5,
282 AlsIntTime::_300ms => 6,
283 AlsIntTime::_350ms => 7,
284 }
285 }
286
287 pub fn lux_compute_value(&self) -> f32 {
289 match *self {
290 AlsIntTime::_100ms => 1.0,
291 AlsIntTime::_50ms => 0.5,
292 AlsIntTime::_200ms => 2.0,
293 AlsIntTime::_400ms => 4.0,
294 AlsIntTime::_150ms => 1.5,
295 AlsIntTime::_250ms => 2.5,
296 AlsIntTime::_300ms => 3.0,
297 AlsIntTime::_350ms => 3.5,
298 }
299 }
300}
301
302#[derive(Debug, Clone, Copy, PartialEq)]
304pub enum AlsPersist {
305 EveryTime,
307 _2v,
309 _3v,
311 _4v,
313 _5v,
315 _6v,
317 _7v,
319 _8v,
321 _9v,
323 _10v,
325 _11v,
327 _12v,
329 _13v,
331 _14v,
333 _15v,
335 _16v,
337}
338
339impl Default for AlsPersist {
340 fn default() -> Self {
341 AlsPersist::EveryTime
342 }
343}
344
345impl AlsPersist {
346 pub fn value(&self) -> u8 {
348 match *self {
349 AlsPersist::EveryTime => 0,
350 AlsPersist::_2v => 1,
351 AlsPersist::_3v => 2,
352 AlsPersist::_4v => 3,
353 AlsPersist::_5v => 4,
354 AlsPersist::_6v => 5,
355 AlsPersist::_7v => 6,
356 AlsPersist::_8v => 7,
357 AlsPersist::_9v => 8,
358 AlsPersist::_10v => 9,
359 AlsPersist::_11v => 10,
360 AlsPersist::_12v => 11,
361 AlsPersist::_13v => 12,
362 AlsPersist::_14v => 13,
363 AlsPersist::_15v => 14,
364 AlsPersist::_16v => 15,
365 }
366 }
367}
368
369#[derive(Debug, Clone, Copy, PartialEq)]
371pub enum PsPersist {
372 EveryTime,
374 _2v,
376 _3v,
378 _4v,
380 _5v,
382 _6v,
384 _7v,
386 _8v,
388 _9v,
390 _10v,
392 _11v,
394 _12v,
396 _13v,
398 _14v,
400 _15v,
402 _16v,
404}
405
406impl Default for PsPersist {
407 fn default() -> Self {
408 PsPersist::EveryTime
409 }
410}
411
412impl PsPersist {
413 pub fn value(&self) -> u8 {
415 const BIT_OFFSET: u8 = 4;
416 match *self {
417 PsPersist::EveryTime => 0,
418 PsPersist::_2v => 1 << BIT_OFFSET,
419 PsPersist::_3v => 2 << BIT_OFFSET,
420 PsPersist::_4v => 3 << BIT_OFFSET,
421 PsPersist::_5v => 4 << BIT_OFFSET,
422 PsPersist::_6v => 5 << BIT_OFFSET,
423 PsPersist::_7v => 6 << BIT_OFFSET,
424 PsPersist::_8v => 7 << BIT_OFFSET,
425 PsPersist::_9v => 8 << BIT_OFFSET,
426 PsPersist::_10v => 9 << BIT_OFFSET,
427 PsPersist::_11v => 10 << BIT_OFFSET,
428 PsPersist::_12v => 11 << BIT_OFFSET,
429 PsPersist::_13v => 12 << BIT_OFFSET,
430 PsPersist::_14v => 13 << BIT_OFFSET,
431 PsPersist::_15v => 14 << BIT_OFFSET,
432 PsPersist::_16v => 15 << BIT_OFFSET,
433 }
434 }
435}
436
437#[derive(Debug, Clone, Copy, PartialEq)]
439pub enum InterruptMode {
440 Inactive,
442 OnlyPS,
444 OnlyALS,
446 Both,
448}
449
450impl Default for InterruptMode {
451 fn default() -> Self {
452 InterruptMode::Inactive
453 }
454}
455
456impl InterruptMode {
457 pub fn value(&self) -> u8 {
459 match *self {
460 InterruptMode::Inactive => 0,
461 InterruptMode::OnlyPS => 1,
462 InterruptMode::OnlyALS => 2,
463 InterruptMode::Both => 3,
464 }
465 }
466}