import threading
import RealTime
import poweroff
import numpy as np
#EMG ############################################################################################################
## All you have to do is to call start_thread1 to start threading smoothly
Real = RealTime.RealTime()

# self.Real.set_GP_instance(self)
Power = poweroff.poweroff()
thread1 = None
thread2 = None
event_stop_thread1 = threading.Event()
event_stop_thread2 = threading.Event()


def start_thread1():
    Real.Flag_Predict = True
    Real.b = np.empty( [0, 8] )
    event_stop_thread1.clear()
    thread1 = threading.Thread( target=loop1 )
    thread1.start()



def loop1():
    while not event_stop_thread1.is_set():
        # if not self.stop_threads.is_set():
        if Real.myo_device.services.waitForNotifications( 1 ):
            print(Real.predictions_array)
           
Esempio n. 2
0
    def __init__(self, parent=None):
        #pyqtgraph.setConfigOption('background', 'w')  # before loading widget
        super(Main, self).__init__()
        self.setupUi(self)
        self.Real = RealTime.RealTime()
        self.Power=poweroff.poweroff()
        self.EMG_Modeling = EMG_Model.EMG_Model()
        self.cv = CV.CV()
        #self.Real.set_GP_instance(self)

        
        XStream.stdout().messageWritten.connect( self.textBrowser.insertPlainText )
        XStream.stdout().messageWritten.connect( self.textBrowser.ensureCursorVisible )
        XStream.stderr().messageWritten.connect( self.textBrowser.insertPlainText )
        XStream.stderr().messageWritten.connect( self.textBrowser.ensureCursorVisible )
        
        #self.emgplot = pg.PlotWidget( name='EMGplot' )
        self.emgplot.setRange( QtCore.QRectF( -50, -200, 1000, 1400 ) )
        self.emgplot.disableAutoRange()
        self.emgplot.setTitle( "EMG" )

        self.emgcurve = []
        for i in range( 8 ):
            c = self.emgplot.plot( pen=(i, 10) )
            c.setPos( 0, i * 150 )
            self.emgcurve.append( c )
        
        self.emgcurve0 = [self.EMG1,self.EMG2,self.EMG3,self.EMG4,self.EMG5\
                           ,self.EMG6,self.EMG7,self.EMG8]
        for i in range (8):
            self.emgcurve0[i].plotItem.showGrid(True, True, 0.7)
            #self.emgcurve0[i].plotItem.setRange(yRange=[0, 1])


        self.pushButton.clicked.connect(self.Real.start_MYO)
        self.pushButton_2.clicked.connect( self.start_thread2 )  # Start Predict
        self.pushButton_3.clicked.connect( self.stop_thread2 )  # Stop Predict
        self.pushButton_4.clicked.connect( self.disconnect_MYO)
        self.pushButton_5.clicked.connect(self.Power.power_off)
        self.pushButton_6.clicked.connect( self.clear_textBrowser )
        self.pushButton_7.clicked.connect( self.start_thread1 )# start Graph1
        self.pushButton_8.clicked.connect( self.stop_thread1 )
        self.pushButton_9.clicked.connect( self.file_save_csv )
        self.pushButton_11.clicked.connect( self.start_thread0 )
        self.pushButton_12.clicked.connect( self.stop_thread0 )
        self.pushButton_10.clicked.connect( self.saveEMGModel )
        self.pushButton_10.setStyleSheet( "background-color: red" )
        self.pushButton_13.clicked.connect( self.browseCSVEMGModel1 )
        self.pushButton_14.clicked.connect( self.browseCSVEMGModel2 )
        self.pushButton_15.clicked.connect( self.browseCSVEMGModel3 )
        self.pushButton_16.clicked.connect( self.browseCSVEMGModel4 )
        self.pushButton_21.clicked.connect( self.joinCSV1 )
        self.pushButton_22.clicked.connect( self.joinCSV2 )
        self.pushButton_23.clicked.connect( self.saveJoinCSV )
        self.pushButton_17.clicked.connect( self.browsePickleEMGModel1 )
        self.pushButton_18.clicked.connect( self.browsePickleEMGModel2 )
        self.pushButton_19.clicked.connect( self.browseCVModel )
        self.pushButton_20.clicked.connect( self.start_thread4 )
        self.pushButton_20.setStyleSheet( "background-color: green" )
        self.pushButton_24.clicked.connect( self.stop_thread4 )
        self.pushButton_24.setStyleSheet( "background-color: red" )
        self.pushButton_25.clicked.connect( QtCore.QCoreApplication.instance().quit )
        self.path1 = self.path2 = self.path3 = self.path4 = self.path5 = self.path6 = self.path7 = self.path8 = None


        palette = QtGui.QPalette()
        palette.setColor(QtGui.QPalette.Foreground, QtCore.Qt.red)
        self.label.setPalette(palette)
        self.stop_request =True

        
        self.thread1 = None
        self.thread2 = None
        self.event_stop_thread0 = threading.Event()
        self.event_stop_thread1 = threading.Event()
        self.event_stop_thread2 = threading.Event()
        self.event_stop_thread3 = threading.Event()
        self.event_stop_thread4 = threading.Event()