Hey Leute, ich versuche schon seid einigen Tagen, meinen Kapazitiven Sensor in eine Library zu verpacken. Soweit geht auch alles aber irgendwie mag der compiler den attachinterrupt in der cpp file nicht:/ Hab schon im Internet nach geschaut und bin einfach nicht fündig geworden. Hat einer von euch vielleicht noch eine Idee? header:
1 | #ifndef tl
|
2 | #define tl
|
3 | |
4 | #if (ARDUINO >=100)
|
5 | #include "Arduino.h" |
6 | #else
|
7 | #include "WProgram.h" |
8 | #endif
|
9 | |
10 | class TestLib{ |
11 | public:
|
12 | // Constructor
|
13 | TestLib(int i_pin=0); |
14 | |
15 | // Methods
|
16 | int _measure(int c_interrupt_delay, int i_measure_amount); |
17 | |
18 | private:
|
19 | volatile unsigned int i_pulse; |
20 | int i_measure_pin; |
21 | void _counter(); |
22 | };
|
23 | #endif
|
cpp:
1 | #include "capSensor.h" |
2 | |
3 | TestLib::TestLib(int i_pin){ |
4 | // Anything you need when instantiating your object goes here
|
5 | i_measure_pin = i_pin; |
6 | }
|
7 | |
8 | |
9 | // Pretend this is one or more complex and involved functions you have written
|
10 | int TestLib::_measure(int c_interrupt_delay, int i_measure_amount){ |
11 | |
12 | volatile unsigned int i_differenz_puls = 0; |
13 | |
14 | delay(1000); // Sensor start toleranz delay |
15 | for(int i = 0; i < i_measure_amount; i++) |
16 | {
|
17 | delay(500); |
18 | i_pulse = 0; // Anzahl der Pulse auf 0 setzen |
19 | attachInterrupt(0, TestLib::_counter, RISING); // Interrupt aktivieren: Steigende Flanken |
20 | delay(c_interrupt_delay); |
21 | detachInterrupt(0); // Interrupt deaktivieren |
22 | i_differenz_puls += i_pulse; |
23 | }
|
24 | |
25 | i_differenz_puls = i_differenz_puls / 10; |
26 | return i_differenz_puls; |
27 | }
|
28 | |
29 | // Private method for this class
|
30 | void TestLib::_counter(){ |
31 | i_pulse++; |
32 | }
|
Fehlermeldung:
1 | /var/folders/19/qr88mkd91kx47d2l25csn_5m0000gn/T/arduino_build_100013/sketch/capSensor.cpp: In member function 'int TestLib::_measure(int, int)': |
2 | capSensor.cpp:19: error: invalid use of non-static member function |
3 | attachInterrupt(0, TestLib::_counter, RISING); // Interrupt aktivieren: Steigende Flanken |
4 | ^ |
5 | exit status 1 |
6 | invalid use of non-static member function |
LG Alex