Class: PaPiRus::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/papirus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options: {}) ⇒ Display

By default, no parameters need to be passed to initialize. It will read all display settings from the panel info file that is created by the fuse driver. However, if you want to test without the display being available, you can pass a fake epd_path set to a folder in /tmp in that case initialize will use all other params to create a fake fuse structure

PaPiRus display sizes:
1.44"     128 x 96
1.9"      144 x 128
2.0"      200 x 96
2.6"      232 x 128
2.7"      264 x 176

All the examples used in the documentation are also used to unit testing the code with yard:doctest, so we have duomentation and testing in one go, great!

  • the display that is used for the examples is a 8x3 mini display for the sake of simplicity.

  • imagewithline is a test helper that create an image of 8x3 pixels

  • testdisplaylookslike is a test helper that shows the bit content of the display

  • lastcommand is a test helper that will show the last command send to the display

Examples:

Initializing the real display

display = PaPiRus::Display.new()

Initializing the display for testing the 2.7 display

display = PaPiRus::Display.new(options:{epd_path: '/tmp/epd', width: 264, height: 176, panel: 'EPD 2.7'})

Options Hash (options:):

  • :epd_path (String) — default: '/tmp/epd'

    The path to the fake display fuse folder

  • :width (Integer) — default: 200

    The width of the fake display (defaults to the 2.0 display size)

  • :height (Integer) — default: 96

    The height of the fake display

  • :panel (String) — default: 'EPD 2.0'

    The panel type

  • :cog (String) — default: 2
  • :film (String) — default: 231
  • :auto (Boolean) — default: false
  • :inverse (Boolean) — default: false
  • :rotation (Integer) — default: 0


56
57
58
59
60
# File 'lib/papirus.rb', line 56

def initialize(options: {})
    initializeOptions(options: options)
    createFakeEpdFileStructure(epd_path: @epd_path) if @epd_path != EPDPATH
    updateOptionsFromPanel
end

Instance Attribute Details

#allowed_commandsArray<String> (readonly)

The possible commands to send to the display with command can be either

'U' for update
'F' for fast update
'P' for partial update
or 'C' for clearing the display


24
25
26
# File 'lib/papirus.rb', line 24

def allowed_commands
  @allowed_commands
end

#autoObject (readonly)

Returns the value of attribute auto.



15
16
17
# File 'lib/papirus.rb', line 15

def auto
  @auto
end

#cogObject (readonly)

Returns the value of attribute cog.



15
16
17
# File 'lib/papirus.rb', line 15

def cog
  @cog
end

#display_pathObject (readonly)

Returns the value of attribute display_path.



15
16
17
# File 'lib/papirus.rb', line 15

def display_path
  @display_path
end

#epd_pathObject (readonly)

Returns the value of attribute epd_path.



15
16
17
# File 'lib/papirus.rb', line 15

def epd_path
  @epd_path
end

#filmObject (readonly)

Returns the value of attribute film.



15
16
17
# File 'lib/papirus.rb', line 15

def film
  @film
end

#heightObject (readonly)

Returns the value of attribute height.



15
16
17
# File 'lib/papirus.rb', line 15

def height
  @height
end

#imageObject

Returns the value of attribute image.



16
17
18
# File 'lib/papirus.rb', line 16

def image
  @image
end

#inverseObject

Returns the value of attribute inverse.



16
17
18
# File 'lib/papirus.rb', line 16

def inverse
  @inverse
end

#panelObject (readonly)

Returns the value of attribute panel.



15
16
17
# File 'lib/papirus.rb', line 15

def panel
  @panel
end

#rotationObject

Returns the value of attribute rotation.



16
17
18
# File 'lib/papirus.rb', line 16

def rotation
  @rotation
end

#widthObject (readonly)

Returns the value of attribute width.



15
16
17
# File 'lib/papirus.rb', line 15

def width
  @width
end

Instance Method Details

#clearObject

Send the clear command to the display

Examples:

Clear the display

display.clear
lastcommand #=> 'C'


105
106
107
# File 'lib/papirus.rb', line 105

def clear()
    command('C')
end

#command(c) ⇒ Object

Send’s the display command to the driver available commands are

* 'U' => update the display
* 'F' => fast update the display
* 'P' => Partial update the display
* 'C' => Clear the display

Examples:

Clear the display

display.command('C')
lastcommand #=> 'C'

Update the display

display.command('U')
lastcommand #=> 'U'

Fast update the display

display.command('F')
lastcommand #=> 'F'

Partial update the display

display.command('P')
lastcommand #=> 'P'


129
130
131
132
133
134
# File 'lib/papirus.rb', line 129

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_updateObject

Send the fast update command to the display

Examples:

Fast Update example

display.fast_update
lastcommand #=> 'F'


81
82
83
# File 'lib/papirus.rb', line 81

def fast_update()
    command('F')
end

#partial_updateObject

Send the partial update command to the display

Examples:

Partial Update example

display.partial_update
lastcommand #=> 'P'


89
90
91
# File 'lib/papirus.rb', line 89

def partial_update()
    command('P')
end

#show(data:, command: 'U') ⇒ Object

Show can be used to send raw image data to the display.

Examples:

Show simpel image

display.show(data: imagewithline)
testdisplaylookslike #=> '000000001111111100000000'
lastcommand #=> 'U'

See Also:



70
71
72
73
74
75
# File 'lib/papirus.rb', line 70

def show(data:, command: 'U')
    File.open(File.join(@epd_path, "LE", "display#{@inverse ? '_inverse': ''}"), 'wb') do |io|
        io.write data
    end
    command(@allowed_commands.include?(command) ? command : 'U')
end

#updateObject

Send the full update command to the display

Examples:

Full Update example

display.update
lastcommand #=> 'U'


97
98
99
# File 'lib/papirus.rb', line 97

def update()
    command('U')
end