Skip to content

Commit

Permalink
serialMonitor added
Browse files Browse the repository at this point in the history
  • Loading branch information
SebCanet committed Dec 31, 2021
1 parent c4bf8d7 commit 26c017c
Show file tree
Hide file tree
Showing 13 changed files with 1,698 additions and 154 deletions.
4 changes: 0 additions & 4 deletions .github/FUNDING.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .vscode/c_cpp_properties.json

This file was deleted.

2 changes: 0 additions & 2 deletions .vscode/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ v0.9.0
- add conversion tool text <-> binary
- add colors conversion tool
- add conversion blocks to send data in SenML format
- add WebSerial API

v0.8.1
- finish text blocks translation in Arudino code
Expand Down
41 changes: 10 additions & 31 deletions S4E/js/boards.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,17 @@ Code.changeBoard = function() {
document.getElementById("boardDescriptionSelector").value = newBoard;
document.getElementById("boardSelected_span").textContent = profile["default"].description;
document.getElementById("portSelected_span").textContent = ' : ' + document.getElementById('serialMenu').options[document.getElementById('serialMenu').selectedIndex].value;
localStorage.setItem("availableSpeed", JSON.stringify(profile.default['serialList']));
sessionStorage.setItem("availableSpeed", JSON.stringify(profile.default['serialList']));
window.history.pushState({}, "S4E", Code.addReplaceParamToUrl(window.location.search, "board", newBoard));
//update serial speed list in serial monitor
document.getElementById('serialConnectSpeed_Menu').length = 0;
var serialConnectSpeedAvailable = profile.default['serialList'];
serialConnectSpeedAvailable.forEach((serialConnectSpeed) => {
var option = document.createElement('option');
option.value = serialConnectSpeed;
option.text = serialConnectSpeed;
document.getElementById('serialConnectSpeed_Menu').appendChild(option);
});
// "reboot" elements
document.getElementById('overlayForModals').style.display = "none";
document.getElementById('boardListModal').classList.remove('show');
Expand All @@ -78,34 +87,4 @@ Code.changeBoard = function() {
var xml = Blockly.Xml.workspaceToDom(Code.mainWorkspace);
Code.mainWorkspace.clear()
Blockly.Xml.domToWorkspace(xml, Code.mainWorkspace);
};

/**
* Set COM port
*/
Code.setPort = function() {
var serialPortMenu = document.getElementById('serialMenu');
var newPort = encodeURIComponent(serialPortMenu.options[serialPortMenu.selectedIndex].value);
document.getElementById('overlayForModals').style.display = "none";
document.getElementById('portListModal').classList.remove('show');
document.getElementById("portSelected_span").textContent = ' : ' + newPort;
if (newPort != 'none') {
document.getElementById('serialButton').classList.add('active');
document.getElementById('serialButton').title = newPort;
document.getElementById('serialButton').onmouseover = function() {
document.getElementById("content_hoverButton").textContent = newPort;
};
document.getElementById('serialButton').onmouseout = function() {
document.getElementById("content_hoverButton").textContent = "";
}
} else {
document.getElementById('serialButton').classList.remove('active');
document.getElementById('serialButton').title = MSG['serialButtonSpan'];
document.getElementById('serialButton').onmouseover = function() {
document.getElementById("content_hoverButton").textContent = MSG['serialButtonSpan'];
};
document.getElementById('serialButton').onmouseout = function() {
document.getElementById("content_hoverButton").textContent = "";
};
}
};
33 changes: 16 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
<span id="verifyButton_span" class="fas fa-tasks">
</span>
</button>
<!-- <button id="serialButton" class="iconButtons"> -->
<!-- <button id="serialButton" class="iconButtons" onclick="Code.portsListModalShow()"> -->
<button id="serialButton" class="iconButtons" onclick="Code.getPorts()">
<span id="serialButton_span" class="fab fa-usb">
Expand Down Expand Up @@ -1266,28 +1267,27 @@
<script src="./S4E/categories/servo/servo.arduino"></script>
<script src="./S4E/categories/X-NUCLEO-IKS01A3/X-NUCLEO-IKS01A3.arduino"></script>
<script>
var require = {
require('../resources/app.asar/Arrowhead.js');
require('../resources/app.asar/renderer.js');
require('../resources/app.asar/menu_functions.js');
require('../resources/app.asar/menu_CLI_functions.js');
require('../resources/app.asar/menu_IDE_functions.js');
// require('../Arrowhead.js');
// require('../renderer.js');
// require('../menu_functions.js');
// require('../menu_CLI_functions.js');
// require('../menu_IDE_functions.js');
</script>
<script src="./tools/vs/loader.js"></script>
<script>
require.config({
paths: {
'vs': './tools/vs'
}
};
});
</script>
<script src="./tools/vs/loader.js"></script>
<script src="./tools/vs/editor/editor.main.nls.js"></script>
<script src="./tools/vs/editor/editor.main.js"></script>

<script>
// require('../resources/app.asar/Arrowhead.js');
// require('../resources/app.asar/renderer.js');
// require('../resources/app.asar/menu_functions.js');
// require('../resources/app.asar/menu_CLI_functions.js');
// require('../resources/app.asar/menu_IDE_functions.js');
// require('./Arrowhead.js');
// require('./renderer.js');
// require('./menu_functions.js');
// require('./menu_CLI_functions.js');
// require('./menu_IDE_functions.js');
</script>
<script type="text/javascript">
window.onload = function() {
if (document.readyState === 'complete') {
Expand All @@ -1313,7 +1313,6 @@
}
}
</script>

</body>

</HTML>
2 changes: 0 additions & 2 deletions js/blockly_playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ function setOnOffLine() {
document.getElementById('verifyButton').disabled = false;
document.getElementById('serialButton').disabled = false;
document.getElementById('uploadButton').disabled = false;
document.getElementById('serialConnectButton').disabled = false;
document.getElementById('serialMenu').disabled = false;
// not same button if in Electron or browser, if local nodejs watches events
document.getElementById('wiringButton').setAttribute('onclick', '');
Expand All @@ -206,7 +205,6 @@ function setOnOffLine() {
document.getElementById('verifyButton').disabled = true;
document.getElementById('serialButton').disabled = true;
document.getElementById('uploadButton').disabled = true;
document.getElementById('serialConnectButton').disabled = true;
document.getElementById('serialMenu').disabled = true;
// not same button if in Electron or browser, if web just webpages launched in browser
document.getElementById('wiringButton').setAttribute('onclick', './tools/hackcable/index.html');
Expand Down
77 changes: 39 additions & 38 deletions js/buttons_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,18 @@ Code.blockPicture = function() {
Code.copyToClipboard = function() {
if (document.selection) { // IE
var range = document.body.createTextRange();
range.moveToElementText(Code.editor.getValue());
if (Code.editor)
range.moveToElementText(Code.editor.getValue());
else range.moveToElementText(Blockly.Arduino.workspaceToCode(Code.mainWorkspace));
range.select();
document.execCommand("copy");
} else if (window.getSelection) {
navigator.clipboard.writeText(Code.editor.getValue())
if (Code.editor)
navigator.clipboard.writeText(Code.editor.getValue())
.then(() => { console.log('Code copied!') })
.catch((error) => { console.log('Copy failed! ${error}') });
else
navigator.clipboard.writeText(Blockly.Arduino.workspaceToCode(Code.mainWorkspace))
.then(() => { console.log('Code copied!') })
.catch((error) => { console.log('Copy failed! ${error}') });
}
Expand Down Expand Up @@ -220,16 +227,16 @@ Code.boardsListModalShow = function() {
window.addEventListener('click', Code.boardsListModalHide, 'once');
Code.boardDescription();
};
// Code.portsListModalShow = function() {
// document.getElementById('overlayForModals').style.display = "block";
// document.getElementById('portListModal').classList.add('show');
// var portValue = document.getElementById("serialMenu").value;
// if (portValue !== 'none') {
// document.getElementById("serialMenu").selectedIndex = portValue;
// document.getElementById("serialMenu").value = portValue;
// }
// window.addEventListener('click', Code.portsListModalHide, 'once');
// };
Code.portsListModalShow = async function() {
document.getElementById('overlayForModals').style.display = "block";
document.getElementById('portListModal').classList.add('show');
var portValue = document.getElementById("serialMenu").value;
if (portValue !== 'none') {
document.getElementById("serialMenu").selectedIndex = portValue;
document.getElementById("serialMenu").value = portValue;
}
window.addEventListener('click', Code.portsListModalHide, 'once');
};
Code.flowsListModalShow = function() {
document.getElementById('overlayForModals').style.display = "block";
document.getElementById('flowsListModal').classList.add('show');
Expand All @@ -239,10 +246,10 @@ document.getElementById("closeModalBoards").onclick = function() {
document.getElementById('overlayForModals').style.display = "none";
document.getElementById('boardListModal').classList.remove('show');
};
// document.getElementById("closeModalPorts").onclick = function() {
// document.getElementById('overlayForModals').style.display = "none";
// document.getElementById('portListModal').classList.remove('show');
// };
document.getElementById("closeModalPorts").onclick = function() {
document.getElementById('overlayForModals').style.display = "none";
document.getElementById('portListModal').classList.remove('show');
};
document.getElementById("closeModalFlows").onclick = function() {
document.getElementById('overlayForModals').style.display = "none";
document.getElementById('flowsListModal').classList.remove('show');
Expand All @@ -254,12 +261,12 @@ Code.boardsListModalHide = function(event) {
document.getElementById('boardListModal').classList.remove('show');
}
};
// Code.portsListModalHide = function(event) {
// if (document.getElementById('portListModal_content').contains(event.target)) {} else {
// document.getElementById('overlayForModals').style.display = "none";
// document.getElementById('portListModal').classList.remove('show');
// }
// };
Code.portsListModalHide = function(event) {
if (document.getElementById('portListModal_content').contains(event.target)) {} else {
document.getElementById('overlayForModals').style.display = "none";
document.getElementById('portListModal').classList.remove('show');
}
};
Code.flowsListModalHide = function(event) {
if (document.getElementById('flowsListModal_content').contains(event.target)) {} else {
document.getElementById('overlayForModals').style.display = "none";
Expand Down Expand Up @@ -874,29 +881,23 @@ Code.getPorts = async function() {
if (!('serial' in navigator)) {
Blockly.alert("This site requires the experimental Web Serial API. Your browser either does not support this, or does not have it enabled.");
} else try {
// request WebSerial API for port list
// in Electron it fires 'select-serial-port' in main.js
Code.serialPort = await navigator.serial.requestPort();
document.getElementById('serialButton').className = 'iconButtonsClicked';
window.sessionStorage.setItem('portSelected', true);
const { usbProductId, usbVendorId } = Code.serialPort.getInfo();
document.getElementById('portSelected_span').innerHTML = 'connected';
// navigator.usb.getDevices()
// .then(devices => {
// devices.forEach(device => {
// if (device.vendorId == usbVendorId)
// console.log("Product name: " + device.productName);
// });
// })
// .catch(error => { Blockly.alert(error); });
} catch (error) {
Blockly.alert('no port selected')
document.getElementById('serialButton').className = 'iconButtons';
window.sessionStorage.setItem('portSelected', false);
document.getElementById('portSelected_span').innerHTML = 'not connected';
if (!Code.serialPort) {
Blockly.alert('no port selected')
document.getElementById('serialButton').className = 'iconButtons';
window.sessionStorage.setItem('portSelected', false);
}
}
}
navigator.usb.addEventListener("connect", (event) => {
navigator.serial.addEventListener("connect", (event) => {
Blockly.alert('New device connected');
});
navigator.usb.addEventListener("disconnect", (event) => {
navigator.serial.addEventListener("disconnect", (event) => {
Blockly.alert('Device disconnected');
// console.log(event.target)
});
5 changes: 3 additions & 2 deletions js/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ function showSerialMonitorModalDialog() {
var id = 'serialMonitorModalDialog';
var dialog = new DialogBox(id, callbackDialogSerialMonitorModal);
dialog.showDialog();
var serialConnectSpeedAvailable = JSON.parse(localStorage.getItem("availableSpeed"));
var serialConnectSpeedAvailable = JSON.parse(sessionStorage.getItem("availableSpeed"));
document.getElementById('serialConnectSpeed_Menu').length = 0;
serialConnectSpeedAvailable.forEach((serialConnectSpeed) => {
var option = document.createElement('option');
option.value = serialConnectSpeed;
Expand All @@ -112,7 +113,7 @@ function showSerialMonitorModalDialog() {
_serialModal.style.height = serialModal_old_height + "px";
document.getElementById("serialMonitorModalDialogContent").style.width = "calc(100% - 32px)";
document.getElementById("serialModalTitle_titlebar").style.width = "calc(100% - 32px)";
_maximiniSerial == 'mini'
_maximiniSerial = 'mini'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Code.renderContent = function() {
else
Code.editor.setValue(generatedCode);
}
var diff = JsDiff.diffWords(PREVIOUS_CODE_, generatedCode);
var diff = Diff.diffWords(PREVIOUS_CODE_, generatedCode);
var resultStringArray = [];
for (var i = 0; i < diff.length; i++) {
if (!diff[i].removed) {
Expand Down
Loading

0 comments on commit 26c017c

Please sign in to comment.