-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.py
More file actions
174 lines (174 loc) · 11 KB
/
config.py
File metadata and controls
174 lines (174 loc) · 11 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
################################################################################################################################
# Constants for Serial UI Application
################################################################################################################################
import logging
import re
from helpers.colors import color_names_sweet16 as COLORS
################################################################################################################################
# Constants General
VERSION = "1.5.3" # this version
AUTHOR = "Urs Utzinger" # me
DATE = "2026" # year of last update
################################################################################################################################
# Enable Features
USE_FASTPLOTLIB = False # use fastplotlib instead of pyqtgraph
USE_PARSERACCEL = True # use compiled C parsers when available (disable to force Python parser)
USE_BLE = True # enable bleak for BLE communication
USE_BLUETOOTHCTL = False # enable bluetoothctl for bluetoothctl functions on Linux
USE_3DPLOT = False # use the 3D vector display in indicator, not implemented yet
################################################################################################################################
# Debug and Profiling
PROFILEME = False # enable/disable profiling (measure execution time of functions)
DEBUGKEYINPUT = False # enable/disable key input debugging
DEBUGSERIAL = False # enable/disable low level serial debugging
DEBUGCHART = False # enable/disable chart debugging
DEBUGFASTPLOTLIB = False # enable/disable fastplotlib debugging
DEBUGRECEIVER = False # enable/disable receiver debugging in main program (switching receiver on/off)
################################################################################################################################
# Constants Chart
MAX_ROWS = 131072 # data history length
MAX_COLS = len(COLORS) # maximum number of data traces [available colors]
DEF_COLS = 2 # default number of data traces at startup
UPDATE_INTERVAL = 40 # [ms] 40ms = 25 Hz plot update, visualization does not improve with higher rate
MAX_ROWS_LINEDATA = 512 # maximum number of rows for temporary array when parsing line data
MAJOR_TICKS = 5 # major ticks on the y-axis
MINOR_TICKS = 4 # minor ticks on the y-axis
WHITE = (1.0, 1.0, 1.0, 1.0) # RR GG BB AA
BLACK = (0.0, 0.0, 0.0, 1.0) #
RED = (1.0, 0.0, 0.0, 1.0) #
GREEN = (0.0, 1.0, 0.0, 1.0) #
BLUE = (0.0, 0.0, 1.0, 1.0) #
DARK_GRAY = (0.2, 0.2, 0.2, 1.0) #
LIGHT_GRAY = (0.9, 0.9, 0.9, 1.0) #
TRANSPARENT_LIGHT_GRAY = (0.9, 0.9, 0.9, 0.8) #
YELLOW = (1.0, 1.0, 0.0, 1.0) #
ORANGE = (1.0, 0.5, 0.0, 1.0) #
MAGENTA = (1.0, 0.0, 1.0, 1.0) #
CYAN = (0.0, 1.0, 1.0, 1.0) #
# Fastplotlib
DISCRETE_GPU = True # prefer discrete GPU if available (e.g. NVIDIA, Radeon on Vulkan backend)
CACHE_FILE = "wgpu_pipeline.cache" # once GPU cache read and write would be exposed in the wgpu library we can
# # pre-load from file which would speed up initialization
################################################################################################################################
# Constants BLE
# Medibrick
DEFAULT_TARGET_DEVICE_NAME = "BLESerialDevice" # The name of the BLE device to search for if its already connected
# Program searches for all Nordic Serial UART service by default
BLEPIN = "123456" # Known pairing pin for Medibrick_BLE
# UUIDs for the Nordic Serial UART service and characteristics
SERVICE_UUID = "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
RX_CHARACTERISTIC_UUID = "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
TX_CHARACTERISTIC_UUID = "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
# BLE Constants
BLETIMEOUT = 30 # Timeout for BLE operations
BLESCAN_SHORT = 2 # [s] short BLE discovery when switching to BLE view
BLESCAN_LONG = 5 # [s] full BLE discovery when user clicks Scan
ATT_HDR = 3 # Attribute header length
BLEMTUMAX = 517 # Maximum MTU size
BLEMTUNORMAL = 247 # Normal MTU size
BLEMTUDEFAULT = 23 # Default MTU size
# Ideally devices send data so that LL fragmentation is avoided
# BLE LL octet size can be set to 27 .. 251 bytes (with 4 bytes header) which results in ideal MTU of 247
# Increasing MTU results in higher throughput, however max settings are set by the peripheral and might
# be lower than what we request.
################################################################################################################################
# Constants Text Display
# Standard Qt widgets should inherit the active application palette.
# Avoid hard-coded widget backgrounds here so OS light/dark themes remain readable.
# Remove ANSI escape sequences
ANSI_ESCAPE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
ENCODING = "utf-8" # default encoding for text display
FLUSH_INTERVAL_MS = 100 # [ms] 100ms = 10 Hz update of the text display (received data is buffered)
DEFAULT_TEXT_LINES = 500 # number of lines in display window (less is faster,
# but with fast transfer rates, some data might be skipped
# when data is streamed to file, no data is skipped
MAX_TEXT_LINES = 5_000 # max number of lines in display window (max value of user adjustable slider)
MAX_BACKLOG_BYTES = 1_000_000 # ~1 MB maximum backlog. when viewer scrolls up the text display,
# update is paused up and incoming data is backlogged up to this limit
################################################################################################################################
# Constants Serial
DEFAULT_BAUDRATE = 2_000_000 # default baud rate for serial port
SERIAL_BUFFER_SIZE = 4_096 # [bytes] size of the serial device buffer, has no effect on Linux and Darwin
################################################################################################################################
# Constants USB Port Monitor
USB_POLLING_INTERVAL = 300 # [ms] interval to check for USB device insertion/removal
################################################################################################################################
# Constants for End of Line (EOL) Options
# Human-readable → bytes
# Please do not change the bytes (second column), you can add and change the labels
EOL_DICT = {
"none" : b"",
"return newline (\\r\\n)" : b"\r\n",
"newline (\\n)" : b"\n",
"return (\\r)" : b"\r",
"newline return (\\n\\r)" : b"\n\r",
}
# Defaults
EOL_DEFAULT_LABEL = "return newline (\\r\\n)" # "none"
EOL_DEFAULT_BYTES = EOL_DICT[EOL_DEFAULT_LABEL]
# Bytes → human-readable (for reverse lookup)
EOL_DICT_INV = {v: k for k, v in EOL_DICT.items()}
DEFAULT_LINETERMINATOR = EOL_DEFAULT_BYTES # default line termination
################################################################################################################################
# Constants Data Parsing Options
# Please do not change "simple", "header", "binary", you can add or change the labels
# currently binary data parsing is not implemented but framework is there
PARSE_OPTIONS = {
"No Labels (simple)" : "simple",
"With [Label:]" : "header",
"Binary" : "binary",
}
# Defaults
PARSE_DEFAULT_LABEL = "No Labels (simple)"
PARSE_DEFAULT_NAME = PARSE_OPTIONS[PARSE_DEFAULT_LABEL]
PARSE_OPTIONS_INV = {v: k for k, v in PARSE_OPTIONS.items()}
###############################################################################################################################
# Constants for EOL Autodetection for USB and BLE data receiving
MAX_DATAREADYCALLS = 10 # if 10 data ready calls occur within MAX_EOL_DETECTION_TIME we autodetect EOL
MAX_EOL_DETECTION_TIME = 1.0 # if data is arriving for 1 second and no EOL found, we autodetect EOL
MAX_EOL_FALLBACK_TIMEOUT= 5.0 # if not EOL is found for 5 seconds we switch to raw (no EOL)
###############################################################################################################################
# Constants LOGLEVEL Options
LOG_OPTIONS = {
"NONE" : logging.NOTSET,
"DEBUG" : logging.DEBUG,
"INFO" : logging.INFO,
"WARNING" : logging.WARNING,
"ERROR" : logging.ERROR,
"CRITICAL" : logging.CRITICAL
}
LOG_DEFAULT_LABEL = "INFO"
LOG_DEFAULT_NAME = LOG_OPTIONS[LOG_DEFAULT_LABEL]
LOG_OPTIONS_INV = {v: k for k, v in LOG_OPTIONS.items()}
# logging level and priority
# CRITICAL 50
# ERROR 40
# WARNING 30
# INFO 20
# DEBUG 10
# NOTSET 0
# PROFILE -1 # custom level for profiling log messages
# FORCED -2 # custom level for forced log messages
DEBUG_LEVEL = LOG_DEFAULT_NAME
###############################################################################################################################
# Constants for CHART Options
LINEWIDTH = 2
AXIS_LINEWIDTH = 2
# Charts are custom-rendered and do not fully inherit Qt widget styling.
# These values act as palette-independent fallbacks when no Qt palette is available.
CHART_BACKGROUND_FALLBACK = WHITE
AXIS_COLOR_FALLBACK = BLACK
POINT_COLOR_FALLBACK = BLACK
GRID_COLOR_FALLBACK = DARK_GRAY
GRID_MINOR_COLOR_FALLBACK = LIGHT_GRAY
GRID_ALPHA = 0.3
TICK_COLOR_FALLBACK = BLACK
FRAME_TITLE_COLOR_FALLBACK = BLACK
FRAME_PLANE_COLOR_FALLBACK = LIGHT_GRAY
LEGEND_BACKGROUND_FALLBACK = TRANSPARENT_LIGHT_GRAY
AXIS_FONT_COLOR_FALLBACK = BLACK
TITLE_FONT_COLOR_FALLBACK = BLACK
LEGEND_FONT_COLOR_FALLBACK = BLACK
CAMERA_PAD = 1.05 # 5% padding for camera view
SMALLEST = 1e-18
REL_TOL = 0.03