Skip to content

Commit b7aa6e0

Browse files
authored
Merge pull request #11 from pimoroni/patch-daemon-brightness
Add brightness control for forum post 10985
2 parents cdb4d51 + 95e5466 commit b7aa6e0

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

daemon/usr/bin/plasma

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CONFIG_FILE = "/etc/plasma/plasma.conf"
1414
PIPE_FILE = "/tmp/plasma"
1515
PATTERNS = "/etc/plasma/"
1616
FPS = 30
17+
BRIGHTNESS = 1.0
1718
LIGHTS = 10 # Actual number of pixels is 4x this number
1819
DEBUG = False
1920

@@ -115,6 +116,12 @@ def main():
115116
log("Framerate set to: {}fps".format(rgb[1]))
116117
except ValueError:
117118
log("Invalid framerate: {}".format(rgb[1]))
119+
elif len(rgb) == 2 and rgb[0] == "brightness":
120+
try:
121+
args.brightness = float(rgb[1])
122+
log("Brightness set to: {}".format(args.brightness))
123+
except ValueError:
124+
log("Invalid brightness {}".format(rgb[1]))
118125
else:
119126
pattern, pattern_w, pattern_h, pattern_meta = load_pattern(command)
120127
alpha = pattern_meta['alpha']
@@ -126,9 +133,9 @@ def main():
126133
for x in range(plasma.get_pixel_count()):
127134
offset_x = (x * channels) % (pattern_w * channels)
128135
r, g, b = row[offset_x:offset_x + 3]
129-
plasma.set_pixel(x, r, g, b)
136+
plasma.set_pixel(x, r, g, b, brightness=args.brightness)
130137
else:
131-
plasma.set_all(r, g, b)
138+
plasma.set_all(r, g, b, brightness=args.brightness)
132139

133140
plasma.show()
134141

@@ -152,6 +159,8 @@ def get_args():
152159
help="run plasma as a daemon")
153160
parser.add_argument("-f", "--fps", type=int, default=FPS,
154161
help="set plasma LED update framerate")
162+
parser.add_argument("-b", "--brightness", type=float, default=BRIGHTNESS,
163+
help="set plasma LED brightness")
155164
parser.add_argument("-c", "--config", type=str, default=CONFIG_FILE,
156165
help="path to plasma config file")
157166
return parser.parse_known_args()[0]

daemon/usr/bin/plasmactl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if __name__ == "__main__":
3737
parser.add_argument('--list', action='store_true', help='List available animations')
3838
parser.add_argument('--colour', nargs=3, type=Color, help='Display an RGB colour (all values 0-255)')
3939
parser.add_argument('--fps', type=int, help='Set the update framerate')
40+
parser.add_argument('--brightness', type=float, help='Set the LED brightness')
4041
parser.add_argument('--pattern', type=str, help='Display an image-based aniamtion from /etc/plasma', choices=list(valid_patterns()))
4142

4243
args = parser.parse_args()
@@ -62,5 +63,13 @@ if __name__ == "__main__":
6263
fifo.flush()
6364
sys.exit(0)
6465

66+
if args.brightness is not None:
67+
brightness = args.brightness
68+
print(f"Setting brightness to {brightness}")
69+
with open_fifo(FIFO) as fifo:
70+
fifo.write(f"brightness {brightness}\n".encode("utf-8"))
71+
fifo.flush()
72+
sys.exit(0)
73+
6574
parser.print_help()
6675
sys.exit(1)

library/plasma/matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def set_light(self, index, r, g, b, brightness=None):
109109
def set_all(self, r, g, b, brightness=None):
110110
"""Set the RGB value and optionally brightness of all pixels."""
111111
for n, d in self._devices.items():
112-
d.get('device').set_all(r, g, b, brightness)
112+
d.get('device').set_all(r, g, b, brightness=brightness)
113113

114114
def set_sequence(self, sequence):
115115
"""Set all LEDs from a buffer of individual colours."""
@@ -141,7 +141,7 @@ def set_pixel(self, x, r, g, b, brightness=None):
141141
count = device.get_pixel_count()
142142

143143
if x >= offset and x < offset + count:
144-
device.set_pixel(x - offset, r, g, b)
144+
device.set_pixel(x - offset, r, g, b, brightness=brightness)
145145

146146
def show(self):
147147
"""Display lights across devices.

0 commit comments

Comments
 (0)