Skip to content

Instantly share code, notes, and snippets.

@proffalken
Last active June 13, 2017 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proffalken/8c1d73735dd30ebc28d352b829f9a65c to your computer and use it in GitHub Desktop.
Save proffalken/8c1d73735dd30ebc28d352b829f9a65c to your computer and use it in GitHub Desktop.
Python Classes and Functions
"""
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]
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()
"""
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