/* RESETER.c (c) 2004 Marcin Lukasik <marcin@milea.pl> */

#include <sys/io.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#include "port.h"

#define ERR " \033[0;22m\033[31m-\033[31;1m>\033[31;22m-\033[0m "

int main(int argc, char **argv) {

     unsigned int t = 0;

     if(getuid() != 0) {
      printf("ERROR: To access LPT from Linux you must run this program as root.");
      exit(-1);
     }

    if(argc != 2) {
	printf("%sUsage: %s reset_time_in_sec\n", ERR, argv[0]);
	exit(-1);
    }


    t = atoi(argv[1]) * 1000000;    


    ioperm(0x378, 3, 1);  // open port
    port_out(0x378, 255); // HI on b2-b9 (relay open - RESET)
    usleep(t);            // sleep for t seconds
    port_out(0x378, 0);   // LOW on (relay closed - NORMAL OPERATION)

    return 0;
}

