/* chaser.c -- An example of wasted cpu cycles                                                   */


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

int main(void) {

	int portdata = 3;
	int indata;
	int shiftin; 
	int fd;

	/* attempt to open i-bus device */
//	if((fd = open("/dev/i-bus0", O_RDWR)) < 0) {
//	if((fd = open("/dev/i-bus1", O_RDWR)) < 0) {
//	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);
	}

	do {
		/* send data byte to io port */
		write(fd, &portdata, 1);

		if(portdata & 0x80) {
			shiftin = 1;
		}
		else {
			shiftin = 0;
		}

		/* shift pattern left */
		portdata = 0xFF & ((portdata << 1) | shiftin);

		/* pause to let user see pattern */
//		usleep(50000);
//		usleep(125000); //  1/8sec gives 1hz across all 8
		usleep(70000);

//		read(fd, &indata, 1);

//	} while(~indata & 1);
	} 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 ;) */

}

