serdisplib-ruby 0.5.1-x86-linux → 0.5.2-x86-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/build.sh CHANGED
@@ -21,8 +21,10 @@ gem build serdisplib-ruby.gemspec
21
21
  # Build make source archive
22
22
  pushd ..
23
23
  find | grep \.svn$ | cut -c3- > exclude.txt
24
- tar cvfX serdisplib-ruby.tar.gz exclude.txt serdisplib-ruby/
25
- rm exclude.txt
24
+ tar cvfX serdisplib-ruby.tar exclude.txt serdisplib-ruby/
25
+ #rm exclude.txt
26
+ gzip serdisplib-ruby.tar
27
+ file serdisplib-ruby.tar.gz
26
28
  popd
27
29
 
28
30
  echo "Done."
@@ -14,40 +14,49 @@ require 'imlib2'
14
14
  module Imlib2Util
15
15
 
16
16
  #
17
+ # Convert Imlib2 image ARGB 8-bit per channel data into a Ruby array.
17
18
  #
19
+ # Note: Imlib2-Ruby returns the data as each array element being a pixel
20
+ # component (i.e. Alpha or Red or Blue or Green), this function combines
21
+ # them back to ARGB data.
18
22
  #
19
- def Imlib2Util.imlib_image_to_serdisp_data( im )
23
+ def Imlib2Util.imlib_image_to_argb_serdisp_data( im )
20
24
 
21
25
  im_width = im.width
22
26
  im_height = im.height
23
27
  im_rgba_data = im.data_for_reading_only( )
24
28
  im_lcd_data = []
25
- im_height.times do
26
- hoz_line = []
27
- im_width.times do hoz_line << 0; end
28
- im_lcd_data << hoz_line
29
+ im_height.times do
30
+ im_lcd_data << Array.new( im_width )
29
31
  end
30
-
32
+
31
33
  im_width.times do |x|
32
34
  im_height.times do |y|
33
35
 
34
- ##### im_lcd_data[y][x] |= ( im_rgba_data[x + (y * im_width)] & 0x00FFFFFF )
35
- im_lcd_data[y][x] = im_rgba_data[x + (y * im_width)]
36
-
37
- #im_lcd_data[y][x] |= ( im_rgba_data[0 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 7 : 0x00 << 7;
38
- #im_lcd_data[y][x] |= ( im_rgba_data[1 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 6 : 0x00 << 6;
39
- #im_lcd_data[y][x] |= ( im_rgba_data[2 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 5 : 0x00 << 5;
40
- #im_lcd_data[y][x] |= ( im_rgba_data[3 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 4 : 0x00 << 4;
41
- #im_lcd_data[y][x] |= ( im_rgba_data[4 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 3 : 0x00 << 3;
42
- #im_lcd_data[y][x] |= ( im_rgba_data[5 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 2 : 0x00 << 2;
43
- #im_lcd_data[y][x] |= ( im_rgba_data[6 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 1 : 0x00 << 1;
44
- #im_lcd_data[y][x] |= ( im_rgba_data[7 + x + (y*im_width)] & 0x00FFFFFF ) > 0 ? 0x01 << 0 : 0x00 << 0;
36
+ pixel_ind = 4 * ( x + ( y * im_width ) )
37
+ a = im_rgba_data[pixel_ind + 0]
38
+ r = im_rgba_data[pixel_ind + 1]
39
+ g = im_rgba_data[pixel_ind + 2]
40
+ b = im_rgba_data[pixel_ind + 3]
41
+
42
+ im_lcd_data[y][x] = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b
45
43
  end
46
44
  end
47
45
 
48
46
  im_lcd_data
49
47
  end
50
48
 
49
+ #
50
+ # Render's centered text on the Imlib2 image buffer given a vertical
51
+ # position.
52
+ #
53
+ def Imlib2Util.imlib_draw_centered_text( dd, ypos, im, font, text )
54
+
55
+ fw, fh = font.size text
56
+ fx, fy = (im.width - fw) / 2, ypos
57
+ im.draw_text( font, text, fx, fy, Imlib2::Color::WHITE )
58
+ end
59
+
51
60
  end
52
61
 
53
62
  # End of imlib2_util.rb
data/examples/uptime.rb CHANGED
@@ -79,9 +79,21 @@ def print_interpreter_usage( )
79
79
  puts "\n\n"
80
80
  puts "exit | quit | q exit this program"
81
81
  puts "help | h display this usage information"
82
+ puts "invert | inv toggle display inversion"
83
+ puts "rotate | rot rotate display 180 degrees"
82
84
  puts "delay | d <[0-9]+> update refresh delay in seconds (default: 2)\n\n"
83
85
  end
84
86
 
87
+ #
88
+ # Call `uptime` and parse uptime output, returning separate pieces as set.
89
+ #
90
+ def get_uptime_info( )
91
+
92
+ uptime_output = `uptime`
93
+ uptime_output =~ /([A-Za-z0-9: ]+),[ \t]+([0-9]+)[ \t]+users,[ \t]+load average: ([0-9.]+), ([0-9.]+), ([0-9.]+)/
94
+ return $1.strip, $2.strip, $3.strip, $4.strip, $5.strip
95
+ end
96
+
85
97
  #-----------------------------------------------------------------------------
86
98
  # Entry-Point
87
99
  #-----------------------------------------------------------------------------
@@ -142,28 +154,25 @@ if ( __FILE__ == $0 ) then
142
154
  h = serdisp_getheight( dd )
143
155
  w = serdisp_getwidth( dd )
144
156
  im = Imlib2::Image.new( w, h )
145
- Imlib2::Font.add_path '/home/dhm/projects/library.ruby/trunk/gem/serdisp/examples/fonts'
146
- font = Imlib2::Font.new( 'yudit/10' )
147
- text = "Testing: UPTIME INFO"
148
- fw, fh = font.size text
149
- fx, fy = (im.width - fw) / 2, (im.height / 2 - fh ) / 2
150
- im.draw_text font, text, fx, fy, Imlib2::Color::RED
151
- im.save( 'test.png' )
152
-
157
+ Imlib2::Font.add_path( 'fonts' )
158
+ font = Imlib2::Font.new( 'yudit/14' )
159
+
153
160
  while ( g_loop )
154
-
155
- uptime_output = `uptime`
156
- puts "output: #{uptime_output}"
161
+ im.clear( )
162
+ time, users, load1, load5, load15 = get_uptime_info( )
163
+ Imlib2Util.imlib_draw_centered_text( dd, 5, im, font, time )
164
+ Imlib2Util.imlib_draw_centered_text( dd, 25, im, font, "#{users} users" )
165
+ Imlib2Util.imlib_draw_centered_text( dd, 45, im, font, "#{load1}, #{load5}, #{load15}" )
157
166
 
158
- lcd_data = Imlib2Util.imlib_image_to_serdisp_data( im )
167
+ lcd_data = Imlib2Util.imlib_image_to_argb_serdisp_data( im )
159
168
  im.width.times do |x|
160
169
  im.height.times do |y|
161
170
 
162
- serdisp_setcolour( dd, x, y, lcd_data[y][x] )
163
- puts "Value: #{lcd_data[y][x]}" unless ( 0 == lcd_data[y][x] )
171
+ pixel = ( lcd_data[y][x] & 0x00FFFFFF ) > 0 ? g_fgcolour : g_bgcolour
172
+ serdisp_setcolour( dd, x, y, pixel )
173
+
164
174
  end
165
175
  end
166
- puts "Done setting LCD."
167
176
 
168
177
  serdisp_update( dd )
169
178
  sleep( g_delay )
@@ -183,6 +192,13 @@ if ( __FILE__ == $0 ) then
183
192
 
184
193
  when 'q', 'quit', 'exit'
185
194
  g_loop = false
195
+
196
+ when 'invert', 'inv'
197
+ serdisp_setoption( dd, 'INVERT', SD_OPTION_TOGGLE )
198
+
199
+ when /rotate( [0-9]+)?/, /rot( [0-9]+)?/
200
+ rc = ( nil == $1 ) ? SD_OPTION_TOGGLE : $1.to_i
201
+ serdisp_setoption( dd, 'ROTATE', rc )
186
202
 
187
203
  when /delay ([0-9]+)?/, /d ([0-9]+)?/
188
204
  puts "Setting delay time to #{$1.to_i} seconds"
Binary file
Binary file
Binary file
@@ -1,7 +1,7 @@
1
1
  require 'date'
2
2
  Gem::Specification.new do |s|
3
3
  s.name = %q{serdisplib-ruby}
4
- s.version = "0.5.1"
4
+ s.version = "0.5.2"
5
5
  s.date = Date.today.to_s
6
6
  s.author = %q{David Muir}
7
7
  s.email = %q{dhm@davidmuir.co.uk}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serdisplib-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: x86-linux
6
6
  authors:
7
7
  - David Muir
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-21 00:00:00 +01:00
12
+ date: 2008-06-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,6 +32,7 @@ files:
32
32
  - ext/serdisplib/serdisplib_wrap.o
33
33
  - ext/serdisplib/serdisplib.i
34
34
  - ext/serdisplib/Makefile
35
+ - serdisplib-ruby-0.5.2-x86-linux.gem
35
36
  - ChangeLog
36
37
  - setup.rb
37
38
  - README