matrixorbital-glk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING ADDED
@@ -0,0 +1,57 @@
1
+ The Matrix Orbital GLK Ruby Gem is copyrighted free software
2
+ by Nicholas J Humfrey <njh@aelius.com>.
3
+ You can redistribute it and/or modify it under either the terms of the GPL
4
+ version 2 (see the file GPL), or the conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) give non-standard binaries non-standard names, with
22
+ instructions on where to get the original software distribution.
23
+
24
+ d) make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or binary form,
27
+ provided that you do at least ONE of the following:
28
+
29
+ a) distribute the binaries and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c) give non-standard binaries non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under these terms.
44
+
45
+ For the list of those files and their copying conditions, see the
46
+ file LEGAL.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
data/NEWS ADDED
@@ -0,0 +1,5 @@
1
+ = Matrix Orbital GLK Ruby Gem
2
+
3
+ == MatrixOrbital-GLK Version 0.0.1 (2008-09-20)
4
+
5
+ Initial Release.
data/README ADDED
@@ -0,0 +1,36 @@
1
+ == MatrixOrbital::GLK
2
+
3
+ MatrixOrbital::GLK is a ruby gem for controlling
4
+ the GLK serial of LCD screens made by Matrix Orbital.
5
+
6
+ For more information about GLK series MatrixOrbital displays, please visit:
7
+ http://www.matrixorbital.ca/products/glk_Series/
8
+
9
+ Please note that I am not an employee and have nothing to do with MatrixOrbital,
10
+ other than being a happy customer.
11
+
12
+ RubyForge Project Page http://rubyforge.org/projects/matrixorbital/
13
+
14
+
15
+ == Installing
16
+
17
+ You may get the latest stable version from Rubyforge. Source gems are also available.
18
+
19
+ $ gem install matrixorbital-glk
20
+
21
+
22
+ === Loading matrixorbital-glk gem Itself
23
+
24
+ You have installed the gem already, yeah?
25
+
26
+ require 'rubygems'
27
+ require 'matrixorbital/glk'
28
+
29
+
30
+ == Contact
31
+
32
+ Author:: Nicholas J Humfrey
33
+ Email:: njh@aelius.com
34
+ Home Page:: http://www.aelius.com/njh/
35
+ License:: Distributes under the same terms as Ruby
36
+
@@ -0,0 +1,83 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+
8
+ NAME = "matrixorbital-glk"
9
+ VERS = "0.0.1"
10
+ CLEAN.include ['pkg', 'rdoc']
11
+
12
+ Gem::manage_gems
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = NAME
16
+ s.version = VERS
17
+ s.author = "Nicholas J Humfrey"
18
+ s.email = "njh@aelius.com"
19
+ s.homepage = "http://matrixorbital.rubyforge.org"
20
+ s.platform = Gem::Platform::RUBY
21
+ s.summary = "A ruby gem to interface Matrix Orbital's GLK series of LCD Screens."
22
+ s.rubyforge_project = "matrixorbital"
23
+ s.files = FileList["Rakefile", "lib/matrixorbital/glk.rb", "examples/*"]
24
+ s.require_path = "lib"
25
+
26
+ # rdoc
27
+ s.has_rdoc = true
28
+ s.extra_rdoc_files = ["README", "NEWS", "COPYING"]
29
+
30
+ # Dependencies
31
+ s.add_dependency "rake"
32
+ end
33
+
34
+ desc "Default: package up the gem."
35
+ task :default => :package
36
+
37
+ task :build_package => [:repackage]
38
+ Rake::GemPackageTask.new(spec) do |pkg|
39
+ pkg.need_zip = false
40
+ pkg.need_tar = true
41
+ pkg.gem_spec = spec
42
+ end
43
+
44
+ desc "Run :package and install the resulting .gem"
45
+ task :install => :package do
46
+ sh %{sudo gem install --local pkg/#{NAME}-#{VERS}.gem}
47
+ end
48
+
49
+ desc "Run :clean and uninstall the .gem"
50
+ task :uninstall => :clean do
51
+ sh %{sudo gem uninstall #{NAME}}
52
+ end
53
+
54
+
55
+
56
+ ## Testing
57
+ #desc "Run all the specification tests"
58
+ #Rake::TestTask.new(:spec) do |t|
59
+ # t.warning = true
60
+ # t.verbose = true
61
+ # t.pattern = 'spec/*_spec.rb'
62
+ #end
63
+
64
+ desc "Check the syntax of all ruby files"
65
+ task :check_syntax do
66
+ `find . -name "*.rb" |xargs -n1 ruby -c |grep -v "Syntax OK"`
67
+ puts "* Done"
68
+ end
69
+
70
+ ## Documentation
71
+ desc "Generate documentation for the library"
72
+ Rake::RDocTask.new("rdoc") { |rdoc|
73
+ rdoc.rdoc_dir = 'rdoc'
74
+ rdoc.title = "Matrix Orbital GLK Documentation"
75
+ rdoc.options << '--line-numbers' << '--inline-source'
76
+ rdoc.main = "README"
77
+ rdoc.rdoc_files.include("README", "NEWS", "COPYING", "lib/matrixorbital/glk.rb")
78
+ }
79
+
80
+ desc "Upload rdoc to rubyforge"
81
+ task :upload_rdoc => [:rdoc] do
82
+ sh %{/usr/bin/scp -r -p rdoc/* matrixorbital.rubyforge.org:/var/www/gforge-projects/matrixorbital}
83
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # Script to display information about the connected LCD Module
4
+ #
5
+ # Author:: Nicholas J Humfrey (mailto:njh@aelius.com)
6
+ # Copyright:: Copyright (c) 2008 Nicholas J Humfrey
7
+ # License:: Distributes under the same terms as Ruby
8
+ #
9
+
10
+ $:.unshift File.dirname(__FILE__)+'/../lib'
11
+
12
+ require 'matrixorbital/glk'
13
+
14
+
15
+ glk = MatrixOrbital::GLK.new(ARGV[0]||'/dev/ttyUSB0')
16
+ puts "Serial Port: #{glk.serialport}"
17
+ puts "Baud Rate: #{glk.baudrate}"
18
+ puts "LCD Type: #{glk.lcd_type}"
19
+ puts "LCD Dimensions: #{glk.lcd_dimensions.join('x')}"
20
+ puts "LCD Firmware: #{glk.firmware_version}"
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ #
3
+ # Linux Script to load USB serial port driver for the GLK19264-7T-1U
4
+ #
5
+
6
+ sudo modprobe ftdi_sio vendor=0x1b3d product=0x0127
@@ -0,0 +1,470 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # A ruby gem to interface Matrix Orbital's GLK series of LCD Screens.
4
+ #
5
+ # Author:: Nicholas J Humfrey (mailto:njh@aelius.com)
6
+ # Copyright:: Copyright (c) 2008 Nicholas J Humfrey
7
+ # License:: Distributes under the same terms as Ruby
8
+ #
9
+
10
+ module MatrixOrbital
11
+
12
+ class GLK < File
13
+ attr_reader :serialport, :baudrate
14
+
15
+ # Connect to an LCD screen.
16
+ # All of the parametes are optional.
17
+ # By default the LCD screen type will be detected automatically.
18
+ def initialize(serialport='/dev/ttyS0', baudrate=19200, manual_lcd_type=nil)
19
+
20
+ # Does the device exist?
21
+ @serialport = serialport
22
+ unless File.exists? serialport
23
+ raise "Serial port '#{serialport}' does not exist."
24
+ end
25
+
26
+ # Use the lcd_type given, or ask the module
27
+ unless manual_lcd_type.nil?
28
+ @lcd_type = manual_lcd_type
29
+ end
30
+
31
+ # Store the baudrate
32
+
33
+ # Configure the serial port
34
+ # FIXME: use pure ruby
35
+ @baudrate = baudrate
36
+ system("stty -F #{serialport} raw speed #{baudrate} cs8 -ixon -echo cbreak -isig -parenb > /dev/null") or
37
+ raise "Failed to set parameters on the serial port."
38
+
39
+ # Now, open the serial port
40
+ super(serialport, "rb+")
41
+
42
+ # Disable buffering
43
+ self.sync = true
44
+
45
+ # Flush the input buffer
46
+
47
+ end
48
+
49
+ # This command sets the I2C write address of the module between 0x00
50
+ # and 0xFF. The I2C write address must be an even number and the read
51
+ # address is automatically set to one higher. For example if the I2 C write
52
+ # address is set to 0x50, then the read address is 0x51.
53
+ def i2c_slave_address=(address)
54
+ raise "I2C slave address is out of range" if (value<0 or value>255)
55
+ send_command( 0x33, address )
56
+ end
57
+
58
+ # This command sets the lcd's RS-232 port to the specified <em>baudrate</em>.
59
+ # The change takes place immediately.
60
+ def lcd_baudrate=(lcd_baudrate)
61
+ case lcd_baudrate
62
+ when 9600 then
63
+ send_command( 0x39, 0xCF )
64
+ when 14400 then
65
+ send_command( 0x39, 0x8A )
66
+ when 19200 then
67
+ send_command( 0x39, 0x67 )
68
+ when 28800 then
69
+ send_command( 0x39, 0x44 )
70
+ when 38400 then
71
+ send_command( 0x39, 0x33 )
72
+ when 57600 then
73
+ send_command( 0x39, 0x22 )
74
+ when 76800 then
75
+ send_command( 0x39, 0x19 )
76
+ when 115200 then
77
+ send_command( 0x39, 0x10 )
78
+ else
79
+ raise "Invalid/unsupported baud rate: #{lcd_baudrate}"
80
+ end
81
+ end
82
+
83
+
84
+ # Turn flow control on or off.
85
+ def flow_control=(state)
86
+ if state
87
+ raise "Flow control is unsupported"
88
+ # send_command( 0x3A )
89
+ else
90
+ send_command( 0x3B )
91
+ end
92
+ end
93
+
94
+
95
+ # Turn the LCD backlight on/off immediately and stay on/off.
96
+ def backlight=(state)
97
+ if state
98
+ # FIXME: backlight hard coded to stay on permanently
99
+ send_command( 0x42, 0 )
100
+ else
101
+ send_command( 0x46 )
102
+ end
103
+ end
104
+
105
+ # This command moves the text insertion point to the top left of the
106
+ # display area, based on the current font metrics.
107
+ def cursor_home
108
+ send_command( 0x48 )
109
+ end
110
+
111
+ # This command sets the text insertion point to the [col] and [row]
112
+ # specified. The insertion point is positioned using the base size of
113
+ # the current font (this command does not position the insertion
114
+ # point at a specific pixel).
115
+ #
116
+ # Example:
117
+ #
118
+ # lcd.cursor_position = [10,4]
119
+ #
120
+ def cursor_position=(params)
121
+ col,row = params
122
+ send_command( 0x47, col, row )
123
+ end
124
+
125
+ # This command positions the insertion point at a specific pixel (X,Y),
126
+ # which references the top left corner of the font insertion point.
127
+ #
128
+ # Example:
129
+ #
130
+ # lcd.cursor_coordinate = [100,40]
131
+ #
132
+ def cursor_coordinate=(params)
133
+ x,y = params
134
+ send_command( 0x79, x, y )
135
+ end
136
+
137
+ # This command sets the display's contrast to <em>value</em>,
138
+ # where <em>value</em> is a value between 0 to 255.
139
+ # Lower values cause 'on' elements in the display area to appear
140
+ # lighter, while higher values cause 'on' elements to appear darker.
141
+ def contrast=(value)
142
+ raise "Contrast value is out of range" if (value<0 or value>255)
143
+ send_command( 0x50, value )
144
+ end
145
+
146
+ # Like the <em>contrast=</em> method, only this command saves the
147
+ # value so that it is not lost after power down.
148
+ def save_contrast(value)
149
+ raise "Contrast value is out of range" if (value<0 or value>255)
150
+ send_command( 0x91, value )
151
+ end
152
+
153
+ # This command sets the display's brightness to <em>value</em>,
154
+ # where <em>value</em> is a value between 0 to 255.
155
+ def brightness=(value)
156
+ raise "Brightness value is out of range" if (value<0 or value>255)
157
+ send_command( 0x99, value )
158
+ end
159
+
160
+ # Like the <em>brightness=</em> method, only this command saves the
161
+ # value so that it is not lost after power down.
162
+ def save_brightness(brightness)
163
+ raise "Brightness value is out of range" if (value<0 or value>255)
164
+ send_command( 0x98, brightness )
165
+ end
166
+
167
+ # This command enabled and disables autoscrolling.
168
+ # When auto scrolling is on, it causes the display to shift the entire
169
+ # display's contents up to make room for a new line of text when the text
170
+ # reaches the end of the scroll row defined in the font metrics (the bottom
171
+ # right character position)
172
+ def autoscroll=(state)
173
+ if state
174
+ send_command( 0x51 )
175
+ else
176
+ send_command( 0x52 )
177
+ end
178
+ end
179
+
180
+ # This command clears any unread key presses.
181
+ def clear_key_buffer
182
+ send_command( 0x45 )
183
+ end
184
+
185
+ # When auto transmit key presses is turned on all key presses are sent
186
+ # immediately to the host system without the use of the <em>poll_keypad</em>
187
+ # method. This is the default mode on power up.
188
+ #
189
+ # When auto transmit key presses is turned off up to 10 key presses are
190
+ # buffered until the unit is polled by the host system.
191
+ def auto_transmit_key_presses=(state)
192
+ if state
193
+ send_command( 0x41 )
194
+ else
195
+ send_command( 0x4F )
196
+ end
197
+ end
198
+
199
+ # This command sets the time (in miliseconds) between key press and key read.
200
+ # All key types with the exception of latched piezo switches will 'bounce'
201
+ # for a varying time, depending on their physical characteristics.
202
+ def debounce_time=(ms)
203
+ time = (ms.to_f / 6.554).to_i
204
+ raise "Debounce time is out of range" if (value<0 or value>255)
205
+ send_command( 0x63, value )
206
+ end
207
+
208
+ # This command sets the drawing color for subsequent graphic commands
209
+ # that do not have the drawing color passed as a parameter. The parameter
210
+ # <em>color</em> is the value of the color where white is <em>false<em>
211
+ # and black <em>true<em>.
212
+ def drawing_color=(color)
213
+ send_command( 0x63, color ? 0 : 1 )
214
+ end
215
+
216
+ # This command clears the display and resets the text insertion position to
217
+ # the top left position of the screen defined in the font metrics.
218
+ def clear_screen
219
+ send_command( 0x58 )
220
+ end
221
+
222
+ # This command will draw a bitmap that is located in the on board memory.
223
+ # The bitmap is referenced by the bitmaps reference identification number,
224
+ # which is established when the bitmap is uploaded to the display module.
225
+ # The bitmap will be drawn beginning at the top left,
226
+ # from the specified <em>x</em>,<em>y</em> coordinates.
227
+ def draw_bitmap(refid, x, y)
228
+ send_command( 0x62, refid, x, y )
229
+ end
230
+
231
+ # This command will draw a pixel at <em>x</em>, <em>y</em> using
232
+ # the current drawing color.
233
+ def draw_pixel(x, y)
234
+ send_command( 0x70, x, y )
235
+ end
236
+
237
+ # This command will draw a line from <em>x1</em>, <em>y1</em>
238
+ # to <em>x2</em>, <em>y2</em> using the current drawing color.
239
+ # Lines may be drawn from any part of the display to any other part.
240
+ # However, it may be important to note that the line may in-terpolate
241
+ # differently right to left, or left to right.
242
+ # This means that a line drawn in white from right to left may not
243
+ # fully erase the same line drawn in black from left to right.
244
+ def draw_line(x1, y1, x2, y2)
245
+ send_command( 0x6C, x1, y1, x2, y2 )
246
+ end
247
+
248
+ # This command will draw a line with the current drawing color from
249
+ # the last line end (x2,y2) to <em>x</em>, <em>y</em>.
250
+ # This command uses the global drawing color.
251
+ def draw_line_continue(x, y)
252
+ send_command( 0x65, x, y )
253
+ end
254
+
255
+ # This command draws a rectangular box in the specified <em>color</em>.
256
+ # The top left corner is specified by <em>x1</em>, <em>y1</em> and
257
+ # the bottom right corner by <em>x2</em>, <em>y2</em>.
258
+ def draw_rect(color, x1, y1, x2, y2)
259
+ send_command( 0x72, color, x1, y1, x2, y2 )
260
+ end
261
+
262
+ # This command erases a single bitmap file from the LCD's internal memory.
263
+ def delete_bitmap(refid)
264
+ send_command( 0xAD, 0x01, refid )
265
+ end
266
+
267
+ # This command erases a single font file from the LCD's internal memory.
268
+ def delete_font(refid)
269
+ send_command( 0xAD, 0x00, refid )
270
+ end
271
+
272
+ # Set the current font to the specified font refernce identifer.
273
+ # The font ID is es-tablished when the font is saved to the display.
274
+ def font=(refid)
275
+ send_command( 0x31, refid )
276
+ end
277
+
278
+ # This command completely erases the display's non-volatile memory. It
279
+ # removes all fonts, font metrics, bitmaps, and settings (current font,
280
+ # cursor position, communication speed, etc.).
281
+ def wipe_filesystem
282
+ send_command( 0x21, 0x59, 0x21 )
283
+ end
284
+
285
+ # This command will return the number of bytes that are
286
+ # remaining in the on board memory.
287
+ def filesystem_space
288
+ send_command( 0xAF )
289
+
290
+ #my count = getint()
291
+
292
+ #count |= ( & 0xFF) << 0;
293
+ #count |= (getchar() & 0xFF) << 8;
294
+ #count |= (getchar() & 0xFF) << 16;
295
+ #count |= (getchar() & 0xFF) << 24;
296
+ #
297
+ #return count;
298
+ end
299
+
300
+ # This command will return a directory of the contents of the file system.
301
+ # It returns an array of directory entires, where each entry is a hash.
302
+ def filesystem_directory
303
+ send_command( 0xB3 )
304
+
305
+ #my lsb = getchar()
306
+
307
+ #my @bytes = getbytes( 4 )
308
+
309
+ #my count = 0;
310
+ #count |= (@bytes[0] & 0xFF) << 0;
311
+ #count |= (@bytes[1] & 0xFF) << 8;
312
+ #count |= (@bytes[2] & 0xFF) << 16;
313
+ #count |= (@bytes[3] & 0xFF) << 24;
314
+
315
+ #return count;
316
+
317
+ #return lsb;
318
+ end
319
+
320
+ # This command draws a solid rectangle in the specified <em>color</em>.
321
+ # The top left corner is specified by <em>x1</em>, <em>y1</em> and the bottom
322
+ # right corner by <em>x2</em>, <em>y2</em>. Since this command involves
323
+ # considerable processing overhead, we strongly recommend the use of flow
324
+ # control, particularly if the command is to be repeated frequently.
325
+ def draw_solid_rect(color, x1, y1, x2, y2)
326
+ send_command( 0x78, color, x1, y1, x2, y2 )
327
+ end
328
+
329
+ # This command turns Off general purpose output <em>num</em>.
330
+ def gpo_off(num)
331
+ send_command( 0x56, num )
332
+ end
333
+
334
+ # This command turns On general purpose output <em>num</em>.
335
+ def gpo_on(num)
336
+ send_command( 0x57, num )
337
+ end
338
+
339
+
340
+
341
+ # Send a raw command to the display, where <em>args<em> is an
342
+ # array of integer bytes to be sent to the lcd module.
343
+ def send_command(command, *args)
344
+ args.unshift(0xFE, command)
345
+ self.print( args.pack('C*') )
346
+ end
347
+
348
+ # Send text string to display and STDOUT too
349
+ def puts_stdout(*args)
350
+ $stdout.puts(*args)
351
+ self.puts(*args)
352
+ end
353
+
354
+
355
+ # Turn LED number <em>num</em> off.
356
+ #
357
+ # The command is only supported on LCD modules with
358
+ # on-board LEDS (such as the GLK19264-7T-1U)
359
+ def led_off(num)
360
+ gpo_base = led_gpo_base(num)
361
+ gpo_on( gpo_base )
362
+ gpo_on( gpo_base+1 )
363
+ end
364
+
365
+ # Turn LED number <em>num</em> on - Red.
366
+ #
367
+ # The command is only supported on LCD modules with
368
+ # on-board LEDS (such as the GLK19264-7T-1U)
369
+ def led_red(num)
370
+ gpo_base = led_gpo_base(num)
371
+ gpo_off( gpo_base )
372
+ gpo_on( gpo_base+1 )
373
+ end
374
+
375
+ # Turn LED number <em>num</em> on - Green.
376
+ #
377
+ # The command is only supported on LCD modules with
378
+ # on-board LEDS (such as the GLK19264-7T-1U)
379
+ def led_green(num)
380
+ gpo_base = led_gpo_base(num)
381
+ gpo_on( gpo_base )
382
+ gpo_off( gpo_base+1 )
383
+ end
384
+
385
+ # Turn LED number <em>num</em> on - Yellow.
386
+ #
387
+ # The command is only supported on LCD modules with
388
+ # on-board LEDS (such as the GLK19264-7T-1U)
389
+ def led_yellow(num)
390
+ gpo_base = led_gpo_base(num)
391
+ gpo_off( gpo_base )
392
+ gpo_off( gpo_base+1 )
393
+ end
394
+
395
+
396
+ # Returns the firmware version of the LCD module that you are
397
+ # communicating with as a dotted integer (for example '5.4').
398
+ def firmware_version
399
+ return @firmware_version unless @firmware_version.nil?
400
+
401
+ # Request firmware version number
402
+ send_command( 0x36 )
403
+
404
+ # Read back one byte
405
+ value = getc
406
+ major = (value & 0xF0) >> 4
407
+ minor = value & 0x0F
408
+ return @firmware_version = "#{major}.#{minor}"
409
+ end
410
+
411
+
412
+ TYPEMAP = {
413
+ 0x10 => 'GLC12232',
414
+ 0x13 => 'GLC24064',
415
+ 0x15 => 'GLK24064-25',
416
+ 0x22 => 'GLK12232-25',
417
+ 0x24 => 'GLK12232-25-SM',
418
+ 0x26 => 'GLK24064-16-1U',
419
+ 0x27 => 'GLK19264-7T-1U',
420
+ 0x28 => 'GLK12232-16',
421
+ 0x29 => 'GLK12232-16-SM',
422
+ 0x72 => 'GLK240128-25'
423
+ }
424
+
425
+ # Return the Product Idenfier for the LCD module (for example 'GLK24064-25').
426
+ # This can be determined automatically or passed as a parameter to new().
427
+ def lcd_type
428
+ return @lcd_type unless @lcd_type.nil?
429
+
430
+ # Request LCD module type
431
+ send_command( 0x37 )
432
+
433
+ # Read back one byte
434
+ type = getc
435
+ if TYPEMAP.has_key?(type)
436
+ @lcd_type = TYPEMAP[type]
437
+ else
438
+ @lcd_type = "Unknown-#{type}"
439
+ end
440
+ end
441
+
442
+ # Returns the dimensions (in pixels) of the LCD module you are talking
443
+ # to as an array, width followed by height.
444
+ def lcd_dimensions
445
+ # Parse the LCD type to work out the dimensions
446
+ if (lcd_type =~ /^(GLC|GLK)(\d{3})(\d{2})-|$/)
447
+ return [$2,$3]
448
+ else
449
+ raise "Can't get screen dimensions: unknown LCD module"
450
+ end
451
+ end
452
+
453
+ private
454
+
455
+ # Private method to get the base GPO bit for specified LED number
456
+ def led_gpo_base(num)
457
+ case num.to_i
458
+ when 0
459
+ 1
460
+ when 1
461
+ 3
462
+ when 2
463
+ 5
464
+ else
465
+ raise 'Invalid LED number'
466
+ end
467
+ end
468
+
469
+ end # GLK
470
+ end # MatrixOrbital
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matrixorbital-glk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas J Humfrey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-20 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description:
25
+ email: njh@aelius.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - NEWS
33
+ - COPYING
34
+ files:
35
+ - Rakefile
36
+ - lib/matrixorbital/glk.rb
37
+ - examples/identify.rb
38
+ - examples/load-usb-driver.sh
39
+ - README
40
+ - NEWS
41
+ - COPYING
42
+ has_rdoc: true
43
+ homepage: http://matrixorbital.rubyforge.org
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project: matrixorbital
64
+ rubygems_version: 0.9.5
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: A ruby gem to interface Matrix Orbital's GLK series of LCD Screens.
68
+ test_files: []
69
+