Skip to content

Commit

Permalink
get the user led settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jul 25, 2012
1 parent b477a5e commit 40211b4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
21 changes: 18 additions & 3 deletions lib/sphero.rb
Expand Up @@ -58,7 +58,13 @@ def heading= h
end

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

# 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).
def user_led
write Request::GetRGB.new(@seq)
end

# Brightness 0x00 - 0xFF
Expand Down Expand Up @@ -106,8 +112,17 @@ def write packet
p s.ping
}

s.heading = 180
s.heading = 0
trap(:INT) {
s.stop
}

s.roll 100, 0

loop do
[0, 180].each do |dir|
s.heading = dir
end
end

#36.times {
# i = 10
Expand Down
13 changes: 12 additions & 1 deletion lib/sphero/request.rb
Expand Up @@ -75,13 +75,24 @@ def initialize seq, rate
end
end

class RGB < Sphero
class SetRGB < Sphero
def initialize seq, r, g, b, persistant
super(seq, [r, g, b, persistant])
@cid = 0x20
end
end

class GetRGB < Sphero
def initialize seq
super(seq, [])
@cid = 0x22
end

def response header, body
Response::GetRGB.new header, body
end
end

class Roll < Sphero
def initialize seq, speed, heading, delay
super(seq, [speed, heading, delay])
Expand Down
6 changes: 6 additions & 0 deletions lib/sphero/response.rb
Expand Up @@ -78,5 +78,11 @@ def bta
body.drop(16).slice_before(0x00).first.pack 'C*'
end
end

class GetRGB < Response
def r; body[0]; end
def g; body[1]; end
def b; body[2]; end
end
end
end

0 comments on commit 40211b4

Please sign in to comment.