Skip to content

Commit ee49f9c

Browse files
committed
Added analog resolution selector checkbox
* Added an SpinBox to in the board manager gui to select the analog resolution to use in the experiment * Setted a default analog resolution on every board (the default is the max resolution of the microcontroller)
1 parent dd0e357 commit ee49f9c

File tree

6 files changed

+1655
-1534
lines changed

6 files changed

+1655
-1534
lines changed

MLC/GUI/Autogenerated/autogenerated.py

Lines changed: 1536 additions & 1507 deletions
Large diffs are not rendered by default.

MLC/GUI/Autogenerated/mlc_qtcreator/board_config_design.ui

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,47 @@
11441144
</layout>
11451145
</widget>
11461146
</item>
1147+
<item>
1148+
<widget class="QFrame" name="frame">
1149+
<property name="frameShape">
1150+
<enum>QFrame::StyledPanel</enum>
1151+
</property>
1152+
<property name="frameShadow">
1153+
<enum>QFrame::Raised</enum>
1154+
</property>
1155+
<layout class="QHBoxLayout" name="horizontalLayout_15">
1156+
<item>
1157+
<widget class="QLabel" name="analog_resolution">
1158+
<property name="sizePolicy">
1159+
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
1160+
<horstretch>0</horstretch>
1161+
<verstretch>0</verstretch>
1162+
</sizepolicy>
1163+
</property>
1164+
<property name="text">
1165+
<string>Analog resolution</string>
1166+
</property>
1167+
</widget>
1168+
</item>
1169+
<item>
1170+
<widget class="QSpinBox" name="analog_resolution_spin">
1171+
<property name="sizePolicy">
1172+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
1173+
<horstretch>0</horstretch>
1174+
<verstretch>0</verstretch>
1175+
</sizepolicy>
1176+
</property>
1177+
<property name="minimum">
1178+
<number>1</number>
1179+
</property>
1180+
<property name="maximum">
1181+
<number>32</number>
1182+
</property>
1183+
</widget>
1184+
</item>
1185+
</layout>
1186+
</widget>
1187+
</item>
11471188
</layout>
11481189
</item>
11491190
</layout>
@@ -1340,6 +1381,22 @@
13401381
</hint>
13411382
</hints>
13421383
</connection>
1384+
<connection>
1385+
<sender>analog_resolution_spin</sender>
1386+
<signal>valueChanged(int)</signal>
1387+
<receiver>BoardConfigurationWindow</receiver>
1388+
<slot>on_analog_resolution_change()</slot>
1389+
<hints>
1390+
<hint type="sourcelabel">
1391+
<x>946</x>
1392+
<y>609</y>
1393+
</hint>
1394+
<hint type="destinationlabel">
1395+
<x>511</x>
1396+
<y>337</y>
1397+
</hint>
1398+
</hints>
1399+
</connection>
13431400
</connections>
13441401
<slots>
13451402
<slot>on_digital_pin_insert()</slot>
@@ -1350,6 +1407,7 @@
13501407
<slot>on_analog_pin_remove()</slot>
13511408
<slot>on_bench_test_click()</slot>
13521409
<slot>on_connection_type_toggle()</slot>
1410+
<slot>on_analog_resolution_change()</slot>
13531411
</slots>
13541412
<buttongroups>
13551413
<buttongroup name="connection_type_group"/>

MLC/GUI/Experiment/ArduinoConfigManager/ArduinoBoardManager.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ class ArduinoBoardManager:
2020
def __init__(self, protocol_config, serial_config, close_handler, parent_win=None):
2121
self.__setup = protocol_config
2222
self.__connection_config = serial_config
23-
self.__main_window = BoardConfigurationWindow(
24-
self, boards.types, self.__setup, parent=parent_win)
23+
self.__main_window = BoardConfigurationWindow(self, boards.types, self.__setup, parent=parent_win)
2524
self.__connectino_status = None
2625
self.__sch = QTimer()
2726
self.PARITY_BITS = [serial.PARITY_NONE, serial.PARITY_EVEN,
2827
serial.PARITY_EVEN, serial.PARITY_MARK, serial.PARITY_SPACE]
29-
self.STOP_BITS = [
30-
serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE, serial.STOPBITS_TWO]
31-
self.BYTE_SIZE = [
32-
serial.EIGHTBITS, serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS]
33-
#FIXME the connection with the handler shold be made by a method of the window
28+
self.STOP_BITS = [serial.STOPBITS_ONE, serial.STOPBITS_ONE_POINT_FIVE, serial.STOPBITS_TWO]
29+
self.BYTE_SIZE = [serial.EIGHTBITS, serial.FIVEBITS, serial.SIXBITS, serial.SEVENBITS]
30+
# FIXME the connection with the handler shold be made by a method of the window
3431
self.__main_window.on_close_signal.connect(close_handler)
3532

3633
def get_protocol_config(self):
@@ -71,7 +68,7 @@ def insert_digital_pin(self, pin_index, pin, type_idx):
7168
else:
7269
self.show_error(
7370
"Error", "Assign error", "Could not set pin %s with the selected type" % (pin),
74-
QMessageBox.Critical, QMessageBox.Ok)
71+
QMessageBox.Critical, QMessageBox.Ok)
7572

7673
# Mover a la vista
7774
def show_error(self, title, text, info, icon, buttons):
@@ -86,7 +83,7 @@ def show_error(self, title, text, info, icon, buttons):
8683
def remove_digital_pin(self, pin):
8784
if pin in self.__setup.digital_input_pins:
8885
self.__setup.digital_input_pins.remove(pin)
89-
86+
9087
if pin in self.__setup.digital_output_pins:
9188
self.__setup.digital_output_pins.remove(int(pin))
9289

@@ -104,13 +101,14 @@ def insert_analog_pin(self, pin_index, pin, type_idx):
104101
self.__main_window.addAnalogPin(pin_index, type_idx)
105102
else:
106103
self.show_error(
107-
"Error", "Assign error", "Could not set pin %d with the selected type" % (pin), QMessageBox.Critical, QMessageBox.Ok)
104+
"Error", "Assign error", "Could not set pin %d with the selected type" % (pin),
105+
QMessageBox.Critical, QMessageBox.Ok)
108106

109107
def remove_analog_pin(self, pin):
110108
if pin in self.__setup.analog_input_pins:
111109
self.__setup.analog_input_pins.remove(pin)
112110

113-
if pin in self.__setup.analog_output_pins:
111+
if pin in self.__setup.analog_output_pins:
114112
self.__setup.analog_output_pins.remove(pin)
115113

116114
def check_connection(self):
@@ -142,7 +140,8 @@ def board_changed(self, new_idx, old_idx):
142140
if self.__setup.digital_input_pins or self.__setup.digital_output_pins or \
143141
self.__setup.analog_input_pins or self.__setup.analog_output_pins or self.__setup.pwm_pins:
144142
ret = self.show_error(
145-
"Warning", "Configuration reset", "Changing the board will reset all I/O pins configuration! Continue?", QMessageBox.Critical, QMessageBox.Yes | QMessageBox.No)
143+
"Warning", "Configuration reset", "Changing the board will reset all I/O pins configuration! Continue?",
144+
QMessageBox.Critical, QMessageBox.Yes | QMessageBox.No)
146145

147146
if (ret == QMessageBox.Yes):
148147
del self.__setup.digital_input_pins[:]
@@ -162,7 +161,7 @@ def start_bench(self):
162161
self.show_error(
163162
"Error", "Connection failure", "Could not start connection to board", QMessageBox.Critical, QMessageBox.Ok)
164163
return
165-
164+
166165
bench = ArduinoBench()
167166
stats = ArduinoStatsDialog(bench)
168167
stats.connect_to_reset(bench)
@@ -171,6 +170,9 @@ def start_bench(self):
171170
stats.exec_()
172171
bench.stop()
173172

173+
def update_analog_resolution(self, value):
174+
self.__setup = self.__setup._replace(analog_resolution=value)
175+
174176

175177
class EventScheduler:
176178

MLC/GUI/Experiment/ArduinoConfigManager/BoardConfigurationWindow.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def closeEvent(self, event):
4444
connection_cfg = [self.__controller.get_connection_config()]
4545
self.on_close_signal.emit(board_setup, connection_cfg)
4646
event.accept()
47-
#super(BoardConfigurationWindow, self).closeEvent(event)
4847

4948
def update(self):
5049
aux_idx = 0
@@ -64,7 +63,7 @@ def update(self):
6463
if i not in self.__setup.analog_input_pins and i not in self.__setup.analog_output_pins:
6564
self.setup_pin(self.ui.analogPins, 0, "Pin A" + str(i - digital_pin_count), i)
6665
aux_idx += 1
67-
66+
6867
# Clear the list (QTableWidget.clearContent doesn't remove the rows!)
6968
for i in xrange(self.ui.digitalPinsList.rowCount(), -1, -1):
7069
self.ui.digitalPinsList.removeRow(i)
@@ -87,6 +86,8 @@ def update(self):
8786
for pin in self.__setup.pwm_pins:
8887
self.insertPin(pin, "Pin " + str(pin), self.ui.digitalPinType.itemText(2), self.ui.digitalPinsList)
8988

89+
self.ui.analog_resolution_spin.setValue(self.__setup.analog_resolution)
90+
9091
def setup_board(self, index, board_name, image_name):
9192
_translate = QtCore.QCoreApplication.translate
9293
image_path = create_local_full_path("images", image_name)
@@ -106,20 +107,24 @@ def on_pinout_show(self):
106107
dialog = ArduinoBoardDialog(path)
107108
dialog.exec_()
108109

110+
def on_analog_resolution_change(self, index):
111+
self.__controller.update_analog_resolution(index)
112+
109113
def checkout_connection_config(self):
110114
# TODO Renombrar para checkout de parametros de conexion serie
111115
serial_config = {
112-
"baudrate": int(self.ui.baud_rate_selector.currentText()),
116+
"baudrate": int(self.ui.baud_rate_selector.currentText()),
113117
"parity": self.ui.parity_bits_selector.currentIndex(),
114118
"stopbits": self.ui.stop_bits_selector.currentIndex(),
115119
"bytesize": self.ui.byte_size_selector.currentIndex(),
116120
"port": self.ui.serial_interface_input.displayText()}
117121
return serial_config
118122

119123
def checkout_board_setup(self):
120-
board_setup = {"report_mode": self.ui.report_mode_combo.currentIndex(),
121-
"read_delay": self.ui.read_delay_spin.value(),
122-
"read_count": self.ui.read_count_spin.value()}
124+
board_setup = {"report_mode": self.ui.report_mode_combo.currentIndex(),
125+
"read_delay": self.ui.read_delay_spin.value(),
126+
"read_count": self.ui.read_count_spin.value(),
127+
"analog_resolution": self.ui.analog_resolution_spin.value()}
123128
return board_setup
124129

125130
def on_check_connection(self):

MLC/arduino/boards.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11

2-
Due = {"NAME":"Arduino Due", "SHORT_NAME": "due","ANALOG_PINS":range(54, 68), "DIGITAL_PINS":range(0,54), "PWM_PINS":(2,3,4,5,6,7,8,9,10,11,12,13)}
3-
Uno = {"NAME":"Arduino Uno", "SHORT_NAME": "uno", "ANALOG_PINS":range(14, 20), "DIGITAL_PINS":range(0,14), "PWM_PINS":(3,5,6,9,10,11)}
4-
Mega = {"NAME":"Arduino Mega", "SHORT_NAME": "mega", "ANALOG_PINS":range(54, 70), "DIGITAL_PINS":range(0,54), "PWM_PINS":range(2,14)}
5-
Leonardo = {"NAME":"Arduino Leonardo", "SHORT_NAME": "leonardo", "ANALOG_PINS":range(14, 20), "DIGITAL_PINS":range(0,14), "PWM_PINS":(3,5,6,9,10,11,12,13)}
2+
Due = {"NAME": "Arduino Due",
3+
"SHORT_NAME": "due",
4+
"ANALOG_PINS": range(54, 68),
5+
"DIGITAL_PINS": range(0, 54),
6+
"PWM_PINS": (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
7+
"ANALOG_DEFAULT_RESOLUTION": 12}
68

7-
types=[Due, Uno, Mega, Leonardo]
9+
Uno = {"NAME": "Arduino Uno",
10+
"SHORT_NAME": "uno", "ANALOG_PINS": range(14, 20),
11+
"DIGITAL_PINS": range(0, 14),
12+
"PWM_PINS": (3, 5, 6, 9, 10, 11),
13+
"ANALOG_DEFAULT_RESOLUTION": 10}
14+
15+
Mega = {"NAME": "Arduino Mega",
16+
"SHORT_NAME": "mega",
17+
"ANALOG_PINS": range(54, 70),
18+
"DIGITAL_PINS": range(0, 54),
19+
"PWM_PINS": range(2, 14),
20+
"ANALOG_DEFAULT_RESOLUTION": 10}
21+
22+
Leonardo = {"NAME": "Arduino Leonardo",
23+
"SHORT_NAME": "leonardo",
24+
"ANALOG_PINS": range(14, 20),
25+
"DIGITAL_PINS": range(0, 14),
26+
"PWM_PINS": (3, 5, 6, 9, 10, 11, 12, 13),
27+
"ANALOG_DEFAULT_RESOLUTION": 10}
28+
29+
types = [Due, Uno, Mega, Leonardo]

MLC/arduino/protocol.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,22 @@ def actuate(self, data):
235235

236236
class ProtocolConfig (namedtuple('ProtocolConfig', ['connection', 'report_mode', 'read_count', 'read_delay', 'board_type',
237237
'digital_input_pins', 'digital_output_pins', 'analog_input_pins',
238-
'analog_output_pins', 'pwm_pins'])):
238+
'analog_output_pins', 'pwm_pins', 'analog_resolution'])):
239239

240240
def __new__(cls, connection, report_mode=REPORT_MODES.AVERAGE, read_count=2, read_delay=0, board_type=boards.Due,
241241
digital_input_pins=None, digital_output_pins=None, analog_input_pins=None, analog_output_pins=None,
242-
pwm_pins=None):
242+
pwm_pins=None, analog_resolution=None):
243+
243244
digital_input_pins = [] if digital_input_pins is None else digital_input_pins
244245
digital_output_pins = [] if digital_output_pins is None else digital_output_pins
245246
analog_input_pins = [] if analog_input_pins is None else analog_input_pins
246247
analog_output_pins = [] if analog_output_pins is None else analog_output_pins
247248
pwm_pins = [] if pwm_pins is None else pwm_pins
249+
analog_resolution = boards.Due["ANALOG_DEFAULT_RESOLUTION"] if analog_resolution is None else analog_resolution
250+
248251
return super(ProtocolConfig, cls).__new__(cls, connection, report_mode, read_count, read_delay,
249252
board_type, digital_input_pins, digital_output_pins,
250-
analog_input_pins, analog_output_pins, pwm_pins)
253+
analog_input_pins, analog_output_pins, pwm_pins, analog_resolution)
251254

252255

253256
def BuildSerial(protocol_config):
@@ -257,6 +260,8 @@ def BuildSerial(protocol_config):
257260
interface.set_report_mode(
258261
protocol_config.report_mode, protocol_config.read_count, protocol_config.read_delay)
259262

263+
interface.set_precision(protocol_config.analog_resolution)
264+
260265
for port in protocol_config.digital_input_pins:
261266
interface.add_input(port)
262267

0 commit comments

Comments
 (0)