Skip to content

Commit c0e88c5

Browse files
committed
Support for selecting serial port based on device serial number
1 parent 8a52496 commit c0e88c5

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

css/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ button#maintenance{
433433
width: 320px;
434434
}
435435

436+
#connection-type {
437+
margin-right: 10px;
438+
}
439+
436440
#maintenance-panel .apply-button,
437441
#advanced-settings .send-button{
438442
position: relative;

js/maintenance-panel.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,39 @@ $(document).ready(function(){
5050
$.post('socketmessage.php', {messageType: "dateTimeFormatDisplay", message: $("#datetime-format-display").val()});
5151
});
5252

53+
function update_serial_selector(){
54+
if($('#connection-type').val() === '1'){
55+
$('select.port-address').hide();
56+
$('input.port-address').show();
57+
}
58+
else {
59+
$.ajax({
60+
type: "POST",
61+
dataType:"json",
62+
contentType:"application/x-www-form-urlencoded; charset=utf-8",
63+
url: 'socketmessage.php',
64+
data: {messageType: "getSerialDevicesAvailable", message: ""},
65+
success: function(list){
66+
$('select.port-address').empty();
67+
for(var i=0; i < list.length; i++){
68+
$('select.port-address').append($('<option>').attr('value', list[i]).text(list[i]));
69+
};
70+
$('input.port-address').hide();
71+
$('select.port-address').show();
72+
},
73+
error: function(){
74+
$('select.port-address').hide();
75+
$('input.port-address').show();
76+
}
77+
});
78+
}
79+
}
80+
81+
$("#connection-type").change(update_serial_selector);
82+
update_serial_selector();
83+
5384
$("button.apply-connection").button({ icons: {primary: "ui-icon-check" } }).unbind('click').click(function(){
54-
const port_address = $("#port-address").val().trim();
85+
const port_address = $(".port-address:visible").val().trim();
5586
let message;
5687
if($("#connection-type").val() == 1){
5788
// ip address selected. Add socket:// and port 6666
@@ -138,8 +169,6 @@ $(document).ready(function(){
138169
startRefreshLogs(2000, 0, 1, '#reprogram-arduino'); // autorefresh stderr as long as the tab remains open
139170
$("#program-stderr-header").text("Programming... keep an eye on the output below to see the progress.");
140171
});
141-
142-
143172
});
144173

145174
boardNames = { "core": "Core", "photon": "Photon", "leonardo": "Arduino", "uno": "Arduino" };

maintenance-panel.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,12 @@ function echoRotarySelect($optionName){
136136
</div>
137137
<div class="setting-container">
138138
<span class="setting-name">Connection to BrewPi Spark</span>
139-
<div class="setting-group">
140139
<select id="connection-type">
141140
<option value="0">Serial port: </option>
142141
<option value="1">IP address:</option>
143142
</select>
144-
<input id="port-address">
145-
</div>
143+
<select class="port-address" />
144+
<input class="port-address" />
146145
<button class="apply-connection apply-button">Apply</button>
147146
</div>
148147
</div>

0 commit comments

Comments
 (0)