Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS Fancy Clock
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheJoeCoder
CS Fancy Clock
Commits
5dd5e9ee
Verified
Commit
5dd5e9ee
authored
4 months ago
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
Docs and bug fixes
parent
daac771e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.idea/cs-fancy-clock.iml
+1
-1
1 addition, 1 deletion
.idea/cs-fancy-clock.iml
.idea/misc.xml
+1
-1
1 addition, 1 deletion
.idea/misc.xml
main.py
+93
-44
93 additions, 44 deletions
main.py
with
95 additions
and
46 deletions
.idea/cs-fancy-clock.iml
+
1
−
1
View file @
5dd5e9ee
...
...
@@ -4,7 +4,7 @@
<content
url=
"file://$MODULE_DIR$"
>
<excludeFolder
url=
"file://$MODULE_DIR$/.venv"
/>
</content>
<orderEntry
type=
"
inheritedJdk
"
/>
<orderEntry
type=
"
jdk"
jdkName=
"Python 3.10 (cs-fancy-clock)"
jdkType=
"Python SDK
"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
.idea/misc.xml
+
1
−
1
View file @
5dd5e9ee
...
...
@@ -3,5 +3,5 @@
<component
name=
"Black"
>
<option
name=
"sdkName"
value=
"Python 3.10 (cs-fancy-clock)"
/>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.1
2
(cs-fancy-clock)"
project-jdk-type=
"Python SDK"
/>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.1
0
(cs-fancy-clock)"
project-jdk-type=
"Python SDK"
/>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
+
93
−
44
View file @
5dd5e9ee
...
...
@@ -95,30 +95,68 @@ def wr_index():
@app.route
(
"
/api/available_fonts
"
)
def
wr_available_fonts
():
"""
Returns a list of available fonts on the system.
:return: A JSON response with a list of available fonts.
"""
return
json_response
(
pygame
.
font
.
get_fonts
())
@app.route
(
"
/api/available_widgets
"
)
def
wr_available_widgets
():
"""
Returns a list of available widgets.
:return: A JSON response with a list of available widgets.
"""
return
json_response
(
PROP_AVAILABLE_WIDGETS
)
@app.route
(
"
/api/get_state
"
)
def
wr_get_state
():
return
json_response
({})
# TODO
return
json_response
({
})
# TODO
@app.route
(
"
/api/toggle_screen_state
"
,
methods
=
[
"
POST
"
])
def
wr_toggle_state
():
mainthread_queue
.
put
(
"
TOGGLE_SCREEN_STATE
"
)
"""
Toggles the screen state between widget cycle and single widget.
:return: A JSON response with the status of the request.
"""
global
screen_state
,
screen_state_lock
with
screen_state_lock
:
if
screen_state
==
ScreenState
.
WIDGET_CYCLE
:
screen_state
=
ScreenState
.
WIDGET_SINGLE
elif
screen_state
==
ScreenState
.
WIDGET_SINGLE
:
screen_state
=
ScreenState
.
WIDGET_CYCLE
return
json_response
({
"
status
"
:
"
OK
"
"
status
"
:
"
OK
"
,
"
state
"
:
screen_state
.
name
})
@app.route
(
"
/api/available_patterns
"
)
def
wr_available_patterns
():
"""
Queries available patterns from the server.
:return: A JSON response with a list of available patterns.
"""
return
json_response
(
PROP_AVAILABLE_PATTERNS
)
@app.route
(
"
/api/set_widget
"
,
methods
=
[
"
POST
"
])
def
wr_set_widget
():
"""
Sets the widget configuration for the screen temporarily (does not write to the config).
Will only really work if the screen mode is set to single rather than cycle,
but it doesn
'
t prevent you from setting it.
:return: A JSON response with the status of the request.
"""
# Make sure the request is valid
valid
,
validation_response
=
verify_json_request
(
request
,
[
"
widget
"
])
if
not
valid
:
...
...
@@ -152,6 +190,15 @@ def wr_set_widget():
@app.route
(
"
/api/set_pattern
"
,
methods
=
[
"
POST
"
])
def
wr_set_pattern
():
"""
Sets the pattern configuration for the LEDs temporarily (does not write to the config).
Will only really work if the screen mode is set to single rather than cycle,
but it doesn
'
t prevent you from setting it.
:return: A JSON response with the status of the request.
"""
# Make sure the request is valid
valid
,
validation_response
=
verify_json_request
(
request
,
[
"
pattern
"
])
if
not
valid
:
...
...
@@ -185,6 +232,12 @@ def wr_set_pattern():
@app.route
(
"
/api/set_sequence
"
,
methods
=
[
"
POST
"
])
def
wr_set_sequence
():
"""
Sets the sequence configuration for the widgets and patterns.
Uses the request json
"
widget
"
and
"
pattern
"
to set the sequence.
:return: A JSON response with the status of the request.
"""
# Make sure the request is valid
valid
,
validation_response
=
verify_json_request
(
request
,
[
"
widget
"
,
"
pattern
"
])
if
not
valid
:
...
...
@@ -395,6 +448,8 @@ if __name__ == "__main__":
raise
ValueError
(
"
No patterns in sequence
"
)
screen_state
=
ScreenState
.
WIDGET_CYCLE
screen_state_lock
=
threading
.
Lock
()
screen_state_event
=
threading
.
Event
()
initial_widget
=
widget_sequence
[
0
]
initial_pattern
=
pattern_sequence
[
0
]
...
...
@@ -457,17 +512,11 @@ if __name__ == "__main__":
force_change_widget
=
True
elif
message
==
"
CYCLE_PATTERN
"
:
force_change_pattern
=
True
elif
message
==
"
TOGGLE_SCREEN_STATE
"
:
if
screen_state
==
ScreenState
.
WIDGET_CYCLE
:
screen_state
=
ScreenState
.
WIDGET_SINGLE
elif
screen_state
==
ScreenState
.
WIDGET_SINGLE
:
screen_state
=
ScreenState
.
WIDGET_CYCLE
else
:
pass
except
queue
.
Empty
:
pass
# Check if time delta has passed
# Widget cycle after time delta
with
screen_state_lock
:
if
screen_state
==
ScreenState
.
WIDGET_CYCLE
:
# For Widgets
curr_widget
=
widget_sequence
[
current_widget_index
]
...
...
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
sign in
to comment