summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLenczu Vex <kuba.lenczowski03@gmail.com>2024-10-09 14:54:35 +0200
committerLenczu Vex <kuba.lenczowski03@gmail.com>2024-10-09 14:54:35 +0200
commit5214303228fd7d969cb58cbd9b0673d9bae0dcd1 (patch)
treefbd95d013d5071bc7e34ce5d1ff632a21441ecb4
Initial push
-rw-r--r--ibus.c39
-rw-r--r--ibus.h7
2 files changed, 46 insertions, 0 deletions
diff --git a/ibus.c b/ibus.c
new file mode 100644
index 0000000..67ac08d
--- /dev/null
+++ b/ibus.c
@@ -0,0 +1,39 @@
+#include "ibus.h"
+
+int encodeIBus(*IBusFrame frame, *channelValues vals){
+ *frame=startByteAlpha;
+ *(frame+1)=startByteAlpha;
+ for (int i=0; i<channelC*2; i++){
+ if (i%2)
+ *(frame+i+2)=(char) (*(vals+(i/2)))>>sizeof(char);
+ else
+ *(frame+i+2)=(char) *(vals+(i/2));
+
+
+}
+
+int CRC16Gen(*IBusFrame frame){
+ unsigned char i;
+ unsigned int data;
+ unsigned int crc = 0xffff;
+
+ if (length == 0)
+ return (~crc);
+
+ do{
+ for (i=0, data=(unsigned int)0xff & *data_p++;
+ i < 8;
+ i++, data >>= 1)
+ {
+ if ((crc & 0x0001) ^ (data & 0x0001))
+ crc = (crc >> 1) ^ POLY;
+ else crc >>= 1;
+ }
+ } while (--length);
+
+ crc = ~crc;
+ data = crc;
+ crc = (crc << 8) | (data >> 8 & 0xff);
+
+ return (crc);
+}
diff --git a/ibus.h b/ibus.h
new file mode 100644
index 0000000..3be61c8
--- /dev/null
+++ b/ibus.h
@@ -0,0 +1,7 @@
+#define IBusSize 34
+#define channelC 15
+#define startByteAlpha 0x20
+#define startByteBeta 0x40
+
+typedef char[IBusSize] IBusFrame
+typedef unsigned short int[15] channelValues