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
/// All possible errors in this crate
#[derive(Debug)]
pub enum Error<E> {
    /// I²C bus error
    I2C(E),
}

/// Wait time between each HRS conversion cycle
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ConversionDelay {
    /// 0 ms
    Ms0,
    /// 12.5 ms
    Ms12_5,
    /// 50 ms
    Ms50,
    /// 75 ms
    Ms75,
    /// 100 ms
    Ms100,
    /// 200 ms
    Ms200,
    /// 400 ms
    Ms400,
    /// 800 ms (default)
    Ms800,
}

impl Default for ConversionDelay {
    fn default() -> Self {
        ConversionDelay::Ms800
    }
}

/// HRS Gain
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Gain {
    /// 1x (default)
    One,
    /// 2x
    Two,
    /// 4x
    Four,
    /// 8x
    Eight,
    /// 64x
    SixtyFour,
}

impl Default for Gain {
    fn default() -> Self {
        Gain::One
    }
}

/// Ambient light sensor resolution
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AlsResolution {
    /// 8 bits (default)
    Bit8,
    /// 9 bits
    Bit9,
    /// 10 bits
    Bit10,
    /// 11 bits
    Bit11,
    /// 12 bits
    Bit12,
    /// 13 bits
    Bit13,
    /// 14 bits
    Bit14,
    /// 15 bits
    Bit15,
    /// 16 bits
    Bit16,
    /// 17 bits
    Bit17,
    /// 18 bits
    Bit18,
}

impl Default for AlsResolution {
    fn default() -> Self {
        AlsResolution::Bit8
    }
}

/// LED drive current
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LedCurrent {
    /// 12.5 mA (default)
    Ma12_5,
    /// 20 mA
    Ma20,
    /// 30 mA
    Ma30,
    /// 40 mA
    Ma40,
}

impl Default for LedCurrent {
    fn default() -> Self {
        LedCurrent::Ma12_5
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    macro_rules! default_test {
        ($name:ident, $type:ident, $default:ident) => {
            #[test]
            fn $name() {
                assert_eq!($type::$default, $type::default());
            }
        };
    }

    default_test!(default_conv_delay, ConversionDelay, Ms800);
    default_test!(default_gain, Gain, One);
    default_test!(default_als_res, AlsResolution, Bit8);
    default_test!(default_led_current, LedCurrent, Ma12_5);
}