Commit 9712e3ee authored by Gunter Windau's avatar Gunter Windau
Browse files

lslder.cc one source for different hardware configs

parent ff855f09
LSLBASE=../labstreaminglayer/build/install/lsl_Release/LSL
CPPFLAGS+=-Wall -Wno-sign-compare -I$(LSLBASE)/include
LSLBASE=../labstreaminglayer/build/install
CXXFLAGS+=-Wall -Wno-sign-compare -I$(LSLBASE)/include
LDFLAGS+=-L$(LSLBASE)/lib -llsl32 -lwiringPi -lboost_system -lpthread
LDLIBS+=-lzmq -lpthread -lboost_system -lboost_regex -lboost_program_options
......@@ -10,6 +10,26 @@ CXXFLAGS+=-Wall -std=c++11
CXX=g++
CC=g++
all: lslder sendrand sendgpioev
lslder: lslder.o led.o
TARGETS=lslder_1chan lslder_8chan sendrand lslder_4chan_proto
all: $(TARGETS)
#lslder : CPPFLAGS+=-DLSLDER_8CHAN
#lslder: lslder_8chan.o led.o
lslder_8chan: CXXFLAGS+=-DLSLDER_8CHAN
lslder_8chan: lslder_8chan.o led.o
lslder_8chan.o: lslder_uni.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
lslder_1chan: CXXFLAGS+=-DLSLDER_1CHAN
lslder_1chan: lslder_1chan.o led.o
lslder_1chan.o: lslder_uni.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
sendrand: sendrand.cc
lslder_4chan_proto: lslder_4chan_proto.cc
clean:
rm -f $(TARGETS) *.o
......@@ -5,13 +5,15 @@
#include <unistd.h>
#include <iostream>
const int nled = 8;
const int ledgpio[] = { 21, 20, 16, 13, 5, 14, 3, 2 };
static int nled = 0;
static const int *ledgpio = 0;
void playleds();
void initleds()
void initleds(int _nled, const int *_ledgpio)
{
nled = _nled;
ledgpio = _ledgpio;
for (int i=0; i<nled; i++)
{
pinMode(ledgpio[i], OUTPUT);
......
void initleds();
void initleds(int nrofleds, const int *ledgpios);
void setled(int lednr, int value);
No preview for this file type
// lslder.cc -- GW/20200110
//
// LSL Digital Event Recorder
//
// This program offers a maximum of eight LSL event streams, each triggered by positive edges on
// raspberry pi GPIO digital inputs. Visual feedback is provided bij eight LEDs.
// The stream type is "Digital Events - $HOSTNAME", where HOSTNAME is the ip hostname of
// the raspberry. This is to uniquely identify devices on the network.
// The data sent with the events is an int8 with value 1, with 1 indicating a rising edge.
// Falling edges can be sent with a 0 value. However this is not implemented in this
// program.
//
// Dependencies: labstreaminglayer C++ and wiringPi
// CHANGES
// GW/20180716 initial version for 8-channel LSL Digital Event Recorder
#include <lsl_cpp.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <mutex>
#include <thread> // std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
#include <wiringPi.h>
#include "led.h"
//#define DEBUG
using namespace lsl;
#ifdef LSLDER_1CHAN
// 1 channel portable version without LEDs
const int ngpio = 8;
const int gpioinp[ngpio] = { 12, 7, 8, 25, 24, 23, 18, 15 };
const int *ledgpio = 0;
const int nled = 0;
#endif
#ifdef LSLDER_8CHAN
// 8-chan version with 8 LEDs
const int ngpio = 8;
const int gpioinp[ngpio] = { 12, 7, 8, 25, 24, 23, 18, 15 };
const int ledgpio[] = { 21, 20, 16, 13, 5, 14, 3, 2 };
const int nled = 8;
#endif
int ledtime=1; // in 1/50 sec., see infinite loop in main()
volatile int ledtimer[ngpio] = { 0, };
int ledstatus[ngpio] = { 0, };
#ifdef DEBUG
volatile int interrupt_count[ngpio] = { 0, };
#endif
stream_outlet *outlet[ngpio];
std::mutex lsl_mutex;
typedef char int8;
void gpioInterrupt(int channel)
{
std::lock_guard<std::mutex> guard(lsl_mutex);
static int edge=1;
outlet[channel]->push_sample(&edge);
ledtimer[channel]=ledtime;
#ifdef DEBUG
interrupt_count[channel]++;
std::cout << channel << " (count=" << interrupt_count[channel] << ")" << std::endl;
#endif
}
void handleLeds()
{
for (int i=0; i<ngpio; i++)
{
if (ledtimer[i] > 0) {
if (!ledstatus[i]) {
//std::lock_guard<std::mutex> guard(lsl_mutex);
setled(i,1);
ledstatus[i]=1;
}
ledtimer[i]--;
}
else {
if (ledstatus[i]) {
//std::lock_guard<std::mutex> guard(lsl_mutex);
setled(i,0);
ledstatus[i]=0;
}
}
}
}
void gpioISR_0()
{
gpioInterrupt(0);
}
void gpioISR_1()
{
gpioInterrupt(1);
}
void gpioISR_2()
{
gpioInterrupt(2);
}
void gpioISR_3()
{
gpioInterrupt(3);
}
void gpioISR_4()
{
gpioInterrupt(4);
}
void gpioISR_5()
{
gpioInterrupt(5);
}
void gpioISR_6()
{
gpioInterrupt(6);
}
void gpioISR_7()
{
gpioInterrupt(7);
}
typedef void(*gpioISR)();
gpioISR ISR[8] = { gpioISR_1, };
int main(int argc, char* argv[]) {
piHiPri(99); // shortcut for running at real time priority
// configure inputs
wiringPiSetupGpio();
initleds(nled, ledgpio);
for (int i=0; i<ngpio; i++)
{
pinMode(gpioinp[i], INPUT);
pullUpDnControl(gpioinp[i], PUD_UP);
}
char hostname[255];
gethostname(hostname,255);
for (int i=0; i<ngpio; i++)
{
// make a new stream_info and open an outlet with it
char info_name[255];
sprintf(info_name, "Digital Events %d", i);
char info_type[255+18];
sprintf(info_type,"Digital Events @ %s",hostname);
stream_info info(info_name, info_type, 1, lsl::IRREGULAR_RATE,
lsl::cf_int8,"Raspberry Pi Digital Event Recorder");
outlet[i] = new stream_outlet(info);
}
// The 4N35 optocoupler in the input circuit inverts the signal, we want to
// detect rising edges in the input signal, so here we program INT_EDGE_FALLING.
wiringPiISR(15, INT_EDGE_FALLING, &gpioISR_0);
wiringPiISR(18, INT_EDGE_FALLING, &gpioISR_1);
wiringPiISR(23, INT_EDGE_FALLING, &gpioISR_2);
wiringPiISR(24, INT_EDGE_FALLING, &gpioISR_3);
wiringPiISR(25, INT_EDGE_FALLING, &gpioISR_4);
wiringPiISR(8, INT_EDGE_FALLING, &gpioISR_5);
wiringPiISR(7, INT_EDGE_FALLING, &gpioISR_6);
wiringPiISR(12, INT_EDGE_FALLING, &gpioISR_7);
// do this forever
while(true) {
std::this_thread::sleep_for(std::chrono::milliseconds(20));
handleLeds();
}
return 0;
}
No preview for this file type
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