From 8d82b4ada1cf1073a98d0aed437673d3c50aaae6 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sat, 5 Apr 2014 18:23:08 +0200 Subject: rumbling demo, and decode_byte --- main.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 4a5135c..a8b7fda 100644 --- a/main.c +++ b/main.c @@ -200,6 +200,18 @@ int send_recv_gc(char* bytes, int len) // a value of >=128 means "0", <127 means "1" bit. } +/* reads eight exploded bits from bufptr, and makes a 8bit-char from them. + * Bit ordering is MSB first. A bit is considered as 1, if bufptr[i] & 0x80 is + * *not* set, and vice versa. */ +char decode_byte(char* bufptr) +{ + char result=0; + for (int i=0;i<8;i++) + result|= ( (bufptr[7-i]&0x80)?0:(1< 25) rumble_count1=0; // rumble strength + + rumble_count2++; + if (rumble_count2 > 256+left_trigger) rumble_count2=0; // rumble frequency. + + if (rumble_count1 < right_trigger/10 && rumble_count2 < 256) + foo[2]=0x01; // turn on rumble. n_received=send_recv_gc(foo, 3); -- cgit v1.2.3