Skip to content

Commit

Permalink
Add UART
Browse files Browse the repository at this point in the history
  • Loading branch information
mesca committed Nov 7, 2023
1 parent d5100dd commit 3a0e374
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018, Pierre Clisson <pierre@clisson.net>
Copyright (c) 2023, Pierre Clisson <pierre@clisson.net>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions examples/uart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ graphs:
filter_type: bandstop
frequencies: [45, 55]
order: 2
# - id: display
# module: timeflux.nodes.debug
# class: Display
- id: ui
module: timeflux_ui.nodes.ui
class: UI
Expand All @@ -20,5 +23,7 @@ graphs:
target: notch
- source: notch
target: ui:data
# - source: data
# target: display
rate: 10

17 changes: 13 additions & 4 deletions timeflux_upsidedownlabs/nodes/driver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# import sys
import numpy as np
import pandas as pd
from timeflux.core.node import Node
from threading import Lock
from pyfirmata2 import Arduino
Expand Down Expand Up @@ -33,6 +32,8 @@ def __init__(self, port=None, rate=500):
self.rate = rate
self.pin = 0
self.timestamp = 0
self.timestamps = []
self.data = []
self.board = Arduino(port)
self.meta = {"rate": rate}
self._lock = Lock()
Expand All @@ -52,14 +53,22 @@ def _blink(self):

def _callback(self, data):
"""Acquire and cache data."""
if self.timestamp == 0:
self.timestamp = time.time()
self._lock.acquire()
print(f"{self.timestamp:.3f}\t{data}")
self.timestamp += 1 / self.samplingRate
# print(f"{self.timestamp:.3f}\t{data}")
self.timestamps.append(self.timestamp)
self.data.append(data)
self._lock.release()
self.timestamp += 1 / self.rate

def update(self):
"""Update the node output."""
self._lock.acquire()
index = pd.to_datetime(self.timestamps, unit="s")
self.o.set(self.data, index, meta=self.meta)
self.data = []
self.timestamps = []
self._lock.release()

def terminate(self):
Expand Down

0 comments on commit 3a0e374

Please sign in to comment.