Sha256: 9bb93af3b07b41155073e54383f8e4f67728dd67f17d24c4891765333aec374e

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 KB

Contents

# -*- coding: utf-8 -*-

# WindowsでのDinoの不具合を修正するモンキーパッチ
if Util.windows?
  require 'dino'

  if Dino::VERSION >= '0.11'
    class Dino::TxRx::Base
      def gets(timeout = 0.005)
        return nil unless IO.select([io], nil, nil, timeout)
        io.read_timeout = (timeout * 1000).to_i
        bytes = []
        until (x = io.getbyte).nil?
          bytes.push(x)
        end
        return nil if bytes.empty?
        bytes.pack("C*")
      end
    end
  elsif Dino::VERSION >= '0.10'
    class Dino::TxRx::USBSerial
      def read
        @thread ||= Thread.new do
          loop do
            line = gets
            if line
              pin, message = *line.chomp.split(/::/)
              pin && message && changed && notify_observers(pin, message)
            end
            sleep 0.004
          end
        end
      end

      def gets(timeout = 0.005)
        return nil unless IO.select([io], nil, nil, timeout)
        io.read_timeout = (timeout * 1000).to_i
        bytes = []
        until (x = io.getbyte).nil?
          bytes.push(x)
        end
        return nil if bytes.empty?
        bytes.pack("C*")
      end
    end
  else
    fail "Dinoのバージョン#{version}はサポートしていません"
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
smalruby-0.0.15-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.15 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.14-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.14 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.13-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.13 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.12-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.12 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.11-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.11 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.10-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.10 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.9-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.9 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.8-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.8 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.7-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.7 lib/smalruby/hardware/dino/fix_gets.rb