|
Revision 8185, 1.3 kB
(checked in by mootoh, 10 months ago)
|
|
lang/cplusplus/gainer++: use thread to receive events from I/O module.
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | * application example |
|---|
| 3 | * from http://8-p.info/gainer-ruby/ |
|---|
| 4 | */ |
|---|
| 5 | #include <iostream> |
|---|
| 6 | #include "gainer.h" |
|---|
| 7 | |
|---|
| 8 | using namespace std; |
|---|
| 9 | |
|---|
| 10 | Gainer *gainer; |
|---|
| 11 | |
|---|
| 12 | static void on_pressed() { |
|---|
| 13 | cout << "pressed" << endl; |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | static void on_released() { |
|---|
| 17 | cout << "released" << endl; |
|---|
| 18 | |
|---|
| 19 | #if 0 |
|---|
| 20 | cout << "digital : "; |
|---|
| 21 | for (size_t i(0); i<gainer->digital_inputs.size(); i++) { |
|---|
| 22 | cout << gainer->digital_inputs[i] << ' '; |
|---|
| 23 | } cout << endl; |
|---|
| 24 | |
|---|
| 25 | cout << "analog : "; |
|---|
| 26 | for (size_t i(0); i<gainer->analog_inputs.size(); i++) { |
|---|
| 27 | cout << gainer->analog_inputs[i] << ' '; |
|---|
| 28 | } cout << endl; |
|---|
| 29 | #endif // 0 |
|---|
| 30 | cout << "A: "; |
|---|
| 31 | for (size_t i(0); i<gainer->analog_inputs.size(); i++) { |
|---|
| 32 | cout << gainer->analog_inputs[i] << ' '; |
|---|
| 33 | } cout << endl; |
|---|
| 34 | |
|---|
| 35 | cout << "D: "; |
|---|
| 36 | for (size_t i(0); i<gainer->digital_inputs.size(); i++) { |
|---|
| 37 | cout << gainer->digital_inputs[i] << ' '; |
|---|
| 38 | } cout << endl; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | int main(int argc, char **argv) { |
|---|
| 42 | if (argc != 2) { |
|---|
| 43 | cerr << "usage: ./gainer-button [device]" << endl; |
|---|
| 44 | exit(1); |
|---|
| 45 | } |
|---|
| 46 | gainer = new Gainer(argv[1], 1); |
|---|
| 47 | gainer->set_on_pressed(on_pressed); |
|---|
| 48 | gainer->set_on_released(on_released); |
|---|
| 49 | |
|---|
| 50 | while (true) { |
|---|
| 51 | //gainer->peek_analog_inputs(); |
|---|
| 52 | gainer->peek_digital_inputs(); |
|---|
| 53 | sleep(1); |
|---|
| 54 | /* |
|---|
| 55 | gainer->peek_analog_inputs(); |
|---|
| 56 | gainer->peek_digital_inputs(); |
|---|
| 57 | */ |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | delete gainer; |
|---|
| 61 | |
|---|
| 62 | return 0; |
|---|
| 63 | } |
|---|
| 64 | |
|---|