You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 rivejä
1.1 KiB

  1. #include <wiringPi.h>
  2. #include <stdio.h>
  3. #define COLORDEF "\x1B[0m"
  4. #define COLORRED "\x1B[31m"
  5. #define COLORGRN "\x1B[32m"
  6. void CheckGPIO(int GPIO, int GPIOIN, int out) {
  7. int in = digitalRead(GPIOIN);
  8. int read = digitalRead(GPIO);
  9. int pass = 0;
  10. if (out==in && in==read) {
  11. pass = 1;
  12. }
  13. if (pass) {
  14. printf("GPIO%d = %d (GPIO%d = %d) -> %spassed%s\n", GPIOIN, in, GPIO, read, COLORGRN, COLORDEF );
  15. } else {
  16. printf("GPIO%d = %d (GPIO%d = %d) -> %sfailed%s\n", GPIOIN, in, GPIO, read, COLORRED, COLORDEF );
  17. }
  18. }
  19. void digitalWriteEx(int GPIO, int GPIOIN, int mode) {
  20. digitalWrite(GPIO, mode);
  21. printf("out = %d ", mode);
  22. delayMicroseconds(5000);
  23. CheckGPIO(GPIO, GPIOIN, mode);
  24. }
  25. void pullUpDnControlEx (int GPIO, int GPIOIN, int mode) {
  26. pullUpDnControl (GPIO, mode);
  27. int out = mode==PUD_UP ? 1:0;
  28. printf("in = %4s ", mode==PUD_UP ? "up":"down");
  29. delayMicroseconds(5000);
  30. CheckGPIO(GPIO, GPIOIN, out);
  31. }
  32. void CheckSame(const char* msg, int value, int expect) {
  33. if (value==expect) {
  34. printf("%s -> %spassed%s\n", msg, COLORGRN, COLORDEF );
  35. } else {
  36. printf("%s -> %sfailed%s\n", msg, COLORRED, COLORDEF );
  37. }
  38. }