Procházet zdrojové kódy

Added operationmode to list controllers (-L)

Fredrik Haikarainen před 10 roky
rodič
revize
b60192102d
2 změnil soubory, kde provedl 43 přidání a 4 odebrání
  1. 4
    1
      include/light.h
  2. 39
    3
      src/light.c

+ 4
- 1
include/light.h Zobrazit soubor

@@ -62,7 +62,8 @@ typedef enum LIGHT_OP_MODE {
62 62
   LIGHT_ADD,
63 63
   LIGHT_SUB,
64 64
   LIGHT_PRINT_HELP,   /* Prints help and exits  */
65
-  LIGHT_PRINT_VERSION /* Prints version info and exits */
65
+  LIGHT_PRINT_VERSION, /* Prints version info and exits */
66
+  LIGHT_LIST_CTRL
66 67
 } LIGHT_OP_MODE;
67 68
 
68 69
 typedef enum LIGHT_VAL_MODE {
@@ -139,4 +140,6 @@ LIGHT_BOOL light_getMinCap(char const *controller, LIGHT_BOOL *hasMinCap, unsign
139 140
 
140 141
 LIGHT_BOOL light_setMinCap(char const *controller, unsigned long v);
141 142
 
143
+LIGHT_BOOL light_listControllers();
144
+
142 145
 #endif /* LIGHT_H */

+ 39
- 3
src/light.c Zobrazit soubor

@@ -31,7 +31,7 @@ LIGHT_BOOL light_parseArguments(int argc, char** argv)
31 31
 
32 32
   unsigned long specLen = 0;
33 33
 
34
-  while((currFlag = getopt(argc, argv, "HhVGSAUbmcas:prv:")) != -1)
34
+  while((currFlag = getopt(argc, argv, "HhVGSAULbmcas:prv:")) != -1)
35 35
   {
36 36
     switch(currFlag)
37 37
     {
@@ -61,6 +61,9 @@ LIGHT_BOOL light_parseArguments(int argc, char** argv)
61 61
         ASSERT_OPSET();
62 62
         light_Configuration.operationMode = LIGHT_SUB;
63 63
         break;
64
+      case 'L':
65
+        ASSERT_OPSET();
66
+        light_Configuration.operationMode = LIGHT_LIST_CTRL;
64 67
 
65 68
       /* -- Targets -- */
66 69
       case 'b':
@@ -185,7 +188,8 @@ void light_printHelp(){
185 188
   printf("  -G:\t\tGet value (default)\n");
186 189
   printf("  -S:\t\tSet value\n");
187 190
   printf("  -A:\t\tAdd value\n");
188
-  printf("  -U:\t\tSubtract value\n\n");
191
+  printf("  -U:\t\tSubtract value\n");
192
+  printf("  -L:\t\tList controllers\n\n");
189 193
   
190 194
   printf("Targets (can not be used in conjunction):\n");
191 195
   printf("  -b:\t\tBrightness (default)\n  \t\tUsed with [GSAU]\n\n");
@@ -216,7 +220,8 @@ LIGHT_BOOL light_initialize(int argc, char** argv)
216 220
     return FALSE;
217 221
   }
218 222
 
219
-  if(light_Configuration.operationMode == LIGHT_PRINT_HELP || light_Configuration.operationMode == LIGHT_PRINT_VERSION)
223
+  /* Just return true for operation modes that do not need initialization */
224
+  if(light_Configuration.operationMode == LIGHT_PRINT_HELP || light_Configuration.operationMode == LIGHT_PRINT_VERSION || light_Configuration.operationMode == LIGHT_LIST_CTRL)
220 225
   {
221 226
       return TRUE;
222 227
   }
@@ -292,6 +297,13 @@ LIGHT_BOOL light_execute()
292 297
     return TRUE;
293 298
   }
294 299
 
300
+  if(light_Configuration.operationMode == LIGHT_LIST_CTRL)
301
+  {
302
+    /* listControllers() can return FALSE, but only if it does not find any controllers. That is not enough for an unsuccessfull run. */
303
+    light_listControllers();
304
+    return TRUE;
305
+  }
306
+
295 307
   /* Prepare variables */
296 308
 
297 309
   /* -- First, get the current, min and max values directly from controller/configuration (raw values) */
@@ -412,6 +424,7 @@ LIGHT_BOOL light_execute()
412 424
         case LIGHT_GET:
413 425
         case LIGHT_PRINT_HELP:
414 426
         case LIGHT_PRINT_VERSION:
427
+        case LIGHT_LIST_CTRL:
415 428
           break;
416 429
       }
417 430
 
@@ -731,3 +744,26 @@ LIGHT_BOOL light_setMinCap(char const * controller, unsigned long v)
731 744
   free(mincapPath);
732 745
   return TRUE;
733 746
 }
747
+
748
+LIGHT_BOOL light_listControllers()
749
+{
750
+  LIGHT_BOOL foundController = FALSE;
751
+
752
+  while(light_iterateControllers())
753
+  {
754
+    if(!foundController)
755
+    {
756
+      foundController = TRUE;
757
+    }
758
+
759
+    printf("%s\n", light_currentController);
760
+  }
761
+
762
+  if(!foundController)
763
+  {
764
+    LIGHT_WARN("no controllers found, either check your system or your permissions");
765
+    return FALSE;
766
+  }
767
+
768
+  return TRUE;
769
+}