Class: PaPiRus::Display
- Inherits:
-
Object
- Object
- PaPiRus::Display
- Defined in:
- lib/papirus.rb
Overview
The Display can be use to send image data to the epd fuse driver
Instance Attribute Summary collapse
-
#allowed_commands ⇒ Object
readonly
The possible commands to send to the display with command can be eitheri ‘U’ for update ‘F’ for fast update ‘P’ for partial update or ‘C’ for clearing the screen.
-
#auto ⇒ Object
readonly
Returns the value of attribute auto.
-
#cog ⇒ Object
readonly
Returns the value of attribute cog.
-
#display_path ⇒ Object
readonly
Returns the value of attribute display_path.
-
#epd_path ⇒ Object
readonly
Returns the value of attribute epd_path.
-
#film ⇒ Object
readonly
Returns the value of attribute film.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#image ⇒ Object
Returns the value of attribute image.
-
#inverse ⇒ Object
Returns the value of attribute inverse.
-
#panel ⇒ Object
readonly
Returns the value of attribute panel.
-
#rotation ⇒ Object
Returns the value of attribute rotation.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #clear ⇒ Object
-
#command(c) ⇒ Object
send’s the display command to the driver.
- #fast_update ⇒ Object
-
#initialize(epd_path: '/dev/epd', width: 200, height: 96, panel: 'EPD 2.0', cog: 2, film: 231, auto: false, inverse: false, rotation: 0) ⇒ Display
constructor
A new instance of Display.
- #partial_update ⇒ Object
- #show(*args) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(epd_path: '/dev/epd', width: 200, height: 96, panel: 'EPD 2.0', cog: 2, film: 231, auto: false, inverse: false, rotation: 0) ⇒ Display
Returns a new instance of Display.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/papirus.rb', line 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) if epd_path != '/dev/epd' # assuming we use a test dir and it is not created yet require 'fileutils' raise 'epd test path should be located somewhere in /tmp/' unless epd_path =~ /\/tmp\/\w+/ if File.exists?(epd_path) #remove old test dir as it may be a different screen size/type FileUtils.rm_f(epd_path) end FileUtils.mkdir_p(File.join([epd_path, 'LE'])) %w{command LE/display, LE/display_inverse}.each do |file| FileUtils.touch File.join([epd_path, file]) end File.open(File.join([epd_path, 'panel']), 'w+') do |file| file.write %{#{panel} #{width}x#{height} COG #{cog} FILM #{film}\n} end end #transver all vars to attr's method(__method__).parameters.each do |type, k| next unless type == :key v = eval(k.to_s) instance_variable_set("@#{k}", v) unless v.nil? end @allowed_commands = ['F', 'P', 'U', 'C'] get_display_info_from_edp end |
Instance Attribute Details
#allowed_commands ⇒ Object (readonly)
The possible commands to send to the display with command can be eitheri ‘U’ for update ‘F’ for fast update ‘P’ for partial update or ‘C’ for clearing the screen
13 14 15 |
# File 'lib/papirus.rb', line 13 def allowed_commands @allowed_commands end |
#auto ⇒ Object (readonly)
Returns the value of attribute auto.
5 6 7 |
# File 'lib/papirus.rb', line 5 def auto @auto end |
#cog ⇒ Object (readonly)
Returns the value of attribute cog.
5 6 7 |
# File 'lib/papirus.rb', line 5 def cog @cog end |
#display_path ⇒ Object (readonly)
Returns the value of attribute display_path.
5 6 7 |
# File 'lib/papirus.rb', line 5 def display_path @display_path end |
#epd_path ⇒ Object (readonly)
Returns the value of attribute epd_path.
5 6 7 |
# File 'lib/papirus.rb', line 5 def epd_path @epd_path end |
#film ⇒ Object (readonly)
Returns the value of attribute film.
5 6 7 |
# File 'lib/papirus.rb', line 5 def film @film end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/papirus.rb', line 5 def height @height end |
#image ⇒ Object
Returns the value of attribute image.
6 7 8 |
# File 'lib/papirus.rb', line 6 def image @image end |
#inverse ⇒ Object
Returns the value of attribute inverse.
6 7 8 |
# File 'lib/papirus.rb', line 6 def inverse @inverse end |
#panel ⇒ Object (readonly)
Returns the value of attribute panel.
5 6 7 |
# File 'lib/papirus.rb', line 5 def panel @panel end |
#rotation ⇒ Object
Returns the value of attribute rotation.
6 7 8 |
# File 'lib/papirus.rb', line 6 def rotation @rotation end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/papirus.rb', line 5 def width @width end |
Instance Method Details
#clear ⇒ Object
64 65 66 |
# File 'lib/papirus.rb', line 64 def clear() command('C') end |
#command(c) ⇒ Object
send’s the display command to the driver
70 71 72 73 74 75 |
# File 'lib/papirus.rb', line 70 def command(c) raise "command #{c} does not exist" unless @allowed_commands.include?(c) File.open(File.join(@epd_path, "command"), "wb") do |io| io.write(c) end end |
#fast_update ⇒ Object
52 53 54 |
# File 'lib/papirus.rb', line 52 def fast_update() command('F') end |
#partial_update ⇒ Object
56 57 58 |
# File 'lib/papirus.rb', line 56 def partial_update() command('P') end |
#show(*args) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/papirus.rb', line 42 def show(*args) raise 'you need to at least provide raw imagedata' if args.length == 0 data = args[0] updatemethod = args[1] || 'U' File.open(File.join(@epd_path, "LE", "display#{@inverse ? '_inverse': ''}"), 'wb') do |io| io.write data end command(@allowed_commands.include?(updatemethod) ? updatemethod : 'U') end |
#update ⇒ Object
60 61 62 |
# File 'lib/papirus.rb', line 60 def update() command('U') end |