Beispiel #1
0
    def __init__(self, serial, printHz=False, bufsize=2048, baudrate=1e6):
        super().__init__()

        self.serial = serial
        self.baudrate = baudrate
        self.bufsize = bufsize
        self.run = True
        self.fs = 80000
        self.c = 34300

        # Filter parameters
        self.alpha = 0.05
        self.cutoff = 100
        self.order = 5

        # Touch detection parameters
        self.threshold = 180.0

        # Creating plot window
        app = QtGui.QApplication(sys.argv)
        loop = QEventLoop(app)
        asyncio.set_event_loop(loop)
        self.resize(800, 400)

        # App ranges
        self.ranges = {'a': (20, 53), 'b': (62, 101), 'c': (110, 150)}

        # Plotting parameters
        p = self.addPlot()
        self.plotline = p.plot(pen='y')
        self.baseline = p.plot(pen='b')
        self.l = pg.TextItem()
        self.l.setText('')
        self.l.setColor('y')
        self.l.setTextWidth(500)
        p.addItem(self.l)
        self.show()

        loop.run_until_complete(self.read_data())
Beispiel #2
0
def main():
    args = get_argparser().parse_args()
    init_logger(args)

    app = QtGui.QApplication([])
    loop = QEventLoop(app)
    asyncio.set_event_loop(loop)
    atexit.register(lambda: loop.close())

    smgr = StateManager(args.db_file)

    schedule_ctl = AsyncioClient()
    loop.run_until_complete(
        schedule_ctl.connect_rpc(args.server, args.port_control,
                                 "master_schedule"))
    atexit.register(lambda: schedule_ctl.close_rpc())

    win = MainWindow(app, args.server)
    area = dockarea.DockArea()
    smgr.register(area)
    smgr.register(win)
    win.setCentralWidget(area)
    status_bar = QtGui.QStatusBar()
    status_bar.showMessage("Connected to {}".format(args.server))
    win.setStatusBar(status_bar)

    d_explorer = ExplorerDock(win, status_bar, schedule_ctl)
    smgr.register(d_explorer)
    loop.run_until_complete(
        d_explorer.sub_connect(args.server, args.port_notify))
    atexit.register(lambda: loop.run_until_complete(d_explorer.sub_close()))

    d_datasets = DatasetsDock(win, area)
    smgr.register(d_datasets)
    loop.run_until_complete(
        d_datasets.sub_connect(args.server, args.port_notify))
    atexit.register(lambda: loop.run_until_complete(d_datasets.sub_close()))

    if os.name != "nt":
        d_ttl_dds = MonInj()
        loop.run_until_complete(d_ttl_dds.start(args.server, args.port_notify))
        atexit.register(lambda: loop.run_until_complete(d_ttl_dds.stop()))

    if os.name != "nt":
        area.addDock(d_ttl_dds.dds_dock, "top")
        area.addDock(d_ttl_dds.ttl_dock, "above", d_ttl_dds.dds_dock)
        area.addDock(d_datasets, "above", d_ttl_dds.ttl_dock)
    else:
        area.addDock(d_datasets, "top")
    area.addDock(d_explorer, "above", d_datasets)

    d_schedule = ScheduleDock(status_bar, schedule_ctl)
    loop.run_until_complete(
        d_schedule.sub_connect(args.server, args.port_notify))
    atexit.register(lambda: loop.run_until_complete(d_schedule.sub_close()))

    d_log = LogDock()
    smgr.register(d_log)
    loop.run_until_complete(d_log.sub_connect(args.server, args.port_notify))
    atexit.register(lambda: loop.run_until_complete(d_log.sub_close()))

    dataset_db = AsyncioClient()
    loop.run_until_complete(
        dataset_db.connect_rpc(args.server, args.port_control,
                               "master_dataset_db"))
    atexit.register(lambda: dataset_db.close_rpc())

    def _set_dataset(k, v):
        asyncio.ensure_future(dataset_db.set(k, v))

    def _del_dataset(k):
        asyncio.ensure_future(dataset_db.delete(k))

    d_console = ConsoleDock(d_datasets.get_dataset, _set_dataset, _del_dataset)

    area.addDock(d_console, "bottom")
    area.addDock(d_log, "above", d_console)
    area.addDock(d_schedule, "above", d_log)

    smgr.load()
    smgr.start()
    atexit.register(lambda: loop.run_until_complete(smgr.stop()))
    win.show()
    loop.run_until_complete(win.exit_request.wait())
Beispiel #3
0
    def __init__(self,
                 serialport,
                 *,
                 baudrate=115200,
                 outpath=None,
                 printlines=False,
                 firstline='',
                 printHz=False,
                 bufsize=2048,
                 pMin=0,
                 pMax=25,
                 convert_pressure=False,
                 socket_start=False):
        super().__init__()

        self.serialport = serialport
        self.baudrate = baudrate
        self.outpath = outpath
        self.outfile = None
        self.printlines = printlines
        self.printHz = printHz
        self.bufsize = bufsize
        self.plotbuf = deque(maxlen=self.bufsize)
        self.rawdata = deque(maxlen=self.bufsize)
        self.pMin = pMin
        self.pMax = pMax

        self.convert_pressure = convert_pressure
        self.f = OneEuroFilter(100, .25, .1)
        self.event = 0
        self.run = True
        self.filterflag = True

        #Touch event detection
        self.diffsamps = 100  #How far back to look for diff
        self.event_thresh = 7  #Standard Deviation value to consider an event is happening
        self.touch = False  #Is a touch happening?
        self.touchcount = 0  #How many touch samples so far?
        self.touchthresh = 1000  #Number of touch samples to check
        self.touch_data = [
        ]  #Data from touch to be sent to machine learning thingy
        self.touch_buf = []
        #		self.model        = load(model) # Path to compiled model file
        self.printed = False

        self.socket = socket_start

        #Keep values to update baseline
        self.baselinebuf = deque(maxlen=self.bufsize // 4)

        app = QtGui.QApplication(sys.argv)
        loop = QEventLoop(app)
        asyncio.set_event_loop(loop)

        self.resize(800, 400)

        p = self.addPlot()
        self.plotline = p.plot(pen='y')
        self.baseline = p.plot(pen='b')
        self.show()

        if self.socket:
            # Create socket and wait for connection
            ip = ''
            port = 6969
            connected = False
            s = socket.socket()
            print('Waiting on connection')
            s.bind((ip, port))
            s.listen(1)
            self.conn, self.addr = s.accept()
            loop.run_until_complete(self.read_data())

        if self.outpath:
            with open(self.outpath, 'w') as self.outfile:
                if firstline:
                    self.log('#{}'.format(firstline))
                loop.run_until_complete(self.read_data())
        else:
            if firstline:
                self.log('#{}'.format(firstline))
            loop.run_until_complete(self.read_data())