improvements
This commit is contained in:
parent
b2a9410aa2
commit
4c186ddd6f
|
@ -1,6 +1,6 @@
|
|||
= SANE FFI
|
||||
|
||||
Scanner Access Now Easier in Ruby.
|
||||
Scanner Access Now Easier in Ruby using FFI. This gem provides bindings
|
||||
|
||||
== Copyright
|
||||
|
||||
|
|
|
@ -155,6 +155,14 @@ class Sane
|
|||
API::Parameters.new(parameters_pointer).to_hash
|
||||
end
|
||||
|
||||
def set_io_mode(handle, non_blocking)
|
||||
check_status!(API.sane_set_io_mode(handle, non_blocking ? 1 : 0))
|
||||
end
|
||||
|
||||
def cancel(handle)
|
||||
API.sane_cancel(handle)
|
||||
end
|
||||
|
||||
def ensure_not_initialized!
|
||||
raise("SANE library is already initialized") if initialized?
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class Sane
|
||||
class Device
|
||||
attr_reader :name, :vendor, :model, :type
|
||||
|
||||
def initialize(options)
|
||||
@name = options[:name]
|
||||
@vendor = options[:vendor]
|
||||
|
@ -44,6 +46,21 @@ class Sane
|
|||
Sane.instance.send(:read, @handle)
|
||||
end
|
||||
|
||||
def cancel
|
||||
ensure_open!
|
||||
Sane.instance.send(:cancel, @handle)
|
||||
end
|
||||
|
||||
def sync
|
||||
ensure_open!
|
||||
Sane.instance.send(:set_io_mode, @handle, false)
|
||||
end
|
||||
|
||||
def async
|
||||
ensure_open!
|
||||
Sane.instance.send(:set_io_mode, @handle, true)
|
||||
end
|
||||
|
||||
def option_count
|
||||
ensure_open!
|
||||
Sane.instance.send(:get_option, @handle, 0)
|
||||
|
@ -76,16 +93,18 @@ class Sane
|
|||
option_count.times.map do |i|
|
||||
begin
|
||||
self[i]
|
||||
rescue Error
|
||||
nil # we can't read values of some options (i.e. buttons), ignore them
|
||||
rescue Error => e
|
||||
if e.status == :inval
|
||||
nil # we can't read values of some options (i.e. buttons), ignore them
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def options
|
||||
result = {}
|
||||
option_count.times { |i| hash[option_names[i]] = option_values[i] }
|
||||
result
|
||||
Hash[*option_names.zip(option_values).flatten]
|
||||
end
|
||||
|
||||
def option_lookup(option_name)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Sane
|
||||
class Sane
|
||||
VERSION = "0.1.0"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue