lib/artoo/drivers/sphero.rb in artoo-sphero-1.3.0 vs lib/artoo/drivers/sphero.rb in artoo-sphero-1.4.0
- old
+ new
@@ -9,11 +9,16 @@
GREEN = [0, 255, 0]
YELLOW = [255, 255, 0]
BLUE = [0, 0, 255]
WHITE = [255, 255, 255]
- COMMANDS = [:roll, :stop, :detect_collisions, :messages, :set_color, :color].freeze
+ COMMANDS = [:ping, :version, :bluetooth_info, :auto_reconnect,
+ :disable_auto_reconnect, :power_state, :sphero_sleep, :roll,
+ :stop, :heading, :stabilization, :color, :rgb, :set_color,
+ :back_led_output, :rotation_rate, :set_power_notification,
+ :set_data_streaming, :detect_collisions,
+ :handle_message_events, :get_rgb].freeze
# Starts drives and required connections
# Public: Starts the driver.
#
@@ -35,12 +40,12 @@
end
# Public: Handles different message events.
#
# Returns sphero_event.
- def handle_message_events
- while not connection.messages.empty? do
+ def handle_message_events
+ while not connection.messages.empty? do
evt = connection.messages.pop
case
when evt.is_a?(::Sphero::Response::CollisionDetected)
handle_collision_detected(evt)
when evt.is_a?(::Sphero::Response::PowerNotification)
@@ -72,11 +77,11 @@
# green - params
# blue -params
#
# Returns true | nil.
def set_color(*colors)
- connection.rgb(*color(*colors))
+ connection.rgb(*color(*colors), true)
end
# Retrieves color
# @param [Collection] colors
@@ -99,15 +104,26 @@
when :white then WHITE
else colors
end
end
+ # Get the sphero color
+
+ # Public: You can retrieve current sphero color
+ #
+ # Returns array of rgb values
+ def get_rgb
+ rgb = connection.user_led
+
+ [rgb.r, rgb.g, rgb.b] if rgb
+ end
+
private
# Publish collision events
- # Public: Handles collision message events.
+ # Handles collision message events.
#
# data - params
#
# Returns nil.
def handle_collision_detected(data)
@@ -125,10 +141,10 @@
publish(event_topic_name("power"), data)
end
# Publish collision events
- # Public: Handles sensor message events.
+ # Handles sensor message events.
#
# data - params
#
# Returns nil.
def handle_sensor_data(data)