]> gitweb.hamatoma.de Git - cpidjinn/commitdiff
server: option --test
authorhama <hama@siduction.net>
Tue, 14 Jun 2016 20:24:20 +0000 (22:24 +0200)
committerhama <hama@siduction.net>
Tue, 14 Jun 2016 20:24:20 +0000 (22:24 +0200)
Server/cpidjinn.cpp

index cfa5c8f481967130b8c23344252e7c55dfc25141..380355ea490c06e86f3418e3f344196e6f315c8c 100644 (file)
@@ -1,5 +1,30 @@
 #include "cpidjinn.hpp"
 
+void blink(PinNumber pin, int count, int duration, Logger* logger){
+       GPIOProcessor proc(logger);
+       for (int ix = 0; ix < count; ix++){
+               proc.writeToGPIO(pin, psHigh);
+               usleep(duration * 1000);
+               proc.writeToGPIO(pin, psLow);
+               usleep(duration * 1000);
+       }
+}
+void test(int argc, char** argv, Logger* logger){
+       if (argc == 0 || strcmp(argv[0], "blink") == 0){
+               int count = 20;
+               int duration = 1000;
+               PinNumber pin = pinRPi2_11;
+
+               if (argc > 1)
+                       count = pinNameToNumber(argv[1]);
+               if (argc > 2)
+                       count = atol(argv[2]);
+               if (argc > 3)
+                       duration = atol(argv[3]);;
+               blink(pin, count, duration, logger);
+       }
+       exit(0);
+}
 /**
  * Main function.
  *
@@ -16,6 +41,8 @@ int main(int argc, char** argv){
                char* arg = argv[1];
                if (strcmp(arg, "-s") == 0 || strcmp(arg, "--simulation")){
                        simulation = true;
+               } else if (strcmp(arg, "-t") == 0 || strcmp(arg, "--test")){
+                       test(argc - 2, argv + 2, &logger);
                } else {
                        logger.sayf(LOG_ERROR, "unknown option: %s", arg);
                }