org.sledv.aurinko
Class MatrixController

java.lang.Object
  extended by java.io.OutputStream
      extended by org.sledv.aurinko.MatrixController
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, Sequencer

public class MatrixController
extends java.io.OutputStream
implements Sequencer

The main interface to the hardware


Constructor Summary
MatrixController(java.io.OutputStream tocontroller, int mtx_width, int mtx_height, int vram)
          Creates a new MatrixController with a software sequencer
MatrixController(java.io.OutputStream tocontroller, int mtx_width, int mtx_height, int vram, boolean external_seq)
          Creates a new MatrixController
 
Method Summary
 void accerlate(Surface surf)
          Puts a surface in the upload queue.
 void clearAccelerationList()
          Clears the list of surfaces scheduled to upload.
 void close()
          Closes the hardware connection.
 void decellerate(Surface surf)
          Removes a surface from the upload queue.
 void flash()
          Flashs the matrix.
 void flip()
          Flushes the rendering buffer and exchanges the contents of the primary surface and the backbuffer.
 void flush()
          Flushes the video rendering buffer.
 Surface getBackBuffer()
          Gets the backbuffer.
 Surface getPrimary()
          Gets the primary surface.
 boolean isExternalSequencer()
          Checks whether seqencer methods such as seqMark or seqSleep are handled locally (internal sequencer, default) or passed on to the unterlying stream (external sequencer)
 void seqMark()
          Marks the current time on the sequencer.
 void seqSleep(long ms)
          Waits for the specified number of milliseconds since seqMark() or the last call to this method.
 void setExternalSequencer(boolean use_external)
          Sets whether seqencer methods such as seqMark or seqSleep should be handled locally (internal sequencer, default) or passed on to the unterlying stream (external sequencer)
 void upload()
          Submits the pixeldata of as many surfaces placed in the acceleration queue as possible.
 void write(byte[] data, int start, int len)
           
 void write(int data)
          Writes a byte directly to the underlying hardware (avoid usage of the function)
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixController

public MatrixController(java.io.OutputStream tocontroller,
                        int mtx_width,
                        int mtx_height,
                        int vram)
                 throws java.io.IOException
Creates a new MatrixController with a software sequencer

Parameters:
tocontroller - The Outputstream to the hardware
mtx_width - Width of the matrix
mtx_height - Height of the matrix
vram - Videoram size in bytes
Throws:
java.io.IOException - In case of a communation error

MatrixController

public MatrixController(java.io.OutputStream tocontroller,
                        int mtx_width,
                        int mtx_height,
                        int vram,
                        boolean external_seq)
                 throws java.io.IOException
Creates a new MatrixController

Parameters:
tocontroller - The Outputstream to the hardware
mtx_width - Width of the matrix
mtx_height - Height of the matrix
vram - Videoram size in bytes
external_seq - Whether to use an external sequencer or not
Throws:
java.io.IOException - In case of a communation error
Method Detail

accerlate

public void accerlate(Surface surf)
Puts a surface in the upload queue. To actually submit surfaces to the hardware call upload(). See the upload()-Method for more info.

Parameters:
surf - The surface to be accelerated

decellerate

public void decellerate(Surface surf)
Removes a surface from the upload queue. To actually remove the surface from the hardware call upload() or draw on it.

Parameters:
surf - The surface to be accelerated

clearAccelerationList

public void clearAccelerationList()
Clears the list of surfaces scheduled to upload. To actually remove surfaces from the hardware call upload() or draw on them.


upload

public void upload()
Submits the pixeldata of as many surfaces placed in the acceleration queue as possible.
Uploading surfaces will speed up them being draw()ed on the primary surface or backbuffer significantly. Changing an accelerated surface (by drawing on it) will make it loose it's acceleration status. To speed things up again you have to call this method again, so only accelerate surfaces which don't change. Also the queue is processed first-come, first-serve so put the most frequently used surfaces in first. Note: Make sure that your hardware-setup has enough video-ram and the value is set correctly!


getPrimary

public Surface getPrimary()
Gets the primary surface. Drawing on it will cause contents to be shown on the screen

Returns:
The primary surface

getBackBuffer

public Surface getBackBuffer()
Gets the backbuffer. The backbuffer is the same size as the primary surface and resides on the hardware as well. The backbuffer is not shown directy, however the front-buffer (primary surface) and the backbuffer can be flipped very fast using the flip() call. This allows you to "build" up your frame in background and then display it "at once" without causing flickering.

Returns:

flip

public void flip()
Flushes the rendering buffer and exchanges the contents of the primary surface and the backbuffer.


flash

public void flash()
Flashs the matrix. This turns the brightness of the LEDs to the maximum (which might be higher than all LEDs at maximum white) for a short periord. The exact duration of the flash is hardware dependent.


flush

public void flush()
Flushes the video rendering buffer. This makes sure that all video calls have be forwarded to the hardware.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream

close

public void close()
           throws java.io.IOException
Closes the hardware connection. All subsequent calls to this class, the primary surface and the backbuffer will fail with a NullPointerException

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - for some reason

write

public void write(int data)
           throws java.io.IOException
Writes a byte directly to the underlying hardware (avoid usage of the function)

Specified by:
write in class java.io.OutputStream
Parameters:
arg0 - The byte to be written
Throws:
java.io.IOException - In case of a communation error

write

public void write(byte[] data,
                  int start,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

seqMark

public void seqMark()
Marks the current time on the sequencer. Call this before rendering an animation, see seqSleep for more details.

This method also flushes rendering buffer

Specified by:
seqMark in interface Sequencer

seqSleep

public void seqSleep(long ms)
Waits for the specified number of milliseconds since seqMark() or the last call to this method. Before rendering an animation call seqMark(), then call seqSleep() after rendering a frame. The Method will make sure that the specified number of milliseconds have passed. If more time has passed, this method will compensate by making the next seqSleep() call shorter. To override this behaviour call seqMark immediately afterwards.

Usually this method calls Thread.sleep(), but this method can also be configured to pass the wait call on to the connected stream if a software relay or the hardware directly support sequencing. In this case the method might not suspend the current Thread at all.

This method also flushes rendering buffer

Specified by:
seqSleep in interface Sequencer
Parameters:
ms - The display time for the current frame

setExternalSequencer

public void setExternalSequencer(boolean use_external)
Sets whether seqencer methods such as seqMark or seqSleep should be handled locally (internal sequencer, default) or passed on to the unterlying stream (external sequencer)

Parameters:
use_external - True, if an external sequencer should be used

isExternalSequencer

public boolean isExternalSequencer()
Checks whether seqencer methods such as seqMark or seqSleep are handled locally (internal sequencer, default) or passed on to the unterlying stream (external sequencer)

Returns:
True, if an external sequencer is in use