ULP-ActivitySupport – blob
1 #!/usr/bin/env python3
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 # This file is part of UrbanLife+ Activity Support. <https://fietkau.software/ulp_activity_support>
5 # Copyright (C) 2019-2020 Julian Fietkau, Laura Stojko
7 from LED.arrows import arrow_up, arrow_down, arrow_left, arrow_right
8 from LED.symbols import hook, bee
9 import os
11 def get_idle_state():
12 return {
13 "id": "idle",
14 "states": [
15 {
16 "function": "clear"
17 }
18 ]
19 }
21 def get_color_state(color, blinking):
23 result = {
24 "id": "color_"+','.join(map(str, color)),
25 "states": [
26 {
27 "function": "clear",
28 "color": color
29 }
30 ]
31 }
33 if blinking:
34 result["id"] += "_blink"
35 result["states"][0]["duration"] = 1.0
36 result['states'].append({"function": "clear", "duration": 1.0 })
37 result["loop"] = True
39 return result
41 def get_arrow_state(direction, fg_color, bg_color, blinking):
42 if direction not in ["up", "down", "left", "right"]:
43 raise ValueError(direction)
45 result = {
46 "id": "arrow_"+direction+"_"+",".join(map(str,fg_color)),
47 "states": [
48 {
49 "function": "set_pixels",
50 }
51 ]
52 }
54 pixels = None
55 if direction == "up":
56 pixels = arrow_up(bg_color, fg_color)
57 if direction == "down":
58 pixels = arrow_down(bg_color, fg_color)
59 if direction == "left":
60 pixels = arrow_left(bg_color, fg_color)
61 if direction == "right":
62 pixels = arrow_right(bg_color, fg_color)
63 result["states"][0]["pixels"] = pixels
65 if blinking:
66 result["id"] += "_blink"
67 result["states"][0]["duration"] = 1.0
68 result['states'].append({"function": "clear", "duration": 1.0 })
69 result["loop"] = True
71 return result
73 def get_symbol_state(symbol, color, blinking):
74 pixels = None
76 if symbol == "hook":
77 pixels = hook(color)
78 elif symbol == "bee":
79 pixels = bee()
81 result = {
82 "id": "symbol_"+symbol+"_"+",".join(map(str,color)),
83 "states": [
84 {
85 "function": "set_pixels",
86 }
87 ]
88 }
90 result["states"][0]["pixels"] = pixels
92 if blinking:
93 result["id"] += "_blink"
94 result["states"][0]["duration"] = 1.0
95 result['states'].append({"function": "clear", "duration": 1.0 })
96 result["loop"] = True
98 return result