Skip to content
Snippets Groups Projects
Commit 75ed9bf6 authored by jsiegle's avatar jsiegle
Browse files

ArduinoOutput is now functional

parent b9101b45
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <stdio.h> #include <stdio.h>
ArduinoOutput::ArduinoOutput() ArduinoOutput::ArduinoOutput()
: GenericProcessor("Arduino Output") : GenericProcessor("Arduino Output"), state(false)
{ {
} }
...@@ -52,15 +52,18 @@ void ArduinoOutput::handleEvent(int eventType, MidiMessage& event) ...@@ -52,15 +52,18 @@ void ArduinoOutput::handleEvent(int eventType, MidiMessage& event)
int eventId = *(dataptr+2); int eventId = *(dataptr+2);
int eventChannel = *(dataptr+3); int eventChannel = *(dataptr+3);
// std::cout << "Received event from " << eventNodeId << std::cout << "Received event from " << eventNodeId <<
// " on channel " << eventChannel << " on channel " << eventChannel <<
// " with value " << eventId << std::endl; " with value " << eventId << std::endl;
// if (eventChannel == 0) if (state)
// { {
// const char byte = 0; arduino.sendDigital(13, ARD_LOW);
// write(handle, &byte, 1); state = false;
// } } else {
arduino.sendDigital(13, ARD_HIGH);
state = true;
}
} }
} }
...@@ -72,6 +75,9 @@ void ArduinoOutput::setParameter (int parameterIndex, float newValue) ...@@ -72,6 +75,9 @@ void ArduinoOutput::setParameter (int parameterIndex, float newValue)
bool ArduinoOutput::enable() bool ArduinoOutput::enable()
{ {
Time timer;
if (arduino.connect("ttyACM0")) if (arduino.connect("ttyACM0"))
{ {
...@@ -80,18 +86,30 @@ bool ArduinoOutput::enable() ...@@ -80,18 +86,30 @@ bool ArduinoOutput::enable()
if (arduino.isArduinoReady()) if (arduino.isArduinoReady())
{ {
uint32 currentTime = timer.getMillisecondCounter();
arduino.sendProtocolVersionRequest(); arduino.sendProtocolVersionRequest();
//sleep(2); timer.waitForMillisecondCounter(currentTime + 2000);
arduino.update(); arduino.update();
arduino.sendFirmwareVersionRequest(); arduino.sendFirmwareVersionRequest();
//sleep(2); timer.waitForMillisecondCounter(currentTime + 4000);
arduino.update(); arduino.update();
std::cout << "firmata v" << arduino.getMajorFirmwareVersion() std::cout << "firmata v" << arduino.getMajorFirmwareVersion()
<< "." << arduino.getMinorFirmwareVersion() << std::endl; << "." << arduino.getMinorFirmwareVersion() << std::endl;
} }
if (arduino.isInitialized())
{
std::cout << "Arduino is initialized." << std::endl;
arduino.sendDigitalPinMode(13, ARD_OUTPUT);
} else {
std::cout << "Arduino is NOT initialized." << std::endl;
}
} }
bool ArduinoOutput::disable() bool ArduinoOutput::disable()
......
...@@ -65,6 +65,8 @@ private: ...@@ -65,6 +65,8 @@ private:
ofArduino arduino; ofArduino arduino;
bool state;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ArduinoOutput); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ArduinoOutput);
}; };
......
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
EventDetector::EventDetector() EventDetector::EventDetector()
: GenericProcessor("Event Detector"), state(0), threshold(250) : GenericProcessor("Event Detector"), state(0), threshold(500.0), bufferZone(500)
{ {
parameters.add(Parameter("thresh", 0.0, 5000.0, 250.0, 0)); parameters.add(Parameter("thresh", 0.0, 500.0, 250.0, 0));
} }
...@@ -59,6 +59,8 @@ void EventDetector::setParameter (int parameterIndex, float newValue) ...@@ -59,6 +59,8 @@ void EventDetector::setParameter (int parameterIndex, float newValue)
Parameter& p = parameters.getReference(parameterIndex); Parameter& p = parameters.getReference(parameterIndex);
p.setValue(newValue, 0); p.setValue(newValue, 0);
threshold = newValue;
//std::cout << float(p[0]) << std::endl; //std::cout << float(p[0]) << std::endl;
} }
...@@ -68,6 +70,8 @@ void EventDetector::process(AudioSampleBuffer &buffer, ...@@ -68,6 +70,8 @@ void EventDetector::process(AudioSampleBuffer &buffer,
int& nSamples) int& nSamples)
{ {
//std::cout << *buffer.getSampleData(0, 0) << std::endl;
for (int i = 0; i < nSamples; i++) for (int i = 0; i < nSamples; i++)
{ {
...@@ -76,11 +80,12 @@ void EventDetector::process(AudioSampleBuffer &buffer, ...@@ -76,11 +80,12 @@ void EventDetector::process(AudioSampleBuffer &buffer,
{ {
// generate midi event // generate midi event
std::cout << "Value = " << *buffer.getSampleData(0, i) << std::endl;
addEvent(events, TTL, i); addEvent(events, TTL, i);
state = true; state = true;
} else if (*buffer.getSampleData(0, i) < threshold && state) } else if (*buffer.getSampleData(0, i) < threshold - bufferZone && state)
{ {
state = false; state = false;
} }
......
...@@ -54,6 +54,7 @@ public: ...@@ -54,6 +54,7 @@ public:
private: private:
float threshold; float threshold;
float bufferZone;
bool state; bool state;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EventDetector); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EventDetector);
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* n) : processor(n), LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* n) : processor(n),
xBuffer(105), yBuffer(2), xBuffer(105), yBuffer(2),
plotHeight(180), selectedChan(-1), screenBufferIndex(0), plotHeight(180), selectedChan(-1), screenBufferIndex(0),
timebase(1.0f), displayGain(0.0004f), displayBufferIndex(0), timebase(1.0f), displayGain(0.0001f), displayBufferIndex(0),
headerHeight(40), plotOverlap(200), interplotDistance(70), headerHeight(40), plotOverlap(200), interplotDistance(70),
timeOffset(0.0f), footerHeight(0) timeOffset(0.0f), footerHeight(0)
{ {
...@@ -175,7 +175,7 @@ void LfpDisplayCanvas::updateScreenBuffer() ...@@ -175,7 +175,7 @@ void LfpDisplayCanvas::updateScreenBuffer()
waves[channel][screenBufferIndex*2+1] += waves[channel][screenBufferIndex*2+1] +=
*(displayBuffer->getSampleData(channel, nextPos))*alpha*gain*displayGain; *(displayBuffer->getSampleData(channel, nextPos))*alpha*gain*displayGain;
waves[channel][screenBufferIndex*2+1] += 1.1f; // to center in viewport waves[channel][screenBufferIndex*2+1] += 0.5f; // to center in viewport
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment