rbbit 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 377a1d4c7fb6aeac90e9612e6567ee2ff51cd1a92cfa589857d2a65e8c46ef48
4
+ data.tar.gz: a723eb889d772a854436a5ba8980926baaab098181ec989fcfc22ffe8f0d61f8
5
+ SHA512:
6
+ metadata.gz: 9654d0c5fc439ef5296b6078a80e0bd3a2bfa525c8c3857ec6a6f69651858cc39e5d8465c1066d29fd236cbc4337042822525dbdc0b1ecd74158b88dd4111e43
7
+ data.tar.gz: 19086d0ca0decc0bc7f1541f88beeb5def3421b1d1d9ea9aa5a98d0be1ae99ba2acc6083446f922aaeed27edaa641b0dd7774dc196b05464be48d436d54c4e74
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /_doc/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rbbit.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 spoolkitamura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # rbbit (rb:-:bit)
2
+
3
+ 'rbbit' is a Class library and WebSocket server to use 'micro:bit'.
4
+
5
+ ## Requirements
6
+
7
+ serialport ~> 1.3
8
+ em-websocket ~> 0.5
9
+ websocket-client-simple ~> 0.3
10
+
11
+ ## Installation
12
+
13
+ Install it yourself as:
14
+
15
+ $ gem install rbbit
16
+
17
+ If you are using Windows, type following in addition to it:
18
+
19
+ $ gem uninstall eventmachine
20
+ $ gem install eventmachine --platform ruby
21
+
22
+ ## Settings
23
+
24
+ ### [micro:bit]
25
+
26
+ Connect the micro:bit to your PC with USB cable.
27
+ Then, save following file and drop to the micro:bit.
28
+
29
+ [microbit-rbbit_20201127_v1.5.hex](microbit/microbit-rbbit_20201127_v1.5.hex) (for micro:bit v1.5)
30
+ [microbit-rbbit_20201127_v2.0.hex](microbit/microbit-rbbit_20201127_v2.0.hex) (for micro:bit v2.0)
31
+
32
+ ### [PC]
33
+
34
+ To specify the port name (MB_PORT),
35
+ find out the serial-port connected the micro:bit like as.
36
+
37
+ **Windows**
38
+
39
+ [windows] + [x] to open Device Manager
40
+
41
+ Find a description like 'mbed Serial Port (`COM5`)'.
42
+
43
+ **macOS**
44
+
45
+ $ ls -l /dev/tty.*
46
+
47
+ Find a device like `/dev/tty.usbmodem14132`.
48
+
49
+ **Linux**
50
+
51
+ $ $ls -l /dev/serial/by-id/
52
+
53
+ Find a device like `/dev/ttyACM1`.
54
+
55
+
56
+ ## Usage
57
+
58
+ ### [as Class library]
59
+ ```ruby
60
+ require 'rbbit'
61
+
62
+ mb = Rbbit:Microbit.new("COM5") # or "/dev/tty.usbmodem14132", "/dev/ttyACM1"
63
+ mb.led_on
64
+ mb.close(1000)
65
+ ```
66
+
67
+ ### [as WebSocket server]
68
+
69
+ $ rbbit COM5 (Windows)
70
+ $ rbbit /dev/tty.usbmodem14132 (macOS)
71
+ $ rbbit /dev/ttyACM1 (Linux)
72
+
73
+ or
74
+
75
+ $ set MB_PORT=COM5 (Windows)
76
+ $ export MB_PORT=/dev/tty.usbmodem14132 (macOS)
77
+ $ export MB_PORT=/dev/ttyACM1 (Linux)
78
+
79
+ $ rbbit
80
+
81
+
82
+ ## Documents
83
+
84
+ https://spoolkitamura.github.io/rbbit/index.html
85
+
86
+ ## Samples
87
+
88
+ https://spoolkitamura.github.io/rbbit/sample_web.html
89
+ https://spoolkitamura.github.io/rbbit/sample_console.html
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
94
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rbbit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/rbbit ADDED
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rbbit"
4
+ require 'optparse'
5
+ require 'readline'
6
+
7
+ #
8
+ # Diagnosis
9
+ #
10
+
11
+ def diagnosis(mb)
12
+ STDOUT.sync = true
13
+ while input = Readline.readline("micro:bit> ", true)
14
+ inputs = input.split(' ')
15
+ case inputs[0]
16
+ when '?'
17
+ puts
18
+ puts "interactive commands"
19
+ puts "\n [LED]"
20
+ puts " on x y ... turn on the LED at (x, y) or whole if omitt x, y"
21
+ puts " off x y ... turn off the LED at (x, y) or whole if omitt x, y"
22
+ puts " turn x y ... toggle the LED at (x, y) or center if omitt x, y"
23
+ puts " puts str ... show string specified or 'Ruby!' if ommit str"
24
+ puts " 1 ... show LED's pattern 1"
25
+ puts " 2 ... show LED's pattern 2"
26
+ puts " 3 ... show LED's pattern 3"
27
+ puts "\n [Sound]"
28
+ puts " play ... play sound"
29
+ puts "\n [Sensor]"
30
+ puts " scan ... print values of 'x', 'y', 'z', 'pitch', 'roll', 'light', 'temp' for 10 seconds"
31
+ puts "\n [Button]"
32
+ puts " button ... print status of button-A and button-B for 10 seconds"
33
+ puts "\n [etc]"
34
+ puts " port ... print port"
35
+ puts " reset ... reset micro:bit"
36
+ puts " exit ... exit this script"
37
+ puts
38
+ when 'exit'
39
+ mb.close
40
+ break
41
+ when 'reset'
42
+ mb.reset
43
+ when 'port'
44
+ puts mb.port
45
+ when 'on'
46
+ x = y = nil
47
+ if inputs.length >= 3
48
+ x = inputs[1].to_i
49
+ y = inputs[2].to_i
50
+ end
51
+ mb.led_on(x, y)
52
+ when 'off'
53
+ x = y = nil
54
+ if inputs.length >= 3
55
+ x = inputs[1].to_i
56
+ y = inputs[2].to_i
57
+ end
58
+ mb.led_off(x, y)
59
+ when 'turn'
60
+ x = y = 2
61
+ if inputs.length >= 3
62
+ x = inputs[1].to_i
63
+ y = inputs[2].to_i
64
+ end
65
+ mb.led_turn(x, y)
66
+ when 'puts'
67
+ str = 'Ruby!'
68
+ if inputs.length >= 2
69
+ str = inputs[1]
70
+ end
71
+ mb.led_puts(str)
72
+ when '1'
73
+ mb.led_show(
74
+ [[1, 1, 1, 1, 1],
75
+ [0, 0, 0, 0, 0],
76
+ [1, 1, 1, 1, 1],
77
+ [0, 0, 0, 0, 0],
78
+ [1, 1, 1, 1, 1]]
79
+ )
80
+ when '2'
81
+ mb.led_show(
82
+ [[1, 1, 1, 1, 1],
83
+ [1, 1, 1, 1, 0],
84
+ [1, 1, 1, 0, 0],
85
+ [1, 1, 0, 0, 0],
86
+ [1, 0, 0, 0, 0]]
87
+ )
88
+ when '3'
89
+ mb.led_show(
90
+ [[1, 0, 1, 0, 1],
91
+ [0, 0, 1, 0, 1],
92
+ [1, 1, 1, 0, 1],
93
+ [0, 0, 0, 0, 1],
94
+ [1, 1, 1, 1, 1]]
95
+ )
96
+ when 'play'
97
+ mb.sound_volume = 48
98
+ mb.sound_tempo = 180
99
+ mb.sound_play(:C4, 1) # do
100
+ mb.sound_play(:D4, 1) # re
101
+ mb.sound_play(:E4, 1) # mi
102
+ mb.sound_play(:F4, 1) # fa
103
+ mb.sound_play(:G4, 1) # so
104
+ mb.sound_play(:A4, 1) # la
105
+ mb.sound_play(:B4, 1) # si
106
+ mb.sound_play(:C5, 1) # do
107
+ mb.sound_rest(2)
108
+ mb.sound_play(:C5, 0.5) # do
109
+ mb.sound_play(:B4, 0.5) # si
110
+ mb.sound_play(:A4, 0.5) # la
111
+ mb.sound_play(:G4, 0.5) # so
112
+ mb.sound_play(:F4, 0.5) # fa
113
+ mb.sound_play(:E4, 0.5) # mi
114
+ mb.sound_play(:D4, 0.5) # re
115
+ mb.sound_play(:C4, 0.5) # do
116
+ mb.sound_rest(2)
117
+ when 'scan'
118
+ 20.times do
119
+ puts "x=%6d y=%6d z=%6d pitch=%3d roll=%3d light=%3d temp=%3d\n" % [mb.x, mb.y, mb.z, mb.p, mb.r, mb.l, mb.t]
120
+ Kernel.sleep 0.5
121
+ end
122
+ when 'button'
123
+ mb.on_press_a { puts "[A] press!" }
124
+ mb.on_press_b { puts "[B] press!" }
125
+ mb.on_release_a { puts "[A] release!" }
126
+ mb.on_release_b { puts "[B] release!" }
127
+ puts "Please press button"
128
+ 500.times do
129
+ puts "[A] down" if mb.button_down?(:a)
130
+ puts "[B] down" if mb.button_down?(:b)
131
+ Kernel.sleep 0.02
132
+ end
133
+ mb.on_press_a {}
134
+ mb.on_press_b {}
135
+ mb.on_release_a {}
136
+ mb.on_release_b {}
137
+ else
138
+ puts 'Invalid'
139
+ end
140
+ end
141
+ end
142
+
143
+
144
+
145
+ # parse options
146
+ usage = "Usage : #{$0} [-r] [-s ws_port] MB_PORT"
147
+ options = {}
148
+ begin
149
+ o = OptionParser.new do |o|
150
+ o.version = Rbbit::VERSION
151
+ o.banner = usage
152
+ o.summary_width = 16
153
+ o.summarize
154
+ o.on("-r", "reset")
155
+ o.on("-s ws_port", "specify WebSocket server port (default: #{Rbbit::WS_PORT})")
156
+ o.parse!(ARGV, into: options)
157
+ end
158
+ rescue => e
159
+ p e
160
+ exit
161
+ end
162
+
163
+ unless options.has_key?(:s)
164
+ options[:s] = :default
165
+ else
166
+ options[:s] = options[:s].to_i
167
+ end
168
+
169
+ # parse arguments
170
+ port = ARGV[0]
171
+ unless port || ENV['MB_PORT']
172
+ puts usage
173
+ else
174
+ mb = Rbbit::Microbit.new(port, options[:s])
175
+ if options[:r]
176
+ mb.reset
177
+ mb.close(1000)
178
+ else
179
+ print "conneted to #{mb.port}. "
180
+ puts (options[:i] ? "('?' for help)" : "")
181
+ diagnosis(mb)
182
+ end
183
+ end
184
+
@@ -0,0 +1,3 @@
1
+ module Rbbit
2
+ VERSION = "0.4.6"
3
+ end