Skip to content

Use custom datetime #9

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
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Use custom datetime #9

wants to merge 17 commits into from

Conversation

dbgen1
Copy link
Contributor

@dbgen1 dbgen1 commented Feb 22, 2025

Description

This change makes it easier for developers to interact with the RV3028 driver in a number of ways by overhauling date/time setting. This PR does the following:

Adds custom basic classes for handling date and time, namely date, time, and datetime. The eventual goal is to add support for iso8601-formatted string parsing into these classes, to make it simple for users to set the time and date of the satellite. With the current changes, instead of having to create and pass arbitrary looking tuples for the date and time, users can create a date or time object.

In addition, the driver has been modified to no longer keep track of weekdays. Realistically, there is no case for our purposes where a weekday is needed, so removing the calculation and storing of weekdays removes some overhead.

Previously:

rtc.set_time(1, 12, 14) # hour, day, second
rtc.set_date(25, 2, 22, 4) # year, month, day, weekday

Now, this same functionality can be achieved with:

rtc.time = dt.time(hour=4, minute=12, second=14)
rtc.date = dt.date(year=2025, month=2, day=22)

And planned for the future:

rtc.date, rtc.time = dt.datetime.fromsioformat("2025-02-22T09:52:07.000Z")

This system is more easily readable and understandable, and has better flexibility than before. It also performs error checking, accounts for year offsets and manages weekdays for the user automatically.

Testing

  • This code has been tested using a slew of new unit tests, at 98% code coverage.
  • This code has been tested on hardware.

Future plans

  • Implement support for iso8601 formatted strings
  • Update the alarm system to use this format
  • Add operator overloading for time, date, and datetime.

Note

The initial goal of this PR was to use the adafruit_datetime library, but it turned out that was too heavy on memory usage for the RP2040 in conjunction with the satellite code. The custom datetime library is intended to strip away unneeded information like time zone info, timedeltas, and more.

@dbgen1
Copy link
Contributor Author

dbgen1 commented Feb 22, 2025

@Mikefly123 If you have time, I would love to get your feedback on this change as well!

@dbgen1 dbgen1 changed the title Use adafruit datetime Use custom datetime Feb 28, 2025
@dbgen1 dbgen1 marked this pull request as ready for review February 28, 2025 05:26
@dbgen1 dbgen1 requested a review from Mikefly123 February 28, 2025 05:36
Copy link

sonarqubecloud bot commented Mar 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants