Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2010
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #define BREAKOUT_CLEAR(x) ((x) | (0 << 8))
  2. #define BREAKOUT_SET(x) ((x) | (1 << 8))
  3.  
  4. int breakout_set_pins(int fd, uint8_t mask)
  5. {
  6. uint16_t val = BREAKOUT_SET(mask);
  7. return write(fd, &val, sizeof(val));
  8. }
  9.  
  10. int breakout_clear_pins(int fd, uint8_t mask)
  11. {
  12. uint16_t val = BREAKOUT_CLEARh(mask);
  13. return write(fd, &val, sizeof(val));
  14. }
  15.  
  16. static void set(int fd, int n)
  17. {
  18. uint16_t buf[2];
  19. if (n & 1) {
  20. buf[0] = BREAKOUT_CLEAR(0xff);
  21. buf[1] = BREAKOUT_SET(1 << n);
  22. } else {
  23. buf[0] = BREAKOUT_SET(0xff);
  24. buf[1] = BREAKOUT_CLEAR(1 << n);
  25. }
  26. write(fd, buf, sizeof(buf));
  27. }
  28.  
  29. int main(int argc, char **argv)
  30. {
  31. int fd, i;
  32.  
  33. fd = open("/dev/breakout", O_RDWR);
  34. if (fd < 0) {
  35. perror("Failed to open /dev/breakout");
  36. exit(1);
  37. }
  38.  
  39. while (1) {
  40. for (i = 0; i != LEDS-1; i++) {
  41. set(fd, i);
  42. usleep(DELAY_US);
  43. }#define BREAKOUT_CLEAR(x) ((x) | (0 << 8))
  44. #define BREAKOUT_SET(x) ((x) | (1 << 8))
  45.  
  46. int breakout_set_pins(int fd, uint8_t mask)
  47. {
  48. uint16_t val = BREAKOUT_SET(mask);
  49. return write(fd, &val, sizeof(val));
  50. }
  51.  
  52. int breakout_clear_pins(int fd, uint8_t mask)
  53. {
  54. uint16_t val = BREAKOUT_CLEARh(mask);
  55. return write(fd, &val, sizeof(val));
  56. }
  57.  
  58. static void set(int fd, int n)
  59. {
  60. uint16_t buf[2];
  61. if (n & 1) {
  62. buf[0] = BREAKOUT_CLEAR(0xff);
  63. buf[1] = BREAKOUT_SET(1 << n);
  64. } else {
  65. buf[0] = BREAKOUT_SET(0xff);
  66. buf[1] = BREAKOUT_CLEAR(1 << n);
  67. }
  68. write(fd, buf, sizeof(buf));
  69. }
  70.  
  71. int main(int argc, char **argv)
  72. {
  73. int fd, i;
  74.  
  75. fd = open("/dev/breakout", O_RDWR);
  76. if (fd < 0) {
  77. perror("Failed to open /dev/breakout");
  78. exit(1);
  79. }
  80.  
  81. while (1) {
  82. for (i = 0; i != LEDS-1; i++) {
  83. set(fd, i);
  84. usleep(DELAY_US);
  85. }
  86. for (i = LEDS-1; i != 0; i--) {
  87. set(fd, i);
  88. usleep(DELAY_US);
  89. }
  90. }
  91. return 0;
  92. }
  93. for (i = LEDS-1; i != 0; i--) {
  94. set(fd, i);
  95. usleep(DELAY_US);
  96. }
  97. }
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement