smalruby 0.0.26 → 0.0.27

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b508a590f263734e3d29d9e1f3af7226befec19e
4
- data.tar.gz: 5055ee4f30c4306b67634b0489c0ca28b37b1ece
3
+ metadata.gz: 12cf0b5241dbdd9be29328dca53e2894f87efb35
4
+ data.tar.gz: 5378af22841268eb3a10e0ea1958fd93a9d8ee3a
5
5
  SHA512:
6
- metadata.gz: 1dd52cf93cc83ae39b7e93b752a23ff6630b06a5c5de4f99f60751b080f980e6649f6222b3f8efab894beaafc3716acd07d5eb604960f39676164b6611a864c9
7
- data.tar.gz: 795d4a73223c55fae1aeeb870fa289abbf0ba32585a80c38bd0ad392ef726b43287500e4e65950fb4f0f797085b67a03bd9859ea5e4f4ed00bc444da84e254f7
6
+ metadata.gz: 8f7e5ed7fac92defed856d3ee4ae8d90f5b295a46a871d0c6c506600d9326dfebc25adb6a42241951364d8cd7f8a3e973db1347458fcd3f4891afb624c3fe2d0
7
+ data.tar.gz: 23e20aee90dc7ba22e88898afd0c5d2110ad689199f99b59bc8da9a073555522c21c1d65fbddefd18978f4be723b9e0dc93c10b8b71c72bb8249fe57f82e8824
@@ -497,6 +497,7 @@ module Smalruby
497
497
  end
498
498
 
499
499
  def alive?
500
+ @threads.compact!
500
501
  @threads.delete_if { |t|
501
502
  if t.alive?
502
503
  false
@@ -514,6 +515,7 @@ module Smalruby
514
515
  end
515
516
 
516
517
  def join
518
+ @threads.compact!
517
519
  @threads.each(&:join)
518
520
  end
519
521
 
@@ -13,12 +13,19 @@ module Smalruby
13
13
  @object = object
14
14
  @options = options
15
15
  @block = block
16
+ @running = false
16
17
  end
17
18
 
18
19
  def call(*args)
20
+ return nil if @running
19
21
  return Thread.start(@object, @block) { |object, block|
20
- object.instance_exec(*args, &block)
21
- }
22
+ begin
23
+ @running = true
24
+ object.instance_exec(*args, &block)
25
+ ensure
26
+ @running = false
27
+ end
28
+ }
22
29
  end
23
30
  end
24
31
  end
@@ -16,38 +16,29 @@ module Smalruby
16
16
  end
17
17
 
18
18
  # 前進する
19
- def forward(left_level = Dino::Board::HIGH,
20
- right_level = Dino::Board::HIGH)
21
- digital_write_pins(left_level, Dino::Board::LOW,
22
- right_level, Dino::Board::LOW)
19
+ def forward(left_level = 100,
20
+ right_level = 100)
21
+ digital_write_pins(left_level, 0, right_level, 0)
23
22
  end
24
23
 
25
24
  # 後退する
26
- def backward(left_level = Dino::Board::HIGH,
27
- right_level = Dino::Board::HIGH)
28
- digital_write_pins(Dino::Board::LOW, left_level,
29
- Dino::Board::LOW, right_level)
25
+ def backward(left_level = 100, right_level = 100)
26
+ digital_write_pins(0, left_level, 0, right_level)
30
27
  end
31
28
 
32
29
  # 左に曲がる
33
- def turn_left(left_level = Dino::Board::HIGH,
34
- right_level = Dino::Board::HIGH)
35
- digital_write_pins(Dino::Board::LOW, left_level,
36
- right_level, Dino::Board::LOW)
30
+ def turn_left(left_level = 100, right_level = 100)
31
+ digital_write_pins(0, left_level, right_level, 0)
37
32
  end
38
33
 
39
34
  # 右に曲がる
40
- def turn_right(left_level = Dino::Board::HIGH,
41
- right_level = Dino::Board::HIGH)
42
- digital_write_pins(left_level, Dino::Board::LOW,
43
- Dino::Board::LOW, right_level)
35
+ def turn_right(left_level = 100, right_level = 100)
36
+ digital_write_pins(left_level, 0, 0, right_level)
44
37
  end
45
38
 
46
39
  # 停止する
47
- def stop(left_level = Dino::Board::HIGH,
48
- right_level = Dino::Board::HIGH)
49
- digital_write_pins(Dino::Board::LOW, Dino::Board::LOW,
50
- Dino::Board::LOW, Dino::Board::LOW)
40
+ def stop
41
+ digital_write_pins(0, 0, 0, 0)
51
42
  end
52
43
 
53
44
  # 命令する
@@ -75,10 +66,12 @@ module Smalruby
75
66
  end
76
67
 
77
68
  def digital_write_pins(*levels)
78
- levels.each.with_index do
79
- |level, i|
80
- analog_write(pins[i], (Dino::Board::HIGH * level / 100.0).to_i)
81
- sleep(0.05) if i % 2 == 0
69
+ 2.times do
70
+ levels.each.with_index do
71
+ |level, i|
72
+ digital_write(pins[i], (Dino::Board::HIGH * level / 100.0).to_i)
73
+ sleep(0.05) if i.odd?
74
+ end
82
75
  end
83
76
  end
84
77
  end
@@ -31,7 +31,8 @@ module Smalruby
31
31
 
32
32
  defaults = {
33
33
  device: nil,
34
- baud: 115_200
34
+ baud: 115_200,
35
+ heart_rate: 40 # HACK: 実機で調整した値
35
36
  }
36
37
  opt = Util.process_options(options, defaults)
37
38
 
@@ -42,6 +43,7 @@ module Smalruby
42
43
  txrx.io = opt[:device] if opt[:device]
43
44
  end
44
45
  world.board = Dino::Board.new(txrx)
46
+ world.board.heart_rate = opt[:heart_rate]
45
47
 
46
48
  @initialized_hardware = true
47
49
  end
data/lib/smalruby/util.rb CHANGED
@@ -21,7 +21,21 @@ module Smalruby
21
21
  #
22
22
  # @return [Boolean] Windowsの場合はtrue、そうでない場合はfalseを返す
23
23
  def windows?
24
- /windows|mingw|cygwin/i =~ RbConfig::CONFIG['arch']
24
+ ENV['SMALRUBY_WINDOWS_MODE'] || /windows|mingw|cygwin/i =~ RbConfig::CONFIG['arch']
25
+ end
26
+
27
+ # プラットフォームがRaspberry Piかどうかを返す
28
+ #
29
+ # @return [Boolean] Raspberry Piの場合はtrue、そうでない場合はfalseを返す
30
+ def raspberrypi?
31
+ ENV['SMALRUBY_RASPBERRYPI_MODE'] || /armv6l-linux-eabihf/i =~ RbConfig::CONFIG['arch']
32
+ end
33
+
34
+ # プラットフォームがMac OS Xかどうかを返す
35
+ #
36
+ # @return [Boolean] Mac OS Xの場合はtrue、そうでない場合はfalseを返す
37
+ def osx?
38
+ ENV['SMALRUBY_OSX_MODE'] || /darwin/i =~ RbConfig::CONFIG['arch']
25
39
  end
26
40
  end
27
41
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.0.26'
4
+ VERSION = '0.0.27'
5
5
  end
data/lib/smalruby.rb CHANGED
@@ -120,7 +120,7 @@ module Smalruby
120
120
 
121
121
  if first
122
122
  unless world.objects.any? { |o| o.is_a?(Stage) }
123
- Stage.new(color: 'white')
123
+ Stage.new(color: 'white') unless Util.raspberrypi?
124
124
  end
125
125
  world.objects.each do |object|
126
126
  object.start
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.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-28 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler