Closed furlow closed 10 years ago
oh right okay, I will try and help you out
For the bluetooth comms threading class, (we'll put this in a separate file as well) you need to do something as i've explained bellow
#The bluetooth_comms class is inheriting the threading.
#Thread class, that's what's happening here
class bluetooth_comms(threading.Thread):
def __init__(self, data): #initlization function for the class
#As with any inheritance in any language you have
#to call the base class constructor to initalize the base class
threading.Thread.__init__(self)
#This line creates self.data and copies data to it
self.data = data
#This function overrides/re-defines the run method for the threading.Thread class
#So this is the section of code that runs when you use the start method
def run(self):
#put the rest of the operation of the bluetooth code in here
In your main function you import the library
from bluetooth_comms import *
data = [0,0,0,0]
#This creates a new instance of the bluetooth_comms class,
#It calls the __init__ function
comms = bluetooth_comms(data)
#Starts the bluetooth comms
comms.start()
Now when you read data it will be updated with what ever the bluetooths_comms class changes
Basically we need to create a thread object details can be found at http://docs.python.org/2/library/threading.html#thread-objects
Oh right, I get what to do in the main function, I have done that already and put it on github. but will have a go at the bluetooth function itself later tomorrow. Cheers.
I have done some stuff and put it on to the threading branch, let me know if you cant see it.
Yeah your changes have made it into the threading branch. Let me know if you need anymore help on this
everything on the previous link I posted is very useful. you might want to look at http://docs.python.org/2/library/threading.html#timer-objects
this was the bit i was confused on, not sure how to make the bluetooth code into a threading class