From f017c649c68a1bf0061cc9869950a4ca2e4f2c63 Mon Sep 17 00:00:00 2001 From: Pavel Kulik Date: Tue, 16 Jan 2024 20:06:32 -0800 Subject: [PATCH] Update Arduino Output --- Plugins/ArduinoOutput/ArduinoOutput.cpp | 15 +++++++++---- Plugins/ArduinoOutput/ArduinoOutputEditor.cpp | 22 +------------------ Plugins/ArduinoOutput/ArduinoOutputEditor.h | 14 ++---------- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/Plugins/ArduinoOutput/ArduinoOutput.cpp b/Plugins/ArduinoOutput/ArduinoOutput.cpp index 34474ec13..07dbdbafb 100644 --- a/Plugins/ArduinoOutput/ArduinoOutput.cpp +++ b/Plugins/ArduinoOutput/ArduinoOutput.cpp @@ -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); @@ -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()) { @@ -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); } diff --git a/Plugins/ArduinoOutput/ArduinoOutputEditor.cpp b/Plugins/ArduinoOutput/ArduinoOutputEditor.cpp index 18af293a4..f1d039872 100644 --- a/Plugins/ArduinoOutput/ArduinoOutputEditor.cpp +++ b/Plugins/ArduinoOutput/ArduinoOutputEditor.cpp @@ -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); - } -} +} \ No newline at end of file diff --git a/Plugins/ArduinoOutput/ArduinoOutputEditor.h b/Plugins/ArduinoOutput/ArduinoOutputEditor.h index 391e4d739..5a410deab 100644 --- a/Plugins/ArduinoOutput/ArduinoOutputEditor.h +++ b/Plugins/ArduinoOutput/ArduinoOutputEditor.h @@ -37,9 +37,7 @@ */ -class ArduinoOutputEditor : public GenericEditor, - public ComboBox::Listener//, - // public Timer +class ArduinoOutputEditor : public GenericEditor { public: @@ -47,18 +45,10 @@ class ArduinoOutputEditor : public GenericEditor, 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 deviceSelector; - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ArduinoOutputEditor); };