birdbrain 0.9.0 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb21675457d7a7b695a6f4b4858987a08cc68ebf295c1d3d869e8f0b5f5a5df6
4
- data.tar.gz: cac303fd2d781c1422ba1409e6f18d95b0878d08fb46809dc850c0beefa95e83
3
+ metadata.gz: 3c97dbbf10c8bd37e84d77c71759400feaba7bac5212e299e55d0eae6f8a1350
4
+ data.tar.gz: 2b56534b9f49f1126b25c3d8c9833e980ec160e613a0df6a0f910ac953a72404
5
5
  SHA512:
6
- metadata.gz: 507384baf7913ffd3cfac814352828169d92b73134846fbac52566416e1ecc87e3e798f9921e3f565ccb7b3ed61a16c892fcd1722f11340c0a2edf41e79be54e
7
- data.tar.gz: 4e24f99216233d97443b45a88139e68515239d75c0ef1c07265cdd2f8648361e6bf9c6f17105fbffcc50edd660e8554b3f5dc2569a5bda25903ba5b7d8c4d80c
6
+ metadata.gz: 613d57a819451c0b50ef06ee7f2931a572b1df62b8e3e8b8ab26f00de58b566064f721a7b6229be6b58d867061b194a61dbe4bce9bcf92ea3eec6b684e32393b
7
+ data.tar.gz: ff072dc975075212f67565716b343022fbaf6ad20394a35312d1a14560dd5df8f4332812bf876537849843157eaee241e5cada879bfc7ea18b264d3ef8f61317
data/README.md CHANGED
@@ -4,9 +4,9 @@ Ruby Library for the BirdBrainTechnologies Hummingbird Bit and Finch 2
4
4
 
5
5
  This Ruby library allows students to use Ruby to read sensors and set motors and LEDs with the Hummingbird Bit. To use Ruby with the Hummingbird Bit, you must connect to the Hummingbird Bit via bluetooth with the BlueBird Connector.
6
6
 
7
- For more information about setting up the BlueBird Connector used with their Python library, see www.birdbraintechnologies.com/hummingbirdbit/python/
7
+ For more information about setting up the BlueBird Connector used with their Python library, see www.birdbraintechnologies.com/hummingbirdbit/python
8
8
 
9
- Rdoc files are available at https://rdoc.info/github/fmorton/BirdBrain-Ruby-Library/
9
+ RubyDoc files are available at https://rubydoc.info/github/fmorton/BirdBrain-Ruby-Library
10
10
 
11
11
  ## Installation
12
12
 
@@ -24,11 +24,64 @@ Or install it yourself as:
24
24
 
25
25
  $ gem install birdbrain
26
26
 
27
- The library is distributed through https://rubygems.org/gems/birdbrain/
27
+ The library is distributed through https://rubygems.org/gems/birdbrain
28
28
 
29
29
  ## Usage
30
30
 
31
- TODO: Write usage instructions here
31
+ Below are two examples causing a Finch 2 to move in the path of a box. The first example is the long way to do it:
32
+
33
+ ```ruby
34
+ require 'birdbrain'
35
+
36
+ finch = BirdbrainFinch.connect('A')
37
+
38
+ finch.beak(0, 50, 0)
39
+
40
+ finch.tail(1, 0, 50, 0)
41
+ finch.move(BirdbrainFinch::FORWARD, 2, 20)
42
+ finch.turn(BirdbrainFinch::LEFT, 90, 50)
43
+
44
+ finch.tail(2, 0, 50, 0)
45
+ finch.move(BirdbrainFinch::FORWARD, 2, 20)
46
+ finch.turn(BirdbrainFinch::RIGHT, 90, 50)
47
+ finch.tail(3, 0, 50, 0)
48
+
49
+ finch.move(BirdbrainFinch::BACKWARD, 2, 20)
50
+ finch.turn(BirdbrainFinch::RIGHT, 90, 50)
51
+ finch.tail(4, 0, 50, 0)
52
+
53
+ finch.move(BirdbrainFinch::FORWARD, 2, 20)
54
+ finch.turn(BirdbrainFinch::LEFT, 90, 50)
55
+ sleep(1)
56
+
57
+ finch.disconnect
58
+ ```
59
+
60
+ The second way has the same result, but is more concise:
61
+
62
+ ```ruby
63
+ require 'birdbrain'
64
+
65
+ def draw(finch, step, move_direction, turn_direction)
66
+ finch.tail(step, 0, 50, 0)
67
+ finch.move(move_direction, 2, 20)
68
+ finch.turn(turn_direction, 90, 50)
69
+ end
70
+
71
+ finch = BirdbrainFinch.connect('A')
72
+
73
+ finch.beak(0, 50, 0)
74
+
75
+ draw(finch, 1, BirdbrainFinch::FORWARD, BirdbrainFinch::LEFT)
76
+ draw(finch, 2, BirdbrainFinch::FORWARD, BirdbrainFinch::RIGHT)
77
+ draw(finch, 3, BirdbrainFinch::BACKWARD, BirdbrainFinch::RIGHT)
78
+ draw(finch, 4, BirdbrainFinch::FORWARD, BirdbrainFinch::LEFT)
79
+ sleep(1)
80
+
81
+ finch.disconnect
82
+ ```
83
+
84
+ RubyDoc files are available at https://rubydoc.info/github/fmorton/BirdBrain-Ruby-Library
32
85
 
33
86
  ## Development
34
87
 
@@ -43,3 +96,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/fmorto
43
96
  ## License
44
97
 
45
98
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
99
+
100
+
data/birdbrain.gemspec CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ['fmorton']
7
7
  spec.email = ['fmorton@mac.com']
8
8
 
9
- spec.summary = 'Ruby Library for Hummingbird Bit (and maybe Finch 2 later)'
9
+ spec.summary = 'Ruby Library for BirdBrain Technologies Hummingbird Bit and Finch 2'
10
10
  spec.description = 'This Ruby library allows students to use Ruby to read sensors and set motors and LEDs with the '\
11
- 'Birdbrain Technologies Hummingbird Bit. To use Ruby with the Hummingbird Bit, you must connect '\
12
- 'to the Hummingbird Bit via bluetooth with the BlueBird Connector.'
11
+ 'Birdbrain Technologies Hummingbird Bit and Finch 2. To use Ruby with the Hummingbird Bit or '\
12
+ 'Finch 2, you must connect via bluetooth with the BlueBird Connector.'
13
13
  spec.homepage = 'https://github.com/fmorton/BirdBrain-Ruby-Library'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
@@ -13,7 +13,7 @@ class BirdbrainDevice
13
13
 
14
14
  def initialize(device = DEFAULT_DEVICE)
15
15
  self.state = BirdbrainState.new
16
- self.device = device
16
+ self.device = remap_device(device)
17
17
  self.connected = nil
18
18
  end
19
19
 
@@ -30,6 +30,10 @@ class BirdbrainDevice
30
30
  device
31
31
  end
32
32
 
33
+ def remap_device(device = DEFAULT_DEVICE)
34
+ device
35
+ end
36
+
33
37
  def connect
34
38
  self.connected = BirdbrainRequest.connected?(device)
35
39
  self.connected = nil unless valid_device_type?
@@ -96,7 +96,7 @@ class BirdbrainFinch < BirdbrainMicrobit
96
96
  end
97
97
 
98
98
  def tail(port, r_intensity, g_intensity, b_intensity)
99
- return unless connected_and_valid?(port, VALID_TAIL_PORTS)
99
+ return nil unless connected_and_valid?(port, VALID_TAIL_PORTS)
100
100
 
101
101
  if port.to_s == 'all'
102
102
  (2..5).each { |each_port| BirdbrainHummingbirdOutput.tri_led(device, each_port, r_intensity, g_intensity, b_intensity) }
@@ -135,7 +135,7 @@ class BirdbrainFinch < BirdbrainMicrobit
135
135
  end
136
136
 
137
137
  def move(direction, distance, speed, wait_to_finish_movement = true)
138
- return false unless connected_and_valid?(direction, VALID_MOVE_DIRECTION)
138
+ return nil unless connected_and_valid?(direction, VALID_MOVE_DIRECTION)
139
139
 
140
140
  unless (response = BirdbrainFinchOutput.move(device, direction, distance, speed))
141
141
  return response
@@ -147,7 +147,7 @@ class BirdbrainFinch < BirdbrainMicrobit
147
147
  end
148
148
 
149
149
  def turn(direction, angle, speed, wait_to_finish_movement = true)
150
- return false unless connected_and_valid?(direction, VALID_TURN_DIRECTION)
150
+ return nil unless connected_and_valid?(direction, VALID_TURN_DIRECTION)
151
151
 
152
152
  unless (response = BirdbrainFinchOutput.turn(device, direction, angle, speed))
153
153
  return response
@@ -4,5 +4,5 @@
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module Birdbrain
7
- VERSION = '0.9.0'
7
+ VERSION = '0.9.5'
8
8
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birdbrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - fmorton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This Ruby library allows students to use Ruby to read sensors and set
14
- motors and LEDs with the Birdbrain Technologies Hummingbird Bit. To use Ruby with
15
- the Hummingbird Bit, you must connect to the Hummingbird Bit via bluetooth with
14
+ motors and LEDs with the Birdbrain Technologies Hummingbird Bit and Finch 2. To
15
+ use Ruby with the Hummingbird Bit or Finch 2, you must connect via bluetooth with
16
16
  the BlueBird Connector.
17
17
  email:
18
18
  - fmorton@mac.com
@@ -72,5 +72,5 @@ requirements: []
72
72
  rubygems_version: 3.2.5
73
73
  signing_key:
74
74
  specification_version: 4
75
- summary: Ruby Library for Hummingbird Bit (and maybe Finch 2 later)
75
+ summary: Ruby Library for BirdBrain Technologies Hummingbird Bit and Finch 2
76
76
  test_files: []