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