#include <stdio.h>	/* for printf() */
#include <sys/io.h>	/* for ioperm() */
#include <unistd.h>	/* for usleep() */

#include "port.h"

#define PORT 0x378
#define TIME 1000

void clockwise(){
	int i;	
	/* i've got one rotor cycle in 12 loops */
	for (i=0; i<12; i++){
		port_out(PORT, 0x01);	/* 0001 */
		usleep(TIME);
		port_out(PORT, 0x03);	/* 0011 */
		usleep(TIME);
		port_out(PORT, 0x02);	/* 0010 */
		usleep(TIME);
		port_out(PORT, 0x06);	/* 0110 */
		usleep(TIME);
		port_out(PORT, 0x04);	/* 0100 */
		usleep(TIME);
		port_out(PORT, 0x0c);	/* 1100 */
		usleep(TIME);
		port_out(PORT, 0x08);	/* 1000	*/
		usleep(TIME);
		port_out(PORT, 0x09);	/* 1001 */
		usleep(TIME);
	}
}

void counter_clockwise(){
	int i;
	for (i=0; i<12; i++){
		port_out(PORT, 0x08);   /* 1000 */
		usleep(TIME);
		port_out(PORT, 0x0c);   /* 1100 */
		usleep(TIME);
		port_out(PORT, 0x04);   /* 0100 */
		usleep(TIME);
		port_out(PORT, 0x06);   /* 0110 */
		usleep(TIME);
		port_out(PORT, 0x02);   /* 0010 */
		usleep(TIME);
		port_out(PORT, 0x03);   /* 0011 */
		usleep(TIME);
		port_out(PORT, 0x01);   /* 0001 */
		usleep(TIME);
		port_out(PORT, 0x09);   /* 1001 */
		usleep(TIME);
	}
}


int main(){
	int i;
	if (ioperm(PORT, 1, 1) == -1)
   		printf("There's something wrong...\n");
	
	
	for (i=0; i<30; i++)
		clockwise();
	
	return 0;
}

