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