Skip to content

Commit 6d780f1

Browse files
committed
fix typos
1 parent 6c7b746 commit 6d780f1

File tree

6 files changed

+64
-62
lines changed

6 files changed

+64
-62
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "rustymind"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
authors = ["Junjun Dong <[email protected]>"]
55
edition = "2018"
6-
description = "A driver, parser and real time plotter for NeuroSky MindWave EGG headset"
6+
description = "A driver, parser and real time plotter for NeuroSky MindWave EEG headset"
77
license-file = "LICENSE.md"
88
documentation = "https://docs.rs/rustymind"
99
homepage = "https://github.com/junjunjd/rustymind"
1010
repository = "https://github.com/junjunjd/rustymind"
11-
keywords = ["brainwave", "neuroscience", "mindwave", "EGG", "NeuroSky"]
11+
keywords = ["brainwave", "neuroscience", "BCI", "EEG", "NeuroSky"]
1212

1313
[lib]
1414
name = "rustymind"

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![crates.io](https://img.shields.io/crates/v/rustymind.svg?style=flat-square)](https://crates.io/crates/rustymind)
44
[![api_doc](https://img.shields.io/badge/doc-api-blue)](https://docs.rs/rustymind)
55

6-
Rustymind is a driver and parser for NeuroSky MindWave EGG headset written in pure Rust. You can use it to connect, interact, and plot real time data from the headset.
6+
Rustymind is a driver and parser for NeuroSky MindWave EEG headset written in pure Rust. You can use it to connect, interact, and plot real time data from the headset.
77

88
The parser is based on the [mindwave mindset communication protocols](./docs) published by NeuroSky.
99

@@ -27,16 +27,16 @@ If you don't pass in the headset ID argument, the dongle will auto-connect to an
2727
To use `rustymind` as a library, you need to use `connect_headset` function and `Parser` struct. For example:
2828

2929
```rust
30-
use rustymind::{connect_headset, PacketType, Parser, HEADSETID_AUTOCONNECT};
30+
use rustymind::{connect_headset, PacketType, Parser};
3131

3232
let mut port = connect_headset("/dev/tty.usbserial-10000", b"\xa0\x5f")?;
33-
let mut temp: Vec<u8> = vec![0; 2048];
33+
let mut buffer: Vec<u8> = vec![0; 2048];
3434
let mut parser = Parser::new();
3535

3636
loop {
37-
let byte_buf = port.read(temp.as_mut_slice()).unwrap();
38-
for i in 0..byte_buf {
39-
if let Some(x) = parser.parse(temp[i]) {
37+
let bytes_read = port.read(buffer.as_mut_slice()).unwrap();
38+
for i in 0..bytes_read {
39+
if let Some(x) = parser.parse(buffer[i]) {
4040
for r in x {
4141
match r {
4242
PacketType::Attention(value) => {
@@ -45,8 +45,8 @@ loop {
4545
PacketType::Meditation(value) => {
4646
println!("Meditation value = {}", value);
4747
}
48-
PacketType::AsicEgg(value) => {
49-
println!("EGG power values = {:?}", value);
48+
PacketType::AsicEeg(value) => {
49+
println!("EEG power values = {:?}", value);
5050
}
5151
_ => (),
5252
}

src/lib.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum PacketType {
2121
Meditation(u8),
2222
Blink(u8),
2323
RawValue(i16),
24-
AsicEgg(AsicEgg),
24+
AsicEeg(AsicEeg),
2525
PacketUndefined(u8),
2626
}
2727

@@ -33,7 +33,7 @@ pub enum State {
3333
}
3434

3535
#[derive(PartialEq, Eq, Debug)]
36-
pub struct AsicEgg {
36+
pub struct AsicEeg {
3737
pub delta: u32,
3838
pub theta: u32,
3939
pub low_alpha: u32,
@@ -250,27 +250,27 @@ impl Parser {
250250
//ASIC_EEG_POWER: eight big-endian 3-byte unsigned integer values representing
251251
//delta, theta, low-alpha high-alpha, low-beta, high-beta, low-gamma, and mid-gamma
252252
//EEG band power values
253-
let mut current_vec: Vec<u32> = vec![];
253+
let mut eeg_vec: Vec<u32> = vec![];
254254

255255
for i in 0..8 {
256256
let asic = ((self.payload[n + 2 + i * 3] as u32) << 16)
257257
| ((self.payload[n + 3 + i * 3] as u32) << 8)
258258
| (self.payload[n + 4 + i * 3] as u32);
259-
current_vec.push(asic);
259+
eeg_vec.push(asic);
260260
}
261261

262-
let egg_power = AsicEgg {
263-
delta: current_vec[0],
264-
theta: current_vec[1],
265-
low_alpha: current_vec[2],
266-
high_alpha: current_vec[3],
267-
low_beta: current_vec[4],
268-
high_beta: current_vec[5],
269-
low_gamma: current_vec[6],
270-
mid_gamma: current_vec[7],
262+
let eeg_power = AsicEeg {
263+
delta: eeg_vec[0],
264+
theta: eeg_vec[1],
265+
low_alpha: eeg_vec[2],
266+
high_alpha: eeg_vec[3],
267+
low_beta: eeg_vec[4],
268+
high_beta: eeg_vec[5],
269+
low_gamma: eeg_vec[6],
270+
mid_gamma: eeg_vec[7],
271271
};
272-
debug!("Delta {:#04x}, Theta {:#04x}, LowAlpha {:#04x}, HighAlpha {:#04x}, LowBeta {:#04x}, highBeta {:#04x}, LowGamma {:#04x}, MidGamma {:#04x}", egg_power.delta, egg_power.theta, egg_power.low_alpha, egg_power.high_alpha, egg_power.low_beta, egg_power.high_beta, egg_power.low_gamma, egg_power.mid_gamma);
273-
result.push(PacketType::AsicEgg(egg_power));
272+
debug!("EEG power values = {:?}", eeg_power);
273+
result.push(PacketType::AsicEeg(eeg_power));
274274
n += 26;
275275
} else {
276276
warn!("packet code undefined {:#04x}", self.payload[n]);
@@ -362,7 +362,7 @@ mod tests {
362362
}
363363
}
364364

365-
let test_asic = AsicEgg {
365+
let test_asic = AsicEeg {
366366
delta: 0x94,
367367
theta: 0x42,
368368
low_alpha: 0x0b,
@@ -377,7 +377,7 @@ mod tests {
377377
result,
378378
vec![
379379
PacketType::PoorSignal(0x00),
380-
PacketType::AsicEgg(test_asic),
380+
PacketType::AsicEeg(test_asic),
381381
PacketType::Attention(0x0d),
382382
PacketType::Meditation(0x3d)
383383
]

src/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ fn main() -> Result<(), Box<dyn Error>> {
2727
});
2828
let path = matches.value_of("dongle-path").unwrap();
2929
let mut port = connect_headset(path, &headset[..])?;
30-
let mut temp: Vec<u8> = vec![0; 2048];
30+
let mut read_buf: Vec<u8> = vec![0; 2048];
3131
let mut parser = Parser::new();
3232

3333
loop {
34-
let byte_buf = port.read(temp.as_mut_slice()).expect(
34+
let bytes_read = port.read(read_buf.as_mut_slice()).expect(
3535
"Found no data when reading from dongle. Please make sure headset is connected.",
3636
);
37-
for i in 0..byte_buf {
38-
if let Some(x) = parser.parse(temp[i]) {
37+
for i in 0..bytes_read {
38+
if let Some(x) = parser.parse(read_buf[i]) {
3939
for r in x {
4040
match r {
4141
PacketType::Attention(value) => {
@@ -44,8 +44,8 @@ fn main() -> Result<(), Box<dyn Error>> {
4444
PacketType::Meditation(value) => {
4545
println!("Meditation value = {}", value);
4646
}
47-
PacketType::AsicEgg(value) => {
48-
println!("EGG power values = {:?}", value);
47+
PacketType::AsicEeg(value) => {
48+
println!("EEG power values = {:?}", value);
4949
}
5050
_ => (),
5151
}

src/plot.rs

+29-27
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::sync::Arc;
1515
const W: usize = 800;
1616
const H: usize = 1000;
1717
const LABEL: [&str; 2] = ["Attention", "Meditation"];
18-
const EGGLABEL: [&str; 8] = [
18+
const EEGLABEL: [&str; 8] = [
1919
"delta",
2020
"theta",
2121
"low-alpha",
@@ -80,15 +80,17 @@ fn main() -> Result<(), Box<dyn Error>> {
8080
});
8181
let path = matches.value_of("dongle-path").unwrap();
8282
let mut port = connect_headset(path, &headset[..])?;
83-
let mut temp: Vec<u8> = vec![0; 2048];
83+
let mut read_buf: Vec<u8> = vec![0; 2048];
8484
let mut parser = Parser::new();
8585
let mut esense = vec![VecDeque::new(); 2];
86-
let mut egg = vec![VecDeque::new(); 8];
87-
let mut buf = BufferWrapper(vec![0u32; W * H]);
86+
let mut eeg = vec![VecDeque::new(); 8];
87+
let mut draw_buf = BufferWrapper(vec![0u32; W * H]);
8888
let mut window = Window::new("mindwave plot", W, H, WindowOptions::default())?;
89-
let root =
90-
BitMapBackend::<BGRXPixel>::with_buffer_and_format(buf.borrow_mut(), (W as u32, H as u32))?
91-
.into_drawing_area();
89+
let root = BitMapBackend::<BGRXPixel>::with_buffer_and_format(
90+
draw_buf.borrow_mut(),
91+
(W as u32, H as u32),
92+
)?
93+
.into_drawing_area();
9294
root.fill(&BLACK)?;
9395
let (upper, lower) = root.split_vertically(400);
9496
let mut chart_up = ChartBuilder::on(&upper)
@@ -122,7 +124,7 @@ fn main() -> Result<(), Box<dyn Error>> {
122124
.label_style(("sans-serif", 15).into_font().color(&GREEN))
123125
.x_labels(1)
124126
.y_labels(8)
125-
.y_desc("EGG power")
127+
.y_desc("EEG power")
126128
.axis_style(&GREEN)
127129
.draw()?;
128130
let cs_up = chart_up.into_chart_state();
@@ -132,11 +134,11 @@ fn main() -> Result<(), Box<dyn Error>> {
132134
drop(lower);
133135

134136
while window.is_open() && !window.is_key_down(Key::Escape) && running.load(Ordering::SeqCst) {
135-
let byte_buf = port.read(temp.as_mut_slice()).expect(
137+
let bytes_read = port.read(read_buf.as_mut_slice()).expect(
136138
"Found no data when reading from dongle. Please make sure headset is connected.",
137139
);
138140
let root = BitMapBackend::<BGRXPixel>::with_buffer_and_format(
139-
buf.borrow_mut(),
141+
draw_buf.borrow_mut(),
140142
(W as u32, H as u32),
141143
)?
142144
.into_drawing_area();
@@ -155,8 +157,8 @@ fn main() -> Result<(), Box<dyn Error>> {
155157
.bold_line_style(&GREEN.mix(0.2))
156158
.light_line_style(&TRANSPARENT)
157159
.draw()?;
158-
for i in 0..byte_buf {
159-
if let Some(x) = parser.parse(temp[i]) {
160+
for i in 0..bytes_read {
161+
if let Some(x) = parser.parse(read_buf[i]) {
160162
for r in x {
161163
match r {
162164
PacketType::Attention(value) => {
@@ -165,15 +167,15 @@ fn main() -> Result<(), Box<dyn Error>> {
165167
PacketType::Meditation(value) => {
166168
esense[1].push_back(value as i32);
167169
}
168-
PacketType::AsicEgg(value) => {
169-
egg[0].push_back((value.delta / 10_000) as f64);
170-
egg[1].push_back((value.theta / 10_000) as f64);
171-
egg[2].push_back((value.low_alpha / 10_000) as f64);
172-
egg[3].push_back((value.high_alpha / 10_000) as f64);
173-
egg[4].push_back((value.low_beta / 10_000) as f64);
174-
egg[5].push_back((value.high_beta / 10_000) as f64);
175-
egg[6].push_back((value.low_gamma / 10_000) as f64);
176-
egg[7].push_back((value.mid_gamma / 10_000) as f64);
170+
PacketType::AsicEeg(value) => {
171+
eeg[0].push_back((value.delta / 10_000) as f64);
172+
eeg[1].push_back((value.theta / 10_000) as f64);
173+
eeg[2].push_back((value.low_alpha / 10_000) as f64);
174+
eeg[3].push_back((value.high_alpha / 10_000) as f64);
175+
eeg[4].push_back((value.low_beta / 10_000) as f64);
176+
eeg[5].push_back((value.high_beta / 10_000) as f64);
177+
eeg[6].push_back((value.low_gamma / 10_000) as f64);
178+
eeg[7].push_back((value.mid_gamma / 10_000) as f64);
177179
}
178180
_ => (),
179181
}
@@ -184,9 +186,9 @@ fn main() -> Result<(), Box<dyn Error>> {
184186
esense[0].pop_front();
185187
esense[1].pop_front();
186188
}
187-
if egg[0].len() == 100 {
189+
if eeg[0].len() == 100 {
188190
for n in 0..8 {
189-
egg[n].pop_front();
191+
eeg[n].pop_front();
190192
}
191193
}
192194
for (idx, esense) in (0..).zip(esense.iter()) {
@@ -207,13 +209,13 @@ fn main() -> Result<(), Box<dyn Error>> {
207209
.background_style(&WHITE.mix(0.5))
208210
.border_style(&BLACK)
209211
.draw()?;
210-
for (idx, egg) in (0..).zip(egg.iter()) {
212+
for (idx, eeg) in (0..).zip(eeg.iter()) {
211213
chart_low
212214
.draw_series(LineSeries::new(
213-
(1..).zip(egg.iter()).map(|(a, b)| (a, *b)),
215+
(1..).zip(eeg.iter()).map(|(a, b)| (a, *b)),
214216
&Palette99::pick(idx),
215217
))?
216-
.label(EGGLABEL[idx])
218+
.label(EEGLABEL[idx])
217219
.legend(move |(x, y)| {
218220
Rectangle::new([(x - 5, y - 5), (x + 5, y + 5)], &Palette99::pick(idx))
219221
});
@@ -231,7 +233,7 @@ fn main() -> Result<(), Box<dyn Error>> {
231233
drop(upper);
232234
drop(lower);
233235
window.set_title("Mindwave real-time plot");
234-
window.update_with_buffer(buf.borrow(), W, H)?;
236+
window.update_with_buffer(draw_buf.borrow(), W, H)?;
235237
}
236238
Ok(())
237239
}

0 commit comments

Comments
 (0)