Skip to content

Commit

Permalink
Update Arduino Output
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Jan 17, 2024
1 parent f58705b commit f017c64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
15 changes: 11 additions & 4 deletions Plugins/ArduinoOutput/ArduinoOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ArduinoOutput::ArduinoOutput()
, gateIsOpen (true)
, deviceSelected (false)
{
addCategoricalParameter(Parameter::PROCESSOR_SCOPE, "device", "Device", "The Arduino device to use", getDevices(), 0);
addCategoricalParameter(Parameter::PROCESSOR_SCOPE, "device", "Device", "The Arduino device to use", getDevices(), 0, true);
addIntParameter(Parameter::PROCESSOR_SCOPE, "output_pin", "Output pin", "The Arduino pin to use", 13, 0, 13);
addIntParameter(Parameter::STREAM_SCOPE, "input_line", "Input line", "The TTL line for triggering output", 1, 1, 16);
addIntParameter(Parameter::STREAM_SCOPE, "gate_line", "Gate line", "The TTL line for gating the output", 0, 0, 16);
Expand Down Expand Up @@ -79,9 +79,12 @@ void ArduinoOutput::setDevice (String devName)

/* Avoid connecting to the same device twice */
if (devName != deviceString)
arduino.connect (devName.toStdString());
{
if (arduino.isArduinoReady())
arduino.disconnect();

LOGC("Connected");
arduino.connect (devName.toStdString());
}

if (arduino.isArduinoReady())
{
Expand All @@ -106,19 +109,23 @@ void ArduinoOutput::setDevice (String devName)
LOGC("firmata v", arduino.getMajorFirmwareVersion(), ".", arduino.getMinorFirmwareVersion());
}

deviceString = devName;

if (arduino.isInitialized())
{
LOGC("Arduino is initialized.");
arduino.sendDigitalPinMode ((int) getParameter("output_pin")->getValue(), ARD_OUTPUT);
CoreServices::sendStatusMessage (("Arduino initialized at " + devName));
deviceSelected = true;
deviceString = devName;
}
else
{
arduino.disconnect();
LOGC("Arduino is NOT initialized.");
CoreServices::sendStatusMessage (("Arduino could not be initialized at " + devName));
deviceSelected = false;
}
CoreServices::updateSignalChain(this);
}


Expand Down
22 changes: 1 addition & 21 deletions Plugins/ArduinoOutput/ArduinoOutputEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,4 @@ ArduinoOutputEditor::ArduinoOutputEditor(GenericProcessor* parentNode)
addComboBoxParameterEditor(Parameter::PROCESSOR_SCOPE, "output_pin", 10, 54);
addComboBoxParameterEditor(Parameter::STREAM_SCOPE, "input_line", 10, 79);
addComboBoxParameterEditor(Parameter::STREAM_SCOPE, "gate_line", 10, 104);
}


void ArduinoOutputEditor::comboBoxChanged(ComboBox* comboBoxThatHasChanged)
{
if (comboBoxThatHasChanged == deviceSelector.get())
{
ArduinoOutput* processor = (ArduinoOutput*) getProcessor();
processor->setDevice(deviceSelector->getText());
CoreServices::updateSignalChain(this);
}
}

void ArduinoOutputEditor::updateDevice(String deviceName)
{
for (int i = 0; i < deviceSelector->getNumItems(); i++)
{
if (deviceSelector->getItemText(i).equalsIgnoreCase(deviceName))
deviceSelector->setSelectedId(deviceSelector->getItemId(i), dontSendNotification);
}
}
}
14 changes: 2 additions & 12 deletions Plugins/ArduinoOutput/ArduinoOutputEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,18 @@
*/

class ArduinoOutputEditor : public GenericEditor,
public ComboBox::Listener//,
// public Timer
class ArduinoOutputEditor : public GenericEditor

{
public:
/** Constructor*/
ArduinoOutputEditor(GenericProcessor* parentNode);

/** Destructor*/
~ArduinoOutputEditor() { }

/** Called when selected device is changed.*/
void comboBoxChanged(ComboBox* comboBoxThatHasChanged);

/** Gets the latest device from the processor*/
void updateDevice(String deviceName);
~ArduinoOutputEditor() {}

private:

std::unique_ptr<ComboBox> deviceSelector;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ArduinoOutputEditor);

};
Expand Down

0 comments on commit f017c64

Please sign in to comment.