diff --git a/grove_lcd.c b/grove_lcd.c index 0545ab0..5f925a5 100644 --- a/grove_lcd.c +++ b/grove_lcd.c @@ -84,31 +84,69 @@ void set_backlight(int r, int g, int b) { } int main(int argc, char *argv[]) { - int l1p = 1; - int l2p = 1; - int option; + int l1_x = 1; + char *l1_message = NULL; + int l2_x = 1; + char *l2_message = NULL; + int r = 1; + int g = 0; + int b = 0; - while ((option = getopt (argc, argv, "l1:l2:")) != -1) { - switch (option) { - case '1': - l1p = atoi(optarg); - break; - case '2': - l2p = atoi(optarg); - break; - default: - fprintf(stderr, "Usage: %s -l1 -l2 \n", argv[0]); - exit(EXIT_FAILURE); + static struct option long_options[] = { + {"x1", required_argument, 0, 'x'}, + {"m1", required_argument, 0, 'm'}, + {"x2", required_argument, 0, 'X'}, + {"m2", required_argument, 0, 'M'}, + {"r", required_argument, 0, 'r'}, + {"g", required_argument, 0, 'g'}, + {"b", required_argument, 0, 'b'}, + {0, 0, 0, 0} // Terminating entry + }; + + int option_index = 0; + int c; + + while ((c = getopt_long(argc, argv, "x:m:X:M:r:g:b:", long_options, &option_index)) != -1) { + switch (c) { + case 'x': + l1_x = atoi(optarg); + break; + case 'm': + l1_message = optarg; + break; + case 'X': + l2_x = atoi(optarg); + break; + case 'M': + l2_message = optarg; + break; + case 'r': + r = atoi(optarg); + break; + case 'g': + g = atoi(optarg); + break; + case 'b': + b = atoi(optarg); + break; + case '?': //unregnoniced inputs or missing args + break; + default: + fprintf(stderr, "Usage: %s --x1 --x1_message \n", argv[0]); + exit(EXIT_FAILURE); + break; } } - printf("l1p = %d, l2p = %d\n", l1p, l2p); - int file; - set_backlight(1, 0, 0); + set_backlight(r, g, b); file = i2c_init(MPC9808_BUS, DISPLAY_TEXT_ADDR); init_display(file); - write_to_display_xy(file, l1p, 1, "Mercantec"); - write_to_display_xy(file, l2p, 2, "Mercantec"); + if (l1_message != 0) { + write_to_display_xy(file, l1_x, 1, l1_message); + } + if (l2_message != 0) { + write_to_display_xy(file, l2_x, 2, l2_message); + } return 0; }