Skip to content

Commit

Permalink
feat: Add feature flags and scene-based ANC mode enum
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallios committed Feb 25, 2024
1 parent 789a96b commit 91f9d63
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions soundcore-lib/src/models/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ pub enum SoundcoreFeatureFlags {
TOUCH_TONE,
GAME_MODE,
AUTO_POWER_OFF_ON,
// TODO: Rename
InEarBeep,
PromptLang,
HearingProtect,
AmbientSoundNotice,
PowerOnBatteryNotice,
SupportTwoCnn,
MultipleDeviceList
}
62 changes: 62 additions & 0 deletions soundcore-lib/src/models/scene_based_anc_mode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use serde::{Deserialize, Serialize};
use strum::{Display, FromRepr};

#[repr(u8)]
#[derive(
Debug,
Serialize,
Deserialize,
Eq,
PartialEq,
Ord,
PartialOrd,
Clone,
Copy,
Default,
FromRepr,
Display,
Hash,
)]
pub enum SceneBasedANCMode {
#[default]
Transport = 0,
Outdoor = 1,
Indoor = 2,
Custom = 3,
}

impl SceneBasedANCMode {
pub fn from_u8(value: u8) -> Option<Self> {
Self::from_repr(value)
}

pub fn as_u8(&self) -> u8 {
*self as u8
}
}

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

#[test]
fn init_from_u8() {
assert_eq!(SceneBasedANCMode::from_u8(0), Some(SceneBasedANCMode::Transport));
assert_eq!(SceneBasedANCMode::from_u8(1), Some(SceneBasedANCMode::Outdoor));
assert_eq!(SceneBasedANCMode::from_u8(2), Some(SceneBasedANCMode::Indoor));
assert_eq!(SceneBasedANCMode::from_u8(3), Some(SceneBasedANCMode::Custom));
}

#[test]
fn init_from_u8_invalid() {
assert_eq!(SceneBasedANCMode::from_u8(10), None);
}

#[test]
fn returns_value() {
assert_eq!(SceneBasedANCMode::Transport.as_u8(), 0);
assert_eq!(SceneBasedANCMode::Outdoor.as_u8(), 1);
assert_eq!(SceneBasedANCMode::Indoor.as_u8(), 2);
assert_eq!(SceneBasedANCMode::Custom.as_u8(), 3);
}
}

0 comments on commit 91f9d63

Please sign in to comment.