Pārlūkot izejas kodu

Added operationmode to list controllers (-L)

Fredrik Haikarainen 10 gadus atpakaļ
vecāks
revīzija
b60192102d
2 mainītis faili ar 43 papildinājumiem un 4 dzēšanām
  1. 4
    1
      include/light.h
  2. 39
    3
      src/light.c

+ 4
- 1
include/light.h Parādīt failu

62
   LIGHT_ADD,
62
   LIGHT_ADD,
63
   LIGHT_SUB,
63
   LIGHT_SUB,
64
   LIGHT_PRINT_HELP,   /* Prints help and exits  */
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
 } LIGHT_OP_MODE;
67
 } LIGHT_OP_MODE;
67
 
68
 
68
 typedef enum LIGHT_VAL_MODE {
69
 typedef enum LIGHT_VAL_MODE {
139
 
140
 
140
 LIGHT_BOOL light_setMinCap(char const *controller, unsigned long v);
141
 LIGHT_BOOL light_setMinCap(char const *controller, unsigned long v);
141
 
142
 
143
+LIGHT_BOOL light_listControllers();
144
+
142
 #endif /* LIGHT_H */
145
 #endif /* LIGHT_H */

+ 39
- 3
src/light.c Parādīt failu

31
 
31
 
32
   unsigned long specLen = 0;
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
     switch(currFlag)
36
     switch(currFlag)
37
     {
37
     {
61
         ASSERT_OPSET();
61
         ASSERT_OPSET();
62
         light_Configuration.operationMode = LIGHT_SUB;
62
         light_Configuration.operationMode = LIGHT_SUB;
63
         break;
63
         break;
64
+      case 'L':
65
+        ASSERT_OPSET();
66
+        light_Configuration.operationMode = LIGHT_LIST_CTRL;
64
 
67
 
65
       /* -- Targets -- */
68
       /* -- Targets -- */
66
       case 'b':
69
       case 'b':
185
   printf("  -G:\t\tGet value (default)\n");
188
   printf("  -G:\t\tGet value (default)\n");
186
   printf("  -S:\t\tSet value\n");
189
   printf("  -S:\t\tSet value\n");
187
   printf("  -A:\t\tAdd value\n");
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
   printf("Targets (can not be used in conjunction):\n");
194
   printf("Targets (can not be used in conjunction):\n");
191
   printf("  -b:\t\tBrightness (default)\n  \t\tUsed with [GSAU]\n\n");
195
   printf("  -b:\t\tBrightness (default)\n  \t\tUsed with [GSAU]\n\n");
216
     return FALSE;
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
       return TRUE;
226
       return TRUE;
222
   }
227
   }
292
     return TRUE;
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
   /* Prepare variables */
307
   /* Prepare variables */
296
 
308
 
297
   /* -- First, get the current, min and max values directly from controller/configuration (raw values) */
309
   /* -- First, get the current, min and max values directly from controller/configuration (raw values) */
412
         case LIGHT_GET:
424
         case LIGHT_GET:
413
         case LIGHT_PRINT_HELP:
425
         case LIGHT_PRINT_HELP:
414
         case LIGHT_PRINT_VERSION:
426
         case LIGHT_PRINT_VERSION:
427
+        case LIGHT_LIST_CTRL:
415
           break;
428
           break;
416
       }
429
       }
417
 
430
 
731
   free(mincapPath);
744
   free(mincapPath);
732
   return TRUE;
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
+}