Commit f33a3d6b authored by Gunter Windau's avatar Gunter Windau
Browse files

azmq rm

parent bbd63c97
azmq @ 6bb101ee
Subproject commit 6bb101eecb357ad9735ebc36e276b7526652d42d
labstreaminglayer @ 9b2f950e
Subproject commit 9b2f950e173d44d674445cb09838700e633d8d7d
LSLBASE=../labstreaminglayer/build/install/lsl_Release/LSL
CPPFLAGS+=-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
#INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11
# LDFLAGS+=-lpigpio
CXX=g++
CC=g++
all: lslder sendrand sendgpioev
lslder: lslder.o led.o
sendrand: sendrand.cc
#include "led.h"
#include <wiringPi.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
const int nled = 8;
const int ledgpio[] = { 21, 20, 16, 13, 5, 14, 3, 2 };
void playleds();
void initleds()
{
for (int i=0; i<nled; i++)
{
pinMode(ledgpio[i], OUTPUT);
}
playleds();
}
void playleds()
{
for (int i=0; i<nled; i++)
{
setled(i, 1);
usleep(200000);
}
for (int i=0; i<nled; i++)
{
setled(i, 0);
usleep(200000);
}
for (int i=0; i<nled; i++)
{
setled(i, 1);
}
usleep(500000);
for (int i=0; i<nled; i++)
{
setled(i, 0);
}
usleep(500000);
for (int i=0; i<nled; i++)
{
setled(i, 1);
}
usleep(500000);
for (int i=0; i<nled; i++)
{
setled(i, 0);
}
}
void setled(int lednr, int value)
{
int bit;
if (value)
bit = 1;
else
bit = 0;
digitalWrite(ledgpio[lednr], bit);
}
void initleds();
void setled(int lednr, int value);
File added
File added
// lslder.cc -- GW/20180716
//
// This program offers 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
#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;
const int ngpio = 8;
const int gpioinp[ngpio] = { 12, 7, 8, 25, 24, 23, 18, 15 };
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 gpioInterrupt_12()
{
gpioInterrupt(0);
}
void gpioInterrupt_7()
{
gpioInterrupt(1);
}
void gpioInterrupt_8()
{
gpioInterrupt(2);
}
void gpioInterrupt_25()
{
gpioInterrupt(3);
}
void gpioInterrupt_24()
{
gpioInterrupt(4);
}
void gpioInterrupt_23()
{
gpioInterrupt(5);
}
void gpioInterrupt_18()
{
gpioInterrupt(6);
}
void gpioInterrupt_15()
{
gpioInterrupt(7);
}
int main(int argc, char* argv[]) {
piHiPri(99); // shortcut for running at real time priority
// configure inputs
wiringPiSetupGpio();
initleds();
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];
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, &gpioInterrupt_15);
wiringPiISR(18, INT_EDGE_FALLING, &gpioInterrupt_18);
wiringPiISR(23, INT_EDGE_FALLING, &gpioInterrupt_23);
wiringPiISR(24, INT_EDGE_FALLING, &gpioInterrupt_24);
wiringPiISR(25, INT_EDGE_FALLING, &gpioInterrupt_25);
wiringPiISR(8, INT_EDGE_FALLING, &gpioInterrupt_8);
wiringPiISR(7, INT_EDGE_FALLING, &gpioInterrupt_7);
wiringPiISR(12, INT_EDGE_FALLING, &gpioInterrupt_12);
// do this forever
while(true) {
std::this_thread::sleep_for(std::chrono::milliseconds(20));
handleLeds();
}
return 0;
}
File added
#!/bin/bash
#run this as root
cd /home/pi/firmware/lslder
export LD_LIBRARY_PATH=../labstreaminglayer/build/install/lsl_Release/LSL/lib/
./lslder
#!/bin/bash
#run this as root
cd /home/pi/firmware/lslder
export LD_LIBRARY_PATH=../labstreaminglayer/build/install/lsl_Release/LSL/lib/
./sendgpioev
// sendgpioev.cc -- GW/20180417
//
// This program offers four LSL event streams, each triggered by positive edges on
// raspberry pi digital inputs 4,17,22,27
// 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
#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>
using namespace lsl;
stream_outlet *outlet[4];
std::mutex lsl_mutex;
typedef char int8;
void gpioInterrupt(int channel)
{
std::lock_guard<std::mutex> guard(lsl_mutex);
#ifdef DEBUG
std::cout << channel << std::endl;
#endif
int edge=1;
outlet[channel]->push_sample(&edge);
}
void gpioInterrupt_4()
{
gpioInterrupt(0); // gpio4 has input label 1
}
void gpioInterrupt_17()
{
gpioInterrupt(1);
}
void gpioInterrupt_22()
{
gpioInterrupt(2);
}
void gpioInterrupt_27()
{
gpioInterrupt(3);
}
int main(int argc, char* argv[]) {
piHiPri(99); // shortcut for running at real time priority
// configure inputs
wiringPiSetupGpio();
pinMode(4, INPUT);
pinMode(17, INPUT);
pinMode(22, INPUT);
pinMode(27, INPUT);
pullUpDnControl(4, PUD_UP);
pullUpDnControl(17, PUD_UP);
pullUpDnControl(22, PUD_UP);
pullUpDnControl(27, PUD_UP);
char hostname[255];
gethostname(hostname,255);
for (int i=0; i<4; i++)
{
// make a new stream_info and open an outlet with it
char info_name[255];
sprintf(info_name, "Digital Events %d", i+1);
char info_type[255];
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 at the input inverts the signal, we want to
// detect rising edges in the input signal, so here we program INT_EDGE_FALLING.
wiringPiISR(4, INT_EDGE_FALLING, &gpioInterrupt_4);
wiringPiISR(17, INT_EDGE_FALLING, &gpioInterrupt_17);
wiringPiISR(22, INT_EDGE_FALLING, &gpioInterrupt_22);
wiringPiISR(27, INT_EDGE_FALLING, &gpioInterrupt_27);
// send data forever
while(true)
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
return 0;
}
#include <lsl_cpp.h>
#include <stdlib.h>
#include <iostream>
#include <mutex>
#include <thread> // std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
#include <wiringPi.h>
using namespace lsl;
/**
* This is an example of how a simple data stream can be offered on the network.
* Here, the stream is named SimpleStream, has content-type EEG, and 8 channels.
* The transmitted samples contain random numbers (and the sampling rate is irregular)
*/
stream_outlet *outlet;
std::mutex lsl_mutex;
typedef char int8;
void gpioInterrupt(const char* mrk)
{
std::lock_guard<std::mutex> guard(lsl_mutex);
#ifdef DEBUG
std::cout << mrk << std::endl;
#endif
std::string sample(mrk);
outlet->push_sample(&sample);
}
void gpioInterrupt_4()
{
gpioInterrupt("EDGE_RISING_1"); // gpio4 has input label 1
}
void gpioInterrupt_17()
{
gpioInterrupt("EDGE_RISING_2");
}
void gpioInterrupt_22()
{
gpioInterrupt("EDGE_RISING_4");
}
void gpioInterrupt_27()
{
gpioInterrupt("EDGE_RISING_3");
}
int main(int argc, char* argv[]) {
piHiPri(99);
//
wiringPiSetupGpio();
pinMode(4, INPUT);
pinMode(17, INPUT);
pinMode(22, INPUT);
pinMode(27, INPUT);
pullUpDnControl(4, PUD_UP);
pullUpDnControl(17, PUD_UP);
pullUpDnControl(22, PUD_UP);
pullUpDnControl(27, PUD_UP);
// make a new stream_info (nchannelsch) and open an outlet with it
stream_info info("Digital Events", "Digital Events", 1, lsl::IRREGULAR_RATE,
lsl::cf_string,"Raspberry Pi Digital Event Recorder");
outlet = new stream_outlet(info);
wiringPiISR(4, INT_EDGE_RISING, &gpioInterrupt_4);
wiringPiISR(17, INT_EDGE_RISING, &gpioInterrupt_17);
wiringPiISR(22, INT_EDGE_RISING, &gpioInterrupt_22);
wiringPiISR(27, INT_EDGE_RISING, &gpioInterrupt_27);
// send data forever
while(true)
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
return 0;
}
File added
#include <lsl_cpp.h>
#include <stdlib.h>
#include <thread> // std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
using namespace lsl;
/**
* This is an example of how a simple data stream can be offered on the network.
* Here, the stream is named SimpleStream, has content-type EEG, and 8 channels.
* The transmitted samples contain random numbers (and the sampling rate is irregular)
*/
constexpr int nchannels = 8;
int main(int argc, char* argv[]) {
// make a new stream_info (nchannelsch) and open an outlet with it
stream_info info(argc > 1 ? argv[1] : "RandomStream", "EEG", nchannels);
stream_outlet outlet(info);
// send data forever
float sample[nchannels];
while(true) {
// generate random data
for (int c=0;c<nchannels;c++) sample[c] = (rand()%1500)/500.0-1.5;
// send it
outlet.push_sample(sample);
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
return 0;
}
wiringPi @ 96344ff7
Subproject commit 96344ff7125182989f98d3be8d111952a8f74e15
LSLBASE=../labstreaminglayer/build/install/lsl_Release/LSL
CPPFLAGS+=-Wall -Wno-sign-compare -I$(LSLBASE)/include
LDFLAGS+=-L$(LSLBASE)/lib -llsl32 -lboost_system -lpthread
LDFLAGS+=-lpigpio
CXX=g++
CC=g++
LDLIBS+=-lzmq -lpthread -lboost_system -lboost_regex -lboost_program_options
#INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11
all: zmq_trigger playtone
playtone: playtone.cc
zmq_trigger: zmq_trigger.cc
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pigpio.h>
#if 1
const int left = 13; // PWM1 audio to jack
const int right = 12; // PWM0 audio to jack
#else
const int left = 18; // PWM1 audio to jack
const int right = 19; // PWM0 audio to jack
#endif
int pin = right;
int freq = 400;
int dt = 1000;
volatile int run;
void stop(int signum)
{
run = 0;
}
int main(int argc,char *argv[])
{
int r;
/*
r = gpioCfgClock(10, 0, 0);
if (r < 0)
{
perror("gpioCfgClock");
return 1;
}
*/
r = gpioInitialise(); // use Broadcom pin numbering
if (r < 0)
{
perror("gpioInitialise");
return 1;
}
gpioSetSignalFunc(SIGINT, stop);
printf("Press control C to stop.\n");
if (gpioSetMode(pin, PI_ALT0) < 0) {
perror("gpioSetMode");
return 1;
}
/*
int d;
if ((d=gpioPWM(pin, 128))<0) {
perror("gpioPWM");
return 1;
}
d=gpioGetPWMdutycycle(pin);
int f;
if ((f=gpioSetPWMfrequency(pin, freq)) < 0) {
perror("gpioSetPWMfrequency");
return 1;
}
*/
int d=500000;
int f=freq;
r=gpioHardwarePWM(pin, freq, d);
if (r < 0)
{
perror("gpioHardwarePWM");
return 1;
}
printf("PWM freq = %d, duty cycle = %d\n", f, d);
run = 1;
while(run)
{
time_sleep(0.01);
}
printf("\ntidying up\n");
r=gpioHardwarePWM(pin, 0, 0);
if (r < 0)
{
perror("gpioHardwarePWM");
return 1;
}
gpioTerminate();
// r = gpioCfgClock(5, 0, 0);
// gpioInitialise();
// gpioTerminate();
}
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