diff options
| author | Lenczu Vex <kuba.lenczowski03@gmail.com> | 2024-10-09 14:54:35 +0200 |
|---|---|---|
| committer | Lenczu Vex <kuba.lenczowski03@gmail.com> | 2024-10-09 14:54:35 +0200 |
| commit | 5214303228fd7d969cb58cbd9b0673d9bae0dcd1 (patch) | |
| tree | fbd95d013d5071bc7e34ce5d1ff632a21441ecb4 | |
Initial push
| -rw-r--r-- | ibus.c | 39 | ||||
| -rw-r--r-- | ibus.h | 7 |
2 files changed, 46 insertions, 0 deletions
@@ -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); +} @@ -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 |
