class Crubyflie::Console
The Console
facility is used to read characters that have been printer using printf in the crazyflie firmware
Public Class Methods
Initialize the console @param crazyflie [Crazyflie]
# File lib/crubyflie/crazyflie/console.rb, line 26 def initialize(crazyflie) @crazyflie = crazyflie @in_queue = crazyflie.crtp_queues[:console] @read_thread = nil end
Public Instance Methods
Reads all the characters from the Crazyflie
that are queued, until the queue is empty, and then return only after executing the given block for each packet that was in the queue. @param block [Proc] a block to call with the read information
# File lib/crubyflie/crazyflie/console.rb, line 36 def read(&block) while @in_queue.size > 0 do packet = @in_queue.pop() # block yield(packet.data_repack) if block_given? end end
Reads all the characters from the Crazyflie
constantly and yields on the the given block is called with the payload. This call will return immediately, but the block will be called asynchronously until stop_reading()
is called. Use stop_read() to stop. @param block [Proc] a block to call with the read information
# File lib/crubyflie/crazyflie/console.rb, line 50 def start_reading(&block) stop_reading() @read_thread = Thread.new do loop do read(&block) sleep 0.3 # no hurries? end end end
Stops reading characters from the Crazyflie
# File lib/crubyflie/crazyflie/console.rb, line 61 def stop_reading @read_thread.kill() if @read_thread @read_thread = nil end