Improved output format possibilities
authorTomas Mudrunka <tomas@mudrunka.cz>
Thu, 2 Aug 2012 16:32:49 +0000 (18:32 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Thu, 2 Aug 2012 16:32:49 +0000 (18:32 +0200)
c/goertzel/dtmf.sh
c/goertzel/goertzel.c
c/goertzel/sleepmon.sh

index 80a9d5926959a9c2c285f946469228b973c4d21e..2abc22b5b9c03f3fbba03a4ff625f729246b5c46 100755 (executable)
@@ -8,7 +8,7 @@
 
 tresh=10
 last='';
-./goertzel -n -q -l -r 8000 -d 20 -t $tresh -f 697 -f 770 -f 852 -f 941 -f 1209 -f 1336 -f 1477 -f 1633 $@ | while read line; do
+./goertzel -n -q -l -r 8000 -d 20 -t $tresh -f 697 -f 770 -f 852 -f 941 -f 1209 -f 1336 -f 1477 -f 1633 $@ | while read line; do
        #echo "$line";
 
        #Get time
@@ -24,16 +24,6 @@ last='';
        g="$(echo "$line" | cut -f 8)";
        h="$(echo "$line" | cut -f 9)";
 
-       #Compare values to treshold
-       test $a -gt $tresh && a=true || a=false
-       test $b -gt $tresh && b=true || b=false
-       test $c -gt $tresh && c=true || c=false
-       test $d -gt $tresh && d=true || d=false
-       test $e -gt $tresh && e=true || e=false
-       test $f -gt $tresh && f=true || f=false
-       test $g -gt $tresh && g=true || g=false
-       test $h -gt $tresh && h=true || h=false
-
        #echo "$pos: $a $b $c $d $e $f $g $h";
        state="$a$b$c$d$e$f$g$h";
 
index 96458a5b83c7cc2cacf5bd4536276df77c17221c..95e30992663201fe3b2f4f4cf50b25a02b9c03e3 100644 (file)
@@ -70,7 +70,11 @@ void print_help(char ** argv) {
                "\t-f <freq>\tAdd frequency in Hz to detect (use multiple times, if no added 440 Hz will be...)\n"
                "\n"
                "\t-t <treshold>\tSet treshold (used to hide magnitudes lower than treshold) (defaults -1)\n"
-               "\t-n\t\tPrint integers rather than floats\n"
+               "\t-n <format>\tSet output format\n"
+               "\t\tf: float (default)\n"
+               "\t\ti: integer\n"
+               "\t\tb: binary (0|1)\n"
+               "\t\tB: Boolean (false|true)\n"
                "\t-l\t\tDo not repeat values while still over treshold\n"
                "\t-b\t\tDo not print first value that will fall under treshold\n"
                "\t-q\t\tQuiet mode: print only values\n"
@@ -107,12 +111,12 @@ int main(int argc, char ** argv) {
        int treshold = -1;
        char noreturn = 0;
        char repeat = 1;
-       char integers=0;
+       char format=0;
        char verbose=1;
        int freqs[argc+1]; freqs[0]=-1;
 
        int opt;
-       while ((opt = getopt(argc, argv, "?i:o:a:r:c:d:f:t:nlbq")) != -1) {
+       while ((opt = getopt(argc, argv, "?i:o:a:r:c:d:f:t:n:lbq")) != -1) {
                switch (opt) {
                        case 'i':
                                freopen(optarg, "r", stdin);
@@ -139,7 +143,7 @@ int main(int argc, char ** argv) {
                                treshold = atoi(optarg);
                                break;
                        case 'n':
-                               integers = 1;
+                               format = optarg[0];
                                break;
                        case 'l':
                                repeat = 0;
@@ -208,10 +212,21 @@ int main(int argc, char ** argv) {
                        printf("%8.2f", position);
                        for(i=0;freqs[i]!=-1;i++) {
                                printf("\t");
-                               if(integers)
-                                       printf("%d",(int)power[i]);
-                               else
-                                       printf("%.4f",power[i]);
+                               switch(format) {
+                                       case 'i':
+                                               printf("%d",(int)power[i]);
+                                               break;
+                                       case 'b':
+                                               printf("%d",power[i]>treshold);
+                                               break;
+                                       case 'B':
+                                               if(power[i]>treshold) printf("true");
+                                                       else printf("false");
+                                               break;
+                                       case 'f':
+                                       default:
+                                               printf("%.4f",power[i]);
+                               }
                        }
                        puts("");
                        fflush(stdout);
index a5d9d8168c790f33924d26ed3d88869b0e9d1299..3ccc670a9d2e7d909e5deec2a2c0fe443d91a8b3 100755 (executable)
@@ -22,7 +22,7 @@ while getopts "s" OPT; do
        test "$OPT" == 's' && screen=true;
 done
 echo "Writing to file: $out";
-arecord | ./goertzel -n -q -l -t $tresh -d 4 | while read line; do
+arecord | ./goertzel -n -q -l -t $tresh -d 4 | while read line; do
        date="$(date +%s)"
        time="$(echo "$line" | cut -f 1)"
        level="$(echo "$line" | cut -f 2)"
This page took 0.141654 seconds and 4 git commands to generate.