Skip to content
Browse files

refactor command declaration

  • Loading branch information...
1 parent 31a5e27 commit c2b15cde94bfe5838e534d2a9314c28b2bbd6152 @tenderlove committed
Showing with 8 additions and 49 deletions.
  1. +1 −1 lib/sphero.rb
  2. +7 −48 lib/sphero/request.rb
View
2 lib/sphero.rb
@@ -124,7 +124,7 @@ def write packet
#s.roll 100, 0
- p s.auto_reconnect
+ p s.user_led
exit
loop do
[0, 180].each do |dir|
View
55 lib/sphero/request.rb
@@ -68,13 +68,14 @@ def self.make_command klass, cid, &block
SetBackLEDOutput = make_command Sphero, 0x21
SetRotationRate = make_command Sphero, 0x03
SetRGB = make_command Sphero, 0x20
+ GetRGB = make_command Sphero, 0x22
- class GetRGB < Sphero
- def initialize seq
- super(seq, [])
- @cid = 0x22
- end
- end
+ Ping = make_command Request, 0x01
+ GetVersioning = make_command Request, 0x02
+ GetBluetoothInfo = make_command Request, 0x11
+ SetAutoReconnect = make_command Request, 0x12
+ GetAutoReconnect = make_command Request, 0x13
+ GetPowerState = make_command Request, 0x20
class Roll < Sphero
def initialize seq, speed, heading, delay
@@ -88,48 +89,6 @@ def packet_body
end
end
- class Ping < Request
- def initialize seq
- super(seq, [])
- @cid = 0x01
- end
- end
-
- class GetVersioning < Request
- def initialize seq
- super(seq, [])
- @cid = 0x02
- end
- end
-
- class GetBluetoothInfo < Request
- def initialize seq
- super(seq, [])
- @cid = 0x11
- end
- end
-
- class SetAutoReconnect < Request
- def initialize seq, time = 7, enabled = 0x01
- super(seq, [enabled, time])
- @cid = 0x12
- end
- end
-
- class GetAutoReconnect < Request
- def initialize seq
- super(seq, [])
- @cid = 0x13
- end
- end
-
- class GetPowerState < Request
- def initialize seq
- super(seq, [])
- @cid = 0x20
- end
- end
-
class Sleep < Request
def initialize seq, wakeup, macro
super(seq, [wakeup, macro])

0 comments on commit c2b15cd

Please sign in to comment.
Something went wrong with that request. Please try again.