login|Register
Forum > Beginners
Post|
看12334|回6|Favorite
nopnop2002 看全部
2016-9-28 21:53:35

quote:

isan replied at 2016-9-27 16:50
I get wiring op from this link
https://github.com/WereCatf/WiringOP
and install it and interrupt w ...

I tried this code.

code:

  1. #include <wiringPi.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>

  4. #define pin     0

  5. void signal(void){
  6.   printf("Signal\n");
  7. }


  8. int main(void){
  9.   if(wiringPiSetup() == -1) {
  10.     printf("wiringPiSetup Error\n");
  11.   }
  12.   pinMode(pin,INPUT);
  13.   wiringPiISR(pin, INT_EDGE_FALLING, signal );
  14. //  wiringPiISR(pin, INT_EDGE_RISING, signal );
  15.   while(1) {
  16.     sleep(10000);
  17.   }
  18.   return 0;
  19. }



But An error occurred.

sudo ./test1
[wiringPiISR2677] the pin:0 is invalid, please check it over!


Please show me your sample source code

nopnop2002 看全部
2016-9-29 22:17:18
Edited by nopnop2002 at 2016-10-9 17:51

I sent Pull Request.

https://github.com/zhaolei/WiringOP/pull/5

You can copy modified source from here.
You can use wiringPiISR with all GPIO(GPIO0-GPIO26).
You need to load gpio_sunxi.
waitForInterrupt function don't work.

Because a device file is being read periodically.

I tested armbian.
This is test code.

code:

  1. #include <wiringPi.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>

  4. void signal_both(void){
  5.   printf("Signal Both\n");
  6. }

  7. void signal_falling(void){
  8.   printf("Signal Falling\n");
  9. }

  10. void signal_rising(void){
  11.   printf("Signal Rising\n");
  12. }

  13. int main(int argc, char **argv){
  14.   int mode=INT_EDGE_BOTH;
  15.   int pin = 0;

  16.   if(wiringPiSetup() == -1) {
  17.     printf("wiringPiSetup Error\n");
  18.   }
  19.   if (argc == 2) {
  20.     mode = atoi(argv[1]);
  21.   }
  22.   if (argc == 3) {
  23.     mode = atoi(argv[1]);
  24.     pin = atoi(argv[2]);
  25.   }
  26.   pinMode(pin,INPUT);
  27.   printf("pin=%d\n",pin);
  28.   if ( mode == INT_EDGE_BOTH) {
  29.     printf("INT_EDGE_BOTH\n");
  30.     wiringPiISR(pin, INT_EDGE_BOTH, signal_both );
  31.   } else if ( mode == INT_EDGE_FALLING) {
  32.     printf("INT_EDGE_FALLING\n");
  33.     wiringPiISR(pin, INT_EDGE_FALLING, signal_falling );
  34.   } else if ( mode == INT_EDGE_RISING) {
  35.     printf("INT_EDGE_RISING\n");
  36.     wiringPiISR(pin, INT_EDGE_RISING, signal_rising );
  37.   }

  38.   while(1) {
  39.     sleep(10000);
  40.   }
  41.   return 0;
  42. }



This is test result.

code:

  1. orangepi@orangepipc:~/test$ sudo ./test2 1 15
  2. pin=15
  3. INT_EDGE_FALLING
  4. Signal Falling
  5. Signal Falling
  6. Signal Falling
  7. Signal Falling
  8. ^Corangepi@orangepipc:~/test$ sudo ./test2 2 15
  9. pin=15
  10. INT_EDGE_RISING
  11. Signal Rising
  12. Signal Rising
  13. Signal Rising
  14. Signal Rising
  15. Signal Rising
  16. ^Corangepi@orangepipc:~/test$ sudo ./test2 3 15
  17. pin=15
  18. INT_EDGE_BOTH
  19. Signal Both
  20. Signal Both
  21. Signal Both
  22. Signal Both
  23. Signal Both
  24. Signal Both
  25. Signal Both
  26. Signal Both
  27. ^Corangepi@orangepipc:~/test$




12

OrangePi En

Powered by Discuz! X3.4

homepage|Simple edition|Touch edition|PC