I Was looking at too much of someone else's code and I thought if I could see all the digitalRead() and digitalWrite() activity (scattered in the program) it might help.
Out on a limb a bit with the namespace feature of C++, I came up with this, which sorta kinda works mostly, but not always.
It may be a completely wrong thing to try. Any way of doing what I want here would be fine with me, the idea is to avoid modifying the original code.
I may be overlooking a totally simpler way. Just want something better than global search and replace, which, trust me, I am not above doing.
Thia code works, to a point, but it does not catch all the calls. Making plausible additions or changes hasn't worked for me, the typical error is
error: call of overloaded 'digitalRead(uint8_t&)' is ambiguous
which comes up if I uncomment my attempt to plug one hole.
/* catch functions here, report and pass them up */
# define USE_ALTO
# ifdef USE_ALTO
namespace ALTO {
void pinMode(int pin, byte val) {
Serial.print(" pinMode : ");
Serial.print(pin); Serial.print(" "); Serial.println(val);
::pinMode(pin, val);
}
/*
void digitalWrite(uint8_t pin, uint8_t val) {
Serial.print(" digitalWrite : ");
Serial.print(pin); Serial.print(" "); Serial.println(val);
::digitalWrite(pin, val);
}
*/
void digitalWrite(int pin, int val) {
Serial.print(" digitalWrite : ");
Serial.print(pin); Serial.print(" "); Serial.println(val);
::digitalWrite(pin, val);
}
byte digitalRead(int pin) {
byte theValue = ::digitalRead(pin);
Serial.print(" digitalRead : ");
Serial.print(pin); Serial.print(" "); Serial.println(theValue);
return theValue;
}
// attempt to fix missing digitalRead call
/* namesake.ino:74:16: error: call of overloaded 'digitalRead(uint8_t&)' is ambiguous
digitalRead(x); // this didn't get caught
byte digitalRead(uint8_t pin) {
byte theValue = ::digitalRead(pin);
Serial.print(" digitalRead : ");
Serial.print(pin); Serial.print(" "); Serial.println(theValue);
return theValue;
}
*/
}
// hardware/arduino/avr/cores/arduino/Arduino.h.
using namespace ALTO;
# endif
void setup()
{
Serial.begin(115200);
Serial.println("namesapce world!\n");
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
Serial.println();
for (int xx = 2; xx <= 5; xx++)
pinMode(xx, INPUT_PULLUP);
Serial.println();
// these don't get caught?
for (uint8_t xx = 7; xx <= 10; xx++)
pinMode(xx, INPUT_PULLUP);
Serial.println();
digitalWrite(7, 0);
digitalRead(7);
Serial.println();
uint8_t x = 11;
digitalWrite(x, 1);
digitalRead(x); // this didn't get caught
Serial.println();
char y = 12;
digitalWrite(y, 0);
digitalRead(y);
Serial.println();
int z = 13;
digitalWrite(z, 1);
digitalRead(z);
Serial.println();
}
void loop() {}
Play with it here. I assume it is either fixable or unfixable and I would appreciate knowing how to fix it, or why it is unfixable and how to do what I am trying to do in any conventional manner.
TIA
a7