smalruby 0.0.32 → 0.1.0

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: 847fbb5e57bbfcea47b0bf1f84a27a62166e0634
4
- data.tar.gz: 4b613d78dfd46c3ba2f1709e61757a4a8bda8172
3
+ metadata.gz: 394212f1249a7f89b50237580b654131fb50e70b
4
+ data.tar.gz: a030834e15aec64cd9a5201d640e1909a609ba31
5
5
  SHA512:
6
- metadata.gz: a8be1b3c75d63b1e88c4d9fa914aef4f7999d901a1a09211016cc43f96a9297390366f491f9a8517c98fe549c94036d5cf21f268b04b56edaa88c1e988338495
7
- data.tar.gz: cc87cbc9c9de2d63e3f603d9e343a60e7f601591b693e820665e0645d4bae39e74b79019e310a4c225ecc2f80a733f892223990d46a3c408338abe1a6e03b1e5
6
+ metadata.gz: a1bc7b61993e39c1fe80ca52376c844a375e332d24165b71c3cdea02eff35d68e21e5e184b030ba0c7702804d998246f9cafaa400c3ad8ef3ea4cdb800af8fea
7
+ data.tar.gz: 0f52a717e36e29b350821aa692361451da0971ea0058331dfa3377d02d758bb7188a8b0e51d85d59440e45ea02bc9be74cbb8be58f68dc45150b41d15ca8b166
@@ -4,44 +4,24 @@ require 'smalruby/hardware'
4
4
  module Smalruby
5
5
  module Hardware
6
6
  # ボタンを表現するクラス
7
- class Button < Dino::Components::Button
7
+ class Button < Smalrubot::Components::BaseComponent
8
8
  def initialize(options)
9
9
  @using_pullup = true
10
- super(board: world.board, pin: Pin.smalruby_to_dino(options[:pin]),
10
+ super(board: world.board, pin: Pin.smalruby_to_smalrubot(options[:pin]),
11
11
  pullup: true)
12
12
  end
13
13
 
14
- # プルアップ抵抗を使わない
15
- def not_use_pullup
16
- @using_pullup = false
17
- board.set_pullup(pin, false)
18
- end
19
-
20
- def stop
21
- @board.remove_digital_hardware(self)
22
- end
23
-
24
14
  def up?
25
- @using_pullup ? @state == DOWN : @state == UP
15
+ digital_read(pin) == Smalrubot::Board::LOW
26
16
  end
27
17
 
28
- alias_method :on?, :up?
18
+ alias_method :off?, :up?
29
19
 
30
20
  def down?
31
21
  !up?
32
22
  end
33
23
 
34
- alias_method :off?, :down?
35
-
36
- private
37
-
38
- def after_initialize(options = {})
39
- super(options)
40
-
41
- s_pin = Pin.dino_to_smalruby(pin)
42
- down { world.button_changed(s_pin, (@using_pullup ? :up : :down)) }
43
- up { world.button_changed(s_pin, (@using_pullup ? :down : :up)) }
44
- end
24
+ alias_method :on?, :down?
45
25
  end
46
26
  end
47
27
  end
@@ -4,9 +4,9 @@ require 'smalruby/hardware'
4
4
  module Smalruby
5
5
  module Hardware
6
6
  # LEDを表現するクラス
7
- class Led < Dino::Components::Led
7
+ class Led < Smalrubot::Components::Led
8
8
  def initialize(options)
9
- super(board: world.board, pin: Pin.smalruby_to_dino(options[:pin]))
9
+ super(board: world.board, pin: Pin.smalruby_to_smalrubot(options[:pin]))
10
10
  end
11
11
 
12
12
  # @!method on
@@ -12,12 +12,12 @@ module Smalruby
12
12
  # 動作確認済みのモータードライバの一覧
13
13
  # * TOSHIBA
14
14
  # * TA7291P
15
- class MotorDriver < Dino::Components::BaseComponent
15
+ class MotorDriver < Smalrubot::Components::BaseComponent
16
16
  # モーターの回転速度の割合(0~100%)
17
17
  attr_reader :speed
18
18
 
19
19
  def initialize(options)
20
- pin = Pin.smalruby_to_dino(options[:pin])
20
+ pin = Pin.smalruby_to_smalrubot(options[:pin])
21
21
  case pin
22
22
  when 3, 5, 6, 9, 10, 11
23
23
  super(board: world.board, pin: (pin...(pin + 3)).to_a)
@@ -64,11 +64,11 @@ module Smalruby
64
64
  levels.each.with_index do |level, i|
65
65
  case level
66
66
  when 0
67
- digital_write(pins[i], Dino::Board::LOW)
67
+ digital_write(pins[i], Smalrubot::Board::LOW)
68
68
  when 100
69
- digital_write(pins[i], Dino::Board::HIGH)
69
+ digital_write(pins[i], Smalrubot::Board::HIGH)
70
70
  else
71
- analog_write(pins[i], (Dino::Board::HIGH * level / 100.0).round)
71
+ analog_write(pins[i], (Smalrubot::Board::HIGH * level / 100.0).round)
72
72
  end
73
73
  end
74
74
  end
@@ -1,26 +1,26 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'dino'
2
+ require 'smalrubot'
3
3
 
4
4
  module Smalruby
5
5
  module Hardware
6
6
  module Pin
7
7
  module_function
8
8
 
9
- DIO_DINO_RE = /\A([0-9]|1[0-3])\z/
9
+ DIO_SMALRUBOT_RE = /\A([0-9]|1[0-3])\z/
10
10
  DIO_SMALRUBY_RE = /\AD([0-9]|1[0-3])\z/
11
11
  AI_RE = /\AA[0-5]\z/
12
12
 
13
- # Smalrubyのピン番号をDinoのピン番号に変換する
13
+ # Smalrubyのピン番号をSmalrubotのピン番号に変換する
14
14
  #
15
15
  # ピン番号が0~13、D0~D13、A0~A5でなければ例外が発生する
16
16
  #
17
17
  # @param [String|Numeric] pin Smalrubyのピン番号
18
- # @return [Numeric] Dinoのデジタル入出力のピン番号
19
- # @return [String] Dinoのアナログ入力のピン番号
20
- def smalruby_to_dino(pin)
18
+ # @return [Numeric] Smalrubotのデジタル入出力のピン番号
19
+ # @return [String] Smalrubotのアナログ入力のピン番号
20
+ def smalruby_to_smalrubot(pin)
21
21
  pin = pin.to_s
22
22
  case pin
23
- when DIO_DINO_RE
23
+ when DIO_SMALRUBOT_RE
24
24
  pin.to_i
25
25
  when DIO_SMALRUBY_RE
26
26
  pin[1..-1].to_i
@@ -31,16 +31,16 @@ module Smalruby
31
31
  end
32
32
  end
33
33
 
34
- # Dinoのピン番号をSmalrubyのピン番号に変換する
34
+ # Smalrubotのピン番号をSmalrubyのピン番号に変換する
35
35
  #
36
36
  # ピン番号が0~13、D0~D13、A0~A5でなければ例外が発生する
37
37
  #
38
- # @param [String|Numeric] pin Dinoのピン番号
38
+ # @param [String|Numeric] pin Smalrubotのピン番号
39
39
  # @return [String] Smalrubyのピン番号
40
- def dino_to_smalruby(pin)
40
+ def smalrubot_to_smalruby(pin)
41
41
  pin = pin.to_s
42
42
  case pin
43
- when DIO_DINO_RE
43
+ when DIO_SMALRUBOT_RE
44
44
  "D#{pin}"
45
45
  when DIO_SMALRUBY_RE
46
46
  pin
@@ -4,9 +4,9 @@ require 'smalruby/hardware'
4
4
  module Smalruby
5
5
  module Hardware
6
6
  # RGB LED(アノード)を表現するクラス
7
- class RgbLedAnode < Dino::Components::BaseComponent
7
+ class RgbLedAnode < Smalrubot::Components::BaseComponent
8
8
  def initialize(options)
9
- pin = Pin.smalruby_to_dino(options[:pin])
9
+ pin = Pin.smalruby_to_smalrubot(options[:pin])
10
10
  case pin
11
11
  when 3..6
12
12
  super(board: world.board, pin: [3, 5, 6, 4])
@@ -28,12 +28,12 @@ module Smalruby
28
28
  analog_write(pins[0], calc_value(color[0]))
29
29
  analog_write(pins[1], calc_value(color[1]))
30
30
  analog_write(pins[2], calc_value(color[2]))
31
- digital_write(pins[3], Dino::Board::HIGH)
31
+ digital_write(pins[3], Smalrubot::Board::HIGH)
32
32
  end
33
33
 
34
34
  # RGB LEDをオフにする
35
35
  def off
36
- digital_write(pins[3], Dino::Board::LOW)
36
+ digital_write(pins[3], Smalrubot::Board::LOW)
37
37
  end
38
38
 
39
39
  def stop
@@ -48,11 +48,11 @@ module Smalruby
48
48
  end
49
49
 
50
50
  def calc_value(value)
51
- v = Dino::Board::HIGH - value
52
- if v < Dino::Board::LOW
53
- Dino::Board::LOW
54
- elsif v > Dino::Board::HIGH
55
- Dino::Board::HIGH
51
+ v = Smalrubot::Board::HIGH - value
52
+ if v < Smalrubot::Board::LOW
53
+ Smalrubot::Board::LOW
54
+ elsif v > Smalrubot::Board::HIGH
55
+ Smalrubot::Board::HIGH
56
56
  else
57
57
  v
58
58
  end
@@ -4,9 +4,9 @@ require 'smalruby/hardware'
4
4
  module Smalruby
5
5
  module Hardware
6
6
  # RGB LED(カソード)を表現するクラス
7
- class RgbLedCathode < Dino::Components::BaseComponent
7
+ class RgbLedCathode < Smalrubot::Components::BaseComponent
8
8
  def initialize(options)
9
- pin = Pin.smalruby_to_dino(options[:pin])
9
+ pin = Pin.smalruby_to_smalrubot(options[:pin])
10
10
  case pin
11
11
  when 3, 5, 6
12
12
  super(board: world.board, pin: [3, 5, 6])
@@ -49,10 +49,10 @@ module Smalruby
49
49
  end
50
50
 
51
51
  def calc_value(value)
52
- if value < Dino::Board::LOW
53
- Dino::Board::LOW
54
- elsif value > Dino::Board::HIGH
55
- Dino::Board::HIGH
52
+ if value < Smalrubot::Board::LOW
53
+ Smalrubot::Board::LOW
54
+ elsif value > Smalrubot::Board::HIGH
55
+ Smalrubot::Board::HIGH
56
56
  else
57
57
  value
58
58
  end
@@ -4,46 +4,13 @@ require 'smalruby/hardware'
4
4
  module Smalruby
5
5
  module Hardware
6
6
  # 汎用的なセンサーを表現するクラス
7
- class Sensor < Dino::Components::Sensor
8
- # デフォルトのセンサーの値に変化があったかどうかをチェックする閾値
9
- DEFAULT_THRESHOLD = 32
10
-
11
- attr_reader :value
12
- attr_accessor :threshold
13
-
7
+ class Sensor < Smalrubot::Components::BaseComponent
14
8
  def initialize(options)
15
- super(board: world.board, pin: Pin.smalruby_to_dino(options[:pin]))
16
- end
17
-
18
- def stop
19
- @board.remove_analog_hardware(self)
20
- end
21
-
22
- private
23
-
24
- def after_initialize(options = {})
25
- super(options)
26
-
27
- @value = 0
28
- @threshold = options[:threshold] || DEFAULT_THRESHOLD
29
-
30
- start_receiving_data
9
+ super(board: world.board, pin: Pin.smalruby_to_smalrubot(options[:pin]))
31
10
  end
32
11
 
33
- def start_receiving_data
34
- prev_data = 0
35
- when_data_received { |data|
36
- begin
37
- @value = data = data.to_i
38
- if (data - prev_data).abs >= @threshold ||
39
- (prev_data != data && (data == 0 || data >= 1023))
40
- world.sensor_changed(pin, data)
41
- prev_data = data
42
- end
43
- rescue
44
- Util.print_exception($ERROR_INFO)
45
- end
46
- }
12
+ def value
13
+ board.analog_read(pin)
47
14
  end
48
15
  end
49
16
  end
@@ -4,9 +4,9 @@ require 'smalruby/hardware'
4
4
  module Smalruby
5
5
  module Hardware
6
6
  # サーボモーターを表現するクラス
7
- class Servo < Dino::Components::Servo
7
+ class Servo < Smalrubot::Components::Servo
8
8
  def initialize(options)
9
- super(board: world.board, pin: Pin.smalruby_to_dino(options[:pin]))
9
+ super(board: world.board, pin: Pin.smalruby_to_smalrubot(options[:pin]))
10
10
  end
11
11
 
12
12
  # @!method position=(angle)
@@ -4,7 +4,7 @@ require 'smalruby/hardware'
4
4
  module Smalruby
5
5
  module Hardware
6
6
  # 2WD車のモーターを表現するクラス
7
- class TwoWheelDriveCar < Dino::Components::BaseComponent
7
+ class TwoWheelDriveCar < Smalrubot::Components::BaseComponent
8
8
  # 左のモーターの速度%
9
9
  attr_reader :left_speed
10
10
 
@@ -15,7 +15,7 @@ module Smalruby
15
15
  @left_speed = 100
16
16
  @right_speed = 100
17
17
 
18
- pin = Pin.smalruby_to_dino(options[:pin])
18
+ pin = Pin.smalruby_to_smalrubot(options[:pin])
19
19
  case pin
20
20
  when 5
21
21
  super(board: world.board, pin: [5, 6, 9, 10])
@@ -87,25 +87,15 @@ module Smalruby
87
87
  end
88
88
 
89
89
  def digital_write_pins(*speeds)
90
- if pins.first == 5
91
- speeds.each.with_index do |speed, i|
92
- level = (Dino::Board::HIGH * speed / 100.0).floor
93
- case level
94
- when 0
95
- digital_write(pins[i], Dino::Board::LOW)
96
- when 100
97
- digital_write(pins[i], Dino::Board::HIGH)
98
- else
99
- analog_write(pins[i], level)
100
- end
101
- end
102
- else
103
- 2.times do
104
- speeds.each.with_index do
105
- |speed, i|
106
- digital_write(pins[i], (Dino::Board::HIGH * speed / 100.0).floor)
107
- sleep(0.05) if i.odd?
108
- end
90
+ speeds.each.with_index do |speed, i|
91
+ level = (Smalrubot::Board::HIGH * speed / 100.0).floor
92
+ case level
93
+ when 0
94
+ digital_write(pins[i], Smalrubot::Board::LOW)
95
+ when 100
96
+ digital_write(pins[i], Smalrubot::Board::HIGH)
97
+ else
98
+ analog_write(pins[i], level)
109
99
  end
110
100
  end
111
101
  end
@@ -1,7 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'dino'
3
2
  require 'mutex_m'
4
- require_relative 'hardware/dino/fix_gets'
3
+ require 'smalrubot'
5
4
 
6
5
  module Smalruby
7
6
  # ハードウェアの名前空間
@@ -34,20 +33,12 @@ module Smalruby
34
33
  defaults = {
35
34
  device: nil,
36
35
  baud: 115_200,
37
- heart_rate: 40 # HACK: 実機で調整した値
38
36
  }
39
37
  opt = Util.process_options(options, defaults)
40
38
 
41
- if Dino::VERSION >= '0.11'
42
- txrx = Dino::TxRx.new(opt)
43
- elsif Dino::VERSION >= '0.10'
44
- txrx = Dino::TxRx.new
45
- txrx.io = opt[:device] if opt[:device]
46
- end
39
+ txrx = Smalrubot::TxRx.new(opt)
47
40
  begin
48
- world.board = Dino::Board.new(txrx)
49
- world.board.heart_rate = opt[:heart_rate]
50
-
41
+ world.board = Smalrubot::Board.new(txrx)
51
42
  @initialized_hardware = true
52
43
  rescue Exception
53
44
  Util.print_exception($!)
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Smalruby
4
- VERSION = '0.0.32'
4
+ VERSION = '0.1.0'
5
5
  end
@@ -0,0 +1,145 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ DESCRIPTION = <<EOS
4
+ モータードライバ(TA7291P)を操作します
5
+ EOS
6
+
7
+ # デジタルの6~11番ピンをそれぞれ左右のモーター用のモータードライバ
8
+ # (TA7291P)の4・5・6に接続してください。
9
+
10
+ require 'smalruby'
11
+
12
+ init_hardware
13
+
14
+ stage1 = Stage.new(color: 'white')
15
+
16
+ stage1.on(:start) do
17
+ fill(color: 'white')
18
+ draw_font(string: DESCRIPTION, color: 'black')
19
+
20
+ motor_driver('D6').speed = 100
21
+ motor_driver('D9').speed = 100
22
+
23
+ loop do
24
+ if Input.key_down?(K_UP)
25
+ fill(color: 'white')
26
+ draw_font(string: '進む', color: 'black')
27
+
28
+ motor_driver('D6').forward
29
+ motor_driver('D9').forward
30
+
31
+ await until !Input.key_down?(K_UP)
32
+
33
+ fill(color: 'white')
34
+
35
+ motor_driver('D6').stop
36
+ motor_driver('D9').stop
37
+ sleep(0.2)
38
+ end
39
+
40
+ if Input.key_down?(K_DOWN)
41
+ fill(color: 'white')
42
+ draw_font(string: 'バックする', color: 'black')
43
+
44
+ motor_driver('D6').backward
45
+ motor_driver('D9').backward
46
+
47
+ await until !Input.key_down?(K_DOWN)
48
+
49
+ fill(color: 'white')
50
+
51
+ motor_driver('D6').stop
52
+ motor_driver('D9').stop
53
+ sleep(0.2)
54
+ end
55
+
56
+ if Input.key_down?(K_LEFT)
57
+ fill(color: 'white')
58
+ draw_font(string: '左に旋回する', color: 'black')
59
+
60
+ motor_driver('D6').backward
61
+ motor_driver('D9').forward
62
+
63
+ await until !Input.key_down?(K_LEFT)
64
+
65
+ fill(color: 'white')
66
+
67
+ motor_driver('D6').stop
68
+ motor_driver('D9').stop
69
+ sleep(0.2)
70
+ end
71
+
72
+ if Input.key_down?(K_RIGHT)
73
+ fill(color: 'white')
74
+ draw_font(string: '右に旋回する', color: 'black')
75
+
76
+ motor_driver('D6').forward
77
+ motor_driver('D9').backward
78
+
79
+ await until !Input.key_down?(K_RIGHT)
80
+
81
+ fill(color: 'white')
82
+
83
+ motor_driver('D6').stop
84
+ motor_driver('D9').stop
85
+ sleep(0.2)
86
+ end
87
+
88
+ if Input.key_down?(K_W)
89
+ motor_driver('D6').speed += 10
90
+
91
+ fill(color: 'white')
92
+ draw_font(string: "左の速度: #{motor_driver('D6').speed}%", color: 'black')
93
+ end
94
+
95
+ if Input.key_down?(K_S)
96
+ motor_driver('D6').speed -= 10
97
+
98
+ fill(color: 'white')
99
+ draw_font(string: "左の速度: #{motor_driver('D6').speed}%", color: 'black')
100
+ end
101
+
102
+ if Input.key_down?(K_O)
103
+ motor_driver('D9').speed += 10
104
+
105
+ fill(color: 'white')
106
+ draw_font(string: "右の速度: #{motor_driver('D9').speed}%", color: 'black')
107
+ end
108
+
109
+ if Input.key_down?(K_L)
110
+ motor_driver('D9').speed -= 10
111
+
112
+ fill(color: 'white')
113
+ draw_font(string: "右の速度: #{motor_driver('D9').speed}%", color: 'black')
114
+ end
115
+
116
+ if Input.key_down?(K_SPACE)
117
+ fill(color: 'white')
118
+ draw_font(string: '右のLED赤色を光らせる', color: 'black')
119
+
120
+ led('D13').on
121
+
122
+ await until !Input.key_down?(K_SPACE)
123
+
124
+ led('D13').off
125
+
126
+ fill(color: 'white')
127
+ draw_font(string: '左のLED緑色を光らせる', color: 'black')
128
+
129
+ led('D2').on
130
+
131
+ sleep(1)
132
+
133
+ led('D2').off
134
+ end
135
+
136
+ if Input.key_down?(K_B)
137
+ until !Input.key_down?(K_B)
138
+ fill(color: 'white')
139
+ draw_font(string: "センサーの情報#{sensor('A0').value}", color: 'black')
140
+ await
141
+ end
142
+ fill(color: 'white')
143
+ end
144
+ end
145
+ end
data/smalruby.gemspec CHANGED
@@ -42,5 +42,5 @@ Gem::Specification.new do |spec|
42
42
  else
43
43
  spec.add_runtime_dependency 'dxruby_sdl', '~> 0.0.12'
44
44
  end
45
- spec.add_runtime_dependency 'dino', '~> 0.11.2'
45
+ spec.add_runtime_dependency 'smalrubot', '~> 0.0.1'
46
46
  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.32
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouji Takao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -193,19 +193,19 @@ dependencies:
193
193
  - !ruby/object:Gem::Version
194
194
  version: 0.0.12
195
195
  - !ruby/object:Gem::Dependency
196
- name: dino
196
+ name: smalrubot
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: 0.11.2
201
+ version: 0.0.1
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: 0.11.2
208
+ version: 0.0.1
209
209
  description: smalruby is a 2D game development library. This is part of "Smalruby"
210
210
  project that is a learning ruby programming environment for kids.
211
211
  email:
@@ -257,7 +257,6 @@ files:
257
257
  - lib/smalruby/event_handler.rb
258
258
  - lib/smalruby/hardware.rb
259
259
  - lib/smalruby/hardware/button.rb
260
- - lib/smalruby/hardware/dino/fix_gets.rb
261
260
  - lib/smalruby/hardware/led.rb
262
261
  - lib/smalruby/hardware/motor_driver.rb
263
262
  - lib/smalruby/hardware/null_hardware.rb
@@ -276,6 +275,7 @@ files:
276
275
  - samples/canvas_color.rb
277
276
  - samples/car.rb
278
277
  - samples/cat.rb
278
+ - samples/check_hardware_motor_driver.rb
279
279
  - samples/console.rb
280
280
  - samples/costume.rb
281
281
  - samples/costumes.rb
@@ -1,78 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- # rubocop:disable all
4
-
5
- # WindowsでのDinoの不具合を修正するモンキーパッチ
6
- if Util.windows?
7
- require 'dino'
8
-
9
- if Dino::VERSION >= '0.11'
10
- require 'mutex_m'
11
-
12
- class Dino::TxRx::Base
13
- def write(message)
14
- loop do
15
- if IO.select(nil, [io], nil)
16
- io.synchronize { io.syswrite(message) }
17
- break
18
- end
19
- end
20
- end
21
-
22
- def gets(timeout = 0.005)
23
- @buffer ||= ""
24
- if !@buffer.include?("\n")
25
- return nil unless IO.select([io], nil, nil, timeout)
26
- io.synchronize do
27
- io.read_timeout = (timeout * 1000).to_i
28
- end
29
- bytes = []
30
- until (x = io.synchronize { io.getbyte }).nil?
31
- bytes.push(x)
32
- end
33
- return nil if bytes.empty?
34
- @buffer += bytes.pack("C*")
35
- end
36
- @buffer.slice!(/\A[^\n]*\n/)
37
- end
38
- end
39
-
40
- class Dino::TxRx::Serial
41
- def io
42
- unless @io
43
- @io = connect
44
- @io.extend(Mutex_m)
45
- end
46
- @io
47
- end
48
- end
49
- elsif Dino::VERSION >= '0.10'
50
- class Dino::TxRx::USBSerial
51
- def read
52
- @thread ||= Thread.new do
53
- loop do
54
- line = gets
55
- if line
56
- pin, message = *line.chomp.split(/::/)
57
- pin && message && changed && notify_observers(pin, message)
58
- end
59
- sleep 0.004
60
- end
61
- end
62
- end
63
-
64
- def gets(timeout = 0.005)
65
- return nil unless IO.select([io], nil, nil, timeout)
66
- io.read_timeout = (timeout * 1000).to_i
67
- bytes = []
68
- until (x = io.getbyte).nil?
69
- bytes.push(x)
70
- end
71
- return nil if bytes.empty?
72
- bytes.pack("C*")
73
- end
74
- end
75
- else
76
- fail "Dinoのバージョン#{version}はサポートしていません"
77
- end
78
- end