diff --git a/openbci/wifi.py b/openbci/wifi.py index 97f5e29..abc286f 100644 --- a/openbci/wifi.py +++ b/openbci/wifi.py @@ -154,6 +154,13 @@ def connect(self): if self.log: print("Connected to %s with %s channels" % (self.board_type, self.eeg_channels_per_sample)) + gains = None + if self.board_type == k.BOARD_CYTON: + gains = [24, 24, 24, 24, 24, 24, 24, 24] + elif self.board_type == k.BOARD_GANGLION: + gains = [51, 51, 51, 51] + self.local_wifi_server.set_parser(ParseRaw(gains=gains, board_type=self.board_type)) + if self.high_speed: output_style = 'raw' else: @@ -340,6 +347,65 @@ def set_channel(self, channel, toggle_position): except Exception as e: print("Something went wrong while setting channels: " + str(e)) + def set_sample_rate(self, sample_rate): + """ Change sample rate """ + try: + if self.board_type == k.BOARD_CYTON: + if sample_rate == 250: + self.wifi_write('~6') + elif sample_rate == 500: + self.wifi_write('~5') + elif sample_rate == 1000: + self.wifi_write('~4') + elif sample_rate == 2000: + self.wifi_write('~3') + elif sample_rate == 4000: + self.wifi_write('~2') + elif sample_rate == 8000: + self.wifi_write('~1') + elif sample_rate == 16000: + self.wifi_write('~0') + else: + print("Sample rate not supported: " + str(sample_rate)) + elif self.board_type == k.BOARD_GANGLION: + if sample_rate == 200: + self.wifi_write('~7') + elif sample_rate == 400: + self.wifi_write('~6') + elif sample_rate == 800: + self.wifi_write('~5') + elif sample_rate == 1600: + self.wifi_write('~4') + elif sample_rate == 3200: + self.wifi_write('~3') + elif sample_rate == 6400: + self.wifi_write('~2') + elif sample_rate == 12800: + self.wifi_write('~1') + elif sample_rate == 25600: + self.wifi_write('~0') + else: + print("Sample rate not supported: " + str(sample_rate)) + else: + print("Board type not supported for setting sample rate") + except Exception as e: + print("Something went wrong while setting sample rate: " + str(e)) + + def set_accelerometer(self, toggle_position): + """ Enable / disable accelerometer """ + try: + if self.board_type == k.BOARD_GANGLION: + # Commands to set toggle to on position + if toggle_position == 1: + self.wifi_write('n') + # Commands to set toggle to off position + elif toggle_position == 0: + self.wifi_write('N') + else: + print("Board type not supported for setting accelerometer") + except Exception as e: + print("Something went wrong while setting accelerometer: " + str(e)) + """ Clean Up (atexit) @@ -474,4 +540,7 @@ def set_callback(self, callback): self.handler.callback = callback def set_gains(self, gains): - self.parser.set_ads1299_scale_factors(gains) \ No newline at end of file + self.parser.set_ads1299_scale_factors(gains) + + def set_parser(self, parser): + self.parser = parser diff --git a/scripts/stream_data_wifi.py b/scripts/stream_data_wifi.py index 17bc0ac..e581b37 100644 --- a/scripts/stream_data_wifi.py +++ b/scripts/stream_data_wifi.py @@ -4,14 +4,14 @@ def printData(sample): - print sample + print(sample) if __name__ == '__main__': shield_name = 'OpenBCI-E2B6' logging.basicConfig(filename="test.log",format='%(asctime)s - %(levelname)s : %(message)s',level=logging.DEBUG) logging.info('---------LOG START-------------') - shield = bci.OpenBCIWiFi(shield_name=shield_name, log=True) + shield = bci.OpenBCIWiFi(shield_name=shield_name, log=True, high_speed=False) print("WiFi Shield Instantiated") shield.start_streaming(printData) diff --git a/scripts/stream_data_wifi_high_speed.py b/scripts/stream_data_wifi_high_speed.py index 1694738..d2ac216 100644 --- a/scripts/stream_data_wifi_high_speed.py +++ b/scripts/stream_data_wifi_high_speed.py @@ -4,7 +4,8 @@ def printData(sample): - print sample.sample_number + print(sample.sample_number) + print(sample.channel_data) if __name__ == '__main__':