Sha256: 957e84e4b0accca6225e96570bed31c27e83b40dba19b1f156eede0a60677ac7

Contents?: true

Size: 1.27 KB

Versions: 28

Compression:

Stored size: 1.27 KB

Contents

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

# rubocop:disable all

# 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

28 entries across 28 versions & 1 rubygems

Version Path
smalruby-0.0.29-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.29 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.28-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.28 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.27-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.27 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.26-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.26 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.25-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.25 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.24-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.24 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.23-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.23 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.22-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.22 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.21-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.21 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.20-x86-mingw32 lib/smalruby/hardware/dino/fix_gets.rb
smalruby-0.0.20 lib/smalruby/hardware/dino/fix_gets.rb