Class: Sphero

Inherits:
Object
  • Object
show all
Defined in:
lib/sphero.rb,
lib/sphero/request.rb,
lib/sphero/response.rb

Defined Under Namespace

Classes: Exception, Request, Response

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dev) ⇒ Sphero



14
15
16
17
18
19
# File 'lib/sphero.rb', line 14

def initialize dev
  @sp   = SerialPort.new dev, 115200, 8, 1, SerialPort::NONE
  @dev  = 0x00
  @seq  = 0x00
  @lock = Mutex.new
end

Class Method Details

.Client(uri) ⇒ Object



9
10
11
12
# File 'lib/sphero.rb', line 9

def self.Client uri
  require 'drb'
  DRbObject.new_with_uri uri
end

Instance Method Details

#auto_reconnectObject



37
38
39
# File 'lib/sphero.rb', line 37

def auto_reconnect
  write(Request::GetAutoReconnect.new(@seq)).time
end

#auto_reconnect=(time_s) ⇒ Object



33
34
35
# File 'lib/sphero.rb', line 33

def auto_reconnect= time_s
  write Request::SetAutoReconnect.new(@seq, time_s)
end

#back_led_output=(h) ⇒ Object

Brightness 0x00 - 0xFF



76
77
78
# File 'lib/sphero.rb', line 76

def back_led_output= h
  write Request::SetBackLEDOutput.new(@seq, h)
end

#bluetooth_infoObject



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

def bluetooth_info
  write Request::GetBluetoothInfo.new(@seq)
end

#color(red, green, blue) ⇒ Object



85
86
87
# File 'lib/sphero.rb', line 85

def color red, green, blue
  write 0x20, [red, green, blue], 0x02
end

#disable_auto_reconnectObject



41
42
43
# File 'lib/sphero.rb', line 41

def disable_auto_reconnect
  write Request::SetAutoReconnect.new(@seq, 0, 0x00)
end

#heading=(h) ⇒ Object



61
62
63
# File 'lib/sphero.rb', line 61

def heading= h
  write Request::Heading.new(@seq, h)
end

#pingObject



21
22
23
# File 'lib/sphero.rb', line 21

def ping
  write Request::Ping.new(@seq)
end

#power_stateObject



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

def power_state
  write Request::GetPowerState.new(@seq)
end

#rgb(r, g, b, persistant = false) ⇒ Object



65
66
67
# File 'lib/sphero.rb', line 65

def rgb r, g, b, persistant = false
  write Request::SetRGB.new(@seq, r, g, b, persistant ? 0x01 : 0x00)
end

#roll(speed, heading, state = true) ⇒ Object



53
54
55
# File 'lib/sphero.rb', line 53

def roll speed, heading, state = true
  write Request::Roll.new(@seq, speed, heading, state ? 0x01 : 0x00)
end

#rotation_rate=(h) ⇒ Object

Rotation Rate 0x00 - 0xFF



81
82
83
# File 'lib/sphero.rb', line 81

def rotation_rate= h
  write Request::SetRotationRate.new(@seq, h)
end

#sleep(wakeup = 0, macro = 0) ⇒ Object



49
50
51
# File 'lib/sphero.rb', line 49

def sleep wakeup = 0, macro = 0
  write Request::Sleep.new(@seq, wakeup, macro)
end

#stopObject



57
58
59
# File 'lib/sphero.rb', line 57

def stop
  roll 0, 0
end

#user_ledObject

This retrieves the “user LED color” which is stored in the config block (which may or may not be actively driven to the RGB LED).



71
72
73
# File 'lib/sphero.rb', line 71

def user_led
  write Request::GetRGB.new(@seq)
end

#versionObject



25
26
27
# File 'lib/sphero.rb', line 25

def version
  write Request::GetVersioning.new(@seq)
end