Skip to content

Commit

Permalink
Add DateTime class, add support for local timezone offset via experim…
Browse files Browse the repository at this point in the history
…ental_config
  • Loading branch information
chrisib committed Jan 8, 2025
1 parent ffa04ba commit 17be47e
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 50 deletions.
5 changes: 5 additions & 0 deletions software/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ shows the default configuration:
{
"VOLTS_PER_OCTAVE": 1.0,
"RTC_IMPLEMENTATION": "",
"UTC_OFFSET_HOURS": 0,
"UTC_OFFSET_MINUTES": 0,
}
```

Expand All @@ -83,6 +85,9 @@ RTC options:
- `"ds3231"`: use a DS3231 module connected to the external I2C interface
- `"ds1307"`: use a DS1307 module connected to the external I2C interface (THIS IS UNTESTED! USE AT YOUR OWN RISK)

Timezone options:
- `UTC_OFFSET_HOURS`: The number of hours ahead/behind UTC the local timezone is (-24 to +24)
- `UTC_OFFSET_MINUTES`: The number of minutes ahead/behind UTC the local timezone is (-59 to +59)

# Accessing config members in Python code

Expand Down
4 changes: 2 additions & 2 deletions software/contrib/daily_random.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Generates pseudo-random gate and CV patterns based on the current date and time.
- `b2`: not used
- `k1`: not used
- `k2`: not used
- `cv1`: daily gate sequence (updates at midnight UTC)
- `cv1`: daily gate sequence (updates at midnight local time)
- `cv2`: hourly gate sequence (updates at the top of every hour)
- `cv3`: minute gate sequence (updates at the top of every minute)
- `cv4`: daily CV sequence (updates at midnight UTC)
- `cv4`: daily CV sequence (updates at midnight local time)
- `cv5`: hourly CV sequence (updates at the top of every hour)
- `cv6`: minute CV sequence (updates at the top of every minute)

Expand Down
27 changes: 14 additions & 13 deletions software/contrib/daily_random.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from europi import *
from europi_script import EuroPiScript

from experimental.rtc import clock, DateTimeIndex
from experimental.rtc import clock

import random

Expand Down Expand Up @@ -95,13 +95,14 @@ def gates_off():
cvs[i].off()

def regenerate_sequences(self):
datetime = clock.now()
(year, month, day, hour, minute) = datetime[0:5]

try:
weekday = datetime[DateTimeIndex.WEEKDAY] % 7
except IndexError:
weekday = 0
datetime = clock.localnow()
year = datetime.year
month = datetime.month
day = datetime.day
hour = datetime.hour
minute = datetime.minute
second = datetime.second if datetime.second is not None else 0
weekday = datetime.weekday if datetime.weekday is not None else 0

# bit-shift the fields around to reduce collisions
# mask: 12 bits
Expand All @@ -120,14 +121,14 @@ def regenerate_sequences(self):
self.sequences[i].regenerate(seeds[i % len(seeds)])

def main(self):
oled.centre_text(str(clock).replace(" ", "\n"))
last_draw_at = clock.now()
last_draw_at = clock.localnow()
oled.centre_text(str(last_draw_at).replace(" ", "\n"))

while True:
now = clock.now()
if not clock.compare_datetimes(now, last_draw_at):
now = clock.localnow()
if now != last_draw_at:
self.regenerate_sequences()
oled.centre_text(str(clock).replace(" ", "\n"))
oled.centre_text(str(now).replace(" ", "\n"))
last_draw_at = now

if self.trigger_recvd:
Expand Down
14 changes: 14 additions & 0 deletions software/firmware/experimental/experimental_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ def config_points(cls):
],
default=RTC_NONE,
),

# RTC Timezone offset for local time
configuration.integer(
"UTC_OFFSET_HOURS",
minimum=-24,
maximum=24,
default=0,
),
configuration.integer(
"UTC_OFFSET_MINUTES",
minimum=-59,
maximum=59,
default=0,
),
]
# fmt: on

Expand Down
Loading

0 comments on commit 17be47e

Please sign in to comment.