From 5afa7988fcaae365795bcc612107ceb6846bb674 Mon Sep 17 00:00:00 2001 From: Wilhelm Westermark Date: Mon, 14 Nov 2016 00:36:59 +0100 Subject: [PATCH] Updated version with proper challenge/response code --- RPi/i2c_challenge.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/RPi/i2c_challenge.c b/RPi/i2c_challenge.c index ea5d48d..cd4a114 100644 --- a/RPi/i2c_challenge.c +++ b/RPi/i2c_challenge.c @@ -1,4 +1,4 @@ -O/* +/* *i2ctest.c * Raspberry Pi I2C test using wiringPi library. * @@ -35,28 +35,24 @@ int main (int argc, char *argv[]) } else { - while(data != 6) { - wiringPiI2CWrite(fd, send); + delay(1); + while(1) { + wiringPiI2CWrite(fd, send); data=wiringPiI2CRead(fd); + printf(" Received data=%d\n", data); if(data==-1) { printf("No data\n"); //return -1; } - else if(data == send*3) { - printf("Sending challenge"); - wiringPiI2CWrite(fd, 4); - } - else if(data == 6) { - printf("Read proper response \n"); + else if(data == 17) { + printf("Exit code received \n"); break; } - else - { - //print data - printf("Waiting to send challenge"); - } - printf(" data=%d\n", data); + else if(data != 0) { + printf("Sending response %d\n", data+3 ); + wiringPiI2CWrite(fd, data+3); + } } }