Commit 4b4599b1 authored by Your Name's avatar Your Name
Browse files

lslder_uni update

parent cf6a703a
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -78,10 +78,10 @@ const int maxgpio = 54; // BCM chip has 54 GPIO
int gpiomap[maxgpio];
void init_gpiomap() {
// map channel wiring 0..ngpio-1 to BCM GPIO
for (int channel = 0; channel < ngpio; channel++) {
int bcmgpio = gpioinp[channel];
gpiomap[bcmgpio] = channel;
// map BNC input channel wiring 0..ngpio-1 to BCM GPIO
for (int bnc_input = 0; bnc_input < ngpio; bnc_input++) {
int bcmgpio = gpioinp[bnc_input];
gpiomap[bcmgpio] = bnc_input;
}
}
......@@ -115,29 +115,28 @@ volatile int run = 1;
void stop(int signum) { run = 0; }
void gpioISR(int gpio, int level, uint32_t tick) {
int bnc_input = gpiomap[gpio];
if (level == 2) // timeout call
return;
int channel = gpiomap[gpio];
if (debouncetimer[channel])
if (debouncetimer[bnc_input])
return;
else
debouncetimer[channel] = debouncetimes[channel];
#ifdef DEBUG
std::cout << "Interrupt on channel " << channel << " (GPIO "
<< gpioinp[channel] << ")" << std::endl;
#endif
debouncetimer[bnc_input] = debouncetimes[bnc_input];
static int edge = 1;
std::lock_guard<std::mutex> guard(lsl_mutex);
outlet[channel]->push_sample(&edge);
ledtimer[channel] = ledtime;
#ifdef DEBUG
std::cout << "Interrupt on bnc_input " << bnc_input << " (GPIO "
<< gpioinp[bnc_input] << ")" << std::endl;
#endif
outlet[bnc_input]->push_sample(&edge);
ledtimer[bnc_input] = ledtime;
#ifdef DEBUG
interrupt_count[channel]++;
std::cout << channel << " (count=" << interrupt_count[channel] << ")"
interrupt_count[bnc_input]++;
std::cout << bnc_input << " (count=" << interrupt_count[bnc_input] << ")"
<< std::endl;
#endif
}
......@@ -196,13 +195,13 @@ int main(int argc, char *argv[]) {
initleds(nled, ledgpio);
for (int i = 0; i < ngpio; i++) {
int dinpin = gpiomap[i];
if (gpioSetMode(dinpin, PI_OUTPUT) < 0) {
int bcmgpio = gpioinp[i]; // BCM GPIO number
if (gpioSetMode(bcmgpio, PI_INPUT) < 0) {
perror("gpioSetMode");
return 1;
}
if (gpioSetPullUpDown(dinpin, PI_PUD_UP) < 0) {
if (gpioSetPullUpDown(bcmgpio, PI_PUD_UP) < 0) {
perror("gpioSetMode");
return 1;
}
......@@ -213,10 +212,14 @@ int main(int argc, char *argv[]) {
// The 4N35 optocoupler in the input circuit inverts the signal, we want
// to detect rising edges in the input signal, so here we program
// FALLING_EDGE.
if (gpioSetISRFunc(dinpin, FALLING_EDGE, timeout_ms, gpioISR) < 0) {
if (gpioSetISRFunc(bcmgpio, FALLING_EDGE, timeout_ms, gpioISR) < 0) {
perror("gpioSetISRFunc");
return 1;
}
#ifdef DEBUG
std::cout << "Set IRQ handler for gpio " << bcmgpio << std::endl;
#endif
}
char hostname[255];
......
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