papirus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +70 -0
  5. data/README.rdoc +18 -0
  6. data/lib/chunky.rb +31 -0
  7. data/lib/papirus.rb +65 -0
  8. metadata +137 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 351e781013b7ce41795cefea94547ff985ac1299
4
+ data.tar.gz: 649bbf301e45d6f35e84538f359bd8b0868d51b9
5
+ SHA512:
6
+ metadata.gz: 3514f623188b3de3dca23ac413de273b625e400114978bade812bdeb4358324bf84d8428e4bf73df3af3313764a2fc3f6f2e0d2b4ea8ae3c0e14d774fa644da9
7
+ data.tar.gz: 222e02a5d40b2d9bbdfd81aab137f95d8d9e9268f15de27c343db0714da4faa75cc2bfb2f20780637732875d0aa882edde7143280cbbc8285bf0d9e26f721bd9
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Mischa Molhoek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 Mischa Molhoek
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # papirus
2
+
3
+ ruby gem to talk to the PAPiRus display
4
+
5
+ ## epaper fuse driver installation instructions (if you have not done that already ::)
6
+ ```bash
7
+ sudo apt-get install libfuse-dev -y
8
+
9
+ mkdir /tmp/papirus
10
+ cd /tmp/papirus
11
+ git clone https://github.com/repaper/gratis.git
12
+
13
+ cd gratis
14
+ make rpi EPD_IO=epd_io.h PANEL_VERSION='V231_G2'
15
+ make rpi-install EPD_IO=epd_io.h PANEL_VERSION='V231_G2'
16
+ systemctl enable epd-fuse.service
17
+ systemctl start epd-fuse
18
+ ```
19
+ ## gem installation
20
+
21
+ ```bash
22
+ $ gem install papirus
23
+ ```
24
+ ## usage
25
+
26
+ ```ruby
27
+ require 'papirus'
28
+
29
+ # first we get ourself a display
30
+ display = PaPiRus::Display.new()
31
+
32
+ #lets get a clean clean png of the size of the display to play with using chunky_png
33
+ image = ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WHITE)
34
+ #and we draw a circle on it which is about the size of the screen
35
+ image.circle(display.width/2, display.height/2, display.height/2-2)
36
+ # have a look at https://github.com/wvanbergen/chunky_png for more examples
37
+
38
+ #and last we dump the image as bitsteam to the display
39
+ display.show(image.to_bit_stream)
40
+
41
+ # now we could also change the circle and fast update the screen
42
+ image.replace!(ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WHITE))
43
+ image.circle(display.width/2, display.height/2, display.height/4)
44
+ display.show(image.to_bit_stream, 'F')
45
+
46
+ # or update the screen for multiple circles
47
+ display.clear
48
+ 2.step(image.height/2-2, 5).each do |radius|
49
+ image.replace!(ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WHITE))
50
+ image.circle(display.width/2, display.height/2, radius)
51
+ display.show(image.to_bit_stream, 'F')
52
+ end
53
+ ```
54
+
55
+ ## from here WIP
56
+
57
+ #img loading does not work yet
58
+ image = ChunkyPNG::Image.from_file(pngfile)
59
+ display.show(image.to_bit_stream)
60
+
61
+ # more control
62
+ display = PaPiRus::Display.new()
63
+ display.load(imagefile)
64
+
65
+ display.update #or
66
+ display.fast_update #or
67
+ display.partial_update
68
+
69
+ #or when testing to a temp file (run createtestepd.sh to create paths in /tmp)
70
+ display = PaPiRus::Display.new(epd_path: '/tmp/epd')
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = papirus
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to papirus
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * 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.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2017 Mischa Molhoek. See LICENSE.txt for
18
+ further details.
data/lib/chunky.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'chunky_png'
2
+
3
+ module ChunkyPNG::Canvas::StreamExporting
4
+ def inspect_bitstream
5
+ #create a simple map of the image of '0's and '1's
6
+ #for debugging purpuses
7
+ pixels.each_slice(@width).map{|row| row.each_slice(8).map{|pixels|pixels.map{|pixel| pixel == ChunkyPNG::Color::WHITE ? '0' : '1'}.join}.join(' ')}
8
+ end
9
+
10
+ def to_bit_stream(inverse = false)
11
+ #as the ChunkyPNG library works with 4 bytes data per pixel (1 byte for R, G, B and transparancy)
12
+ #and the EDP needs 1 bit per pixel (on or off), we need some way to traverse over all pixels
13
+ #and add a bit to a byte stream for each pixel. so
14
+
15
+ bytes = []
16
+ #for each 8 pixels (the ChunkyPNG library keeps an array of all pixels used, containing ChunkyPNG::Color elements)
17
+ pixels.each_slice(8).map do |pixels|
18
+ #we create a byte with its bits set to 00000000
19
+ byte = 0
20
+ 0.upto(7) do |bit|
21
+ #and switch the bit to 1 (or 0 if not inverse) for each pixel if it was white
22
+ #we have to check pixels[7-bit] as the order is right to left
23
+ byte |= 1 << bit if (inverse && pixels[7-bit] == ChunkyPNG::Color::WHITE) || (!inverse && pixels[7-bit] != ChunkyPNG::Color::WHITE)
24
+ end
25
+ #and add it to the output byte stream
26
+ bytes.push(byte)
27
+ end
28
+ #now we just need to pack all bytes into a file writable string
29
+ bytes.pack('C'*bytes.length)
30
+ end
31
+ end
data/lib/papirus.rb ADDED
@@ -0,0 +1,65 @@
1
+ require_relative "chunky"
2
+
3
+ module PaPiRus
4
+ class Display
5
+ attr_reader :epd_path, :width, :height, :panel, :cog, :film, :auto
6
+ attr_accessor :rotation, :inverse, :image
7
+
8
+ def initialize(epd_path: '/dev/epd', width: 200, height: 96, panel: 'EPD 2.0', cog: 0, film: 0, auto: false, inverse: false, rotation: 0)
9
+ #transver all vars to attr's
10
+ method(__method__).parameters.each do |type, k|
11
+ next unless type == :key
12
+ v = eval(k.to_s)
13
+ instance_variable_set("@#{k}", v) unless v.nil?
14
+ end
15
+ get_display_info_from_edp
16
+ end
17
+
18
+ def show(*args)
19
+ raise 'you need to al least provide raw imagedata' if args.length == 0
20
+ data = args[0]
21
+ updatemethod = args[1] || 'U'
22
+ File.open(File.join(@epd_path, "LE", "display#{@inverse ? '_inverse': ''}"), 'wb') do |io|
23
+ io.write data
24
+ end
25
+ command(updatemethod)
26
+ end
27
+
28
+ def fast_update()
29
+ command('F')
30
+ end
31
+
32
+ def partial_update()
33
+ command('P')
34
+ end
35
+
36
+ def update()
37
+ command('U')
38
+ end
39
+
40
+ def clear()
41
+ command('C')
42
+ end
43
+
44
+ private
45
+ def get_display_info_from_edp
46
+ if File.exists?(File.join(@epd_path, 'panel'))
47
+ info = File.read(File.join(@epd_path, 'panel'))
48
+ if match = info.match(/^([A-Za-z]+\s+\d+\.\d+)\s+(\d+)x(\d+)\s+COG\s+(\d+)\s+FILM\s+(\d+)\s*$/)
49
+ @panel, @width, @height, @cog, @film = match.captures.each_with_index.map{|val, index| index > 0 ? val.to_i : val}
50
+ else
51
+ 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"
52
+ exit 1
53
+ end
54
+ else
55
+ STDERR.puts "could not find the epd driver at #{@epd_path}, is the epd driver properly installed? have a look at the README.md to see how to install the epaper driver"
56
+ exit 1
57
+ end
58
+ end
59
+
60
+ def command(c)
61
+ f = File.new(File.join(@epd_path, "command"), "wb")
62
+ f.write(c)
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: papirus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mischa Molhoek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: juwelier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: chunky_png
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This gem can be used to talk to the PaPiRus e-paper display
98
+ email: mischamolhoek@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - LICENSE
103
+ - LICENSE.txt
104
+ - README.md
105
+ - README.rdoc
106
+ files:
107
+ - LICENSE
108
+ - LICENSE.txt
109
+ - README.md
110
+ - README.rdoc
111
+ - lib/chunky.rb
112
+ - lib/papirus.rb
113
+ homepage: http://github.com/mmolhoek/papirus
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.6.13
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: ruby gem to access the PaPiRus display
137
+ test_files: []