Permalink
Browse files

Using fprintf for errors and printf for stdout

  • Loading branch information...
giuliomoro committed Dec 6, 2017
1 parent 00f08e7 commit 4d602104663c25823a9b4e64f1a8bbcb8c292bbf
Showing with 16 additions and 16 deletions.
  1. +6 −6 core/I2c_Codec.cpp
  2. +10 −10 core/I2c_TouchKey.cpp
View
@@ -25,7 +25,7 @@ int I2c_Codec::initCodec()
// Write the reset register of the codec
if(writeRegister(0x01, 0x80)) // Software reset register
{
cout << "Failed to reset codec\n";
fprintf(stderr, "Failed to reset codec\n");
return 1;
}
@@ -239,7 +239,7 @@ int I2c_Codec::setPllJ(short unsigned int j){
return 1;
}
if(writeRegister(0x04, j<<2)){ // PLL register B: j<<2
printf("I2C error while writing PLL j: %d", j);
fprintf(stderr, "I2C error while writing PLL j: %d", j);
return 1;
}
pllJ=j;
@@ -251,11 +251,11 @@ int I2c_Codec::setPllD(unsigned int d){
if(d >9999)
return 1;
if(writeRegister(0x05, (d>>6)&255)){ // PLL register C: part 1 : 8 most significant bytes of a 14bit integer
printf("I2C error while writing PLL d part 1 : %d", d);
fprintf(stderr, "I2C error while writing PLL d part 1 : %d", d);
return 1;
}
if(writeRegister(0x06, (d<<2)&255)){ // PLL register D: D=5264, part 2
printf("I2C error while writing PLL d part 2 : %d", d);
fprintf(stderr, "I2C error while writing PLL d part 2 : %d", d);
return 1;
}
pllD=d;
@@ -276,7 +276,7 @@ int I2c_Codec::setPllP(short unsigned int p){
else
bits = bits | p; // other values are written with their binary representation.
if(writeRegister(0x03, bits)){ // PLL register B: j<<2
printf("I2C error while writing PLL p: %d", p);
fprintf(stderr, "I2C error while writing PLL p: %d", p);
return 1;
}
pllP = p;
@@ -293,7 +293,7 @@ int I2c_Codec::setPllR(unsigned int r){
else
bits |= r; // other values are written with their binary representation.
if(writeRegister(0x0B, bits)){ // PLL register B: j<<2
printf("I2C error while writing PLL r: %d", r);
fprintf(stderr, "I2C error while writing PLL r: %d", r);
return 1;
}
pllR = r;
View
@@ -32,7 +32,7 @@ int I2c_TouchKey::initTouchKey(int sensorTypeToUse)
char buf[3] = { 0x00, 0x01, 0x00 }; // code for centroid mode
if(write(i2C_file, buf, 3) !=3)
{
cout << "Failed to set TouchKey in \"Centroid Mode\" " << endl;
fprintf(stderr, "Failed to set TouchKey in \"Centroid Mode\"\n");
return 1;
}
@@ -41,7 +41,7 @@ int I2c_TouchKey::initTouchKey(int sensorTypeToUse)
char buf4[4] = { 0x00, 0x07, 0x00, 0x64}; // code for change minimum touch area
if(write(i2C_file, buf4, 4) !=4)
{
cout << "Failed to set TouchKey minimum touch size" << endl;
fprintf(stderr, "Failed to set TouchKey minimum touch size\n");
return 1;
}
@@ -54,7 +54,7 @@ int I2c_TouchKey::initTouchKey(int sensorTypeToUse)
if(write(i2C_file, buf, 1) !=1)
{
cout << "Failed to prepare data collection " << endl;
fprintf(stderr, "Failed to prepare TouchKey data collection\n");
return 2;
}
@@ -71,13 +71,13 @@ int I2c_TouchKey::readI2C()
bytesRead = read(i2C_file, dataBuffer, numBytesToRead);
if (bytesRead != numBytesToRead)
{
cout << "Failure to read Byte Stream" << endl;
fprintf(stderr, "Failure to read Byte Stream\n");
return 2;
}
/*cout << NUM_BYTES << " bytes read" << endl;
/*printf("%d bytes read\n", NUM_BYTES);
for(int j=0; j<9; j++)
cout << "\t" << (int)dataBuffer[j];
cout << endl;
printf("\t %d", (int)dataBuffer[j]);
printf("\n");
*/
touchCount = 0;
@@ -156,11 +156,11 @@ int I2c_TouchKey::readI2C()
for(int i = 0; i < bytesRead; i++) {
printf("%2X ", dataBuffer[i]);
}
cout << touchCount << " touches: ";
printf("%d touches: ", touchCount);
for(int i = 0; i < touchCount; i++) {
cout << "(" << sliderPosition[i] << ", " << sliderSize[i] << ") ";
printf("(%d, %d) ", sliderPosition[i], sliderSize[i]) ;
}
cout << "H = " << sliderPositionH << endl;
printf("H = %d\n", sliderPositionH);
#endif
return 0;

0 comments on commit 4d60210

Please sign in to comment.