# File lib/sensors/ultrasonic_sensor.rb, line 43
  def get_distance
    @nxt.ls_write(@port, UltrasonicComm.read_measurement_byte(0))
    
    # Keep checking until we have 1 byte of data to read
    while @nxt.ls_get_status(@port)[0] < 1
      sleep(0.1)
      @nxt.ls_write(@port, UltrasonicComm.read_measurement_byte(0))
      # TODO: implement timeout so we don't get stuck if the expected data never comes
    end
    
    resp = @nxt.ls_read(@port)
    # TODO: probably need a better error message here...
        raise "ls_read returned more than one byte!" if resp[:bytes_read] > 1
        raise "ls_read did not return any data!" if resp[:bytes_read] < 1
 
                # If the sensor cannot determine the distance, it will return
                # 0xff (255)... this usually means that the object is out of
                # sensor range, but it can also mean that there is too much
                # interference or that the object is too close to the sensor.
                # I considered returning nil or false under such cases, but
                # this makes numeric comparison (i.e. greather than/less than)
                # more difficult
                d = resp[:data][0]
  end