Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BREAKOUT_CLEAR(x) ((x) | (0 << 8))
- #define BREAKOUT_SET(x) ((x) | (1 << 8))
- int breakout_set_pins(int fd, uint8_t mask)
- {
- uint16_t val = BREAKOUT_SET(mask);
- return write(fd, &val, sizeof(val));
- }
- int breakout_clear_pins(int fd, uint8_t mask)
- {
- uint16_t val = BREAKOUT_CLEARh(mask);
- return write(fd, &val, sizeof(val));
- }
- static void set(int fd, int n)
- {
- uint16_t buf[2];
- if (n & 1) {
- buf[0] = BREAKOUT_CLEAR(0xff);
- buf[1] = BREAKOUT_SET(1 << n);
- } else {
- buf[0] = BREAKOUT_SET(0xff);
- buf[1] = BREAKOUT_CLEAR(1 << n);
- }
- write(fd, buf, sizeof(buf));
- }
- int main(int argc, char **argv)
- {
- int fd, i;
- fd = open("/dev/breakout", O_RDWR);
- if (fd < 0) {
- perror("Failed to open /dev/breakout");
- exit(1);
- }
- while (1) {
- for (i = 0; i != LEDS-1; i++) {
- set(fd, i);
- usleep(DELAY_US);
- }#define BREAKOUT_CLEAR(x) ((x) | (0 << 8))
- #define BREAKOUT_SET(x) ((x) | (1 << 8))
- int breakout_set_pins(int fd, uint8_t mask)
- {
- uint16_t val = BREAKOUT_SET(mask);
- return write(fd, &val, sizeof(val));
- }
- int breakout_clear_pins(int fd, uint8_t mask)
- {
- uint16_t val = BREAKOUT_CLEARh(mask);
- return write(fd, &val, sizeof(val));
- }
- static void set(int fd, int n)
- {
- uint16_t buf[2];
- if (n & 1) {
- buf[0] = BREAKOUT_CLEAR(0xff);
- buf[1] = BREAKOUT_SET(1 << n);
- } else {
- buf[0] = BREAKOUT_SET(0xff);
- buf[1] = BREAKOUT_CLEAR(1 << n);
- }
- write(fd, buf, sizeof(buf));
- }
- int main(int argc, char **argv)
- {
- int fd, i;
- fd = open("/dev/breakout", O_RDWR);
- if (fd < 0) {
- perror("Failed to open /dev/breakout");
- exit(1);
- }
- while (1) {
- for (i = 0; i != LEDS-1; i++) {
- set(fd, i);
- usleep(DELAY_US);
- }
- for (i = LEDS-1; i != 0; i--) {
- set(fd, i);
- usleep(DELAY_US);
- }
- }
- return 0;
- }
- for (i = LEDS-1; i != 0; i--) {
- set(fd, i);
- usleep(DELAY_US);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement