]> mj.ucw.cz Git - home-hw.git/commitdiff
ir-remote
authorMartin Mares <mj@ucw.cz>
Wed, 10 Jul 2019 08:15:05 +0000 (10:15 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 10 Jul 2019 08:15:05 +0000 (10:15 +0200)
ir-remote/Makefile [new file with mode: 0644]
ir-remote/decode.c [new file with mode: 0644]

diff --git a/ir-remote/Makefile b/ir-remote/Makefile
new file mode 100644 (file)
index 0000000..6c8a968
--- /dev/null
@@ -0,0 +1,8 @@
+PC := pkg-config
+UCW_CFLAGS := $(shell $(PC) --cflags libucw)
+UCW_LDFLAGS := $(shell $(PC) --libs libucw)
+
+CFLAGS=-std=gnu99 -Wall -Wextra -Wno-parentheses $(UCW_CFLAGS)
+LDFLAGS=$(UCW_LDFLAGS)
+
+all: decode
diff --git a/ir-remote/decode.c b/ir-remote/decode.c
new file mode 100644 (file)
index 0000000..1abe049
--- /dev/null
@@ -0,0 +1,55 @@
+#include <ucw/lib.h>
+#include <ucw/fastbuf.h>
+#include <ucw/unaligned.h>
+
+#include <stdio.h>
+
+int main(void)
+{
+       struct fastbuf *f = bfdopen_shared(0, 4096);
+
+       byte hdr[48];
+       breadb(f, hdr, sizeof(hdr));
+
+       uint i = 0;
+       int last = -1;
+       uint lasti = 0;
+       for (;;) {
+               byte x[2];
+               if (!bread(f, x, 2))
+                       break;
+               int a = (s16) get_u16_le(x);
+               int boo = (a >= 8000);
+               if (boo != last) {
+                       if (last >= 0) {
+                               uint len = i - lasti;
+#if 0
+                               printf("%d\t%d\t%6.3f\n", last, len, (double)len / 44100 * 1000);
+#else
+                               if (!last) {
+                                       if (len > 2000) {
+                                               putchar('\n');
+                                       } else if (len >= 26 && len <= 32) {
+                                       } else {
+                                               printf("<%d>", len);
+                                       }
+                               } else {
+                                       if (len >= 18 && len <= 24) {
+                                               putchar('0');
+                                       } else if (len >= 68 && len <= 72) {
+                                               putchar('1');
+                                       } else if (len >= 194 && len <= 200) {
+                                               putchar('^');
+                                       } else {
+                                               printf("[%d]", len);
+                                       }
+                               }
+#endif
+                       }
+                       last = boo;
+                       lasti = i;
+               }
+               i++;
+       }
+       putchar('\n');
+}