-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindicator_lights.py
More file actions
90 lines (69 loc) · 2.81 KB
/
Copy pathindicator_lights.py
File metadata and controls
90 lines (69 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Copyright (C) 2025 Allied Vision Technologies. All Rights Reserved.
Subject to the BSD 3-Clause License.
"""
import sys
from typing import Optional, Tuple
from typing import List
import time
from vmbpy import *
from vmbpy.transportlayer import TransportLayersTuple
def print_preamble() -> None:
print('/////////////////////////////////////////////')
print('/// Smart Camera Indicator Lights Example ///')
print('/////////////////////////////////////////////\n')
def print_usage() -> None:
print('Usage:')
print(' python indicator_lights.py [LED_number] red_intensity green_intensity blue_intensity')
print(' python indicator_lights.py -h')
print()
print('Parameters:')
print(' LED_number The LED to set (0-9), if omitted all the LEDs will be set')
print(' red_intensity The desired red intensity (0-255) of the LED')
print(' green_intensity The desired green intensity (0-255) of the LED')
print(' blue_intensity The desired blue intensity (0-255) of the LED')
print()
def abort(reason: str, return_code: int = 1, usage: bool = False) -> None:
print(reason + '\n')
if usage:
print_usage()
sys.exit(return_code)
def parse_args() -> Tuple[Optional[int], List[int]]:
args = sys.argv[1:]
argc = len(args)
led_number: int = None
rgb_values: List[int]
for arg in args:
if arg == '-h':
print_usage()
sys.exit(0)
if argc == 3:
rgb_values = args
elif argc == 4:
led_number = args[0]
rgb_values = args[1:]
else:
abort(reason="Invalid number of arguments. Abort.", return_code=2, usage=True)
return (led_number, rgb_values)
def set_rgb_values(transport_layer: TransportLayer, rgb_values: List[int]) -> None:
transport_layer.LEDValueRed.set(rgb_values[0])
transport_layer.LEDValueGreen.set(rgb_values[1])
transport_layer.LEDValueBlue.set(rgb_values[2])
transport_layer.LEDValuesSave.run()
if __name__ == '__main__':
print_preamble()
led_number, rgb_values = parse_args()
with VmbSystem.get_instance() as vmb_system:
transport_layers: TransportLayersTuple = vmb_system.get_all_transport_layers()
if len(transport_layers) == 0:
abort('No transport layer found.')
transport_layer: TransportLayer = transport_layers[0]
led_selector_feature: EnumFeature = transport_layer.get_feature_by_name("LEDSelector")
if led_number is None:
for enumEntry in led_selector_feature.get_all_entries():
led_selector_feature.set(str(enumEntry))
set_rgb_values(transport_layer, rgb_values)
time.sleep(0.1)
else:
led_selector_feature.set(f"LED {led_number}")
set_rgb_values(transport_layer, rgb_values)