Class StreamDeck

java.lang.Object
de.rcblum.stream.deck.device.StreamDeck
All Implemented Interfaces:
IStreamDeck, purejavahidapi.InputReportListener

public class StreamDeck extends Object implements purejavahidapi.InputReportListener, IStreamDeck
Provides low level access to a connected stream deck. Allows to do the following without having to deal with the HID format:
1. Reset the device
2. Set the brightness of the device
3. Set an image for one of the key at a time.
4. Receive an KeyEvent whenever a key was pressed/released/clicked.


For the device to properly function, it has to be initialised properly. This is done by 1.) resetting it, 2) setting the brightness of the device.

All processing is don asynchronous, meaning anything sent to the deck is put in a queue and processed in another thread. Processing is done at a tick rate of 100 (100 updates per second max).

MIT License

Copyright (c) 2017 Roland von Werden

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Version:
1.0.0
Author:
Roland von Werden
  • Constructor Details

    • StreamDeck

      public StreamDeck(DeckDescriptor descriptor, purejavahidapi.HidDevice streamDeck, int brightness)
      Creates a wrapper for the Stream Deck HID
      Parameters:
      streamDeck - Stream Decks HID Devices
      brightness - Brightness from 0 .. 99
  • Method Details

    • getKeySize

      public int getKeySize()
      Description copied from interface: IStreamDeck
      Returns the amount of keys on the StreamDeck.
      Specified by:
      getKeySize in interface IStreamDeck
      Returns:
      Numbers of keys on the deck (Default 15).
    • getRowSize

      public int getRowSize()
      Description copied from interface: IStreamDeck
      Returns the amount of rows on the StreamDeck.
      Specified by:
      getRowSize in interface IStreamDeck
      Returns:
      Numbers of keys on the deck (Default 15).
    • addKey

      public void addKey(int keyId, StreamItem item)
      Description copied from interface: IStreamDeck
      Adds a StreamKeyListener to the given index
      Specified by:
      addKey in interface IStreamDeck
      Parameters:
      keyId - Index of the key, 0..14
      item - StreamItem to be bound to the index
    • addKeyListener

      public boolean addKeyListener(StreamKeyListener listener)
      Description copied from interface: IStreamDeck
      Adds an StreamKeyListener to the ESD. WHenever a Event is generated, the Listener will be informed.
      Specified by:
      addKeyListener in interface IStreamDeck
      Parameters:
      listener - Listener to be added
      Returns:
      true if listener was added, false if listener is already registered.
    • removeKeyListener

      public boolean removeKeyListener(StreamKeyListener listener)
      Description copied from interface: IStreamDeck
      Removes an StreamKeyListener from the ESD.
      Specified by:
      removeKeyListener in interface IStreamDeck
      Parameters:
      listener - Listener to be removed
      Returns:
      true if listener was removed, false if listener is not registered.
    • drawImage

      public void drawImage(int keyIndex, SDImage imgData)
      Description copied from interface: IStreamDeck
      Creates a Job to send the give icon to the ESD to be displayed on the given keyxIndex
      Specified by:
      drawImage in interface IStreamDeck
      Parameters:
      keyIndex - Index on the ESD as defined by DeckDescriptor
      imgData - Image to be displayed
    • drawImage

      public void drawImage(int keyIndex, SDImage imgData, Dimension overrideSize)
      Description copied from interface: IStreamDeck
      Creates a Job to send the give icon to the ESD to be displayed on the given keyxIndex
      Specified by:
      drawImage in interface IStreamDeck
      Parameters:
      keyIndex - Index on the ESD as defined by DeckDescriptor
      imgData - Image to be displayed
      overrideSize - Overrides the default icon size of the given streamdeck
    • drawFullImage

      public void drawFullImage(SDImage imgData)
      Specified by:
      drawFullImage in interface IStreamDeck
    • hasTouchScreen

      public boolean hasTouchScreen()
      Description copied from interface: IStreamDeck
      Returns if the stream deck has a touch screen
      Specified by:
      hasTouchScreen in interface IStreamDeck
      Returns:
      True if it has a touch screen, false if not
    • getTouchScreen

      public TouchScreen getTouchScreen()
      Description copied from interface: IStreamDeck
      Return the touch screen of the stream deck.
      Specified by:
      getTouchScreen in interface IStreamDeck
      Returns:
      Returns the touch screen object or null, if the stream deck has none.
    • hasDials

      public boolean hasDials()
      Description copied from interface: IStreamDeck
      Returns if the stream deck has dials
      Specified by:
      hasDials in interface IStreamDeck
      Returns:
      True if it has one or more dials, false if not
    • getDials

      public DialKey[] getDials()
      Description copied from interface: IStreamDeck
      Return the dials of the stream deck.
      Specified by:
      getDials in interface IStreamDeck
      Returns:
      Returns the dial objects or an empty array, if the stream deck has none.
    • getDial

      public DialKey getDial(int keyIndex)
      Description copied from interface: IStreamDeck
      Return the dials of the stream deck.
      Specified by:
      getDial in interface IStreamDeck
      Parameters:
      keyIndex - Index on the ESD as defined by DeckDescriptor
      Returns:
      Returns the dial objects or an empty array, if the stream deck has none.
    • drawTouchScreenImage

      public void drawTouchScreenImage(SDImage imgData)
      Description copied from interface: IStreamDeck
      Creates a Job to send the give icon to the ESD to be displayed on the the Touch screen at the given starting point
      Specified by:
      drawTouchScreenImage in interface IStreamDeck
      Parameters:
      imgData - Image to be displayed
    • drawTouchScreenImage

      public void drawTouchScreenImage(Point startPoint, SDImage imgData)
      Description copied from interface: IStreamDeck
      Creates a Job to send the give icon to the ESD to be displayed on the the Touch screen at the given starting point
      Specified by:
      drawTouchScreenImage in interface IStreamDeck
      Parameters:
      startPoint - Pixel coordinates to start drawing the image
      imgData - Image to be displayed
    • sendOutputReport

      public boolean sendOutputReport(byte[] report)
    • getHidDevice

      public purejavahidapi.HidDevice getHidDevice()
      Description copied from interface: IStreamDeck
      Returns the Hid Devices representation the stream deck.
      Specified by:
      getHidDevice in interface IStreamDeck
      Returns:
      HidDevice representation the stream deck.
    • onInputReport

      public void onInputReport(purejavahidapi.HidDevice source, byte reportID, byte[] reportData, int reportLength)
      Specified by:
      onInputReport in interface purejavahidapi.InputReportListener
    • removeKey

      public void removeKey(int keyId)
      Description copied from interface: IStreamDeck
      Removes a registered Key. Queues update to the stream deck
      Specified by:
      removeKey in interface IStreamDeck
      Parameters:
      keyId - id of the key to be removed
    • reset

      public void reset()
      Description copied from interface: IStreamDeck
      Queues a task to reset the stream deck.
      Specified by:
      reset in interface IStreamDeck
    • setBrightness

      public void setBrightness(int brightness)
      Description copied from interface: IStreamDeck
      Sets the desired brightness from 0 - 100 % and queues the change.
      Specified by:
      setBrightness in interface IStreamDeck
      Parameters:
      brightness - Brightness in percentile
    • stop

      public void stop()
      Description copied from interface: IStreamDeck
      Tells the background task for the stream deck to stop working.
      Specified by:
      stop in interface IStreamDeck
    • waitForCompletion

      public void waitForCompletion()
      Description copied from interface: IStreamDeck
      Wait for all tasks to be executed
      Specified by:
      waitForCompletion in interface IStreamDeck
    • clearButton

      public void clearButton(int i)
      Specified by:
      clearButton in interface IStreamDeck
      See Also:
    • getItems

      public StreamItem[] getItems()
    • isHardware

      public boolean isHardware()
      Description copied from interface: IStreamDeck
      Returns if behind the interface is actual hardware or a software only StreamDeck.
      Specified by:
      isHardware in interface IStreamDeck
      Returns:
      true if hardware is sued, false if the implementation is only software.
    • isRunning

      public boolean isRunning()
    • getDescriptor

      public DeckDescriptor getDescriptor()
      Description copied from interface: IStreamDeck
      Returns the descriptor representing this device
      Specified by:
      getDescriptor in interface IStreamDeck
      Returns:
      DeckDescriptor with the appropriate information
    • pushButton

      public void pushButton(int no)
      Manually Pushing a button at the given id.
      Specified by:
      pushButton in interface IStreamDeck
      Parameters:
      no - Number of the button to be pushed, 0 - 14, right top to left bottom.
    • pressButton

      public void pressButton(int no)
      Manually presses a button at the given id until releaseButton(int) is called.
      Specified by:
      pressButton in interface IStreamDeck
      Parameters:
      no - Number of the button to be pushed, 0 - 14, right top to left bottom.
    • releaseButton

      public void releaseButton(int no)
      Manually releases a button at the given id. If the button is not pressed, it will be pushed instead.
      Specified by:
      releaseButton in interface IStreamDeck
      Parameters:
      no - Number of the button to be pushed, 0 - 14, right top to left bottom.
    • isRecievePoolEmpty

      public boolean isRecievePoolEmpty()
    • getKey

      public StreamItem getKey(int i)
    • pollRecievePool

      public KeyEvent pollRecievePool()
    • getListeners

      public List<StreamKeyListener> getListeners()
    • isSendPoolEmpty

      public boolean isSendPoolEmpty()
    • getSendPoolSize

      public int getSendPoolSize()
    • pollSendPool

      public DeckUpdater pollSendPool()
    • addToSendPool

      public void addToSendPool(DeckUpdater task)