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 @@
#include <stdio.h>
ArduinoOutput::ArduinoOutput()
: GenericProcessor("Arduino Output")
: GenericProcessor("Arduino Output"), state(false)
{
}
......@@ -52,15 +52,18 @@ void ArduinoOutput::handleEvent(int eventType, MidiMessage& event)
int eventId = *(dataptr+2);
int eventChannel = *(dataptr+3);
// std::cout << "Received event from " << eventNodeId <<
// " on channel " << eventChannel <<
// " with value " << eventId << std::endl;
// if (eventChannel == 0)
// {
// const char byte = 0;
// write(handle, &byte, 1);
// }
std::cout << "Received event from " << eventNodeId <<
" on channel " << eventChannel <<
" with value " << eventId << std::endl;
if (state)
{
arduino.sendDigital(13, ARD_LOW);
state = false;
} else {
arduino.sendDigital(13, ARD_HIGH);
state = true;
}
}
}
......@@ -72,6 +75,9 @@ void ArduinoOutput::setParameter (int parameterIndex, float newValue)
bool ArduinoOutput::enable()
{
Time timer;
if (arduino.connect("ttyACM0"))
{
......@@ -80,18 +86,30 @@ bool ArduinoOutput::enable()
if (arduino.isArduinoReady())
{
uint32 currentTime = timer.getMillisecondCounter();
arduino.sendProtocolVersionRequest();
//sleep(2);
timer.waitForMillisecondCounter(currentTime + 2000);
arduino.update();
arduino.sendFirmwareVersionRequest();
//sleep(2);
timer.waitForMillisecondCounter(currentTime + 4000);
arduino.update();
std::cout << "firmata v" << arduino.getMajorFirmwareVersion()
<< "." << 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()
......
......@@ -65,6 +65,8 @@ private:
ofArduino arduino;
bool state;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ArduinoOutput);
};
......
......@@ -28,11 +28,11 @@
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)
Parameter& p = parameters.getReference(parameterIndex);
p.setValue(newValue, 0);
threshold = newValue;
//std::cout << float(p[0]) << std::endl;
}
......@@ -68,6 +70,8 @@ void EventDetector::process(AudioSampleBuffer &buffer,
int& nSamples)
{
//std::cout << *buffer.getSampleData(0, 0) << std::endl;
for (int i = 0; i < nSamples; i++)
{
......@@ -76,11 +80,12 @@ void EventDetector::process(AudioSampleBuffer &buffer,
{
// generate midi event
std::cout << "Value = " << *buffer.getSampleData(0, i) << std::endl;
addEvent(events, TTL, i);
state = true;
} else if (*buffer.getSampleData(0, i) < threshold && state)
} else if (*buffer.getSampleData(0, i) < threshold - bufferZone && state)
{
state = false;
}
......
......@@ -54,6 +54,7 @@ public:
private:
float threshold;
float bufferZone;
bool state;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EventDetector);
......
......@@ -28,7 +28,7 @@
LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* n) : processor(n),
xBuffer(105), yBuffer(2),
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),
timeOffset(0.0f), footerHeight(0)
{
......@@ -175,7 +175,7 @@ void LfpDisplayCanvas::updateScreenBuffer()
waves[channel][screenBufferIndex*2+1] +=
*(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