1919# You should have received a copy of the GNU General Public License
2020# along with this program. If not, see <http://www.gnu.org/licenses/>
2121
22- from ArduinoBoardDialog import ArduinoBoardDialog
2322from ArduinoBench import ArduinoBench
2423
25- from MLC .GUI .Autogenerated .autogenerated import Ui_BoardConfigurationWindow
2624from MLC .GUI .Experiment .ArduinoConfigManager .BoardConfigurationWindow import BoardConfigurationWindow
2725from MLC .arduino import boards
2826from MLC .arduino .connection .serialconnection import SerialConnection , SerialConnectionConfig
2927from MLC .arduino .protocol import ProtocolConfig , init_interface
3028from MLC .arduino .connection .base import ConnectionException , ConnectionTimeoutException
3129
3230from PyQt5 .QtWidgets import QMessageBox
33- from PyQt5 .QtCore import QTimer
3431
3532import serial
3633import threading
@@ -161,7 +158,7 @@ def board_changed(self, new_idx, old_idx):
161158 "Warning" , "Configuration reset" , "Changing the board will reset all I/O pins configuration! Continue?" ,
162159 QMessageBox .Critical , QMessageBox .Yes | QMessageBox .No )
163160
164- if ( ret == QMessageBox .Yes ) :
161+ if ret == QMessageBox .Yes :
165162 del self .__setup .digital_input_pins [:]
166163 del self .__setup .digital_output_pins [:]
167164 del self .__setup .analog_input_pins [:]
@@ -171,15 +168,19 @@ def board_changed(self, new_idx, old_idx):
171168 analog_resolution = boards .types [new_idx ]["ANALOG_DEFAULT_RESOLUTION" ])
172169 self .__main_window .set_board (new_idx )
173170 self .__main_window .update (self .__setup )
171+ return new_idx
174172 else :
175173 self .__main_window .set_board (old_idx )
174+ return old_idx
176175
177176 def start_bench (self ):
178177 try :
179- self .__setup = self .__setup ._replace (connection = self .start_connection (), ** self .__main_window .checkout_board_setup ())
178+ self .__setup = self .__setup ._replace (connection = self .start_connection (),
179+ ** self .__main_window .checkout_board_setup ())
180180 except SerialConnectionException :
181181 self .show_error (
182- "Error" , "Connection failure" , "Could not start connection to board" , QMessageBox .Critical , QMessageBox .Ok )
182+ "Error" , "Connection failure" , "Could not start connection to board" ,
183+ QMessageBox .Critical , QMessageBox .Ok )
183184 return
184185
185186 bench = ArduinoBench ()
@@ -190,6 +191,14 @@ def start_bench(self):
190191 stats .exec_ ()
191192 bench .stop ()
192193
194+ def autodetect_board (self ):
195+ board_id = boards .detect_board ()
196+
197+ if board_id and board_id != self .__main_window .current_board_idx ():
198+ self .board_changed (board_id , self .__main_window .current_board_idx ())
199+
200+ return board_id
201+
193202 def update_analog_resolution (self , value ):
194203 self .__setup = self .__setup ._replace (analog_resolution = value )
195204
0 commit comments