Skip to content

Commit

Permalink
Command line options for x/y offset.
Browse files Browse the repository at this point in the history
  • Loading branch information
rayner committed May 19, 2014
1 parent 3cf9212 commit 908f6ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
29 changes: 26 additions & 3 deletions fbclock.c
Expand Up @@ -4,6 +4,7 @@
* Requires: libpng
*/

#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Expand All @@ -21,9 +22,24 @@ int main(int argc, char *argv[]) {
struct framebuffer fb;

/* Display offset from top left of screen, in pixels */
/* TODO: turn into command-line option */
int x_offset = 0;
int y_offset = 0;
unsigned int x_offset = 0;
unsigned int y_offset = 0;

/* Parse command-line options */
int opt;
while ((opt = getopt(argc, argv, "x:y:")) != -1) {
switch (opt) {
case 'x':
x_offset = atoi(optarg);
break;
case 'y':
y_offset = atoi(optarg);
break;
default:
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
}

/* Set up framebuffer */
new_framebuffer(&fb, "/dev/fb0");
Expand Down Expand Up @@ -98,3 +114,10 @@ void display_time(struct tm *tp, struct framebuffer *fb, int x_offset,
return;
}


/* print_usage: print a usage message */
void print_usage(char *name) {
fprintf(stderr, "Usage: %s [-x x_offset] [-y y_offset]\n", name);
return;
}

1 change: 1 addition & 0 deletions fbclock.h
Expand Up @@ -35,3 +35,4 @@ char *short_month_filenames[] = {
/* Function prototypes */
void display_time(struct tm *tp, struct framebuffer *fb, int x_offset,
int y_offset);
void print_usage();

0 comments on commit 908f6ba

Please sign in to comment.