]> mj.ucw.cz Git - osdd.git/commitdiff
A bit of debugging and also setting of default durations
authorMartin Mares <mj@ucw.cz>
Sat, 17 Jul 2010 15:46:40 +0000 (17:46 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 17 Jul 2010 15:46:40 +0000 (17:46 +0200)
osdd.c

diff --git a/osdd.c b/osdd.c
index 4659493ad074cf00df8783d961c6b9ddcc401688..98a35a6d09d23285afed741cc992664e8b264b32 100644 (file)
--- a/osdd.c
+++ b/osdd.c
 
 static xosd *osd;
 
+typedef uint64_t timestamp_t;
+static timestamp_t now;
+
+/*** Options ***/
+
 static int num_lines = 4;
 static char *font_name = "-bitstream-bitstream vera sans-bold-r-normal-*-*-320-*-*-p-*-*";
 static char *default_color = "green";
 static char *default_outline_color = "black";
+static int default_duration = 1000;
+static int default_min_duration = 1000;
 
-typedef uint64_t timestamp_t;
-static timestamp_t now;
+static const char short_opts[] = "c:d:f:l:m:o:";
+
+static const struct option long_opts[] = {
+  { "color",           required_argument,      NULL,   'c' },
+  { "duration",                required_argument,      NULL,   'd' },
+  { "font",            required_argument,      NULL,   'f' },
+  { "lines",           required_argument,      NULL,   'l' },
+  { "min-duration",    required_argument,      NULL,   'm' },
+  { "outline-color",   required_argument,      NULL,   'o' },
+  { NULL,      0,                      NULL,   0   },
+};
+
+static void NONRET
+usage(void)
+{
+  fprintf(stderr, "Usage: osdd <options>\n\n\
+Options:\n\
+-c, --color=<c>\t\tDefault color (#rgb, #rrggbb or a name from rgb.txt)\n\
+-d, --duration=<ms>\tDefault message duration in milliseconds\n\
+-f, --font=<f>\t\tFont to use for the OSD\n\
+-l, --lines=<n>\t\tNumber of lines of the OSD\n\
+-m, --min-duration=<ms>\tDefault minimum message duration in milliseconds\n\
+-o, --outline-color=<c>\tDefault outline color\n\
+");
+  exit(1);
+}
+
+static void
+parse_opts(int argc, char **argv)
+{
+  int opt;
+  while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) >= 0)
+    switch (opt)
+      {
+      case 'c':
+       default_color = optarg;
+       break;
+      case 'd':
+       default_duration = atoi(optarg);
+       break;
+      case 'f':
+       font_name = optarg;
+       break;
+      case 'l':
+       num_lines = atoi(optarg);
+       if (num_lines < 1)
+         usage();
+       break;
+      case 'm':
+       default_min_duration = atoi(optarg);
+       break;
+      case 'o':
+       default_outline_color = optarg;
+       break;
+      default:
+       usage();
+      }
+
+  if (optind < argc)
+    usage();
+}
 
 /*** Displaying of messages ***/
 
@@ -39,7 +105,9 @@ struct msg {
 static void
 display_msg(struct msg *msg)
 {
-  msg->min_light = msg->max_light = now + 1000;
+  DBG("## Displaying message\n");
+  msg->min_light = now + default_min_duration;
+  msg->max_light = now + default_duration;
   xosd_set_colour(osd, default_color);
   xosd_set_outline_colour(osd, default_outline_color);
 
@@ -63,6 +131,7 @@ display_msg(struct msg *msg)
          key = "";
          val = line;
        }
+      DBG("\t%s:%s\n", key, val);
 
       if (!key[0])
        {
@@ -87,6 +156,8 @@ display_msg(struct msg *msg)
        xosd_set_colour(osd, val);
       else if (!strcmp(key, "outline-color"))
        xosd_set_outline_colour(osd, val);
+      else
+       DBG("\tPARSE ERROR\n");
 
       line = nl;
     }
@@ -98,6 +169,7 @@ display_msg(struct msg *msg)
 static void
 hide_msg(struct msg *msg)
 {
+  DBG("## Hiding message\n");
   for (int i=0; i<num_lines; i++)
     xosd_display(osd, i, XOSD_string, "");
   xosd_hide(osd);
@@ -111,7 +183,7 @@ static struct msg *current_msg, *first_msg, *last_msg;
 static void
 enqueue_msg(unsigned char *buf, int len)
 {
-  DBG("[%.*s]\n", len, buf);
+  DBG("Received: [%.*s]\n", len, buf);
   if (!len || buf[len-1] != '\n')
     return;
 
@@ -146,60 +218,6 @@ parse_input(unsigned char *buf, int len)
     }
 }
 
-/*** Options ***/
-
-static const char short_opts[] = "c:f:l:o:";
-
-static const struct option long_opts[] = {
-  { "color",   required_argument,      NULL,   'c' },
-  { "font",    required_argument,      NULL,   'f' },
-  { "lines",   required_argument,      NULL,   'l' },
-  { "outline-color", required_argument,        NULL,   'o' },
-  { NULL,      0,                      NULL,   0   },
-};
-
-static void NONRET
-usage(void)
-{
-  fprintf(stderr, "Usage: osdd <options>\n\n\
-Options:\n\
--c, --color=<c>\t\tDefault color (#rgb, #rrggbb or a name from rgb.txt)\n\
--f, --font=<f>\t\tFont to use for the OSD\n\
--l, --lines=<n>\t\tNumber of lines of the OSD\n\
--o, --outline-color=<c>\tDefault outline color\n\
-");
-  exit(1);
-}
-
-static void
-parse_opts(int argc, char **argv)
-{
-  int opt;
-  while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) >= 0)
-    switch (opt)
-      {
-      case 'c':
-       default_color = optarg;
-       break;
-      case 'f':
-       font_name = optarg;
-       break;
-      case 'l':
-       num_lines = atoi(optarg);
-       if (num_lines < 1)
-         usage();
-       break;
-      case 'o':
-       default_outline_color = optarg;
-       break;
-      default:
-       usage();
-      }
-
-  if (optind < argc)
-    usage();
-}
-
 /*** Main loop ***/
 
 int
@@ -261,7 +279,7 @@ main(int argc, char **argv)
            }
        }
 
-      DBG("Waiting for %d ms\n", (int)(wait_until - now));
+      DBG("... waiting for %d ms\n", (int)(wait_until - now));
       poll(&pfd, 1, wait_until - now);
       if (pfd.revents & POLLIN)
        {