def on_spatial_data(obj=nil, &block)
      @on_spatial_data_obj = obj
      @on_spatial_data = Proc.new { |device, obj_ptr, data, data_count|
		
	  acceleration = []
	  if accelerometer_axes.size > 0
	    acceleration = [accelerometer_axes[0].acceleration, accelerometer_axes[1].acceleration, accelerometer_axes[2].acceleration]
	  end

      magnetic_field= []
      if compass_axes.size > 0 
        #Even when there is a compass chip, sometimes there won't be valid data in the event.
		begin
          magnetic_field = [compass_axes[0].magnetic_field, compass_axes[1].magnetic_field, compass_axes[2].magnetic_field]
        rescue Phidgets::Error::UnknownVal => e
          magnetic_field = ['Unknown', 'Unknown', 'Unknown']
        end
      end

      angular_rate = []
      if gyro_axes.size > 0
        angular_rate = [gyro_axes[0].angular_rate, gyro_axes[1].angular_rate, gyro_axes[2].angular_rate]
      end
	
      yield self, acceleration, magnetic_field, angular_rate, object_for(obj_ptr)
	}
      Klass.set_OnSpatialData_Handler(@handle, @on_spatial_data, pointer_for(obj))
    end
def on_spatial_data(obj=nil, &block)
      @on_spatial_data_obj = obj
      @on_spatial_data = Proc.new { |device, obj_ptr, data, data_count|
		
	  acceleration = []
	  if accelerometer_axes.size > 0
	    acceleration = [accelerometer_axes[0].acceleration, accelerometer_axes[1].acceleration, accelerometer_axes[2].acceleration]
	  end

      magnetic_field= []
      if compass_axes.size > 0 
        #Even when there is a compass chip, sometimes there won't be valid data in the event.
		begin
          magnetic_field = [compass_axes[0].magnetic_field, compass_axes[1].magnetic_field, compass_axes[2].magnetic_field]
        rescue Phidgets::Error::UnknownVal => e
          magnetic_field = ['Unknown', 'Unknown', 'Unknown']
        end
      end

      angular_rate = []
      if gyro_axes.size > 0
        angular_rate = [gyro_axes[0].angular_rate, gyro_axes[1].angular_rate, gyro_axes[2].angular_rate]
      end
	
      yield self, acceleration, magnetic_field, angular_rate, object_for(obj_ptr)
	}
      Klass.set_OnSpatialData_Handler(@handle, @on_spatial_data, pointer_for(obj))
    end
Sets a spatial data handler callback function. This is called at a fixed rate as determined by the data rate property. Contains data for acceleration/gyro/compass depending on what the board supports.

 @param [String] obj Object to pass to the callback function. This is optional.
 @param [Proc] Block When the callback is executed, the device and object are yielded to this block.
 @example
     spatial.on_spatial_data do |device, acceleration, magnetic_field, angular_rate, obj|
       puts "Acceleration: #{acceleration[0]},#{acceleration[1]}, #{acceleration[2]} | Magnetic field: #{magnetic_field[0]},#{magnetic_field[1]}, #{magnetic_field[2]} | Angular rate: #{angular_rate[0]},#{angular_rate[1]}, #{angular_rate[2]}"    #     end
 As this runs in it's own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.
 @return [Boolean] returns true or raises an error