Skip to content

Commit 6ae5d8d

Browse files
committed
Add Delta, Theta Support
1 parent 3578cbf commit 6ae5d8d

4 files changed

Lines changed: 73 additions & 15 deletions

File tree

INFO.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Run the following command: ``pip install PyNeuro``
1414
Usage
1515
-----
1616

17-
1. Importing the module: ``from NeuroPy import NeuroPy``
17+
1. Importing the module: ``from PyNeuro.PyNeuro import PyNeuro``
1818
2. Initializing: ``pn = PyNeuro()``
1919
3. After initializing, if required the callbacks can be set
2020
4. Then call ``pn.connect()`` method, it will connect with TCP Socket
@@ -27,7 +27,7 @@ Obtaining Data from Device
2727

2828
- **Obtaining value:** ``attention = pn.attention`` #to get value of
2929
attention\_ >\ **Other Variable** attention, meditation,
30-
blinkStrength, will be added more soon.
30+
blinkStrength, delta, theta, will be added more soon.
3131

3232
- **Setting callback:** A call back can be associated with all the
3333
above variables so that a function is called when the variable is
@@ -46,7 +46,7 @@ Sample Program 1 (Access via callback)
4646

4747
.. code:: python
4848
49-
from PyNeuro import PyNeuro
49+
from PyNeuro.PyNeuro import PyNeuro
5050
from time import sleep
5151
5252
pn = PyNeuro()
@@ -71,7 +71,7 @@ Sample Program 2 (Access via object)
7171

7272
.. code:: python
7373
74-
from PyNeuro import PyNeuro
74+
from PyNeuro.PyNeuro import PyNeuro
7575
from time import sleep
7676
7777
pn = PyNeuro()

PyNeuro/PyNeuro.py

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
@Author Zach Wang
33
@Date 2021.9.27
4-
@Version 1.1.0
4+
@Version 1.2.1
55
"""
66
import json
77
from telnetlib import Telnet
@@ -26,6 +26,9 @@ class PyNeuro:
2626
__blinkStrength = 0
2727
__status = "NotConnected"
2828

29+
__delta = 0
30+
__theta = 0
31+
2932
__attention_records = []
3033
__meditation_records = []
3134
__blinkStrength_records = []
@@ -36,6 +39,8 @@ class PyNeuro:
3639
__attention_callbacks = []
3740
__meditation_callbacks = []
3841
__blinkStrength__callbacks = []
42+
__delta__callbacks = []
43+
__theta__callbacks = []
3944
__status__callbacks = []
4045

4146
callBacksDictionary = {} # keep a track of all callbacks
@@ -79,7 +84,6 @@ def close(self):
7984
:return:
8085
"""
8186
self.__threadRun = False
82-
self.__parserThread.join()
8387

8488
def __packetParser(self):
8589
while True:
@@ -98,13 +102,18 @@ def __packetParser(self):
98102
else:
99103
if "eSense" in data.keys():
100104
if data["eSense"]["attention"] + data["eSense"]["meditation"] == 0:
101-
self.__status = "fitting"
105+
if self.__status != "fitting":
106+
self.__status = "fitting"
107+
print("[PyNeuro] Fitting Device..")
102108

103109
else:
104-
105-
self.__status = "connected"
110+
if self.__status != "connected":
111+
self.__status = "connected"
112+
print("[PyNeuro] Successfully Connected ..")
106113
self.attention = data["eSense"]["attention"]
107114
self.meditation = data["eSense"]["meditation"]
115+
self.theta = data['eegPower']['theta']
116+
self.delta = data['eegPower']['delta']
108117
self.__attention_records.append(data["eSense"]["attention"])
109118
self.__attention_records.append(data["eSense"]["meditation"])
110119
elif "blinkStrength" in data.keys():
@@ -137,6 +146,22 @@ def set_blinkStrength_callback(self, callback):
137146

138147
self.__blinkStrength__callbacks.append(callback)
139148

149+
def set_delta_callback(self, callback):
150+
"""
151+
Set callback function of meditation value
152+
:param callback: function(blinkStrength: int)
153+
"""
154+
155+
self.__delta__callbacks.append(callback)
156+
157+
def set_theta_callback(self, callback):
158+
"""
159+
Set callback function of meditation value
160+
:param callback: function(blinkStrength: int)
161+
"""
162+
163+
self.__theta__callbacks.append(callback)
164+
140165
# attention
141166
@property
142167
def attention(self):
@@ -178,6 +203,38 @@ def blinkStrength(self, value):
178203
for callback in self.__blinkStrength__callbacks:
179204
callback(self.__blinkStrength)
180205

206+
@property
207+
def delta(self):
208+
"Get value for delta"
209+
return self.__delta
210+
211+
@delta.setter
212+
def delta(self, value):
213+
self.__delta = value
214+
# if callback has been set, execute the function
215+
for callback in self.__delta__callbacks:
216+
callback(self.__delta)
217+
218+
@property
219+
def theta(self):
220+
"Get value for theta"
221+
return self.__theta
222+
@theta.setter
223+
def theta(self,value):
224+
self.__theta = value
225+
# if callback has been set, execute the function
226+
for callback in self.__theta__callbacks:
227+
callback(self.__theta)
228+
229+
230+
@delta.setter
231+
def delta(self, value):
232+
self.__delta = value
233+
# if callback has been set, execute the function
234+
for callback in self.__delta__callbacks:
235+
callback(self.__delta)
236+
237+
181238
# status
182239
@property
183240
def status(self):
@@ -189,4 +246,3 @@ def status(self, value):
189246
self.__status = value
190247
for callback in self.__status__callbacks:
191248
callback(self.__status)
192-

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Run the following command: `pip install PyNeuro`
99

1010
## Usage
1111

12-
1. Importing the module: `from NeuroPy import NeuroPy`
12+
1. Importing the module: `from PyNeuro.PyNeuro import PyNeuro`
1313
2. Initializing: `pn = PyNeuro()`
1414
3. After initializing, if required the callbacks can be set
1515
4. Then call `pn.connect()` method, it will connect with TCP Socket server.
@@ -19,22 +19,24 @@ Run the following command: `pip install PyNeuro`
1919
### Obtaining Data from Device
2020

2121
* **Obtaining value:** `attention = pn.attention` \#to get value of attention_
22-
>**Other Variable** attention, meditation, blinkStrength, will be added more soon.
22+
>**Other Variable** attention, meditation, blinkStrength, delta, theta will be added more soon.
2323
2424
* **Setting callback:** A call back can be associated with all the above variables so that a function is called when the variable is updated. Syntax:
2525

2626
```
2727
pn.set_attention_callback(callback_function1)
2828
pn.set_meditation_callback(callback_function2)
2929
pn.set_blinkStrength_callback(callback_function3)
30+
pn.set_delta_callback(callback_function4)
31+
pn.set_theta_callback(callback_function5)
3032
```
3133
>You can add any number of callback functions to a variable..
3234
3335
3436
## Sample Program 1 (Access via callback)
3537
3638
```python
37-
from PyNeuro import PyNeuro
39+
from PyNeuro.PyNeuro import PyNeuro
3840
from time import sleep
3941
4042
pn = PyNeuro()
@@ -59,7 +61,7 @@ finally:
5961
## Sample Program 2 (Access via object)
6062

6163
```python
62-
from PyNeuro import PyNeuro
64+
from PyNeuro.PyNeuro import PyNeuro
6365
from time import sleep
6466

6567
pn = PyNeuro()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
setup(name="PyNeuro",
6-
version="1.2",
6+
version="1.2.1",
77
description="Library for connect with Neurosky's Mindwave EEG headset via TCP Socket",
88
author="Zach Wang",
99
author_email="wangziqi0325@gmail.com",

0 commit comments

Comments
 (0)