smalruby 0.0.26-x86-mingw32 → 0.0.27-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbdf7a1afdee0f3b3c6146f24a86b040aafdedf1
4
- data.tar.gz: 338eb85a1739c979ff36a9fbd7c3d83fd6f1f61b
3
+ metadata.gz: fa8c09967a7b2bbc4f20c9ed175e4cf0de7815c8
4
+ data.tar.gz: 44f19f82f887bd606f622ce377e826d8cf7c0735
5
5
  SHA512:
6
- metadata.gz: 1df9e1b10eb14204ff8b013daaeea528da1ee6b30c8999a5d9173fdf44e65205cb552d103493c4de3cb71522fbfb5a3568fcc9ec7f13c8c9329b79924bdafb2c
7
- data.tar.gz: c0dbfea0422843bcaed75a15b016f550809a8c353c792ce9cd0063209820a4f71852db6f00af0465fc87d3d1afb07e9657ecdc2a5d746b3b4a1328fcec17ab09
6
+ metadata.gz: 5c5ee978cdf45f04acd54f58d8d1fde907d858a34c5ea1f63f87db1c1aa8a2ab37dc4770505463c1655e136cacdfd42428edc9de2c312dbbb34b6f8ca7023885
7
+ data.tar.gz: 940819b7d174f5dfccebc7a48ed2b37b30d63e87a58ef518cb791ff758959b281cb15c4bed74d6098da56569bc189afba2af9499d80b65729d83c650cc5cfa68
@@ -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: x86-mingw32
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