From 63013786daf52afeb628cdac720492c16b4c9cce Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Wed, 12 Aug 2020 22:41:25 +0100 Subject: [PATCH] Better parsing on the Bluetooth game controller packets --- part8-breakout-ble/kernel.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/part8-breakout-ble/kernel.c b/part8-breakout-ble/kernel.c index 8544521..bbc4e70 100644 --- a/part8-breakout-ble/kernel.c +++ b/part8-breakout-ble/kernel.c @@ -207,9 +207,9 @@ struct Object *detectCollision(struct Object *with, int xoff, int yoff) for (int i=0; ix + 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) { - // with is too far up or down to ocllide + // with is too far up or down to collide } else { // Collision! return &objects[i]; @@ -313,20 +313,23 @@ void acl_poll() unsigned char h1 = bt_readByte(); unsigned char h2 = bt_readByte(); - unsigned int length = h1 | (h2 << 8); - unsigned char data[length]; + unsigned int dlen = h1 | (h2 << 8); + unsigned char data[dlen]; - for (int i=0;i 7) { + for (int i=0;iy); - } - } + if (length == 4 && opcode == 0x1b) { + if (channel == 4 && data[5] == 0x2a && data[6] == 0x00) { + dir = data[7]; + moveObjectAbs(paddle, MARGIN + (dir * ((VIRTWIDTH - paddlewidth + MARGIN)/100)), paddle->y); + } + } + } } } }