settings/light/
light_hardware_configuration.rs

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
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use crate::config::default_settings::DefaultSetting;
use crate::inspect::config_logger::InspectConfigLogger;
use crate::light::types::LightType;
use serde::{Deserialize, Serialize};
use std::rc::Rc;
use std::sync::Mutex;

#[derive(PartialEq, Debug, Clone, Deserialize)]
pub struct LightHardwareConfiguration {
    /// List of light groups to surface to clients of the API.
    pub light_groups: Vec<LightGroupConfiguration>,
}

#[derive(PartialEq, Debug, Clone, Deserialize)]
pub struct LightGroupConfiguration {
    /// Name of the light group.
    ///
    /// Must be unique as this is the primary identifier for light groups.
    pub name: String,

    /// Each light in the underlying fuchsia.hardware.light API has a unique, fixed index. We need
    /// to remember the index of the lights in this light group in order to write values back.
    pub hardware_index: Vec<u32>,

    /// Type of values the light group supports, must match the underlying type of all the lights in
    /// the group.
    pub light_type: LightType,

    /// True if the values of this light group should be persisted across reboots and restored when
    /// the settings service starts.
    pub persist: bool,

    /// A list of conditions under which the "enabled" field of the light group should be false,
    /// which signals to clients the light's state is being overridden by external conditions, such
    /// as an LED dedicated to showing that a device's mic is muted that is off when the mic is not
    /// muted.
    ///
    /// Lights that are disabled can still have their value set, but the changes may not be
    /// noticeable to the user until the condition disabling/overriding ends.
    pub disable_conditions: Vec<DisableConditions>,
}

#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub enum DisableConditions {
    /// Signals that the light group should be marked as disabled when the device's mic switch is
    /// set to "on".
    MicSwitch,
}

pub fn build_light_default_settings(
    config_logger: Rc<Mutex<InspectConfigLogger>>,
) -> DefaultSetting<LightHardwareConfiguration, &'static str> {
    DefaultSetting::new(None, "/config/data/light_hardware_config.json", config_logger)
}