Skip to content

Commit

Permalink
ArduinoOutput is now functional
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiegle committed Oct 8, 2012
1 parent b9101b4 commit 75ed9bf
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
42 changes: 30 additions & 12 deletions Source/Processors/ArduinoOutput.cpp
Expand Up @@ -26,7 +26,7 @@
#include <stdio.h>

ArduinoOutput::ArduinoOutput()
: GenericProcessor("Arduino Output")
: GenericProcessor("Arduino Output"), state(false)
{

}
Expand All @@ -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;
}
}

}
Expand All @@ -72,6 +75,9 @@ void ArduinoOutput::setParameter (int parameterIndex, float newValue)

bool ArduinoOutput::enable()
{

Time timer;

if (arduino.connect("ttyACM0"))
{

Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions Source/Processors/ArduinoOutput.h
Expand Up @@ -65,6 +65,8 @@ class ArduinoOutput : public GenericProcessor

ofArduino arduino;

bool state;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ArduinoOutput);

};
Expand Down
11 changes: 8 additions & 3 deletions Source/Processors/EventDetector.cpp
Expand Up @@ -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));

}

Expand All @@ -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;

}
Expand All @@ -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++)
{
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions Source/Processors/EventDetector.h
Expand Up @@ -54,6 +54,7 @@ class EventDetector : public GenericProcessor
private:

float threshold;
float bufferZone;
bool state;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EventDetector);
Expand Down
4 changes: 2 additions & 2 deletions Source/Processors/Visualization/LfpDisplayCanvas.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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

}

Expand Down

0 comments on commit 75ed9bf

Please sign in to comment.