#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
+#include <getopt.h>
#define PAGE_SIZE (4*1024)
#define BLOCK_SIZE (4*1024)
#define CLOSE_IN 20
-int main()
+int main(int argc, char *argv[])
{
int i;
// Set up gpi pointer for direct register access
setup_io();
+ // Initialize the IO pins.
INP_GPIO(OPEN_OUT); // must use INP_GPIO before we can use OUT_GPIO
OUT_GPIO(OPEN_OUT);
INP_GPIO(OPEN_IN);
OUT_GPIO(CLOSE_OUT);
INP_GPIO(CLOSE_IN);
- GPIO_SET = 1 << OPEN_OUT; // Close the switch
- sleep(1);
- GPIO_CLR = 1 << OPEN_OUT; // Open the switch
+ // Scan the arguments.
+
+ const char *usage = "Usage: curtain [-c close_seconds] [-o open_seconds]\n";
+
+ int option;
+ int pulse_time;
+
+
+ while ((option = getopt(argc, argv, "c:o:")) != -1)
+ {
+ switch (option)
+ {
+ case 'c':
+ pulse_time = atoi(optarg);
+ GPIO_SET = 1 << CLOSE_OUT; // Close the switch
+ sleep(pulse_time);
+ GPIO_CLR = 1 << CLOSE_OUT; // Open the switch
+ break;
+
+ case 'o':
+ pulse_time = atoi(optarg);
+ GPIO_SET = 1 << OPEN_OUT; // Close the switch
+ sleep(pulse_time);
+ GPIO_CLR = 1 << OPEN_OUT; // Open the switch
+ break;
+
+ case '?':
+ case ':':
+ fprintf(stderr, "%s", usage);
+ exit(1);
+
+ }
+ }
+
return 0;
}