#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChannelType {
Eeg,
Aux,
Reference,
Ground,
}
#[derive(Debug, Clone)]
pub struct Channel {
pub index: usize,
pub name: String,
pub channel_type: ChannelType,
pub location: Option<String>,
}
impl Channel {
pub fn new(index: usize, name: impl Into<String>, channel_type: ChannelType) -> Self {
Self {
index,
name: name.into(),
channel_type,
location: None,
}
}
pub fn eeg(index: usize, name: impl Into<String>) -> Self {
Self::new(index, name, ChannelType::Eeg)
}
pub fn aux(index: usize, name: impl Into<String>) -> Self {
Self::new(index, name, ChannelType::Aux)
}
pub fn with_location(mut self, location: impl Into<String>) -> Self {
self.location = Some(location.into());
self
}
}
#[derive(Debug, Clone)]
pub struct ChannelConfig {
channels: Vec<Channel>,
}
impl ChannelConfig {
pub fn new(channels: Vec<Channel>) -> Self {
Self { channels }
}
pub fn simple(count: usize) -> Self {
let channels = (0..count)
.map(|i| Channel::eeg(i, format!("Ch{i}")))
.collect();
Self { channels }
}
pub fn muse() -> Self {
Self::new(vec![
Channel::eeg(0, "TP9").with_location("TP9"),
Channel::eeg(1, "AF7").with_location("AF7"),
Channel::eeg(2, "AF8").with_location("AF8"),
Channel::eeg(3, "TP10").with_location("TP10"),
])
}
pub fn muse_athena() -> Self {
Self::new(vec![
Channel::eeg(0, "TP9").with_location("TP9"),
Channel::eeg(1, "AF7").with_location("AF7"),
Channel::eeg(2, "AF8").with_location("AF8"),
Channel::eeg(3, "TP10").with_location("TP10"),
Channel::eeg(4, "AUX_1").with_location("AUX_1"),
Channel::eeg(5, "AUX_2").with_location("AUX_2"),
Channel::eeg(6, "AUX_3").with_location("AUX_3"),
Channel::eeg(7, "AUX_4").with_location("AUX_4"),
])
}
pub fn channels(&self) -> &[Channel] {
&self.channels
}
pub fn channel_count(&self) -> usize {
self.channels.len()
}
pub fn eeg_channels(&self) -> impl Iterator<Item = &Channel> {
self.channels
.iter()
.filter(|c| c.channel_type == ChannelType::Eeg)
}
pub fn eeg_channel_count(&self) -> usize {
self.eeg_channels().count()
}
pub fn get_by_name(&self, name: &str) -> Option<&Channel> {
self.channels.iter().find(|c| c.name == name)
}
pub fn get_by_index(&self, index: usize) -> Option<&Channel> {
self.channels.get(index)
}
}