diff --git a/INFO.rst b/INFO.rst index c18c330..2bb4566 100644 --- a/INFO.rst +++ b/INFO.rst @@ -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 @@ -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 @@ -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() @@ -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() diff --git a/PyNeuro/PyNeuro.py b/PyNeuro/PyNeuro.py index 4ac5311..979d271 100644 --- a/PyNeuro/PyNeuro.py +++ b/PyNeuro/PyNeuro.py @@ -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 @@ -26,6 +26,9 @@ class PyNeuro: __blinkStrength = 0 __status = "NotConnected" + __delta = 0 + __theta = 0 + __attention_records = [] __meditation_records = [] __blinkStrength_records = [] @@ -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 @@ -79,7 +84,6 @@ def close(self): :return: """ self.__threadRun = False - self.__parserThread.join() def __packetParser(self): while True: @@ -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(): @@ -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): @@ -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): @@ -189,4 +246,3 @@ def status(self, value): self.__status = value for callback in self.__status__callbacks: callback(self.__status) - diff --git a/README.md b/README.md index 1807f14..80f39fb 100644 --- a/README.md +++ b/README.md @@ -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. @@ -19,7 +19,7 @@ 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: @@ -27,6 +27,8 @@ Run the following command: `pip install PyNeuro` 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.. @@ -34,7 +36,7 @@ Run the following command: `pip install PyNeuro` ## Sample Program 1 (Access via callback) ```python -from PyNeuro import PyNeuro +from PyNeuro.PyNeuro import PyNeuro from time import sleep pn = PyNeuro() @@ -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() diff --git a/setup.py b/setup.py index 280582e..331b343 100644 --- a/setup.py +++ b/setup.py @@ -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",