Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swym
firmware
Commits
54e82152
Commit
54e82152
authored
5 years ago
by
Daniel Hoffend
Browse files
Options
Downloads
Patches
Plain Diff
feat(main.py) add theme/color switching to main clock
parent
6e712c77
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/main.py
+83
-8
83 additions, 8 deletions
preload/main.py
with
83 additions
and
8 deletions
preload/main.py
+
83
−
8
View file @
54e82152
...
...
@@ -4,6 +4,7 @@ from utime import sleep
import
utime
import
math
import
leds
import
buttons
class
Time
:
def
__init__
(
self
,
start
=
0
):
...
...
@@ -42,22 +43,96 @@ class Clock:
self
.
run_once
=
run_once
self
.
offsetx
=
offsetx
self
.
time
=
Time
()
white
=
(
255
,
255
,
255
)
self
.
center_col
=
white
self
.
m1_col
=
white
self
.
m5_col
=
white
self
.
hour_hand_col
=
white
self
.
minute_hand_col
=
white
self
.
second_hand_col
=
white
self
.
theme
=
0
self
.
default_themes
=
[
{
"
background
"
:
[
0
,
0
,
0
],
"
center
"
:
[
255
,
255
,
255
],
"
m1
"
:
[
255
,
255
,
255
],
"
m5
"
:
[
255
,
255
,
255
],
"
hour_hand
"
:
[
255
,
255
,
255
],
"
minute_hand
"
:
[
255
,
255
,
255
],
"
second_hand
"
:
[
255
,
255
,
255
],
},
{
"
background
"
:
[
255
,
255
,
255
],
"
center
"
:
[
0
,
0
,
0
],
"
m1
"
:
[
0
,
0
,
0
],
"
m5
"
:
[
0
,
0
,
0
],
"
hour_hand
"
:
[
0
,
0
,
0
],
"
minute_hand
"
:
[
0
,
0
,
0
],
"
second_hand
"
:
[
0
,
0
,
0
],
},
]
self
.
themes
=
self
.
default_themes
# TODO load themes from clock.json
# TODO load current theme from clock.json
# load colors
print
(
"
theme:
"
,
self
.
theme
)
print
(
"
themes:
"
,
self
.
themes
)
self
.
setTheme
(
self
.
theme
)
def
setTheme
(
self
,
theme
):
self
.
theme
=
theme
%
len
(
self
.
themes
)
self
.
background_col
=
(
self
.
themes
[
self
.
theme
][
'
background
'
]
if
'
background
'
in
self
.
themes
[
self
.
theme
]
else
self
.
default_themes
[
0
][
'
background
'
]
)
self
.
center_col
=
(
self
.
themes
[
self
.
theme
][
'
center
'
]
if
'
center
'
in
self
.
themes
[
self
.
theme
]
else
self
.
default_themes
[
0
][
'
center
'
]
)
self
.
m1_col
=
(
self
.
themes
[
self
.
theme
][
'
m1
'
]
if
'
m1
'
in
self
.
themes
[
self
.
theme
]
else
self
.
default_themes
[
0
][
'
m1
'
]
)
self
.
m5_col
=
(
self
.
themes
[
self
.
theme
][
'
m5
'
]
if
'
m5
'
in
self
.
themes
[
self
.
theme
]
else
self
.
default_themes
[
0
][
'
m5
'
]
)
self
.
hour_hand_col
=
(
self
.
themes
[
self
.
theme
][
'
hour_hand
'
]
if
'
hour_hand
'
in
self
.
themes
[
self
.
theme
]
else
self
.
default_themes
[
0
][
'
hour_hand
'
]
)
self
.
minute_hand_col
=
(
self
.
themes
[
self
.
theme
][
'
minute_hand
'
]
if
'
minute_hand
'
in
self
.
themes
[
self
.
theme
]
else
self
.
default_themes
[
0
][
'
minute_hand
'
]
)
self
.
second_hand_col
=
(
self
.
themes
[
self
.
theme
][
'
second_hand
'
]
if
'
second_hand
'
in
self
.
themes
[
self
.
theme
]
else
self
.
default_themes
[
0
][
'
second_hand
'
]
)
def
loop
(
self
):
colored
=
False
try
:
with
display
.
open
()
as
disp
:
button_pressed
=
False
while
True
:
self
.
updateClock
(
disp
)
if
self
.
run_once
:
break
# check for button presses
v
=
buttons
.
read
(
buttons
.
BOTTOM_LEFT
|
buttons
.
BOTTOM_RIGHT
)
if
v
==
0
:
button_pressed
=
False
if
not
button_pressed
and
v
&
buttons
.
BOTTOM_LEFT
!=
0
:
button_pressed
=
True
self
.
setTheme
(
self
.
theme
-
1
)
elif
not
button_pressed
and
v
&
buttons
.
BOTTOM_RIGHT
!=
0
:
button_pressed
=
True
self
.
setTheme
(
self
.
theme
+
1
)
except
KeyboardInterrupt
:
for
i
in
range
(
11
):
leds
.
set
(
i
,
(
0
,
0
,
0
))
...
...
@@ -72,7 +147,7 @@ class Clock:
d
.
update
()
def
updateClock
(
self
,
disp
):
disp
.
clear
()
disp
.
clear
(
self
.
background_col
)
localtime
=
utime
.
localtime
()
disp
.
pixel
(
self
.
center
[
0
]
+
self
.
offsetx
,
self
.
center
[
1
],
col
=
self
.
center_col
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment