From: Tomas Mudrunka Date: Mon, 21 Oct 2013 20:57:57 +0000 (+0200) Subject: Beermeter X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=1e697494e8ab6554b87982e15bd5abe3b5b8f67f;p=mirrors%2FPrograms.git Beermeter --- diff --git a/c/beermeter/Makefile b/c/beermeter/Makefile new file mode 100644 index 0000000..18cfc57 --- /dev/null +++ b/c/beermeter/Makefile @@ -0,0 +1 @@ +all: audio diff --git a/c/beermeter/accounts/.gitignore b/c/beermeter/accounts/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/c/beermeter/accounts/.gitignore @@ -0,0 +1 @@ +* diff --git a/c/beermeter/audio.c b/c/beermeter/audio.c new file mode 100644 index 0000000..839f47d --- /dev/null +++ b/c/beermeter/audio.c @@ -0,0 +1,22 @@ +#include + +#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 index 0000000..8ecffca --- /dev/null +++ b/c/beermeter/audio.sh @@ -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 index 0000000..e6c7e6a --- /dev/null +++ b/c/beermeter/beermeter.sh @@ -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