Class: MatrixCreator::Everloop::Animation

Inherits:
Object
  • Object
show all
Defined in:
lib/matrix_creator/everloop/animation.rb

Overview

Class to be inherited by Animations

Direct Known Subclasses

Pulse, Spinner

Constant Summary collapse

ANIMATION_SPEED =

Interval between animation updates in milliseconds

0.1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(color = Color::WHITE) { ... } ⇒ Object

Run a block of code while displaying an animation on the Everloop driver

Examples:

Run a block of code and display a spinner until it finishes


MatrixCreator::Everloop::Spinner.run {
  // Do Something
}

Run a block of code and display a green spinner until it finishes


color = MatrixCreator::Everloop::Color::GREEN

MatrixCreator::Everloop::Spinner.run(color) {
  // Do Something
}

Run a block of code and display a pulse until it finishes


MatrixCreator::Everloop::Pulse.run {
  // Do Something
}

Parameters:

  • color (Hash) (defaults to: Color::WHITE)

    with the rgb+w values for the color

Yields:

  • Block of code to be executed while displaying the spinner

Returns:

  • response from the block of code execution



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/matrix_creator/everloop/animation.rb', line 36

def self.run(color = Color::WHITE, &block)
  result = nil

  code_thread = Thread.new do
    Thread.current[:finished] = false
    result = yield if block
    Thread.current[:finished] = true
  end

  animation_thread = Thread.new do
    animation = new(color, code_thread)
    animation.loop_animation
    animation.destroy_context
  end

  # Turn off the leds on the Everloop driver
  code_thread.join
  animation_thread.join
  Everloop.modify_color(Color::OFF)

  # Return result of the code block
  result
end

Instance Method Details

#destroy_contextObject

Sends a request to destroy the context of the everloop comm instance



62
63
64
# File 'lib/matrix_creator/everloop/animation.rb', line 62

def destroy_context
  @everloop_comm.destroy
end