Skip to content

Commit 7abb380

Browse files
committed
Fixing global variable issue
1 parent 010021e commit 7abb380

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

chordspy/chords_serial.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,35 +244,35 @@ def start_timer(self):
244244
"""
245245
global start_time, last_ten_minute_time, total_packet_count, cumulative_packet_count
246246
current_time = time.time()
247-
start_time = current_time # Session start time
248-
last_ten_minute_time = current_time # 10-minute interval start time
249-
total_packet_count = 0 # Counter for packets in current second
250-
cumulative_packet_count = 0 # Counter for all packets
247+
self.start_time = current_time # Session start time
248+
self.last_ten_minute_time = current_time # 10-minute interval start time
249+
self.total_packet_count = 0 # Counter for packets in current second
250+
self.cumulative_packet_count = 0 # Counter for all packets
251251

252252
def log_one_second_data(self):
253253
"""
254254
Log data for one second intervals and displays: Number of packets received in the last second, Number of missing samples (if any)
255255
"""
256256
global total_packet_count, samples_per_second, missing_samples
257-
samples_per_second = total_packet_count
257+
self.samples_per_second = total_packet_count
258258
print(f"Data count for the last second: {total_packet_count} samples, "f"Missing samples: {missing_samples}")
259-
total_packet_count = 0 # Reset for next interval
259+
self.total_packet_count = 0 # Reset for next interval
260260

261261
def log_ten_minute_data(self):
262262
"""
263263
Log data for 10-minute intervals and displays: Total packets received, Actual sampling rate, Drift from expected rate
264264
"""
265265
global cumulative_packet_count, last_ten_minute_time, supported_boards, board
266-
print(f"Total data count after 10 minutes: {cumulative_packet_count}")
267-
sampling_rate = cumulative_packet_count / (10 * 60) # Calculate actual sampling rate
266+
print(f"Total data count after 10 minutes: {self.cumulative_packet_count}")
267+
sampling_rate = self.cumulative_packet_count / (10 * 60) # Calculate actual sampling rate
268268
print(f"Sampling rate: {sampling_rate:.2f} samples/second")
269-
expected_sampling_rate = supported_boards[board]["sampling_rate"]
269+
expected_sampling_rate = self.supported_boards[board]["sampling_rate"]
270270
drift = ((sampling_rate - expected_sampling_rate) / expected_sampling_rate) * 3600 # Calculate drift from expected rate
271271
print(f"Drift: {drift:.2f} seconds/hour")
272272

273273
# Reset counters
274-
cumulative_packet_count = 0
275-
last_ten_minute_time = time.time()
274+
self.cumulative_packet_count = 0
275+
self.last_ten_minute_time = time.time()
276276

277277
if __name__ == "__main__":
278278
client = Chords_USB() # Create and run the USB client

0 commit comments

Comments
 (0)