Beermeter
authorTomas Mudrunka <tomas@mudrunka.cz>
Mon, 21 Oct 2013 20:57:57 +0000 (22:57 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Mon, 21 Oct 2013 20:57:57 +0000 (22:57 +0200)
c/beermeter/Makefile [new file with mode: 0644]
c/beermeter/accounts/.gitignore [new file with mode: 0644]
c/beermeter/audio.c [new file with mode: 0644]
c/beermeter/audio.sh [new file with mode: 0755]
c/beermeter/beermeter.sh [new file with mode: 0755]

diff --git a/c/beermeter/Makefile b/c/beermeter/Makefile
new file mode 100644 (file)
index 0000000..18cfc57
--- /dev/null
@@ -0,0 +1 @@
+all: audio
diff --git a/c/beermeter/accounts/.gitignore b/c/beermeter/accounts/.gitignore
new file mode 100644 (file)
index 0000000..72e8ffc
--- /dev/null
@@ -0,0 +1 @@
+*
diff --git a/c/beermeter/audio.c b/c/beermeter/audio.c
new file mode 100644 (file)
index 0000000..839f47d
--- /dev/null
@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+#define SAMPLE_MIN -128
+#define SAMPLE_MAX 127
+
+int main() {
+       unsigned long count=0;
+       char sample, sample_last=SAMPLE_MIN, x=0, y=0;
+       while(!feof(stdin)) {
+               fread(&sample,1,1,stdin);
+               if(
+                       (sample_last < 0 && sample > SAMPLE_MAX/2)
+                       || (sample_last >= 0 && sample < SAMPLE_MIN/2)
+               )
+               {
+                       putchar('.');
+                       //printf("\r%lu    ", ++count);
+                       fflush(stdout);
+                       sample_last=sample;
+               }
+       }
+}
diff --git a/c/beermeter/audio.sh b/c/beermeter/audio.sh
new file mode 100755 (executable)
index 0000000..8ecffca
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+PATH="$PATH:./"
+arecord -c 1 -f S8 -r 8000 -t raw 2>/dev/null | audio
diff --git a/c/beermeter/beermeter.sh b/c/beermeter/beermeter.sh
new file mode 100755 (executable)
index 0000000..e6c7e6a
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/sh
+title='Beer-O-Meter'
+accounts='./accounts'
+backend='./audio.sh'
+tmp="/tmp/beertmp-$$";
+dialog=$(which dialog);
+
+beer_stat() {
+       echo $(wc -c "$accounts/$1" | cut -d ' ' -f 1) piv
+}
+
+add_account() {
+       "$dialog" --inputbox "New account name" 0 0 2>"$tmp"
+       [ $? = 0 ] && touch "$accounts/$(cat "$tmp")";
+}
+
+servis_menu() {
+       $dialog --menu "$title servis" 0 0 0 new "Novy stamgast" exit "Konec party" 2>"$tmp"
+       option="$(cat "$tmp")"
+
+       case $option in
+               new)
+                       add_account
+                       ;;
+               exit)
+                       exit
+                       ;;
+       esac
+}
+
+beer_menu() {
+       echo -n > "$accounts/.totals"
+       ls -1 --group-directories-first "$accounts" | while read i; do
+               echo -n "$i"; echo -ne "\x00";
+               echo -n $(beer_stat "$i");  echo -ne "\x00"
+               echo -e "$i\t$(beer_stat "$i")" >> "$accounts/.totals"
+       done | xargs -0 $dialog --menu "$title stamgasti" 0 0 0
+}
+
+main_menu() {
+       while true; do
+               beer_menu 2>"$tmp"
+               [ "$?" = "0" ] && {
+                       stamgast="$(cat "$tmp")"
+                       echo == Cepuje stamgast $stamgast, ukonci ctrl+c ==
+                       "$backend" | tee -a "$accounts/$stamgast"
+                       true
+               } || servis_menu
+       done
+}
+
+main_menu
This page took 0.199802 seconds and 4 git commands to generate.