smalruby 0.0.12-x86-mingw32 → 0.0.13-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of smalruby might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/smalruby/character.rb +26 -0
- data/lib/smalruby/hardware/button.rb +35 -0
- data/lib/smalruby/hardware/servo.rb +34 -0
- data/lib/smalruby/hardware.rb +3 -0
- data/lib/smalruby/version.rb +1 -1
- data/lib/smalruby/world.rb +9 -0
- data/lib/smalruby.rb +24 -0
- data/samples/hardware_button.rb +32 -0
- data/samples/hardware_servo.rb +25 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1000156099f8bcf1bf2b1729bcb5b151b922f738
|
4
|
+
data.tar.gz: acadb5ea4a761b44a280d966ee0332b8bd3d902e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 965143c6fadafed0f0965dff950736629a391a78af012c2b98a85e75b81c24b7a0374711d381000259baf7fb9bceab24e6c9966edcd6f1fe55a2ed9c5ecd6021
|
7
|
+
data.tar.gz: f397c4132c9e557326d7ca552064b493e29a13b48bc62e97091446439174396c59f1c5c7a4c4fde5a3e5f4bc28df9353938150fb951149b0a8f98e3f1c5a0906
|
data/lib/smalruby/character.rb
CHANGED
@@ -208,6 +208,16 @@ module Smalruby
|
|
208
208
|
Hardware.create_hardware(Hardware::RgbLedCathode, pin)
|
209
209
|
end
|
210
210
|
|
211
|
+
# サーボモーター
|
212
|
+
def servo(pin)
|
213
|
+
Hardware.create_hardware(Hardware::Servo, pin)
|
214
|
+
end
|
215
|
+
|
216
|
+
# ボタン
|
217
|
+
def button(pin)
|
218
|
+
Hardware.create_hardware(Hardware::Button, pin)
|
219
|
+
end
|
220
|
+
|
211
221
|
# 汎用的なセンサー
|
212
222
|
def sensor(pin)
|
213
223
|
Hardware.create_hardware(Hardware::Sensor, pin)
|
@@ -246,6 +256,8 @@ module Smalruby
|
|
246
256
|
@checking_hit_targets.uniq!
|
247
257
|
when :sensor_change
|
248
258
|
sensor(options.first)
|
259
|
+
when :button_up, :button_down
|
260
|
+
button(options.first)
|
249
261
|
end
|
250
262
|
end
|
251
263
|
|
@@ -302,6 +314,20 @@ module Smalruby
|
|
302
314
|
end
|
303
315
|
end
|
304
316
|
|
317
|
+
def button_up(pin)
|
318
|
+
@event_handlers[:button_up].try(:each) do |h|
|
319
|
+
next unless h.options.include?(pin)
|
320
|
+
@threads << h.call
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def button_down(pin)
|
325
|
+
@event_handlers[:button_down].try(:each) do |h|
|
326
|
+
next unless h.options.include?(pin)
|
327
|
+
@threads << h.call
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
305
331
|
def alive?
|
306
332
|
@threads.delete_if { |t|
|
307
333
|
if t.alive?
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'smalruby/hardware'
|
3
|
+
|
4
|
+
module Smalruby
|
5
|
+
module Hardware
|
6
|
+
# ボタンを表現するクラス
|
7
|
+
class Button < Dino::Components::Button
|
8
|
+
def initialize(options)
|
9
|
+
super(board: world.board, pin: Pin.smalruby_to_dino(options[:pin]))
|
10
|
+
end
|
11
|
+
|
12
|
+
def up?
|
13
|
+
@state == UP
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :on?, :up?
|
17
|
+
|
18
|
+
def down?
|
19
|
+
@state == DOWN
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :off?, :down?
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def after_initialize(options = {})
|
27
|
+
super(options)
|
28
|
+
|
29
|
+
s_pin = Pin.dino_to_smalruby(pin)
|
30
|
+
down { world.button_changed(s_pin, :down) }
|
31
|
+
up { world.button_changed(s_pin, :up) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'smalruby/hardware'
|
3
|
+
|
4
|
+
module Smalruby
|
5
|
+
module Hardware
|
6
|
+
# サーボモーターを表現するクラス
|
7
|
+
class Servo < Dino::Components::Servo
|
8
|
+
def initialize(options)
|
9
|
+
super(board: world.board, pin: Pin.smalruby_to_dino(options[:pin]))
|
10
|
+
end
|
11
|
+
|
12
|
+
# @!method position=(angle)
|
13
|
+
# サーボモーターを( )度にする
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# HACK: GROVEシステムのサーボモーターでは5よりも小さい値を指定す
|
18
|
+
# るとモーターが発振してしまう
|
19
|
+
MIN_ANGLE = 5
|
20
|
+
MAX_ANGLE = 180
|
21
|
+
|
22
|
+
def angle(value)
|
23
|
+
v = value.to_i
|
24
|
+
if v < MIN_ANGLE
|
25
|
+
MIN_ANGLE
|
26
|
+
elsif v > MAX_ANGLE
|
27
|
+
MAX_ANGLE
|
28
|
+
else
|
29
|
+
v
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/smalruby/hardware.rb
CHANGED
data/lib/smalruby/version.rb
CHANGED
data/lib/smalruby/world.rb
CHANGED
@@ -9,12 +9,15 @@ module Smalruby
|
|
9
9
|
attr_accessor :objects
|
10
10
|
attr_accessor :board
|
11
11
|
attr_reader :sensor_change_queue
|
12
|
+
attr_reader :button_change_queue
|
12
13
|
|
13
14
|
def initialize
|
14
15
|
@objects = []
|
15
16
|
@board = nil
|
16
17
|
@sensor_change_queue = []
|
17
18
|
@sensor_change_queue.extend(Mutex_m)
|
19
|
+
@button_change_queue = []
|
20
|
+
@button_change_queue.extend(Mutex_m)
|
18
21
|
end
|
19
22
|
|
20
23
|
def sensor_changed(pin, value)
|
@@ -22,5 +25,11 @@ module Smalruby
|
|
22
25
|
@sensor_change_queue.push([pin, value])
|
23
26
|
end
|
24
27
|
end
|
28
|
+
|
29
|
+
def button_changed(pin, up_or_down)
|
30
|
+
@button_change_queue.synchronize do
|
31
|
+
@button_change_queue.push([pin, up_or_down])
|
32
|
+
end
|
33
|
+
end
|
25
34
|
end
|
26
35
|
end
|
data/lib/smalruby.rb
CHANGED
@@ -97,6 +97,8 @@ module Smalruby
|
|
97
97
|
|
98
98
|
sensor_change
|
99
99
|
|
100
|
+
button_change
|
101
|
+
|
100
102
|
world.objects.delete_if do |o|
|
101
103
|
if !o.alive?
|
102
104
|
o.join
|
@@ -189,6 +191,28 @@ module Smalruby
|
|
189
191
|
end
|
190
192
|
end
|
191
193
|
end
|
194
|
+
|
195
|
+
def button_change
|
196
|
+
if world.button_change_queue.length > 0
|
197
|
+
queue = nil
|
198
|
+
world.button_change_queue.synchronize do
|
199
|
+
queue = world.button_change_queue.dup
|
200
|
+
world.button_change_queue.clear
|
201
|
+
end
|
202
|
+
|
203
|
+
world.objects.each do |o|
|
204
|
+
if o.respond_to?(:button_up) && o.respond_to?(:button_down)
|
205
|
+
queue.each do |pin, up_or_down|
|
206
|
+
if up_or_down == :up
|
207
|
+
o.button_up(pin)
|
208
|
+
else
|
209
|
+
o.button_down(pin)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
192
216
|
end
|
193
217
|
end
|
194
218
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
DESCRIPTION = <<EOS
|
4
|
+
ハードウェアのボタンを操作します
|
5
|
+
EOS
|
6
|
+
|
7
|
+
# デジタルの3番ピンにボタンを接続してください。
|
8
|
+
|
9
|
+
require 'smalruby'
|
10
|
+
|
11
|
+
init_hardware
|
12
|
+
|
13
|
+
stage1 = Stage.new(color: 'white')
|
14
|
+
frog1 = Character.new(costume: 'frog1.png', x: 300, y: 200, visible: false)
|
15
|
+
|
16
|
+
stage1.on(:start) do
|
17
|
+
draw_font(string: DESCRIPTION, color: 'black')
|
18
|
+
|
19
|
+
if button('D3').up?
|
20
|
+
frog1.visible = false
|
21
|
+
else
|
22
|
+
frog1.visible = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
stage1.on(:button_down, 'D3') do
|
27
|
+
frog1.visible = true
|
28
|
+
end
|
29
|
+
|
30
|
+
stage1.on(:button_up, 'D3') do
|
31
|
+
frog1.visible = false
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
DESCRIPTION = <<EOS
|
4
|
+
カーソルキーでサーボモーターを操作します
|
5
|
+
EOS
|
6
|
+
|
7
|
+
require 'smalruby'
|
8
|
+
|
9
|
+
init_hardware
|
10
|
+
|
11
|
+
stage1 = Stage.new(color: 'white')
|
12
|
+
|
13
|
+
stage1.on(:start) do
|
14
|
+
draw_font(string: DESCRIPTION, color: 'black')
|
15
|
+
|
16
|
+
servo('D3').position = 90
|
17
|
+
end
|
18
|
+
|
19
|
+
stage1.on(:key_down, K_UP, K_LEFT) do
|
20
|
+
servo('D3').position += 2
|
21
|
+
end
|
22
|
+
|
23
|
+
stage1.on(:key_down, K_DOWN, K_RIGHT) do
|
24
|
+
servo('D3').position -= 2
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smalruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- Kouji Takao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -252,12 +252,14 @@ files:
|
|
252
252
|
- lib/smalruby/console.rb
|
253
253
|
- lib/smalruby/event_handler.rb
|
254
254
|
- lib/smalruby/hardware.rb
|
255
|
+
- lib/smalruby/hardware/button.rb
|
255
256
|
- lib/smalruby/hardware/dino/fix_gets.rb
|
256
257
|
- lib/smalruby/hardware/led.rb
|
257
258
|
- lib/smalruby/hardware/pin.rb
|
258
259
|
- lib/smalruby/hardware/rgb_led_anode.rb
|
259
260
|
- lib/smalruby/hardware/rgb_led_cathode.rb
|
260
261
|
- lib/smalruby/hardware/sensor.rb
|
262
|
+
- lib/smalruby/hardware/servo.rb
|
261
263
|
- lib/smalruby/stage.rb
|
262
264
|
- lib/smalruby/util.rb
|
263
265
|
- lib/smalruby/version.rb
|
@@ -270,10 +272,12 @@ files:
|
|
270
272
|
- samples/costume.rb
|
271
273
|
- samples/extra_car.png
|
272
274
|
- samples/finding_cars.rb
|
275
|
+
- samples/hardware_button.rb
|
273
276
|
- samples/hardware_led.rb
|
274
277
|
- samples/hardware_rgb_led_anode.rb
|
275
278
|
- samples/hardware_rgb_led_cathode.rb
|
276
279
|
- samples/hardware_sensor.rb
|
280
|
+
- samples/hardware_servo.rb
|
277
281
|
- samples/hit_car.rb
|
278
282
|
- samples/piano.rb
|
279
283
|
- smalruby.gemspec
|