From 392406805b82bcfae3b1e577b2db84f4d7936f81 Mon Sep 17 00:00:00 2001 From: hama Date: Tue, 14 Jun 2016 22:24:20 +0200 Subject: [PATCH] server: option --test --- Server/cpidjinn.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Server/cpidjinn.cpp b/Server/cpidjinn.cpp index cfa5c8f..380355e 100644 --- a/Server/cpidjinn.cpp +++ b/Server/cpidjinn.cpp @@ -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); } -- 2.39.5