Class: Artoo::Drivers::Sphero

Inherits:
Driver
  • Object
show all
Defined in:
lib/artoo/drivers/sphero.rb

Overview

The Sphero driver behaviors

Constant Summary collapse

RED =
[255, 0,   0]
GREEN =
[0,   255, 0]
YELLOW =
[255, 255, 0]
BLUE =
[0,   0,   255]
WHITE =
[255, 255, 255]
COMMANDS =
[:detect_collisions, :clear_collisions, :collisions,
:power_notifications, :sensor_data, :set_color, :color].freeze

Instance Attribute Summary

Attributes inherited from Driver

#parent

Instance Method Summary collapse

Methods inherited from Driver

#command, #commands, #connection, #event_topic_name, #initialize, #interval, #known_command?, #method_missing, #pin, #start_driver

Constructor Details

This class inherits a constructor from Artoo::Drivers::Driver

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Artoo::Drivers::Driver

Instance Method Details

#clear_collisionsObject

Clears collisions



24
25
26
# File 'lib/artoo/drivers/sphero.rb', line 24

def clear_collisions
  messages.clear if responses = messages
end

#collisionsCollisionDetected

Returns collision.

Returns:

  • (CollisionDetected)

    collision



29
30
31
# File 'lib/artoo/drivers/sphero.rb', line 29

def collisions
  matching_response_types messages, ::Sphero::Response::CollisionDetected
end

#color(*colors) ⇒ Object

Retrieves color

Parameters:

  • colors (Collection)


51
52
53
54
55
56
57
58
59
60
# File 'lib/artoo/drivers/sphero.rb', line 51

def color(*colors)
  case colors.first
  when :red    then RED
  when :green  then GREEN
  when :yellow then YELLOW
  when :blue   then BLUE
  when :white  then WHITE
  else colors
  end
end

#detect_collisions(params = {}) ⇒ Object

Detects collisions

Parameters:

  • params (Hash) (defaults to: {})


19
20
21
# File 'lib/artoo/drivers/sphero.rb', line 19

def detect_collisions(params={})
  connection.configure_collision_detection 0x01, 0x20, 0x20, 0x20, 0x20, 0x50
end

#power_notificationsPowerNotification

Returns power notification.

Returns:

  • (PowerNotification)

    power notification



34
35
36
# File 'lib/artoo/drivers/sphero.rb', line 34

def power_notifications
  matching_response_types messages, ::Sphero::Response::PowerNotification
end

#sensor_dataSensorData

Returns sensor data.

Returns:

  • (SensorData)

    sensor data



39
40
41
# File 'lib/artoo/drivers/sphero.rb', line 39

def sensor_data
  matching_response_types messages, ::Sphero::Response::SensorData
end

#set_color(*colors) ⇒ Object

Set color

Parameters:

  • colors (Collection)


45
46
47
# File 'lib/artoo/drivers/sphero.rb', line 45

def set_color(*colors)
  connection.rgb(*color(*colors))
end