class TestSerial : public Stream {
public:
TestSerial() {state_ = 0;};
virtual int available(void);
virtual int peek(void);
virtual void flush(void);
virtual size_t write(uint8_t c);
virtual int read(void);
using Print::write;
size_t nonVirtualfunc(uint8_t c);
uint8_t state_;
};
int TestSerial::available(void) {return 0;}
int TestSerial::peek(void){return 0;}
void TestSerial::flush(void) {return;}
size_t TestSerial::write(uint8_t c) {
digitalWrite(3, HIGH);
state_ = state_? 0 : 1;
digitalWrite(13, state_);
digitalWrite(3, LOW);
return 0;
}
size_t TestSerial::nonVirtualfunc(uint8_t c) {
digitalWrite(3, HIGH);
state_ = state_? 0 : 1;
digitalWrite(13, state_);
delay(100);
digitalWrite(3, LOW);
return 0;
}
int TestSerial::read(void){return 0;}
TestSerial ts;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
for (uint8_t i=0; i< 5; i++) {
digitalWrite(13, HIGH);
delay(250);
digitalWrite(13, LOW);
delay(250);
}
}
uint8_t buf[]={0,1};
void loop() {
digitalWrite(2, HIGH);
//ts.write((uint8_t)0x00); // see if we call through the virtual function
ts.write(buf, 1);
//ts.nonVirtualfunc(0);
digitalWrite(2, LOW);
delay(500);
}