From 31bc8cb96008b2931a747e784cd8bd6ab8cd3a40 Mon Sep 17 00:00:00 2001 From: Daniel Rivas Date: Tue, 23 Apr 2019 16:06:30 -0400 Subject: [PATCH 1/3] Moving plugin_interface to its right place --- openbci/plugins/plugin_interface.py | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 openbci/plugins/plugin_interface.py diff --git a/openbci/plugins/plugin_interface.py b/openbci/plugins/plugin_interface.py new file mode 100644 index 0000000..f984ee7 --- /dev/null +++ b/openbci/plugins/plugin_interface.py @@ -0,0 +1,44 @@ +""" +Extends Yapsy IPlugin interface to pass information about the board to plugins. +Fields of interest for plugins: + args: list of arguments passed to the plugins + sample_rate: actual sample rate of the board + eeg_channels: number of EEG + aux_channels: number of AUX channels + +If needed, plugins that need to report an error can set self.is_activated to False during activate() call. +NB: because of how yapsy discovery system works, plugins must use the following syntax to inherit to use polymorphism (see http://yapsy.sourceforge.net/Advices.html): + import plugin_interface as plugintypes + class PluginExample(plugintypes.IPluginExtended): + ... +""" + +from __future__ import print_function +from yapsy.IPlugin import IPlugin + + +class IPluginExtended(IPlugin): + # args: passed by command line + def pre_activate(self, args, sample_rate=250, eeg_channels=8, aux_channels=3, imp_channels=0): + self.args = args + self.sample_rate = sample_rate + self.eeg_channels = eeg_channels + self.aux_channels = aux_channels + self.imp_channels = imp_channels + # by default we say that activation was okay -- inherited from IPlugin + self.is_activated = True + self.activate() + # tell outside world if init went good or bad + return self.is_activated + + # inherited from IPlugin + def activate(self): + print("Plugin %s activated." % (self.__class__.__name__)) + + # inherited from IPlugin + def deactivate(self): + print("Plugin %s deactivated." % (self.__class__.__name__)) + + # plugins that require arguments should implement this method + def show_help(self): + print("I, %s, do not need any parameter." % (self.__class__.__name__)) From 50b28a23c9a5a4f87d61e9c400ece9244928bf0a Mon Sep 17 00:00:00 2001 From: Daniel Rivas Date: Tue, 23 Apr 2019 16:07:00 -0400 Subject: [PATCH 2/3] Delete plugin_interface.py --- plugin_interface.py | 48 --------------------------------------------- 1 file changed, 48 deletions(-) delete mode 100755 plugin_interface.py diff --git a/plugin_interface.py b/plugin_interface.py deleted file mode 100755 index 70550fe..0000000 --- a/plugin_interface.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Extends Yapsy IPlugin interface to pass information about the board to plugins. - -Fields of interest for plugins: - args: list of arguments passed to the plugins - sample_rate: actual sample rate of the board - eeg_channels: number of EEG - aux_channels: number of AUX channels - -If needed, plugins that need to report an error can set self.is_activated to False during activate() call. - -NB: because of how yapsy discovery system works, plugins must use the following syntax to inherit to use polymorphism (see http://yapsy.sourceforge.net/Advices.html): - - import plugin_interface as plugintypes - - class PluginExample(plugintypes.IPluginExtended): - ... -""" - -from __future__ import print_function -from yapsy.IPlugin import IPlugin - - -class IPluginExtended(IPlugin): - # args: passed by command line - def pre_activate(self, args, sample_rate=250, eeg_channels=8, aux_channels=3, imp_channels=0): - self.args = args - self.sample_rate = sample_rate - self.eeg_channels = eeg_channels - self.aux_channels = aux_channels - self.imp_channels = imp_channels - # by default we say that activation was okay -- inherited from IPlugin - self.is_activated = True - self.activate() - # tell outside world if init went good or bad - return self.is_activated - - # inherited from IPlugin - def activate(self): - print("Plugin %s activated." % (self.__class__.__name__)) - - # inherited from IPlugin - def deactivate(self): - print("Plugin %s deactivated." % (self.__class__.__name__)) - - # plugins that require arguments should implement this method - def show_help(self): - print("I, %s, do not need any parameter." % (self.__class__.__name__)) From 3da8042ebde89c5ad97517db91d9c780a24f4327 Mon Sep 17 00:00:00 2001 From: rivasd Date: Tue, 23 Apr 2019 16:26:15 -0400 Subject: [PATCH 3/3] Corrected importing scheme to import classes explicitely and not a whole module --- README.md | 4 ++-- openbci/plugins/csv_collect.py | 4 ++-- openbci/plugins/noise_test.py | 4 ++-- openbci/plugins/plugin_interface.py | 4 ++-- openbci/plugins/print.py | 4 ++-- openbci/plugins/sample_rate.py | 4 ++-- openbci/plugins/streamer_lsl.py | 4 ++-- openbci/plugins/streamer_osc.py | 4 ++-- openbci/plugins/streamer_tcp_server.py | 4 ++-- openbci/plugins/udp_server.py | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e53ddbc..c47c66e 100644 --- a/README.md +++ b/README.md @@ -299,9 +299,9 @@ Note: type `/start` to launch the selected plugins. Add new functionalities to user.py by creating new scripts inside the `plugins` folder. You class must inherit from yapsy.IPlugin, see below a minimal example with `print` plugin: ```python -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended -class PluginPrint(plugintypes.IPluginExtended): +class PluginPrint(IPluginExtended): def activate(self): print("Print activated") diff --git a/openbci/plugins/csv_collect.py b/openbci/plugins/csv_collect.py index 9829213..0ad5992 100755 --- a/openbci/plugins/csv_collect.py +++ b/openbci/plugins/csv_collect.py @@ -3,10 +3,10 @@ import timeit import datetime -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended -class PluginCSVCollect(plugintypes.IPluginExtended): +class PluginCSVCollect(IPluginExtended): def __init__(self, file_name="collect.csv", delim=",", verbose=False): now = datetime.datetime.now() self.time_stamp = '%d-%d-%d_%d-%d-%d' \ diff --git a/openbci/plugins/noise_test.py b/openbci/plugins/noise_test.py index 120dc57..00fd59f 100755 --- a/openbci/plugins/noise_test.py +++ b/openbci/plugins/noise_test.py @@ -1,10 +1,10 @@ from __future__ import print_function import timeit import numpy as np -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended -class PluginNoiseTest(plugintypes.IPluginExtended): +class PluginNoiseTest(IPluginExtended): # update counters value def __call__(self, sample): # keep tract of absolute value of diff --git a/openbci/plugins/plugin_interface.py b/openbci/plugins/plugin_interface.py index f984ee7..8e59095 100644 --- a/openbci/plugins/plugin_interface.py +++ b/openbci/plugins/plugin_interface.py @@ -8,8 +8,8 @@ If needed, plugins that need to report an error can set self.is_activated to False during activate() call. NB: because of how yapsy discovery system works, plugins must use the following syntax to inherit to use polymorphism (see http://yapsy.sourceforge.net/Advices.html): - import plugin_interface as plugintypes - class PluginExample(plugintypes.IPluginExtended): + from .plugin_interface import IPluginExtended + class PluginExample(IPluginExtended): ... """ diff --git a/openbci/plugins/print.py b/openbci/plugins/print.py index 32c5ce0..020045a 100755 --- a/openbci/plugins/print.py +++ b/openbci/plugins/print.py @@ -1,8 +1,8 @@ from __future__ import print_function -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended -class PluginPrint(plugintypes.IPluginExtended): +class PluginPrint(IPluginExtended): def activate(self): print("Print activated") diff --git a/openbci/plugins/sample_rate.py b/openbci/plugins/sample_rate.py index d4e9dc3..834a848 100755 --- a/openbci/plugins/sample_rate.py +++ b/openbci/plugins/sample_rate.py @@ -3,7 +3,7 @@ import timeit from threading import Thread -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended # counter for sampling rate nb_samples_out = -1 @@ -36,7 +36,7 @@ def run(self): time.sleep(self.polling_interval) -class PluginSampleRate(plugintypes.IPluginExtended): +class PluginSampleRate(IPluginExtended): # update counters value def __call__(self, sample): global nb_samples_out diff --git a/openbci/plugins/streamer_lsl.py b/openbci/plugins/streamer_lsl.py index 0c4e2dd..ea6f922 100755 --- a/openbci/plugins/streamer_lsl.py +++ b/openbci/plugins/streamer_lsl.py @@ -2,7 +2,7 @@ # Eg: ftp://sccn.ucsd.edu/pub/software/LSL/SDK/liblsl-Python-1.10.2.zip # put in "lib" folder (same level as user.py) from __future__ import print_function -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended from pylsl import StreamInfo, StreamOutlet import sys @@ -13,7 +13,7 @@ # Use LSL protocol to broadcast data using one stream for EEG, # one stream for AUX, one last for impedance testing # (on supported board, if enabled) -class StreamerLSL(plugintypes.IPluginExtended): +class StreamerLSL(IPluginExtended): # From IPlugin def activate(self): eeg_stream = "OpenBCI_EEG" diff --git a/openbci/plugins/streamer_osc.py b/openbci/plugins/streamer_osc.py index 828cd57..b02a901 100755 --- a/openbci/plugins/streamer_osc.py +++ b/openbci/plugins/streamer_osc.py @@ -2,13 +2,13 @@ # requires python-osc from pythonosc import osc_message_builder from pythonosc import udp_client -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended # Use OSC protocol to broadcast data (UDP layer), using "/openbci" stream. # (NB. does not check numbers of channel as TCP server) -class StreamerOSC(plugintypes.IPluginExtended): +class StreamerOSC(IPluginExtended): """ Relay OpenBCI values to OSC clients diff --git a/openbci/plugins/streamer_tcp_server.py b/openbci/plugins/streamer_tcp_server.py index 077504f..d021bb8 100755 --- a/openbci/plugins/streamer_tcp_server.py +++ b/openbci/plugins/streamer_tcp_server.py @@ -4,7 +4,7 @@ import select import struct import time -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended # Simple TCP server to "broadcast" data to clients, handling deconnections. @@ -34,7 +34,7 @@ def run(self): time.sleep(1) -class StreamerTCPServer(plugintypes.IPluginExtended): +class StreamerTCPServer(IPluginExtended): """ Relay OpenBCI values to TCP clients diff --git a/openbci/plugins/udp_server.py b/openbci/plugins/udp_server.py index 833bbc4..9153567 100755 --- a/openbci/plugins/udp_server.py +++ b/openbci/plugins/udp_server.py @@ -15,7 +15,7 @@ import json import socket -import plugin_interface as plugintypes +from .plugin_interface import IPluginExtended # class PluginPrint(IPlugin): @@ -48,7 +48,7 @@ # # print(sample_string) -class UDPServer(plugintypes.IPluginExtended): +class UDPServer(IPluginExtended): def __init__(self, ip='localhost', port=8888): self.ip = ip self.port = port