using namespace std; #include #include #include #include #include #include static long pdelay; // busy loop delay static void delay() { for (long i=0; i> 1; // right shift by one bit } write(fd, bufhigh, 1); // stop bit delay(); } int main(int argc, char *argv[]) { // read in pulse delay cin >> pdelay; //cout << "pdelay = " << pdelay << endl; // read in two bytes uint8_t byte1 = 0x00, byte2 = 0x00; int tmp; cin >> tmp; for (int i=0; i> tmp; for (int i=0; i> reps; // gpio0/2 pin are dead on geode2 due to overvoltage accident // the pins are ok on geode1 int fd = open("/dev/gpio0", O_WRONLY); if (fd == -1) { cerr << "open /dev/gpio0 failed" << endl; exit(1); } else { //cout << "open /dev/gpio0 ok" << endl; } // turn pin output on char buf[1]; buf[0] = 'O'; ssize_t nwri = write(fd, buf, 1); if (nwri != 1) { cerr << "failed to turn gpio0 pin on" << endl; exit(1); } else { //cout << "turned gpio0 pin on" << endl; } // set pin output high char bufhigh[1]; bufhigh[0] = '1'; if (write(fd, bufhigh, 1) != 1) { cerr << "failed to set pin high" << endl; exit(1); } else { //cerr << "set pin high, sleeping for one second" << endl; //sleep(1); } // loop forever while (reps--) { writebyte(fd, 0xff); writebyte(fd, byte1); writebyte(fd, byte2); writebyte(fd, checksum); } return 0; }