Module: CP2112
- Extended by:
- Fiddle::Importer
- Includes:
- Fiddle::Win32Types
- Defined in:
- lib/cp2112.rb,
lib/cp2112/version.rb
Defined Under Namespace
Modules: GPIO_Definitions, Part_Number_Definitions, Return_Code, SMBUS_Definitions, String_Definitions, User_Customization_Definitions, WinAPI
Classes: Device
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Class Method Details
.[](index, vid = 0x0000, pid = 0x0000) ⇒ Object
338
339
340
341
342
|
# File 'lib/cp2112.rb', line 338
def [](index, vid = 0x0000, pid = 0x0000)
lim = devices(vid, pid)
raise "Incorrect index (must be < #{lim})" unless lim > index
Device::new(index, vid, pid)
end
|
.devices(vid = 0x0000, pid = 0x0000) ⇒ Object
335
336
337
|
# File 'lib/cp2112.rb', line 335
def devices(vid = 0x0000, pid = 0x0000)
getNumDevices(vid, pid)[0]
end
|
.get_ptr(type) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/cp2112.rb', line 59
def CP2112.get_ptr(type)
array, type = [1, type.to_s]
size = if type =~ /\[(\d*)\]$/ then
type, array = [$`, $1.to_i]
array = 0x200 if array <= 0
CP2112::sizeof(type) * array
else
CP2112::sizeof(type)
end
content = Fiddle::malloc(size)
ptr = Fiddle::Pointer[content]
if (array > 1) && ("char" == type) then
ptr.define_singleton_method(:to_value){self.to_str(size).unpack('Z*')[0]}
else
ctype = parse_ctype(type, type_alias)
packer = Fiddle::Packer[ctype]
packer.instance_eval{
=begin
Fix bug in original library; negative value means unsigned type
An unsigned value is treated with the same manner of a signed value in the original library.
Therefore, modification of @template, which is used for unpack method, is performed.
Alternative way is
module Fiddle
PackInfo::PACK_MAP[-TYPE_CHAR] = "C"
PackInfo::PACK_MAP[-TYPE_SHORT] = "S!"
PackInfo::PACK_MAP[-TYPE_INT] = "I!"
PackInfo::PACK_MAP[-TYPE_LONG] = "L!"
end
, which affects globally.
=end
@template.sub!(/^./){$&.upcase} if ctype < 0
@template.sub!(/$/, array.to_s) if array > 1
}
ptr.define_singleton_method(:to_value){
values = packer.unpack([self.to_str(size)])
(array == 1) ? values[0] : values
}
end
return ptr
end
|