Skip to content

Add begin() function to class example as best practice #849

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

Merged
merged 6 commits into from
Apr 20, 2023

Conversation

jasonacox
Copy link
Contributor

What This PR Changes

  • The current document, "Writing a Library for Arduino," instructs the user to place a hardware configuration call, pinMode(), in the class constructor. The problem is that the constructor will execute this before Arduino core's main() has time to call the init() function to initialize the hardware. In many cases, this will be fine, but there are cases where the hardware is not ready until after init() is called. To address this, this PR updates the Morse library class example in this document to include a begin() function similar to Serial.begin() that is placed in setup(). This will encourage students of this guide to follow that best practice.
  • Note, the Morse.zip file will need to be updated. I have an updated version here: https://github.com/jasonacox/Morse and will zip and submit that for a replacement if this PR is acceptable.

Contribution Guidelines

The guide instructs the user to place a hardware configuration call, pinMode(), in the class constructor. The problem is that the constructor will execute this in globals scope before Arduino core's main() has time to call the init() function to initialize the hardware. In many cases, this will be fine, but there are cases where the hardware is not ready until after init() is called. To address this, the Morse library class example should include a `begin()` function similar to `Serial.begin()` that is placed in `setup()`. This will encourage students of this guide to follow that best practice.

Note, the Morse.zip file will need to be updated.  I have an updated version here: https://github.com/jasonacox/Morse and will zip and submit that for a replacement if this PR is acceptable.
@CLAassistant
Copy link

CLAassistant commented Feb 19, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this important correction @jasonacox!

I have offered a few suggestions.

@per1234 per1234 added bug Something isn't working Tutorial community Bugs and fixes suggested by the community maker and removed Tutorial labels Feb 19, 2023
jasonacox and others added 4 commits February 19, 2023 08:13
Co-authored-by: per1234 <accounts@perglass.com>
Co-authored-by: per1234 <accounts@perglass.com>
Co-authored-by: per1234 <accounts@perglass.com>
Change configure to configures
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great (and thanks for fixing the grammar error I introduced in my suggestion 🤦‍♂️)!

@jasonacox
Copy link
Contributor Author

jasonacox commented Feb 19, 2023

Thank you @per1234 ! I hope this helps provide more clarity for the community.

Morse.zip

Now we need to submit a new Morse.zip file with the adjustments to the code. The link in the document is https://www.arduino.cc/en/uploads/Hacking/Morse.zip in the tutorial, but I'm not sure how to update that.

I captured the example code here: https://github.com/jasonacox/Morse and there is a zip file release we could use but I would like a peer review on that as well.

@per1234
Copy link
Contributor

per1234 commented Feb 19, 2023

I would like a peer review on that as well.

I will be happy to provide one. Are you planning to maintain https://github.com/jasonacox/Morse permanently, or did you only create it as a temporary staging repository to accompany this PR?

Either is fine of course. I ask only because I have a few suggestions that are specific to the content of the tutorial ZIP file, but not necessarily applicable to your repository.

If the repo is only for this PR then I would submit a PR to your repo for my suggestions. Otherwise I would describe them here in this PR thread.

@jasonacox
Copy link
Contributor Author

Thanks! This repo is for only for this tutorial, so please feel free to open a PR. Also, I have no issue leaving the repo up for others to reference. My thought is that it should be a helpful "reference template" we anonymize (I just realize I had my properties file in there with my contact info we should anonymize). Also, we may want it hosted in github.com/arduino somewhere or just leave it as a zip archive.

@per1234
Copy link
Contributor

per1234 commented Feb 20, 2023

I have now submitted PRs to your repo for my two minor suggestions:

https://github.com/jasonacox/Morse/pulls

@jasonacox
Copy link
Contributor Author

Thank you, @per1234 ! 🙏 - Both of your changes make sense to me. I accepted and merged.

I released 1.0.0 using the updated files: https://github.com/jasonacox/Morse/releases/tag/v1.0.0 with a zip file that could be use as the replacement for https://www.arduino.cc/en/uploads/Hacking/Morse.zip

Please let me know if I can do anything else to help.

@jasonacox
Copy link
Contributor Author

Hi @per1234 is there anything else I can do to help complete this merge?

@per1234
Copy link
Contributor

per1234 commented Feb 22, 2023

@jasonacox not that I know of. I'm not in a role to merge PRs in this repository so one of the primary maintainers will need to find time to do a review. They will let you know if any action is needed on your part.

@jasonacox
Copy link
Contributor Author

Understood! Thanks @per1234! 🙏

Maintainer: We do need to update the Morse.zip file at https://www.arduino.cc/en/uploads/Hacking/Morse.zip - I'm not sure how to do that. Ideally it should happen at the same time this is merged so the document matches the zip file. The updated files are stored here https://github.com/jasonacox/Morse/releases/tag/v1.0.0 with help from @per1234, if we want to use that. Let me know if you need anything else.

@jasonacox
Copy link
Contributor Author

Hi friends - If it helps with the review and merge, I have attached the updated Morse.zip of the code that needs to replace https://www.arduino.cc/en/uploads/Hacking/Morse.zip as part of this merge request.

Updated zip file here: Morse.zip

This is the example code described in the tutorial that includes the files needed to build an Arduino library:

image

Alternatively, I could submit an update to this PR to change the link in the tutorial text to point to the above github hosted link (https://github.com/arduino/docs-content/files/11130152/Morse.zip. However, I assumed we would want to keep the example code host under the arduino.cc URL. Thoughts?

Please let me know if you have any questions or you need anything else to help review/accept this PR.

Thank you!
Jason

@jhansson-ard
Copy link
Contributor

@jasonacox thank you for your contribution! We will now merge your updates to this tutorial ⭐

@jhansson-ard jhansson-ard merged commit 54dc501 into arduino:main Apr 20, 2023
@jasonacox jasonacox deleted the patch-1 branch April 23, 2023 04:30
@jasonacox
Copy link
Contributor Author

Thank you @jhansson-ard !!!

I notice the updated "Writing a Library for Arduino" Tutorial is live. 🚀 ❤️ 👏 However, I did notice the link on the page for Morse.zip (see below) still downloads the old zip file.

image

Can the zip file at https://github.com/arduino/docs-content/files/11130152/Morse.zip be uploaded to https://www.arduino.cc/en/uploads/Hacking/Morse.zip?

jhansson-ard added a commit that referenced this pull request Apr 24, 2023
Updated the link to the morse zip file in the Library tutorial.

See more [here](#849)
@jhansson-ard
Copy link
Contributor

Yes of course, I've made a PR here: #1012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community Bugs and fixes suggested by the community maker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants