Add history of `tone` / `noTone` to pinHistory or GODMODE
Issue / Feature Request Summary
First reported in #24
The tone functions should create some sort of testable history in the GODMODE struct.
What are your thoughts on implementing this?
Something along these lines might suffice:
- ToneHistory class, similar to pin history
- ToneHistory uses a ArduinoCIQueue to record state
- ToneState class or struct with the following members:
- pin
- frequency
- duration
- start tick
- playSound (bool reflecting play start or end)
assertEqual(2, state->toneHistory[PIN].size());
ToneState toneStates[] = state->toneHistory[PIN].toArray();
assetEqual(true,toneStates[0].play); // started playing
assetEqual(false,toneStates[1].play); //stopped
Would that fit with your code base? or is there a better way?
That's more or less what I'm thinking, although I'm not sure how best to combine that with all of pulseIn, pulseOut, PinHistory, etc. I put a bunch of work into making PinHistory compatible with a readable bytestream to support SoftwareSerial. I can't imagine any reason you'd mix those functions with tone/pulse in a real application, so it should be fine to just create a separate history queue for tone stuff.
The other thing that crossed my mind is that if you start a tone and then delay(), then eventually the tone will end. I'm not sure if it's as simple as revisiting that history / Queue template that I made.
How many use cases do you think there are?
Use cases:
- start tone, stop tone
- start tone with time, let tone finish automatically
- start tone with time, explicitly stop tone
- start tone, call tone again on the same pin with a different frequency
Tone can only be called on PWM pins (3 and 11 on most boards). There could be multiple tones running at the same time on different pins, but that would be a bit odd.
Aah, my own ignorance getting the better of me again -- didn't know that these were PWM-pins-only features. Are there other PWM functions I need to support or are those just commanded via analogWrite()?
All PWM features are via analogWrite() as far as I know.