mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-22 10:10:45 +00:00
Better parsing on the Bluetooth game controller packets
This commit is contained in:
parent
6fe0e6682d
commit
63013786da
1 changed files with 16 additions and 13 deletions
|
@ -207,9 +207,9 @@ struct Object *detectCollision(struct Object *with, int xoff, int yoff)
|
||||||
for (int i=0; i<numobjs;i++) {
|
for (int i=0; i<numobjs;i++) {
|
||||||
if (&objects[i] != with && objects[i].alive == 1) {
|
if (&objects[i] != with && objects[i].alive == 1) {
|
||||||
if (with->x + xoff > objects[i].x + objects[i].width || objects[i].x > with->x + xoff + with->width) {
|
if (with->x + xoff > objects[i].x + objects[i].width || objects[i].x > with->x + xoff + with->width) {
|
||||||
// with is too far left or right to ocllide
|
// with is too far left or right to collide
|
||||||
} else if (with->y + yoff > objects[i].y + objects[i].height || objects[i].y > with->y + yoff + with->height) {
|
} else if (with->y + yoff > objects[i].y + objects[i].height || objects[i].y > with->y + yoff + with->height) {
|
||||||
// with is too far up or down to ocllide
|
// with is too far up or down to collide
|
||||||
} else {
|
} else {
|
||||||
// Collision!
|
// Collision!
|
||||||
return &objects[i];
|
return &objects[i];
|
||||||
|
@ -313,22 +313,25 @@ void acl_poll()
|
||||||
unsigned char h1 = bt_readByte();
|
unsigned char h1 = bt_readByte();
|
||||||
unsigned char h2 = bt_readByte();
|
unsigned char h2 = bt_readByte();
|
||||||
|
|
||||||
unsigned int length = h1 | (h2 << 8);
|
unsigned int dlen = h1 | (h2 << 8);
|
||||||
unsigned char data[length];
|
unsigned char data[dlen];
|
||||||
|
|
||||||
for (int i=0;i<length;i++) data[i] = bt_readByte();
|
if (dlen > 7) {
|
||||||
|
for (int i=0;i<dlen;i++) data[i] = bt_readByte();
|
||||||
|
|
||||||
length = data[0] | (data[1] << 8);
|
unsigned int length = data[0] | (data[1] << 8);
|
||||||
|
unsigned int channel = data[2] | (data[3] << 8);
|
||||||
unsigned char opcode = data[4];
|
unsigned char opcode = data[4];
|
||||||
|
|
||||||
if (opcode == 0x1b) {
|
if (length == 4 && opcode == 0x1b) {
|
||||||
if (length == 4) {
|
if (channel == 4 && data[5] == 0x2a && data[6] == 0x00) {
|
||||||
dir = data[7];
|
dir = data[7];
|
||||||
moveObjectAbs(paddle, MARGIN + (dir * ((VIRTWIDTH - paddlewidth + MARGIN)/100)), paddle->y);
|
moveObjectAbs(paddle, MARGIN + (dir * ((VIRTWIDTH - paddlewidth + MARGIN)/100)), paddle->y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void breakout()
|
void breakout()
|
||||||
|
|
Loading…
Reference in a new issue