website.app module
Flask Control Application for EEG, Motion, PPG, and Video/Stimuli Programs
This module serves as a centralized controller for multiple programs: - Program 1 (p1): Camera control - Program 2 (p2): Image stimuli control - Program 4 (p4): Video stimuli control
It connects to a Muse EEG device via LSL streams, collects EEG, accelerometer, gyroscope, and PPG data, and stores it in shared memory for visualization. It also exposes Flask routes for starting/stopping recordings, controlling video feeds, and managing stimuli.
Key Features: - Real-time data acquisition from Muse device (EEG, accelerometer, gyroscope, PPG) - Shared memory for inter-process communication with visualization - Flask REST API for user interaction (recording, visualization, stimuli control) - Multiprocessing support for external programs (p1, p2, p4) - Performance-optimized real-time visualization of EEG and motion data
Clean up shared memory resources and notify the video feed program.
This should be called when the Flask application exits to release system resources.
- website.app.close_visualization_video()
- website.app.connect_to_muse()[source]
Connect to Muse EEG, accelerometer, gyroscope, and PPG LSL streams.
Sets global connection flags and initializes StreamInlet objects for each available stream. Prints connection status to console.
- website.app.index()
- website.app.load_stimuli_config()
- website.app.load_video_stimuli_config()
- website.app.open_visualization()
- website.app.open_visualization_video()
- website.app.process_data_thread()[source]
Continuous thread for reading Muse LSL streams and updating shared memory buffers.
Reads EEG, accelerometer, gyroscope, and PPG chunks.
Updates global buffers and shared memory arrays.
Appends recorded data if recording is enabled.
- website.app.save_stimuli_config()
- website.app.save_video_stimuli_config()
- website.app.send_command(conn, command, json_data=None)[source]
Send a command to a child process via a Pipe connection.
- Parameters:
conn (multiprocessing.Connection) – Parent end of a Pipe connection.
command (str) – Command string to send.
json_data (dict, optional) – Optional JSON data to send after command.
- Returns:
True if command successfully sent and response received, False otherwise.
- Return type:
bool
- website.app.start_recording()
- website.app.start_recording_video()
- website.app.start_stimuli()
- website.app.start_video_stimuli()
- website.app.start_visualization(shared_memory_names, time_buffer_list, ppg_time_buffer_list, buffer_size, ppg_buffer_size)[source]
Start a Tkinter-based visualization window showing EEG, frequency bands, accelerometer, gyroscope, and PPG signals.
- Parameters:
shared_memory_names (dict) – Names of shared memory blocks.
time_buffer_list (list) – Time vector for EEG, ACC, GYRO plotting.
ppg_time_buffer_list (list) – Time vector for PPG plotting.
buffer_size (int) – Buffer size for EEG/ACC/GYRO.
ppg_buffer_size (int) – Buffer size for PPG.
- website.app.stop_recording()
- website.app.stop_recording_video()
- website.app.subject_information()