Forum: Mikrocontroller und Digitale Elektronik Klassenfunktion kann nicht in den Timer geladen werden


von Happy Programmer (Gast)


Lesenswert?

header-file:
1
class ReadADCValues {
2
    public:
3
        bool is_active;         
4
        bool error;             
5
        
6
        void init  ();
7
        void start ();          
8
        void stopp ();          
9
        void set_sampling_rate (uint16_t value);  
10
    
11
    private:
12
        bool check;                     
13
        void tickerfunction (); 
14
        uint16_t sampling_rate;
15
};


cpp-file:
1
void ReadADCValues::init() {
2
    is_active     = false;             
3
    error         = false;             
4
    check         = false;             
5
    sampling_rate = 100;
6
}
7
8
void ReadADCValues::start() {
9
    timer.attach(&ReadADCValues::tickerfunction, sampling_rate);
10
}
11
12
void ReadADCValues::stopp() {
13
    timer.detach();    
14
}
15
16
void ReadADCValues::set_sampling_rate(uint16_t value) {
17
    sampling_rate = value;
18
}
19
20
void ReadADCValues::tickerfunction() {
21
    if (check == true) {
22
        error = true;
23
    }
24
    check = true;
25
    // tu was...
26
    
27
    check = false;    
28
}

Der Teil aus dem C-Programm macht Probleme:
1
void ReadADCValues::start() {
2
    timer.attach(&ReadADCValues::tickerfunction, sampling_rate);
3
}

Fehlermeldung: "no instance of overloaded function"

Was mache ich falsch?

von Dr. Sommer (Gast)


Lesenswert?

Welche Plattform, welcher Compiler? Was ist "timer", wie sieht 
"timer.attach" aus? Spontan würde ich raten, dass diese Funktion nur 
normale Funktionspointer annimmt, und keine Member-Function-Pointer. Was 
auch erfordern würde, dass du "this" übergeben müsstest.

von Oszi 40 (Gast)


Lesenswert?

so geht das:
1
void ReadADCValues::start() {
2
    timer.attach(this, &ReadADCValues::tickerfunction, sampling_rate);
3
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.