@@ -15,7 +15,7 @@ use std::sync::Arc;
15
15
const W : usize = 800 ;
16
16
const H : usize = 1000 ;
17
17
const LABEL : [ & str ; 2 ] = [ "Attention" , "Meditation" ] ;
18
- const EGGLABEL : [ & str ; 8 ] = [
18
+ const EEGLABEL : [ & str ; 8 ] = [
19
19
"delta" ,
20
20
"theta" ,
21
21
"low-alpha" ,
@@ -80,15 +80,17 @@ fn main() -> Result<(), Box<dyn Error>> {
80
80
} ) ;
81
81
let path = matches. value_of ( "dongle-path" ) . unwrap ( ) ;
82
82
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 ] ;
84
84
let mut parser = Parser :: new ( ) ;
85
85
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 ] ) ;
88
88
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 ( ) ;
92
94
root. fill ( & BLACK ) ?;
93
95
let ( upper, lower) = root. split_vertically ( 400 ) ;
94
96
let mut chart_up = ChartBuilder :: on ( & upper)
@@ -122,7 +124,7 @@ fn main() -> Result<(), Box<dyn Error>> {
122
124
. label_style ( ( "sans-serif" , 15 ) . into_font ( ) . color ( & GREEN ) )
123
125
. x_labels ( 1 )
124
126
. y_labels ( 8 )
125
- . y_desc ( "EGG power" )
127
+ . y_desc ( "EEG power" )
126
128
. axis_style ( & GREEN )
127
129
. draw ( ) ?;
128
130
let cs_up = chart_up. into_chart_state ( ) ;
@@ -132,11 +134,11 @@ fn main() -> Result<(), Box<dyn Error>> {
132
134
drop ( lower) ;
133
135
134
136
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 (
136
138
"Found no data when reading from dongle. Please make sure headset is connected." ,
137
139
) ;
138
140
let root = BitMapBackend :: < BGRXPixel > :: with_buffer_and_format (
139
- buf . borrow_mut ( ) ,
141
+ draw_buf . borrow_mut ( ) ,
140
142
( W as u32 , H as u32 ) ,
141
143
) ?
142
144
. into_drawing_area ( ) ;
@@ -155,8 +157,8 @@ fn main() -> Result<(), Box<dyn Error>> {
155
157
. bold_line_style ( & GREEN . mix ( 0.2 ) )
156
158
. light_line_style ( & TRANSPARENT )
157
159
. 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] ) {
160
162
for r in x {
161
163
match r {
162
164
PacketType :: Attention ( value) => {
@@ -165,15 +167,15 @@ fn main() -> Result<(), Box<dyn Error>> {
165
167
PacketType :: Meditation ( value) => {
166
168
esense[ 1 ] . push_back ( value as i32 ) ;
167
169
}
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 ) ;
177
179
}
178
180
_ => ( ) ,
179
181
}
@@ -184,9 +186,9 @@ fn main() -> Result<(), Box<dyn Error>> {
184
186
esense[ 0 ] . pop_front ( ) ;
185
187
esense[ 1 ] . pop_front ( ) ;
186
188
}
187
- if egg [ 0 ] . len ( ) == 100 {
189
+ if eeg [ 0 ] . len ( ) == 100 {
188
190
for n in 0 ..8 {
189
- egg [ n] . pop_front ( ) ;
191
+ eeg [ n] . pop_front ( ) ;
190
192
}
191
193
}
192
194
for ( idx, esense) in ( 0 ..) . zip ( esense. iter ( ) ) {
@@ -207,13 +209,13 @@ fn main() -> Result<(), Box<dyn Error>> {
207
209
. background_style ( & WHITE . mix ( 0.5 ) )
208
210
. border_style ( & BLACK )
209
211
. draw ( ) ?;
210
- for ( idx, egg ) in ( 0 ..) . zip ( egg . iter ( ) ) {
212
+ for ( idx, eeg ) in ( 0 ..) . zip ( eeg . iter ( ) ) {
211
213
chart_low
212
214
. draw_series ( LineSeries :: new (
213
- ( 1 ..) . zip ( egg . iter ( ) ) . map ( |( a, b) | ( a, * b) ) ,
215
+ ( 1 ..) . zip ( eeg . iter ( ) ) . map ( |( a, b) | ( a, * b) ) ,
214
216
& Palette99 :: pick ( idx) ,
215
217
) ) ?
216
- . label ( EGGLABEL [ idx] )
218
+ . label ( EEGLABEL [ idx] )
217
219
. legend ( move |( x, y) | {
218
220
Rectangle :: new ( [ ( x - 5 , y - 5 ) , ( x + 5 , y + 5 ) ] , & Palette99 :: pick ( idx) )
219
221
} ) ;
@@ -231,7 +233,7 @@ fn main() -> Result<(), Box<dyn Error>> {
231
233
drop ( upper) ;
232
234
drop ( lower) ;
233
235
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 ) ?;
235
237
}
236
238
Ok ( ( ) )
237
239
}
0 commit comments