Skip to content

Commit d74e1fc

Browse files
authored
Merge pull request #27 from PayalLakra/bio_amptool
Changes done in gui.py
2 parents f510135 + b49eb9a commit d74e1fc

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

app.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ def run_app():
6868
@app.route("/app_status", methods=["GET"])
6969
def app_status():
7070
# Check the status of all apps
71-
statuses = {
72-
app_name: (process.poll() is None) # True if running, False if not
73-
for app_name, process in app_processes.items()
74-
}
75-
return jsonify(statuses)
71+
try:
72+
statuses = {
73+
app_name: (process.poll() is None) # True if running, False if not
74+
for app_name, process in app_processes.items()
75+
}
76+
return jsonify(statuses)
77+
except Exception as e:
78+
return jsonify({"error": str(e)}), 500
7679

7780
@app.route("/stop_lsl", methods=['POST'])
7881
def stop_lsl():

gui.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
# Initialize global variables
88
inlet = None
9-
data = np.zeros((6, 2000)) # Buffer to hold the last 2000 samples for each channel
9+
data = None
10+
num_channels = 6 # Default number of channels
11+
curves = []
12+
plots = []
1013

1114
def update_plots():
1215
global data
@@ -17,14 +20,14 @@ def update_plots():
1720
# Update data buffer
1821
for sample in samples:
1922
data = np.roll(data, -1, axis=1) # Shift data left
20-
data[:, -1] = sample # Add new channel data to the right end of the array
23+
data[:, -1] = sample[:num_channels] # Add new channel data to the right end of the array
2124

2225
# Update the curves with the new data
23-
for i in range(6):
26+
for i in range(num_channels):
2427
curves[i].setData(data[i])
2528

2629
def plot_lsl_data():
27-
global inlet
30+
global inlet, num_channels, data
2831
print("Looking for LSL Stream.")
2932
streams = resolve_stream('name', 'BioAmpDataStream')
3033

@@ -33,6 +36,15 @@ def plot_lsl_data():
3336
return
3437

3538
inlet = StreamInlet(streams[0])
39+
40+
# Get the number of channels from the stream
41+
info = inlet.info()
42+
num_channels = info.channel_count()
43+
print(f"Detected {num_channels} channels.")
44+
45+
# Initialize data buffer based on the number of channels
46+
data = np.zeros((num_channels, 2000)) # Buffer to hold the last 2000 samples for each channel
47+
3648
init_gui()
3749

3850
def init_gui():
@@ -47,15 +59,16 @@ def init_gui():
4759
pg.setConfigOption('background', 'w') # Background color
4860
pg.setConfigOption('foreground', 'k') # Foreground color
4961

50-
# Create plots for each channel (6 in total)
62+
# Create plots for each channel based on num_channels
5163
global plots, curves
5264
plots = []
5365
curves = []
5466
colors = ['#D10054', '#007A8C', '#0A6847', '#674188', '#E65C19', '#2E073F' ] # Different colors for each channel
55-
for i in range(6):
67+
for i in range(num_channels):
5668
plot = pg.PlotWidget(title=f"Channel {i + 1}") # Create a plot widget for each channel
5769
layout.addWidget(plot) # Add the plot to the layout
58-
curve = plot.plot(pen=colors[i]) # Create a curve (line) for plotting data
70+
color = colors[i % len(colors)] # Cycle colors if fewer colors than channels
71+
curve = plot.plot(pen=color) # Create a curve (line) for plotting data
5972
curve.setDownsampling(auto=True) # Automatically downsample if needed
6073
curve.setClipToView(True) # Clip the data to the view
6174
plots.append(plot) # Store the plot
@@ -65,7 +78,7 @@ def init_gui():
6578
status_bar = QtWidgets.QHBoxLayout()
6679

6780
# LSL status label
68-
lsl_label = QtWidgets.QLabel("LSL Status: Connected")
81+
lsl_label = QtWidgets.QLabel(f"LSL Status: Connected ({num_channels} channels detected)")
6982
status_bar.addWidget(lsl_label)
7083

7184
layout.addLayout(status_bar) # Add the status bar to the layout

static/style.css

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@ body {
1313
.header h1 {
1414
font-size: 48px;
1515
font-weight: bold;
16-
background: linear-gradient(to right, #ec4899, #a855f7, #3b82f6); /* Background gradient */
17-
-webkit-background-clip: text; /* Vendor-prefixed for WebKit-based browsers */
18-
background-clip: text; /* Standard property */
19-
-webkit-text-fill-color: transparent; /* Makes the text transparent */
16+
background: linear-gradient(90deg, #ec4899, #a855f7, #3b82f6, #ec4899);
17+
background-size: 300%;
18+
-webkit-background-clip: text;
19+
background-clip: text;
20+
-webkit-text-fill-color: transparent;
21+
animation: scroll-gradient 5s linear infinite;
22+
}
23+
24+
/* Keyframes for scrolling the gradient */
25+
@keyframes scroll-gradient {
26+
0% {
27+
background-position: 0% 50%;
28+
}
29+
100% {
30+
background-position: 100% 50%;
31+
}
2032
}
2133

2234
.subtitle {
@@ -89,7 +101,7 @@ button:disabled {
89101
}
90102

91103
button.running {
92-
background-color: rgb(105, 206, 105) !important;
104+
background-color: rgb(105, 206, 105);
93105
cursor: not-allowed;
94106
color: white;
95107
}

0 commit comments

Comments
 (0)