Skip to content

Add history of tone / noTone to pinHistory or GODMODE #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ianfixes opened this issue Mar 28, 2018 · 5 comments
Open

Add history of tone / noTone to pinHistory or GODMODE #26

ianfixes opened this issue Mar 28, 2018 · 5 comments
Labels
arduino mocks Compilation mocks for the Arduino library enhancement New feature or request

Comments

@ianfixes
Copy link
Collaborator

Issue / Feature Request Summary

First reported in #24

The tone functions should create some sort of testable history in the GODMODE struct.

@ianfixes ianfixes added enhancement New feature or request arduino mocks Compilation mocks for the Arduino library labels Mar 28, 2018
@dfrencham
Copy link

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?

@ianfixes
Copy link
Collaborator Author

ianfixes commented Apr 4, 2018

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?

@dfrencham
Copy link

Use cases:

  1. start tone, stop tone
  2. start tone with time, let tone finish automatically
  3. start tone with time, explicitly stop tone
  4. 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.

@ianfixes
Copy link
Collaborator Author

ianfixes commented Apr 4, 2018

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()?

@dfrencham
Copy link

All PWM features are via analogWrite() as far as I know.

@ianfixes ianfixes added this to the Arduino library completeness milestone Dec 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arduino mocks Compilation mocks for the Arduino library enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants