()
| 7 | |
| 8 | |
| 9 | def main(): |
| 10 | BoardShim.enable_board_logger() |
| 11 | DataFilter.enable_data_logger() |
| 12 | MLModel.enable_ml_logger() |
| 13 | |
| 14 | parser = argparse.ArgumentParser() |
| 15 | # use docs to check which parameters are required for specific board, e.g. for Cyton - set serial port |
| 16 | parser.add_argument('--timeout', type=int, help='timeout for device discovery or connection', required=False, |
| 17 | default=0) |
| 18 | parser.add_argument('--ip-port', type=int, help='ip port', required=False, default=0) |
| 19 | parser.add_argument('--ip-protocol', type=int, help='ip protocol, check IpProtocolType enum', required=False, |
| 20 | default=0) |
| 21 | parser.add_argument('--ip-address', type=str, help='ip address', required=False, default='') |
| 22 | parser.add_argument('--serial-port', type=str, help='serial port', required=False, default='') |
| 23 | parser.add_argument('--mac-address', type=str, help='mac address', required=False, default='') |
| 24 | parser.add_argument('--other-info', type=str, help='other info', required=False, default='') |
| 25 | parser.add_argument('--streamer-params', type=str, help='streamer params', required=False, default='') |
| 26 | parser.add_argument('--serial-number', type=str, help='serial number', required=False, default='') |
| 27 | parser.add_argument('--board-id', type=int, help='board id, check docs to get a list of supported boards', |
| 28 | required=True) |
| 29 | parser.add_argument('--file', type=str, help='file', required=False, default='') |
| 30 | args = parser.parse_args() |
| 31 | |
| 32 | params = BrainFlowInputParams() |
| 33 | params.ip_port = args.ip_port |
| 34 | params.serial_port = args.serial_port |
| 35 | params.mac_address = args.mac_address |
| 36 | params.other_info = args.other_info |
| 37 | params.serial_number = args.serial_number |
| 38 | params.ip_address = args.ip_address |
| 39 | params.ip_protocol = args.ip_protocol |
| 40 | params.timeout = args.timeout |
| 41 | params.file = args.file |
| 42 | |
| 43 | board = BoardShim(args.board_id, params) |
| 44 | master_board_id = board.get_board_id() |
| 45 | sampling_rate = BoardShim.get_sampling_rate(master_board_id) |
| 46 | board.prepare_session() |
| 47 | board.start_stream(45000, args.streamer_params) |
| 48 | BoardShim.log_message(LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread') |
| 49 | time.sleep(5) # recommended window size for eeg metric calculation is at least 4 seconds, bigger is better |
| 50 | data = board.get_board_data() |
| 51 | board.stop_stream() |
| 52 | board.release_session() |
| 53 | |
| 54 | eeg_channels = BoardShim.get_eeg_channels(int(master_board_id)) |
| 55 | bands = DataFilter.get_avg_band_powers(data, eeg_channels, sampling_rate, True) |
| 56 | feature_vector = bands[0] |
| 57 | print(feature_vector) |
| 58 | |
| 59 | mindfulness_params = BrainFlowModelParams(BrainFlowMetrics.MINDFULNESS.value, |
| 60 | BrainFlowClassifiers.DEFAULT_CLASSIFIER.value) |
| 61 | mindfulness = MLModel(mindfulness_params) |
| 62 | mindfulness.prepare() |
| 63 | print('Mindfulness: %s' % str(mindfulness.predict(feature_vector))) |
| 64 | mindfulness.release() |
| 65 | |
| 66 | restfulness_params = BrainFlowModelParams(BrainFlowMetrics.RESTFULNESS.value, |
no test coverage detected