Matt-and-Gib/gleemail

Think about the optimization of hardcoding read/write pins for Morse Code

Opened this issue · 0 comments

The following code could be significantly simplified if we hardcoded the read/write calls;

(main.cpp 699 - 717)

currentPin = input->getPins();
while(*currentPin) {
if((*currentPin)->mode == Pin::PIN_MODE::READ) {
	(*currentPin)->value = digitalRead((*currentPin)->pinLocation);
}

++currentPin;
}

input->Update();

currentPin = input->getPins();
while(*currentPin) {
if((*currentPin)->mode == Pin::PIN_MODE::WRITE) {
	digitalWrite((*currentPin)->pinLocation, (*currentPin)->value);
}

++currentPin;
}

Morse code has two pins, one input and one output, so as you can no doubt see, the way we're doing this is completely unnecessary. It is also, I will say, rather specific to Morse Code. Sure, it could be used for other input methods, but maybe we can come up with a better plan.

I think we did it this way to keep Arduino.h out of morsecode.h, but taking a step back and thinking about it, Arduino.h is empirically a dependency of the Morse Code input method. In light of that, I recommend including Arduino.h in morsecode.h and simply calling Update from within. All of that logic/code belongs in MorseCode, and by separating it like this, we're really just hiding the dependency.