Esempio n. 1
0
class OSXGyroscope(Gyroscope):
    def _enable(self):
        try:
            self.device_cache = DEVICE_CACHE
            # Run the UDP server in the background.
            self.thread = ServerThread( GyroHandler )
            self.thread.start()
        except:
            raise Exception('Could not enable gyroscope on this macbook!')

    def _disable(self):
        # Shutdown the server.
        self.thread.shutdown()

    def _get_orientation(self):
        """ Return a 3-tuple of 3 angles in the form of x_rot, y_rot, z_rot measured in radians. """
        try:
            # Access the latest data from the device cache.
            x_rot, y_rot, z_rot = self.device_cache[-1]
            return x_rot, y_rot, z_rot 
        except IndexError:
            # self.device_cache is empty
            return 0,0,0
        except ValueError:
            # data isn't a 3-tuple.
            return 0,0,0
Esempio n. 2
0
 def _enable(self):
     try:
         self.device_cache = DEVICE_CACHE
         # Run the UDP server in the background.
         self.thread = ServerThread( GyroHandler )
         self.thread.start()
     except:
         raise Exception('Could not enable gyroscope on this macbook!')
class OSXAccelerometer(Accelerometer):
    def _enable(self):
        # Run the UDP server in the background.
        self.device_cache = DEVICE_CACHE
        self.thread = ServerThread( AccHandler )
        self.thread.start()

    def _disable(self):
        # Shutdown the server.
        self.thread.shutdown()

    def _get_acceleration(self):
        """ Return a 3-tuple of the accelerations due to user motion on each axis measured in g-forces. """
        try:
            # Access the latest data from the device cache.
            x_acc, y_acc, z_acc = self.device_cache[-1]
            return x_acc, y_acc, z_acc 
        except IndexError:
            # self.device_cache is empty
            return 0,0,0
        except ValueError:
            # data isn't a 3-tuple.
            return 0,0,0
Esempio n. 4
0
class OSXCompass(Compass):
    def _enable(self):
        # Run the UDP server in the background.
        self.device_cache = DEVICE_CACHE
        self.thread = ServerThread( CompassHandler )
        self.thread.start()

    def _disable(self):
        # Shutdown the server.
        self.thread.shutdown()

    def _get_orientation(self):
        """ Return a 3-tuple of the 3  orientations on each axis measured in g-forces. """
        try:
            # Access the latest data from the device cache.
            x, y, z = self.device_cache[-1]
            return x, y, z 
        except IndexError:
            # self.device_cache is empty
            return 0,0,0
        except ValueError:
            # data isn't a 3-tuple.
            return 0,0,0
 def _enable(self):
     # Run the UDP server in the background.
     self.device_cache = DEVICE_CACHE
     self.thread = ServerThread( AccHandler )
     self.thread.start()