diff --git a/deploy/HyperCon.jar.REMOVED.git-id b/deploy/HyperCon.jar.REMOVED.git-id index 90278ffd..2ea5f8fc 100644 --- a/deploy/HyperCon.jar.REMOVED.git-id +++ b/deploy/HyperCon.jar.REMOVED.git-id @@ -1 +1 @@ -a63791e2794fa0c76a2a5da3d0ce7b3e4f4089ff \ No newline at end of file +ada8097cb71b680dd6fa48cf190ff66c8814ad0b \ No newline at end of file diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 85069d50..b1ccc93e 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -40,6 +40,7 @@ SET(Hyperion_HEADERS ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd8806.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.h + ${CURRENT_SOURCE_DIR}/device/LedDevicePaintpack.h ${CURRENT_SOURCE_DIR}/device/LedDeviceMultiLightpack.h ) @@ -65,6 +66,7 @@ SET(Hyperion_SOURCES ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd8806.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.cpp + ${CURRENT_SOURCE_DIR}/device/LedDevicePaintpack.cpp ${CURRENT_SOURCE_DIR}/device/LedDeviceMultiLightpack.cpp ) @@ -87,6 +89,7 @@ add_library(hyperion target_link_libraries(hyperion hyperion-utils effectengine + hidapi-libusb serialport ${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev ${CMAKE_THREAD_LIBS_INIT} diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 8e42ac05..af71daae 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -23,6 +23,7 @@ #include "device/LedDeviceTest.h" #include "device/LedDeviceWs2801.h" #include "device/LedDeviceAdalight.h" +#include "device/LedDevicePaintpack.h" #include "device/LedDeviceLightpack.h" #include "device/LedDeviceMultiLightpack.h" @@ -40,7 +41,7 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig) std::transform(type.begin(), type.end(), type.begin(), ::tolower); LedDevice* device = nullptr; - if (type == "ws2801") + if (type == "ws2801" || type == "lightberry") { const std::string output = deviceConfig["output"].asString(); const unsigned rate = deviceConfig["rate"].asInt(); @@ -99,6 +100,13 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig) device = deviceLightpack; } + else if (type == "paintpack") + { + LedDevicePaintpack * devicePainLightpack = new LedDevicePaintpack(); + devicePainLightpack->open(); + + device = devicePainLightpack; + } else if (type == "multi-lightpack") { LedDeviceMultiLightpack* deviceLightpack = new LedDeviceMultiLightpack(); diff --git a/libsrc/hyperion/device/LedDevicePaintpack.cpp b/libsrc/hyperion/device/LedDevicePaintpack.cpp new file mode 100644 index 00000000..7ed0c847 --- /dev/null +++ b/libsrc/hyperion/device/LedDevicePaintpack.cpp @@ -0,0 +1,77 @@ + +// Hyperion includes +#include "LedDevicePaintpack.h" + +LedDevicePaintpack::LedDevicePaintpack() : + LedDevice(), + _deviceHandle(nullptr) +{ + // empty +} + +int LedDevicePaintpack::open() +{ + // initialize the usb context + int error = hid_init(); + if (error != 0) + { + std::cerr << "Error while initializing the hidapi context" << std::endl; + return -1; + } + std::cout << "Hidapi initialized" << std::endl; + + // Initialise the paintpack device + const unsigned short Paintpack_VendorId = 0x0ebf; + const unsigned short Paintpack_ProductId = 0x0025; + _deviceHandle = hid_open(Paintpack_VendorId, Paintpack_ProductId, nullptr); + if (_deviceHandle == nullptr) + { + // Failed to open the device + std::cerr << "Failed to open HID Paintpakc device " << std::endl; + return -1; + } + + return 0; +} + +LedDevicePaintpack::~LedDevicePaintpack() +{ + if (_deviceHandle != nullptr) + { + hid_close(_deviceHandle); + _deviceHandle = nullptr; + } + + hid_exit(); +} + +int LedDevicePaintpack::write(const std::vector& ledValues) +{ + if (_ledBuffer.size() < 3 + ledValues.size()*3) + { + _ledBuffer.resize(3 + ledValues.size()*3, uint8_t(0)); + + _ledBuffer[0] = 0; + _ledBuffer[1] = 3; + _ledBuffer[2] = 0; + } + + auto bufIt = _ledBuffer.begin()+3; + for (const ColorRgb & ledValue : ledValues) + { + *bufIt = ledValue.red; + ++bufIt; + *bufIt = ledValue.green; + ++bufIt; + *bufIt = ledValue.blue; + ++bufIt; + } + + return hid_write(_deviceHandle, _ledBuffer.data(), _ledBuffer.size()); +} + +int LedDevicePaintpack::switchOff() +{ + std::fill(_ledBuffer.begin()+3, _ledBuffer.end(), uint8_t(0)); + return hid_write(_deviceHandle, _ledBuffer.data(), _ledBuffer.size()); +} diff --git a/libsrc/hyperion/device/LedDevicePaintpack.h b/libsrc/hyperion/device/LedDevicePaintpack.h new file mode 100644 index 00000000..8247bfb6 --- /dev/null +++ b/libsrc/hyperion/device/LedDevicePaintpack.h @@ -0,0 +1,59 @@ +#pragma once + +// STL includes +#include + +// libusb include +#include + +// Hyperion includes +#include + +/// +/// LedDevice implementation for a paintpack device () +/// +class LedDevicePaintpack : public LedDevice +{ +public: + /** + * Constructs the paintpack device + */ + LedDevicePaintpack(); + + /** + * Destructs the paintpack device, closes USB connection if open + */ + virtual ~LedDevicePaintpack(); + + /** + * Opens the Paintpack device + * + * @return Zero on succes else negative + */ + int open(); + + /// + /// Writes the RGB-Color values to the leds. + /// + /// @param[in] ledValues The RGB-color per led + /// + /// @return Zero on success else negative + /// + virtual int write(const std::vector& ledValues); + + /// + /// Switch the leds off + /// + /// @return Zero on success else negative + /// + virtual int switchOff(); + +private: + /// libusb device handle + hid_device * _deviceHandle; + + /// buffer for led data + std::vector _ledBuffer; + + +}; diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/JsonStringBuffer.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/JsonStringBuffer.java index 58b2aa17..853423d2 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/JsonStringBuffer.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/JsonStringBuffer.java @@ -104,11 +104,15 @@ public class JsonStringBuffer { ++mIndentLevel; } - public void stopArray() { + public void stopArray(boolean lastValue) { --mIndentLevel; startLine(); - mStrBuf.append("],\n"); + if (lastValue) { + mStrBuf.append("]\n"); + } else { + mStrBuf.append("],\n"); + } } diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/ColorTransformPanel.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/ColorTransformPanel.java index e7dd3278..31e5bc73 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/ColorTransformPanel.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/ColorTransformPanel.java @@ -28,6 +28,8 @@ import org.hyperion.hypercon.spec.TransformConfig; */ public class ColorTransformPanel extends JPanel { + private final Dimension maxDim = new Dimension(1024, 20); + private final TransformConfig mColorConfig; private JPanel mIndexPanel; @@ -131,45 +133,57 @@ public class ColorTransformPanel extends JPanel { mRedTransformLabel = new JLabel("RED"); mRgbTransformPanel.add(mRedTransformLabel); mRedThresholdSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mRedThreshold, 0.0, 1.0, 0.1)); + mRedThresholdSpinner.setMaximumSize(maxDim); mRedThresholdSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mRedThresholdSpinner); mRedGammaSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mRedGamma, 0.0, 100.0, 0.1)); - mRedThresholdSpinner.addChangeListener(mChangeListener); + mRedGammaSpinner.setMaximumSize(maxDim); + mRedGammaSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mRedGammaSpinner); mRedBlacklevelSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mRedBlacklevel, 0.0, 1.0, 0.1)); - mRedThresholdSpinner.addChangeListener(mChangeListener); + mRedBlacklevelSpinner.setMaximumSize(maxDim); + mRedBlacklevelSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mRedBlacklevelSpinner); mRedWhitelevelSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mRedWhitelevel, 0.0, 1.0, 0.1)); - mRedThresholdSpinner.addChangeListener(mChangeListener); + mRedWhitelevelSpinner.setMaximumSize(maxDim); + mRedWhitelevelSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mRedWhitelevelSpinner); mGreenTransformLabel = new JLabel("GREEN"); mRgbTransformPanel.add(mGreenTransformLabel); mGreenThresholdSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mGreenThreshold, 0.0, 1.0, 0.1)); + mGreenThresholdSpinner.setMaximumSize(maxDim); mGreenThresholdSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mGreenThresholdSpinner); mGreenGammaSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mGreenGamma, 0.0, 100.0, 0.1)); + mGreenGammaSpinner.setMaximumSize(maxDim); mGreenGammaSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mGreenGammaSpinner); mGreenBlacklevelSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mGreenBlacklevel, 0.0, 1.0, 0.1)); + mGreenBlacklevelSpinner.setMaximumSize(maxDim); mGreenBlacklevelSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mGreenBlacklevelSpinner); mGreenWhitelevelSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mGreenWhitelevel, 0.0, 1.0, 0.1)); + mGreenWhitelevelSpinner.setMaximumSize(maxDim); mGreenWhitelevelSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mGreenWhitelevelSpinner); mBlueTransformLabel = new JLabel("BLUE"); mRgbTransformPanel.add(mBlueTransformLabel); mBlueThresholdSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mBlueThreshold, 0.0, 1.0, 0.1)); + mBlueThresholdSpinner.setMaximumSize(maxDim); mBlueThresholdSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mBlueThresholdSpinner); mBlueGammaSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mBlueGamma, 0.0, 100.0, 0.1)); + mBlueGammaSpinner.setMaximumSize(maxDim); mBlueGammaSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mBlueGammaSpinner); mBlueBlacklevelSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mBlueBlacklevel, 0.0, 1.0, 0.1)); + mBlueBlacklevelSpinner.setMaximumSize(maxDim); mBlueBlacklevelSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mBlueBlacklevelSpinner); mBlueWhitelevelSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mBlueWhitelevel, 0.0, 1.0, 0.1)); + mBlueWhitelevelSpinner.setMaximumSize(maxDim); mBlueWhitelevelSpinner.addChangeListener(mChangeListener); mRgbTransformPanel.add(mBlueWhitelevelSpinner); } @@ -187,6 +201,7 @@ public class ColorTransformPanel extends JPanel { mHsvTransformPanel.add(mSaturationAdjustLabel); mSaturationAdjustSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mSaturationGain, 0.0, 1024.0, 0.01)); + mSaturationAdjustSpinner.setMaximumSize(maxDim); mSaturationAdjustSpinner.addChangeListener(mChangeListener); mHsvTransformPanel.add(mSaturationAdjustSpinner); @@ -194,6 +209,7 @@ public class ColorTransformPanel extends JPanel { mHsvTransformPanel.add(mValueAdjustLabel); mValueAdjustSpinner = new JSpinner(new SpinnerNumberModel(mColorConfig.mValueGain, 0.0, 1024.0, 0.01)); + mValueAdjustSpinner.setMaximumSize(maxDim); mValueAdjustSpinner.addChangeListener(mChangeListener); mHsvTransformPanel.add(mValueAdjustSpinner); diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/DeviceTypePanel.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/DeviceTypePanel.java new file mode 100644 index 00000000..09e75dd2 --- /dev/null +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/DeviceTypePanel.java @@ -0,0 +1,24 @@ +package org.hyperion.hypercon.gui.device; + +import java.awt.Dimension; + +import javax.swing.JPanel; + +import org.hyperion.hypercon.spec.DeviceConfig; + +public abstract class DeviceTypePanel extends JPanel { + + protected final Dimension firstColMinDim = new Dimension(80, 10); + protected final Dimension maxDim = new Dimension(1024, 20); + + protected DeviceConfig mDeviceConfig = null; + + public DeviceTypePanel() { + super(); + } + + public void setDeviceConfig(DeviceConfig pDeviceConfig) { + mDeviceConfig = pDeviceConfig; + } + +} diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/LightPackPanel.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/LightPackPanel.java new file mode 100644 index 00000000..05b015ab --- /dev/null +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/LightPackPanel.java @@ -0,0 +1,63 @@ +package org.hyperion.hypercon.gui.device; + +import javax.swing.GroupLayout; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.hyperion.hypercon.spec.DeviceConfig; + +public class LightPackPanel extends DeviceTypePanel { + + private JLabel mSerialNoLabel; + private JTextField mSerialNoField; + + public LightPackPanel() { + super(); + + initialise(); + } + + @Override + public void setDeviceConfig(DeviceConfig pDeviceConfig) { + super.setDeviceConfig(pDeviceConfig); + + mSerialNoField.setText(mDeviceConfig.mOutput); + } + + private void initialise() { + mSerialNoLabel = new JLabel("Serial #: "); + mSerialNoLabel.setMinimumSize(firstColMinDim); + add(mSerialNoLabel); + + mSerialNoField = new JTextField(); + mSerialNoField.setMaximumSize(maxDim); + mSerialNoField.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void removeUpdate(DocumentEvent e) { + mDeviceConfig.mOutput = mSerialNoField.getText(); + } + @Override + public void insertUpdate(DocumentEvent e) { + mDeviceConfig.mOutput = mSerialNoField.getText(); + } + @Override + public void changedUpdate(DocumentEvent e) { + mDeviceConfig.mOutput = mSerialNoField.getText(); + } + }); + add(mSerialNoField); + + GroupLayout layout = new GroupLayout(this); + setLayout(layout); + + layout.setHorizontalGroup(layout.createSequentialGroup() + .addComponent(mSerialNoLabel) + .addComponent(mSerialNoField)); + layout.setVerticalGroup(layout.createParallelGroup() + .addComponent(mSerialNoLabel) + .addComponent(mSerialNoField)); + } + +} diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/SerialPanel.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/SerialPanel.java new file mode 100644 index 00000000..204a6bf9 --- /dev/null +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/SerialPanel.java @@ -0,0 +1,104 @@ +package org.hyperion.hypercon.gui.device; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.GroupLayout; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import org.hyperion.hypercon.spec.DeviceConfig; + +/** + * Panel for configuring Ws2801 specific settings + */ +public class SerialPanel extends DeviceTypePanel { + + public static final String[] KnownOutputs = { "/dev/ttyS0", "/dev/ttyUSB0", "/dev/ttyAMA0", "/dev/null"}; + + private JLabel mOutputLabel; + private JComboBox mOutputCombo; + + private JLabel mBaudrateLabel; + private JSpinner mBaudrateSpinner; + + + public SerialPanel() { + super(); + + initialise(); + } + + @Override + public void setDeviceConfig(DeviceConfig pDeviceConfig) { + super.setDeviceConfig(pDeviceConfig); + + mOutputCombo.setSelectedItem(mDeviceConfig.mOutput); + ((SpinnerNumberModel)mBaudrateSpinner.getModel()).setValue(mDeviceConfig.mBaudrate); + } + + private void initialise() { + mOutputLabel = new JLabel("Output: "); + mOutputLabel.setMinimumSize(firstColMinDim); + add(mOutputLabel); + + mOutputCombo = new JComboBox<>(KnownOutputs); + mOutputCombo.setMaximumSize(maxDim); + mOutputCombo.setEditable(true); + mOutputCombo.addActionListener(mActionListener); + add(mOutputCombo); + + mBaudrateLabel = new JLabel("Baudrate: "); + mBaudrateLabel.setMinimumSize(firstColMinDim); + add(mBaudrateLabel); + + mBaudrateSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 1000000, 128)); + mBaudrateSpinner .setMaximumSize(maxDim); + mBaudrateSpinner.addChangeListener(mChangeListener); + add(mBaudrateSpinner); + + + GroupLayout layout = new GroupLayout(this); + layout.setAutoCreateGaps(true); + setLayout(layout); + + layout.setHorizontalGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup() + .addComponent(mOutputLabel) + .addComponent(mBaudrateLabel)) + .addGroup(layout.createParallelGroup() + .addComponent(mOutputCombo) + .addComponent(mBaudrateSpinner)) + ); + layout.setVerticalGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup() + .addComponent(mOutputLabel) + .addComponent(mOutputCombo)) + .addGroup(layout.createParallelGroup() + .addComponent(mBaudrateLabel) + .addComponent(mBaudrateSpinner)) + ); + } + + private ActionListener mActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == mOutputCombo) { + mDeviceConfig.mOutput = (String)mOutputCombo.getSelectedItem(); + } else if (e.getSource() == mBaudrateSpinner) { + mDeviceConfig.mBaudrate = (Integer)mBaudrateSpinner.getValue(); + } + } + }; + + private ChangeListener mChangeListener = new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + mDeviceConfig.mBaudrate = (Integer)mBaudrateSpinner.getValue(); + } + }; +} diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/TestDevicePanel.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/TestDevicePanel.java new file mode 100644 index 00000000..edf2487e --- /dev/null +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/TestDevicePanel.java @@ -0,0 +1,63 @@ +package org.hyperion.hypercon.gui.device; + +import javax.swing.GroupLayout; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.hyperion.hypercon.spec.DeviceConfig; + +public class TestDevicePanel extends DeviceTypePanel { + + private JLabel mFilenameLabel; + private JTextField mFilenameField; + + public TestDevicePanel() { + super(); + + initialise(); + } + + @Override + public void setDeviceConfig(DeviceConfig pDeviceConfig) { + super.setDeviceConfig(pDeviceConfig); + + mFilenameField.setText(mDeviceConfig.mOutput); + } + + private void initialise() { + mFilenameLabel = new JLabel("Filename: "); + mFilenameLabel.setMinimumSize(firstColMinDim); + add(mFilenameLabel); + + mFilenameField = new JTextField(); + mFilenameField.setMaximumSize(maxDim); + mFilenameField.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void removeUpdate(DocumentEvent e) { + mDeviceConfig.mOutput = mFilenameField.getText(); + } + @Override + public void insertUpdate(DocumentEvent e) { + mDeviceConfig.mOutput = mFilenameField.getText(); + } + @Override + public void changedUpdate(DocumentEvent e) { + mDeviceConfig.mOutput = mFilenameField.getText(); + } + }); + add(mFilenameField); + + GroupLayout layout = new GroupLayout(this); + setLayout(layout); + + layout.setHorizontalGroup(layout.createSequentialGroup() + .addComponent(mFilenameLabel) + .addComponent(mFilenameField)); + layout.setVerticalGroup(layout.createParallelGroup() + .addComponent(mFilenameLabel) + .addComponent(mFilenameField)); + } + +} diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/Ws2801Panel.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/Ws2801Panel.java new file mode 100644 index 00000000..ffea3a46 --- /dev/null +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/device/Ws2801Panel.java @@ -0,0 +1,104 @@ +package org.hyperion.hypercon.gui.device; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.GroupLayout; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import org.hyperion.hypercon.spec.DeviceConfig; + +/** + * Panel for configuring Ws2801 specific settings + */ +public class Ws2801Panel extends DeviceTypePanel { + + public static final String[] KnownOutputs = {"/dev/spidev0.0", "/dev/spidev0.1", "/dev/null"}; + + private JLabel mOutputLabel; + private JComboBox mOutputCombo; + + private JLabel mBaudrateLabel; + private JSpinner mBaudrateSpinner; + + + public Ws2801Panel() { + super(); + + initialise(); + } + + @Override + public void setDeviceConfig(DeviceConfig pDeviceConfig) { + super.setDeviceConfig(pDeviceConfig); + + mOutputCombo.setSelectedItem(mDeviceConfig.mOutput); + ((SpinnerNumberModel)mBaudrateSpinner.getModel()).setValue(mDeviceConfig.mBaudrate); + } + + private void initialise() { + mOutputLabel = new JLabel("Output: "); + mOutputLabel.setMinimumSize(firstColMinDim); + add(mOutputLabel); + + mOutputCombo = new JComboBox<>(KnownOutputs); + mOutputCombo.setMaximumSize(maxDim); + mOutputCombo.setEditable(true); + mOutputCombo.addActionListener(mActionListener); + add(mOutputCombo); + + mBaudrateLabel = new JLabel("Baudrate: "); + mBaudrateLabel.setMinimumSize(firstColMinDim); + add(mBaudrateLabel); + + mBaudrateSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 1000000, 128)); + mBaudrateSpinner.setMaximumSize(maxDim); + mBaudrateSpinner.addChangeListener(mChangeListener); + add(mBaudrateSpinner); + + + GroupLayout layout = new GroupLayout(this); + layout.setAutoCreateGaps(true); + setLayout(layout); + + layout.setHorizontalGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup() + .addComponent(mOutputLabel) + .addComponent(mBaudrateLabel)) + .addGroup(layout.createParallelGroup() + .addComponent(mOutputCombo) + .addComponent(mBaudrateSpinner)) + ); + layout.setVerticalGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup() + .addComponent(mOutputLabel) + .addComponent(mOutputCombo)) + .addGroup(layout.createParallelGroup() + .addComponent(mBaudrateLabel) + .addComponent(mBaudrateSpinner)) + ); + } + + private ActionListener mActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == mOutputCombo) { + mDeviceConfig.mOutput = (String)mOutputCombo.getSelectedItem(); + } else if (e.getSource() == mBaudrateSpinner) { + mDeviceConfig.mBaudrate = (Integer)mBaudrateSpinner.getValue(); + } + } + }; + + private ChangeListener mChangeListener = new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + mDeviceConfig.mBaudrate = (Integer)mBaudrateSpinner.getValue(); + } + }; +} diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/ColorConfig.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/ColorConfig.java index 824c3f1d..e55a76cf 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/ColorConfig.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/ColorConfig.java @@ -47,8 +47,8 @@ public class ColorConfig { strBuf.append("\t/// - 'gamma' The gamma-curve correction factor\n"); strBuf.append("\t/// - 'blacklevel' The lowest possible value (when the channel is black)\n"); strBuf.append("\t/// - 'whitelevel' The highest possible value (when the channel is white)\n"); - strBuf.append("\t///"); - strBuf.append("\t/// Next to the list with color transforms there is also a smoothing option."); + strBuf.append("\t///\n"); + strBuf.append("\t/// Next to the list with color transforms there is also a smoothing option.\n"); strBuf.append("\t/// * 'smoothing' : Smoothing of the colors in the time-domain with the following tuning \n"); strBuf.append("\t/// parameters:\n"); strBuf.append("\t/// - 'type' The type of smoothing algorithm ('linear' or 'none')\n"); diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java index 7be938f7..ec07096b 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/DeviceConfig.java @@ -12,7 +12,7 @@ public class DeviceConfig { /** The device 'file' name */ public String mOutput = "/dev/spidev0.0"; /** The baudrate of the device */ - public int mBaudrate = 1000000; + public int mBaudrate = 250000; /** The order of the color bytes */ public ColorByteOrder mColorByteOrder = ColorByteOrder.RGB; diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/EffectConfig.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/EffectConfig.java deleted file mode 100644 index 3d348525..00000000 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/EffectConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.hyperion.hypercon.spec; - -import java.util.Vector; - -import org.hyperion.hypercon.JsonStringBuffer; - -/** - * The configuration structure for a single 'effect'. - */ -public class EffectConfig { - - /** The identifier of the effect */ - public String mId; - - /** The python-script used to generate the effect */ - public String mScript; - - /** The arguments (key-value) of the python-script */ - public final Vector mArgs = new Vector<>(); - - /** - * The effect argument contains a key-value combination that holds a single argument of an - * effect - */ - static public class EffectArg { - /** The key of the effect argument */ - public String key; - /** The value of the effect argument */ - public Object value; - - /** - * Constructs an new effect argument with empty key and value - */ - public EffectArg() { - this("", ""); - } - - /** - * Constructs an effect argument with the given key and value - * - * @param pKey The key of the new argument - * @param pValue The value of the new argument - */ - public EffectArg(String pKey, Object pValue) { - key = pKey; - value = pValue; - } - } - - public void append(JsonStringBuffer pJsonBuf, boolean endOfEffects) { - pJsonBuf.startObject(mId); - pJsonBuf.addValue("script", mScript, false); - - //pJsonBuf.addRawValue("args", String.format(Locale.ENGLISH, "{\n%s\n}", mArgs), true); - - pJsonBuf.stopObject(endOfEffects); - } - - @Override - public String toString() { - return mId; - } - - @Override - public EffectConfig clone() { - EffectConfig thisClone = new EffectConfig(); - thisClone.mId = mId; - thisClone.mScript = mScript; - - for (EffectArg arg : mArgs) { - thisClone.mArgs.add(new EffectArg(arg.key, arg.value)); - } - - return thisClone; - } -} diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/MiscConfig.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/MiscConfig.java index 86ec65f5..21e5971e 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/MiscConfig.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/spec/MiscConfig.java @@ -13,7 +13,7 @@ public class MiscConfig { /** Flag indicating that the boot sequence is enabled(true) or not(false) */ public boolean mBootSequenceEnabled = true; /** The effect selected for the boot sequence */ - public String mBootSequenceEffect = "Rainbow Swirl (fast)"; + public String mBootSequenceEffect = "Rainbow swirl fast"; /** Flag indicating that the Frame Grabber is enabled */ public boolean mFrameGrabberEnabled = true; @@ -68,7 +68,7 @@ public class MiscConfig { for (String effectPath : effectPaths) { strBuf.addArrayElement(effectPath, effectPath == effectPaths[effectPaths.length-1]); } - strBuf.stopArray(); + strBuf.stopArray(!mBootSequenceEnabled); strBuf.toggleComment(!mBootSequenceEnabled); strBuf.addValue("bootsequence", mBootSequenceEffect, true); strBuf.toggleComment(false);