Commit f417e727 authored by Your Name's avatar Your Name
Browse files

add IR triggers to zmq_trigger_subscriber

parent f3182e0e
......@@ -5,7 +5,7 @@ CXX=g++
CC=gcc
LDLIBS+=-lzmq -lboost_program_options -lpigpio -llsl32
LDLIBS+=-lzmq -lboost_program_options -lpigpio -llsl32
#LDLIBS+=-lzmq -lpthread -lboost_system -lboost_regex -lboost_program_options
#INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11
......@@ -23,6 +23,7 @@ pcm: pcm.c
pcm_async: pcm_async.cc
playtone: playtone.cc
zmq_trigger: zmq_trigger.cc
zmq_trigger: LDLIBS+=-lpthread -lboost_system -lboost_regex
msgqueue_pubsub: msgqueue_pubsub.cc
lsldert_proxy: lsldert_proxy.cc
lsldert_proxy: LDLIBS+=-lpthread
......
No preview for this file type
......@@ -31,6 +31,12 @@ int pwmpin = chan_left;
int doutpin = 8;
int dinpin = 7;
int IRpin[] = { 14, 23 }; // GPIO pins of IR LED open collector drivers for fNIRS sync
const int IRnum = sizeof(IRpin)/sizeof(IRpin[0]); // number of IR outputs
const int IRmask = (1<<IRnum)-1; // the bit mask of the IR outputs
const int IR_ON = 1;
const int IR_OFF = 0;
stream_outlet *outlet;
string info_name, info_type, info_sourceid;
std::mutex lsl_mutex;
......@@ -175,6 +181,31 @@ void setdio(int value)
}
}
void pulseIR(int mask, int durationmsec)
{
for (int i=0; i< IRnum; i++)
{
int r=gpioWrite(IRpin[i], IR_ON);
if (r < 0)
{
perror("gpioWrite");
exit(1);
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(durationmsec));
for (int i=0; i< IRnum; i++)
{
int r=gpioWrite(IRpin[i], IR_OFF);
if (r < 0)
{
perror("gpioWrite");
exit(1);
}
}
}
void beep(int freq, int durationmsec)
{
int d=500000;
......@@ -250,6 +281,18 @@ int main(int argc, const char* argv[])
return 1;
}
for (int i; i<IRnum; i++) {
if (gpioSetMode(IRpin[i], PI_OUTPUT) < 0) {
perror("gpioSetMode");
return 1;
}
if (gpioSetPullUpDown(IRpin[i], PI_PUD_DOWN) < 0) {
perror("gpioSetMode");
return 1;
}
}
if (gpioSetMode(dinpin, PI_OUTPUT) < 0) {
perror("gpioSetMode");
return 1;
......@@ -344,6 +387,22 @@ int main(int argc, const char* argv[])
setdio(level);
}
else
if (cmd == "I") {
int mask, duration;
string marker;
s >> mask;
s >> duration;
s >> marker;
if (verbose) {
cout << "mask=" << mask << endl;
cout << "duration=" << duration << endl;
cout << "marker=" << marker << endl;
}
std::lock_guard<std::mutex> guard(lsl_mutex);
outlet->push_sample(&marker);
pulseIR(mask, duration);
}
else
if (cmd == "M") {
string marker;
s >> marker;
......
......@@ -32,6 +32,12 @@ int pwmpin = chan_left;
int doutpin = 8;
int dinpin = 7;
int IRpin[] = { 14, 23 }; // GPIO pins of IR LED open collector drivers for fNIRS sync
const int IRnum = sizeof(IRpin)/sizeof(IRpin[0]); // number of IR outputs
const int IRmask = (1<<IRnum)-1; // the bit mask of the IR outputs
const int IR_ON = 1;
const int IR_OFF = 0;
stream_outlet *outlet;
string info_name, info_type, info_sourceid;
std::mutex lsl_mutex;
......@@ -183,6 +189,30 @@ void setdio(int value) {
}
}
void pulseIR(int mask, int durationmsec)
{
for (int i=0; i< IRnum; i++)
{
int r=gpioWrite(IRpin[i], IR_ON);
if (r < 0)
{
perror("gpioWrite");
exit(1);
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(durationmsec));
for (int i=0; i< IRnum; i++)
{
int r=gpioWrite(IRpin[i], IR_OFF);
if (r < 0)
{
perror("gpioWrite");
exit(1);
}
}
}
void beep(int freq, int durationmsec) {
int d = 500000;
int r = gpioHardwarePWM(pwmpin, freq, d);
......@@ -247,6 +277,18 @@ int initialize_gpio() {
return r;
}
for (int i; i<IRnum; i++) {
if (gpioSetMode(IRpin[i], PI_OUTPUT) < 0) {
perror("gpioSetMode");
return 1;
}
if (gpioSetPullUpDown(IRpin[i], PI_PUD_DOWN) < 0) {
perror("gpioSetMode");
return 1;
}
}
if ((r = gpioSetMode(dinpin, PI_OUTPUT)) < 0) {
perror("gpioSetMode");
return r;
......@@ -315,6 +357,7 @@ int main(int argc, const char *argv[]) {
ssub.setsockopt(ZMQ_SUBSCRIBE, "b", 0);
ssub.setsockopt(ZMQ_SUBSCRIBE, "B", 0);
ssub.setsockopt(ZMQ_SUBSCRIBE, "D", 0);
ssub.setsockopt(ZMQ_SUBSCRIBE, "I", 0);
ssub.setsockopt(ZMQ_SUBSCRIBE, "M", 0);
zmq::socket_t srep(context, ZMQ_REP);
......@@ -416,6 +459,22 @@ int main(int argc, const char *argv[]) {
outlet->push_sample(&marker);
setdio(level);
}
else
if (cmd == "I") {
int mask, duration;
string marker;
s >> mask;
s >> duration;
s >> marker;
if (verbose) {
cout << "mask=" << mask << endl;
cout << "duration=" << duration << endl;
cout << "marker=" << marker << endl;
}
std::lock_guard<std::mutex> guard(lsl_mutex);
outlet->push_sample(&marker);
pulseIR(mask, duration);
}
else if (cmd == "M") {
string marker;
s >> marker;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment