Last active
June 13, 2017 18:44
-
-
Save proffalken/8c1d73735dd30ebc28d352b829f9a65c to your computer and use it in GitHub Desktop.
Python Classes and Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
HeartRate - Use bluetooth low energy to detect heartrate | |
""" | |
import threading | |
import random | |
import ble | |
class HeartRate(threading.Thread): | |
def __init__(self, thread_id, name): | |
threading.Thread.__init__(self) | |
self.threadID = thread_id | |
self.name = name | |
def run(self): | |
global current_heartrate | |
dev = ble.discover_device(lambda d: ble.uuids.heart_rate in d.uuids) | |
try: | |
dev.connect() | |
except: | |
print("Failed to connect to Heartrate Monitor") | |
sys.exit(1) | |
dev.heart_rate_service.heart_rate_measurement.notifying=True | |
while True: | |
current_heartrate = dev.heart_rate_service.heart_rate_measurement.value[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from HeartRate import HeartRate | |
from VideoPlayer import VideoPlayer | |
current_heartrate = 0 | |
heartrate_thread = HeartRate(0, 'HeartRateSensor') | |
vid_player_thread = VideoPlayer(1, 'VideoPlayer', 'file1.mp4') | |
heartrate_thread.start() | |
vid_player_thread.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
VideoPlayer - Display the heartrate over the top of the video | |
""" | |
import threading | |
class VideoPlayer(threading.Thread): | |
def __init__(self, thread_id, name): | |
threading.Thread.__init__(self) | |
self.threadID = thread_id | |
self.name = name | |
def run(self): | |
global current_heartrate | |
## Load the video | |
## Play the Video and display the heartrate over the top |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment