Skip to content

Commit

Permalink
Add Delta, Theta Support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZACHSTRIVES committed Sep 30, 2021
1 parent 3578cbf commit 6ae5d8d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 15 deletions.
8 changes: 4 additions & 4 deletions INFO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Run the following command: ``pip install PyNeuro``
Usage
-----

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

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

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

.. code:: python
from PyNeuro import PyNeuro
from PyNeuro.PyNeuro import PyNeuro
from time import sleep
pn = PyNeuro()
Expand All @@ -71,7 +71,7 @@ Sample Program 2 (Access via object)

.. code:: python
from PyNeuro import PyNeuro
from PyNeuro.PyNeuro import PyNeuro
from time import sleep
pn = PyNeuro()
Expand Down
68 changes: 62 additions & 6 deletions PyNeuro/PyNeuro.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
@Author Zach Wang
@Date 2021.9.27
@Version 1.1.0
@Version 1.2.1
"""
import json
from telnetlib import Telnet
Expand All @@ -26,6 +26,9 @@ class PyNeuro:
__blinkStrength = 0
__status = "NotConnected"

__delta = 0
__theta = 0

__attention_records = []
__meditation_records = []
__blinkStrength_records = []
Expand All @@ -36,6 +39,8 @@ class PyNeuro:
__attention_callbacks = []
__meditation_callbacks = []
__blinkStrength__callbacks = []
__delta__callbacks = []
__theta__callbacks = []
__status__callbacks = []

callBacksDictionary = {} # keep a track of all callbacks
Expand Down Expand Up @@ -79,7 +84,6 @@ def close(self):
:return:
"""
self.__threadRun = False
self.__parserThread.join()

def __packetParser(self):
while True:
Expand All @@ -98,13 +102,18 @@ def __packetParser(self):
else:
if "eSense" in data.keys():
if data["eSense"]["attention"] + data["eSense"]["meditation"] == 0:
self.__status = "fitting"
if self.__status != "fitting":
self.__status = "fitting"
print("[PyNeuro] Fitting Device..")

else:

self.__status = "connected"
if self.__status != "connected":
self.__status = "connected"
print("[PyNeuro] Successfully Connected ..")
self.attention = data["eSense"]["attention"]
self.meditation = data["eSense"]["meditation"]
self.theta = data['eegPower']['theta']
self.delta = data['eegPower']['delta']
self.__attention_records.append(data["eSense"]["attention"])
self.__attention_records.append(data["eSense"]["meditation"])
elif "blinkStrength" in data.keys():
Expand Down Expand Up @@ -137,6 +146,22 @@ def set_blinkStrength_callback(self, callback):

self.__blinkStrength__callbacks.append(callback)

def set_delta_callback(self, callback):
"""
Set callback function of meditation value
:param callback: function(blinkStrength: int)
"""

self.__delta__callbacks.append(callback)

def set_theta_callback(self, callback):
"""
Set callback function of meditation value
:param callback: function(blinkStrength: int)
"""

self.__theta__callbacks.append(callback)

# attention
@property
def attention(self):
Expand Down Expand Up @@ -178,6 +203,38 @@ def blinkStrength(self, value):
for callback in self.__blinkStrength__callbacks:
callback(self.__blinkStrength)

@property
def delta(self):
"Get value for delta"
return self.__delta

@delta.setter
def delta(self, value):
self.__delta = value
# if callback has been set, execute the function
for callback in self.__delta__callbacks:
callback(self.__delta)

@property
def theta(self):
"Get value for theta"
return self.__theta
@theta.setter
def theta(self,value):
self.__theta = value
# if callback has been set, execute the function
for callback in self.__theta__callbacks:
callback(self.__theta)


@delta.setter
def delta(self, value):
self.__delta = value
# if callback has been set, execute the function
for callback in self.__delta__callbacks:
callback(self.__delta)


# status
@property
def status(self):
Expand All @@ -189,4 +246,3 @@ def status(self, value):
self.__status = value
for callback in self.__status__callbacks:
callback(self.__status)

10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Run the following command: `pip install PyNeuro`

## Usage

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

* **Obtaining value:** `attention = pn.attention` \#to get value of attention_
>**Other Variable** attention, meditation, blinkStrength, will be added more soon.
>**Other Variable** attention, meditation, blinkStrength, delta, theta will be added more soon.
* **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:

```
pn.set_attention_callback(callback_function1)
pn.set_meditation_callback(callback_function2)
pn.set_blinkStrength_callback(callback_function3)
pn.set_delta_callback(callback_function4)
pn.set_theta_callback(callback_function5)
```
>You can add any number of callback functions to a variable..

## Sample Program 1 (Access via callback)

```python
from PyNeuro import PyNeuro
from PyNeuro.PyNeuro import PyNeuro
from time import sleep

pn = PyNeuro()
Expand All @@ -59,7 +61,7 @@ finally:
## Sample Program 2 (Access via object)

```python
from PyNeuro import PyNeuro
from PyNeuro.PyNeuro import PyNeuro
from time import sleep

pn = PyNeuro()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


setup(name="PyNeuro",
version="1.2",
version="1.2.1",
description="Library for connect with Neurosky's Mindwave EEG headset via TCP Socket",
author="Zach Wang",
author_email="wangziqi0325@gmail.com",
Expand Down

0 comments on commit 6ae5d8d

Please sign in to comment.