Mr_
Posts: 2
Joined: Thu Jun 27, 2019 8:16 am

Problem using wiringPiISR (c++)

Thu Jun 27, 2019 9:13 am

Hello,

I began to use c++ two weeks ago with QT Creator and a Raspberry Pi.

I'm struggling with wiringPiISR (wiringPi Library) and I didn't found any answer for my problem on this forum, so I'm asking you some help :)

I'm trying to configure wiringPiISR to trigger an interrupt (on both rising and falling edge) and call a method in the same class called here "void visualisation::traitement(void()".

I call wiringPiISR here at the launch of my visualisation.cpp, and in the same .cpp I have my method : "void visualisation::traitement(void)".

Here is the part of my .cpp (I erased the content of my visualisation::traitement because I think it's not the point of my question, I Don't use any return, I just modify some global variables and set text in widgets)

Code: Select all

#include<iostream>
#include<QMessageBox>
#include<QDebug>
#include<math.h>
#include<functional>

#include"visualisation.h"
#include"ui_visualisation.h"
#include"wiringPi.h"

using namespace std;

visualisation::visualisation(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::visualisation)
{

wiringPiISR(G_conv1, INT_EDGE_BOTH,&visualisation::traitement());

}

void visualisation :: traitement(void){
//...
}

And the .h:

Code: Select all

#ifndef VISUALISATION_H
#define VISUALISATION_H

#include <QDialog>

namespace Ui {
class visualisation;
}

class visualisation : public QDialog
{
    Q_OBJECT

public:
    explicit visualisation(QWidget *parent = 0);
    ~visualisation();

private slots:

    void traitement(void);
    
private:

    Ui::visualisation *ui;

};

#endif // VISUALISATION_H


I Don't understand how to use my method as a void(*)(), I tried to use std::bin, but it didn't work.

I have those messages in the output:

"lvalue required as unary '&' operand"

with static_cast:

Code: Select all

static_cast<void*>(visualisation::traitement())


"invalid static_cast from type 'void' to type 'void*'

I think that I Don't really understand what to put in wiringPiISR.

I'm trying to be clear, thank you for your help, I will update my post if there isn't enough information :)

deepo
Posts: 25
Joined: Sun Dec 30, 2018 8:36 pm

Re: Problem using wiringPiISR (c++)

Thu Jun 27, 2019 9:24 pm

According to your code:

Code: Select all

static_cast<void*>(visualisation::traitement())
you are trying to take the output of:

Code: Select all

void visualisation::traitement(void)
which is void and cast that to void * which won't work, as the traitement() function does not return anything.
Apart from that you can't call visualisation::traitement() as you do because it's not a static function.

But I don't know anything about Qt, so I'm afraid I can't help you with that.

Does this function:

Code: Select all

wiringPiISR(G_conv1, INT_EDGE_BOTH,&visualisation::traitement());
require you to provide a function that returns a "void *" ?

/Mogens

deepo
Posts: 25
Joined: Sun Dec 30, 2018 8:36 pm

Re: Problem using wiringPiISR (c++)

Thu Jun 27, 2019 9:30 pm

This thread seems to have info on the function:
https://www.raspberrypi.org/forums/view ... p?t=184388

There may be help to find here:
https://stackoverflow.com/questions/308 ... a-function

And more code here:
https://gist.github.com/antimodular/b1f ... a0bdb30d67

/Mogens

Mr_
Posts: 2
Joined: Thu Jun 27, 2019 8:16 am

Re: Problem using wiringPiISR (c++)

Fri Jun 28, 2019 6:13 am

Thank you for your reply deepo :)

It requires a void(*function)(void) (WiringPi website) or &function for Qt.

I will read the links you gave me!!:)

Return to “C/C++”