/* kernelspace pulse generator -- An example of wasted cpu cycles */ 
/* infinite loop */
/* see pulse1.c for single pulse suitable for procomp "heart throb" */

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h> /* contains the prototype for usleep */

int main(void) {

  int indata;
  int fd;
  int p;  // portdata to send to parallel port
  int temp = 0x01;
  int i;

  /* attempt to open i-bus device */
//if((fd = open("/dev/ibus0", O_RDWR)) < 0) {
  if((fd = open("/dev/ibus1", O_RDWR)) < 0) {
    fprintf(stderr, "Cannot open i-bus device, aborting...\n");
    exit(1);
  }

while (1) {
  // this is short pulse
  p = 0x00;
  temp = 0x01;
  for (i=0;i<4;i++){
    p = p | temp;
    write(fd, &p, 1);
    temp = temp << 1;
    usleep(30000);
  }
  for (i=0;i<=4;i++){
    write(fd, &p, 1);
    p = (p >> 1);
    usleep(30000);
  }

  usleep(300000);

  // this is long pulse
  p = 0x00;
  temp = 0x01;
  for (i=0;i<8;i++){
    p = p | temp;
    write(fd, &p, 1);
    temp = temp << 1;
    usleep(30000);
  }
  for (i=0;i<=8;i++){
    write(fd, &p, 1);
    p = (p >> 1);
    usleep(30000);
  }
  usleep(1000000);
} // end while 1

	/* attempt to close i-bus device */
	if(close(fd) < 0) {
		fprintf(stderr, "Cannot close i-bus device, aborting...\n");
		exit(1);
	}

	return(0);  /* just to be nice ;) */

}

