papirus 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +68 -48
  3. data/lib/papirus.rb +136 -44
  4. metadata +44 -4
  5. data/README.rdoc +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a76933b098f5b78df7b2d885b938f171fa79896d
4
- data.tar.gz: e8d561a393c6380ef13b0c674a4e62171dbd30de
3
+ metadata.gz: 5a26e1edf6b65c615e866725ea32e8c76b376a7e
4
+ data.tar.gz: 799cc512691f78a1400a588d0f1c19ed3c6a418a
5
5
  SHA512:
6
- metadata.gz: 97fcf810d33adf0868454ffd407a71ee2038032cec814a3bdc771302db9b9f1535d928c5c59b0c66456014495c0bb3e075e8e657d2c3c001b88d54ba630d4d22
7
- data.tar.gz: d561835c1dfa3dfda5f73918bcccc5ef9cc210498cc137dc84ff1a179bb59b9ee37b352af94e9b5e9afa7f2de2b4a13e6d8b40485a1970a53bd0ab5ac6621230
6
+ metadata.gz: a821ef2457c0ccfdf3ccb826e99b9920b97401032dc61ac6a48edc0a7c38b24efa49e550f9150f3430d3c3b2029515fba120c8462277b020d10cf2e85234767a
7
+ data.tar.gz: 8c7da2f32417ca1953fe23209bae94d4491467d82c6682b47f5a6424cfdd2c728d53b6cf849aeec9a3bb3e77317b350b096023a1e2a47d45cd3ed229cd8e2fc2
data/README.md CHANGED
@@ -24,59 +24,32 @@ You can find more detailed instructions and updates at the [gratis](https://gith
24
24
  $ gem install papirus
25
25
  ```
26
26
 
27
- ## usage
28
-
29
- ```ruby
30
- require 'papirus'
31
-
32
- # first we get ourself a display
33
- display = PaPiRus::Display.new()
34
- ```
35
-
36
- ## there are multiple screen commands ['F', 'P', 'U', 'C']
37
-
38
- The `image.to_bit_stream` will be explained for both RMagic and ChunkyPNG below
39
-
40
- Full update (with screen cleaning):
41
-
42
- `display.show(image.to_bit_stream(display.width, display.height))`
43
-
44
- Fast update:
45
-
46
- `display.show(image.to_bit_stream(display.width, display.height)), 'F')`
47
-
48
- Partial update:
49
-
50
- `display.show(image.to_bit_stream(display.width, display.height), 'P')`
51
-
52
- # Playing with RMagic
27
+ # Using with RMagic
53
28
 
54
29
  First install rmagick
55
30
 
56
31
  ```bash
57
- $ # install native Image Magick library
32
+ $ # Install native Image Magick library
58
33
  $ (OSX) brew install imagemagick@6 && brew link imagemagick@6 --force
59
34
  $ (debian/ubuntu) sudo apt-get install imagemagick
60
35
  $ (Windows) no idea (did not use windows for 20 years, and would like to add some more)
61
- $ # install the gem that talks to the native Image Magick library
36
+ $ # Install the gem that talks to the native Image Magick library
62
37
  $ gem install rmagick
63
38
  ```
64
39
 
65
- Then, start an irb session to play around
66
- ```ruby
67
- require 'papirus'
68
- require 'papirus/rmagick'
40
+ ## Using an irb session to play around:
69
41
 
42
+ ```
43
+ $ bundle exec irb -r lib/papirus -r ./lib/papirus/rmagick
70
44
  display = PaPiRus::Display.new()
71
45
  image = Magick::Image::read('/path/to/img/file.[png|jpg|etc]').first
72
46
  display.show(image.to_bit_stream(display.width, display.height))
73
47
  ```
74
48
 
75
- # Playing with Chunky_PNG
76
-
77
- First install chunky_png
49
+ # Using with ChunkyPNG
78
50
 
79
51
  ```bash
52
+ # install on
80
53
  $ (OSX) brew install chunky_png
81
54
  $ (debian/ubuntu) sudo apt-get install chunky_png
82
55
  $ (Windows) no idea (did not use windows for 20 years, and would like to add some more)
@@ -86,9 +59,7 @@ $ gem install chunky_png
86
59
  ## Load an image from a png file
87
60
 
88
61
  ```ruby
89
- irb
90
- require 'papirus'
91
- require 'papirus/chunky'
62
+ $ bundle exec irb -r lib/papirus -r ./lib/papirus/chunky
92
63
  display = PaPiRus::Display.new()
93
64
  image = ChunkyPNG::Image.from_file('out.png')
94
65
  display.show(image.to_bit_stream(display.width, display.height))
@@ -98,15 +69,16 @@ The only problem here is the aspect ration of the image is not ok anymore. is a
98
69
  But for now you could also use Image magick's convert tool to rescale the image and place it in the middle
99
70
 
100
71
  First, let's use Image Magick's `convert` tool to convert any image into an scaled, centered png
72
+
101
73
  ```bash
102
74
  convert in.jpg -resize '264x176' -gravity center -extent '264x176' out.png
103
75
  ```
104
76
 
105
77
  now, load it like explaned above and the image should be in the right aspect ration
106
78
 
107
- ## Playing with drawing circles
79
+ ## Drawing circles with ChunkyPNG
108
80
 
109
- ```ruby
81
+ ```
110
82
  irb
111
83
  require 'papirus'
112
84
  require 'papirus/chunky' # add's to_bit_stream function to chucky
@@ -117,9 +89,9 @@ image = ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WH
117
89
  image.circle(display.width/2, display.height/2, display.height/2-2)
118
90
  ```
119
91
 
120
- have a look at [chunky_png](https://github.com/wvanbergen/chunky_png/wiki) for more examples
92
+ have a look at [chunkypng](https://github.com/wvanbergen/chunky_png/wiki) for more examples
121
93
 
122
- ```ruby
94
+ ```
123
95
  #and last we dump the image as bitsteam to the display
124
96
  display.show(image.to_bit_stream)
125
97
 
@@ -137,18 +109,43 @@ display.clear
137
109
  end
138
110
  ```
139
111
 
112
+ ## there are multiple screen commands ['F', 'P', 'U', 'C']
113
+
114
+ Full update (with screen cleaning):
115
+
116
+ ```
117
+ display.show(image.to_bit_stream(display.width, display.height))
118
+ ```
119
+
120
+ Fast update:
121
+
122
+ ```
123
+ display.show(image.to_bit_stream(display.width, display.height)), 'F')
124
+ ```
125
+
126
+ Partial update:
127
+
128
+ ```
129
+ display.show(image.to_bit_stream(display.width, display.height), 'P')
130
+ ```
131
+
140
132
  ## Testing without a PaPiRus display
141
133
 
142
134
  If you want to test the gem, but don't have your PaPiRus available, you can do the following
143
135
 
144
- * clone this repo
136
+ clone this repo
145
137
  * start irb
146
- * require 'papirus'
147
- The gem will create the epd_path test folder and will add all params for the 2.0 panel
148
- * display = PaPiRus::Display.new(epd_path: '/tmp/epd')
149
- When you want to add the 2.7 display panel, you would do
150
- * display = PaPiRus::Display.new(epd_path: '/tmp/epd', width: 264, height: 176, panel: 'EPD 2.7')
138
+
139
+ ```
140
+ $ bundle exec irb -r ./lib/papirus
141
+ # The gem will create the epd_path test folder (the folder needs to be somwhere in /tmp/) and will set it by default to the 2.0 panel
142
+ display = PaPiRus::Display.new(options:{epd_path: '/tmp/epd'})
143
+ # When you want to add the 2.7 display panel, you would do
144
+ display = PaPiRus::Display.new(options:{epd_path: '/tmp/epd', width: 264, height: 176, panel: 'EPD 2.7'})
145
+ ```
146
+
151
147
  Now play with the examples above
148
+
152
149
  * when you run `display.show` the **fake** display /tmp/epd/LE/display is filled with your image
153
150
  * now you can use a bin editor like xxd to have a look at the result: `xxd -b /tmp/epd/LE/display`
154
151
  * or, use `image.inspect_bitstream(display.width, display.height)` to dump the image as 1's and 0's to the terminal
@@ -157,9 +154,11 @@ Now play with the examples above
157
154
  ## handy convert command
158
155
 
159
156
  This Image Magick convert command creates a 1-bit 2-color png
157
+
160
158
  ```bash
161
159
  convert in.jpg -resize '264x176' -gravity center -extent '264x176' -colorspace gray -colors 2 -type bilevel out.png
162
160
  ```
161
+
163
162
  Where
164
163
  * the -resize scales the image to fit the display
165
164
  * The -gravity and -extent combination (order is important!) makes sure the image stays at the size of the display and in the centre
@@ -177,3 +176,24 @@ Where
177
176
  ## Other resources
178
177
 
179
178
  * [pi supply python driver](https://github.com/PiSupply/PaPiRus)
179
+
180
+ ## Development
181
+
182
+ * Install bundler with ```gem install bundler```
183
+ * Run ```bundle install``` to get all the gems
184
+ * Create the documentation with: ```bundle exec yard```
185
+ * Run the tests with: ```bundle exec rake yard:doctest```
186
+
187
+ ## Contributing to papirus
188
+
189
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
190
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
191
+ * Fork the project.
192
+ * Start a feature/bugfix branch.
193
+ * Commit and push until you are happy with your contribution.
194
+ * Make sure to add unit tests for it. This is important so I don't break it in a future version unintentionally.
195
+ * Create a PR
196
+
197
+ ## Copyright
198
+
199
+ Copyright (c) 2017 Mischa Molhoek. See LICENSE.txt for further details.
data/lib/papirus.rb CHANGED
@@ -1,72 +1,131 @@
1
+ # The PaPiRus::Display can be use to send image data to the
2
+ # epd fuse driver
3
+ #
4
+ # Example usage
5
+ # require 'papirus'
6
+ # require 'papirus/rmagick'
7
+ # display = PaPiRus::Display.new()
8
+ # image = Magick::Image::read('/path/to/img/file.[png|jpg|etc]').first
9
+ # display.show(image.to_bit_stream(display.width, display.height))
1
10
  module PaPiRus
2
- # The {PaPiRus::Display} can be use to send image data to the
3
- # epd fuse driver
11
+ # Default epd driver path
12
+ EPDPATH = '/dev/epd'
13
+
4
14
  class Display
5
15
  attr_reader :epd_path, :width, :height, :panel, :cog, :film, :auto, :allowed_commands, :display_path
6
16
  attr_accessor :rotation, :inverse, :image
7
17
  # The possible commands to send to the display with {PaPiRus::Display.command}
8
- # can be eitheri
9
- # 'U' for update
10
- # 'F' for fast update
11
- # 'P' for partial update
12
- # or 'C' for clearing the screen
18
+ # can be either
19
+ # 'U' for update
20
+ # 'F' for fast update
21
+ # 'P' for partial update
22
+ # or 'C' for clearing the display
23
+ # @return [Array<String>] All allowed command strings
13
24
  attr_reader :allowed_commands
14
-
15
- def initialize(epd_path: '/dev/epd', width: 200, height: 96, panel: 'EPD 2.0', cog: 2, film: 231, auto: false, inverse: false, rotation: 0)
16
- if epd_path != '/dev/epd'
17
- # assuming we use a test dir and it is not created yet
18
- require 'fileutils'
19
- raise 'epd test path should be located somewhere in /tmp/' unless epd_path =~ /\/tmp\/\w+/
20
- if File.exists?(epd_path)
21
- #remove old test dir as it may be a different screen size/type
22
- FileUtils.rm_f(epd_path)
23
- end
24
- FileUtils.mkdir_p(File.join([epd_path, 'LE']))
25
- %w{command LE/display, LE/display_inverse}.each do |file|
26
- FileUtils.touch File.join([epd_path, file])
27
- end
28
- File.open(File.join([epd_path, 'panel']), 'w+') do |file|
29
- file.write %{#{panel} #{width}x#{height} COG #{cog} FILM #{film}\n}
30
- end
31
- end
32
- #transver all vars to attr's
33
- method(__method__).parameters.each do |type, k|
34
- next unless type == :key
35
- v = eval(k.to_s)
36
- instance_variable_set("@#{k}", v) unless v.nil?
37
- end
38
- @allowed_commands = ['F', 'P', 'U', 'C']
39
- get_display_info_from_edp
25
+ # By default, no parameters need to be passed to initialize. It will read all display settings
26
+ # from the panel info file that is created by the fuse driver. However, if you want to test
27
+ # without the display being available, you can pass a fake epd_path set to a folder in /tmp
28
+ # in that case initialize will use all other params to create a fake fuse structure
29
+ # PaPiRus display sizes:
30
+ # 1.44" 128 x 96
31
+ # 1.9" 144 x 128
32
+ # 2.0" 200 x 96
33
+ # 2.6" 232 x 128
34
+ # 2.7" 264 x 176
35
+ # All the examples used in the documentation are also used to unit testing the code with
36
+ # yard:doctest[https://github.com/p0deje/yard-doctest],
37
+ # so we have duomentation and testing in one go, great!
38
+ # * the display that is used for the examples is a 8x3 mini display for the sake of simplicity.
39
+ # * imagewithline is a test helper that create an image of 8x3 pixels
40
+ # * testdisplaylookslike is a test helper that shows the bit content of the display
41
+ # * lastcommand is a test helper that will show the last command send to the display
42
+ # @example Initializing the real display
43
+ # display = PaPiRus::Display.new()
44
+ # @example Initializing the display for testing the 2.7 display
45
+ # display = PaPiRus::Display.new(options:{epd_path: '/tmp/epd', width: 264, height: 176, panel: 'EPD 2.7'})
46
+ # @param [Hash] options The options setup options when using a fake display file structure for testing.
47
+ # @option options [String] :epd_path ('/tmp/epd') The path to the fake display fuse folder
48
+ # @option options [Integer] :width (200) The width of the fake display (defaults to the 2.0 display size)
49
+ # @option options [Integer] :height (96) The height of the fake display
50
+ # @option options [String] :panel ('EPD 2.0') The panel type
51
+ # @option options [String] :cog (2)
52
+ # @option options [String] :film (231)
53
+ # @option options [Boolean] :auto (false)
54
+ # @option options [Boolean] :inverse (false)
55
+ # @option options [Integer] :rotation (0)
56
+ def initialize(options: {})
57
+ initializeOptions(options: options)
58
+ createFakeEpdFileStructure(epd_path: @epd_path) if @epd_path != EPDPATH
59
+ updateOptionsFromPanel
40
60
  end
41
61
 
42
- def show(*args)
43
- raise 'you need to at least provide raw imagedata' if args.length == 0
44
- data = args[0]
45
- updatemethod = args[1] || 'U'
62
+ # Show can be used to send raw image data to the display.
63
+ # @param data [raw image data file] The file containing the raw 1-bits 2 color image bitmap without any header/footer/imageinfo
64
+ # @param command ['U'|'F'|'P']
65
+ # @example Show simpel image
66
+ # display.show(data: imagewithline)
67
+ # testdisplaylookslike #=> '000000001111111100000000'
68
+ # lastcommand #=> 'U'
69
+ # @see #initialize if you are wondering what display type is used for the tests and what imagewithline and lastcommand is all about
70
+ def show(data:, command: 'U')
46
71
  File.open(File.join(@epd_path, "LE", "display#{@inverse ? '_inverse': ''}"), 'wb') do |io|
47
72
  io.write data
48
73
  end
49
- command(@allowed_commands.include?(updatemethod) ? updatemethod : 'U')
74
+ command(@allowed_commands.include?(command) ? command : 'U')
50
75
  end
51
76
 
77
+ # Send the fast update command to the display
78
+ # @example Fast Update example
79
+ # display.fast_update
80
+ # lastcommand #=> 'F'
52
81
  def fast_update()
53
82
  command('F')
54
83
  end
55
84
 
85
+ # Send the partial update command to the display
86
+ # @example Partial Update example
87
+ # display.partial_update
88
+ # lastcommand #=> 'P'
56
89
  def partial_update()
57
90
  command('P')
58
91
  end
59
92
 
93
+ # Send the full update command to the display
94
+ # @example Full Update example
95
+ # display.update
96
+ # lastcommand #=> 'U'
60
97
  def update()
61
98
  command('U')
62
99
  end
63
100
 
101
+ # Send the clear command to the display
102
+ # @example Clear the display
103
+ # display.clear
104
+ # lastcommand #=> 'C'
64
105
  def clear()
65
106
  command('C')
66
107
  end
67
108
 
68
- # send's the display command to the driver
69
- # @param c [string] command to execute, have a look at {}
109
+ # Send's the display command to the driver
110
+ # available commands are
111
+ # * 'U' => update the display
112
+ # * 'F' => fast update the display
113
+ # * 'P' => Partial update the display
114
+ # * 'C' => Clear the display
115
+ # @param c [String] command to execute
116
+ #
117
+ # @example Clear the display
118
+ # display.command('C')
119
+ # lastcommand #=> 'C'
120
+ # @example Update the display
121
+ # display.command('U')
122
+ # lastcommand #=> 'U'
123
+ # @example Fast update the display
124
+ # display.command('F')
125
+ # lastcommand #=> 'F'
126
+ # @example Partial update the display
127
+ # display.command('P')
128
+ # lastcommand #=> 'P'
70
129
  def command(c)
71
130
  raise "command #{c} does not exist" unless @allowed_commands.include?(c)
72
131
  File.open(File.join(@epd_path, "command"), "wb") do |io|
@@ -75,15 +134,49 @@ module PaPiRus
75
134
  end
76
135
 
77
136
  private
78
- # Reads all panel info and updates the according attributes
79
- def get_display_info_from_edp
137
+ # Creates a fake test structure of the display fuse driver
138
+ def createFakeEpdFileStructure(epd_path:)
139
+ # assuming we use a test dir and it is not created yet
140
+ # test dirs can only be subdir of /tmp/
141
+ raise 'epd test path should be located somewhere in /tmp/' unless epd_path =~ /\/tmp\/\w+/
142
+ require 'fileutils'
143
+ #remove old test dir as it may be a different display size/type
144
+ if File.exists?(epd_path)
145
+ FileUtils.rm_f(epd_path)
146
+ end
147
+ #create all folders and files
148
+ FileUtils.mkdir_p(File.join([epd_path, 'LE']))
149
+ %w{command LE/display, LE/display_inverse}.each do |file|
150
+ FileUtils.touch File.join([epd_path, file])
151
+ end
152
+ #create the panel info file
153
+ File.open(File.join([epd_path, 'panel']), 'w+') do |file|
154
+ file.write %{#{@panel} #{@width}x#{@height} COG #{@cog} FILM #{@film}\n}
155
+ end
156
+ end
157
+
158
+ # Reads all panel info from /dev/epd/panel and updates the according attributes
159
+ def initializeOptions(options:)
160
+ @allowed_commands = ['F', 'P', 'U', 'C']
161
+ @epd_path = options[:epd_path] || EPDPATH
162
+ @width = options[:width] || 200
163
+ @height = options[:height] || 96
164
+ @panel = options[:panel] || "EPD 2.0"
165
+ @cog = options[:cog] || 2
166
+ @film = options[:film] || 231
167
+ @auto = options[:auto] || false
168
+ @inverse = options[:inverse] || false
169
+ @rotation = options[:rotation] || 0
170
+ end
171
+
172
+ def updateOptionsFromPanel
80
173
  if File.exists?(File.join(@epd_path, 'panel'))
81
174
  info = File.read(File.join(@epd_path, 'panel'))
82
175
  @display_path = File.join([@epd_path, 'LE', 'display'])
83
176
  if match = info.match(/^([A-Za-z]+\s+\d+\.\d+)\s+(\d+)x(\d+)\s+COG\s+(\d+)\s+FILM\s+(\d+)\s*$/)
84
177
  @panel, @width, @height, @cog, @film = match.captures.each_with_index.map{|val, index| index > 0 ? val.to_i : val}
85
178
  else
86
- STDERR.puts "did not recognize screen info: #{info}, is the epd driver properly installed? have a look at the README.md to see how to install the epaper driver"
179
+ STDERR.puts "did not recognize display info: #{info}, is the epd driver properly installed? have a look at the README.md to see how to install the epaper driver"
87
180
  exit 1
88
181
  end
89
182
  else
@@ -91,6 +184,5 @@ module PaPiRus
91
184
  exit 1
92
185
  end
93
186
  end
94
-
95
187
  end
96
188
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papirus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mischa Molhoek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-28 00:00:00.000000000 Z
11
+ date: 2017-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard-doctest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description: This gem can be used to talk to the PaPiRus e-paper display
84
126
  email: mischamolhoek@gmail.com
85
127
  executables: []
@@ -88,12 +130,10 @@ extra_rdoc_files:
88
130
  - LICENSE
89
131
  - LICENSE.txt
90
132
  - README.md
91
- - README.rdoc
92
133
  files:
93
134
  - LICENSE
94
135
  - LICENSE.txt
95
136
  - README.md
96
- - README.rdoc
97
137
  - lib/papirus.rb
98
138
  - lib/papirus/chunky.rb
99
139
  - lib/papirus/rmagick.rb
data/README.rdoc DELETED
@@ -1,18 +0,0 @@
1
- = papirus
2
-
3
- This gem can be used to communicate with the {PaPiRus}[https://github.com/PiSupply/PaPiRus] display.
4
- Checkout {GitHub}[http://github.com/mmolhoek/papirus] for examples and documentation
5
-
6
- == Contributing to papirus
7
-
8
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
9
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
10
- * Fork the project.
11
- * Start a feature/bugfix branch.
12
- * Commit and push until you are happy with your contribution.
13
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
14
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
15
-
16
- == Copyright
17
-
18
- Copyright (c) 2017 Mischa Molhoek. See LICENSE.txt for further details.