Skip to content

Commit 7201ca5

Browse files
authored
Merge pull request #86 from Open-STEM/frank-next-work
Update for non-beta board
2 parents d3396cd + 22b0da2 commit 7201ca5

40 files changed

Lines changed: 690 additions & 177 deletions

CHANGELOG.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# Version 1.2.1
2+
3+
## Support for new XRP control board
4+
* Updates appropriate firmware for the board
5+
* Adds a block for the color LED
6+
7+
8+
# Version 1.2.0
9+
10+
## Updated version of Micropython and XRPLib
11+
There is now a version of Micropython that is specific to the XRP. Going forward from Micropython version 1.25.0 the XRP should use the XRP specific version of Micropython.
12+
XRPLib has also been updated to work specifically with the XRP versions of Micropython.
13+
14+
### Fixed
15+
* We needed to stop reseting Micropython when a program ended when we added bluetooth support, since that would also reset the bluetooth connection. This gave an added benefit of having all of your global variables and classes still in memory for debugging.
16+
But this created a bug where the second time a program was run it could run out of memory. The memory is now cleared of all modules, except XRPLib, and variables that are not needed when the a program is run from XRPCode.
17+
* The above fix also fixed a problem for programs that used more than one file. Updates to imported parts of the program are now updated each time the program is run.
18+
* When using XRPCode over bluetooth there was a problem of missing characters in the terminal if a person was typing too fast. That has been fixed.
19+
* Updates of XRPLib were only being allowed if you were connected via a USB cable. You can now also update the library over bluetooth. Although it will always be much faster when using a cable.
20+
21+
122
# Version 1.1.0
223

324
#### Bluetooth support
169 KB
Loading

images/sad-battery.jpg

108 KB
Loading

images/sad-battery.png

-101 KB
Binary file not shown.

index.html

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77

88
<title>XRP Code Editor</title>
99

10-
<link rel="stylesheet" href="uikit-3.16.22/css/uikit.css?version=1.1.0" />
10+
<link rel="stylesheet" href="uikit-3.16.22/css/uikit.css?version=1.2.1" />
1111

12-
<link rel="stylesheet" href="js/xterm/css/xterm.css?version=1.1.0"/>
12+
<link rel="stylesheet" href="js/xterm/css/xterm.css?version=1.2.1"/>
1313

14-
<link rel="stylesheet" href="golden-layout/css/goldenlayout-base.css?version=1.1.0">
15-
<link rel="stylesheet" href="golden-layout/css/themes/goldenlayout-dark-theme.css?version=1.1.0">
14+
<link rel="stylesheet" href="golden-layout/css/goldenlayout-base.css?version=1.2.1">
15+
<link rel="stylesheet" href="golden-layout/css/themes/goldenlayout-dark-theme.css?version=1.2.1">
1616

17-
<link rel="stylesheet" href="css/dark/main-dark.css?version=1.1.0">
18-
<link rel="stylesheet" href="css/dark/fs-dark.css?version=1.1.0">
19-
<link rel="stylesheet" href="css/dark/dir_chooser-dark.css?version=1.1.0">
20-
<link rel="stylesheet" href="css/dark/shell-dark.css?version=1.1.0">
21-
<link rel="stylesheet" href="css/dark/editor-dark.css?version=1.1.0">
22-
<link rel="stylesheet" href="css/dark/changelog-dark.css?version=1.1.0">
17+
<link rel="stylesheet" href="css/dark/main-dark.css?version=1.2.1">
18+
<link rel="stylesheet" href="css/dark/fs-dark.css?version=1.2.1">
19+
<link rel="stylesheet" href="css/dark/dir_chooser-dark.css?version=1.2.1">
20+
<link rel="stylesheet" href="css/dark/shell-dark.css?version=1.2.1">
21+
<link rel="stylesheet" href="css/dark/editor-dark.css?version=1.2.1">
22+
<link rel="stylesheet" href="css/dark/changelog-dark.css?version=1.2.1">
2323

24-
<link rel="stylesheet" href="js/treejs/treejs.css?version=1.1.0" />
24+
<link rel="stylesheet" href="js/treejs/treejs.css?version=1.2.1" />
2525

2626
<link rel="preconnect" href="https://fonts.googleapis.com">
2727
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
@@ -304,28 +304,28 @@ <h2 class="uk-modal-title"></h2>
304304
<script src="js/blockly-10.0.0/blockly.min.js"></script>
305305
<script src="js/blockly-10.0.0/python_compressed.js"></script>
306306

307-
<script src="js/treejs/tree.js?version=1.1.0"></script>
307+
<script src="js/treejs/tree.js?version=1.2.1"></script>
308308

309-
<script src="js/xterm/lib/xterm.js?version=1.1.0"></script>
310-
<script src="js/xterm-addon-fit/lib/xterm-addon-fit.js?version=1.1.0"></script>
309+
<script src="js/xterm/lib/xterm.js?version=1.2.1"></script>
310+
<script src="js/xterm-addon-fit/lib/xterm-addon-fit.js?version=1.2.1"></script>
311311

312312
<script src="js/marked/marked.min.js"></script>
313313

314314

315-
<script src="js/ace/ace.js?version=1.1.0" type="text/javascript" charset="utf-8"></script>
316-
<script src="js/ace/ext-language_tools.js?version=1.1.0"></script>
315+
<script src="js/ace/ace.js?version=1.2.1" type="text/javascript" charset="utf-8"></script>
316+
<script src="js/ace/ext-language_tools.js?version=1.2.1"></script>
317317

318318
<script src="js/xrp_blocks.js"></script>
319319
<script src="js/xrp_blocks_python.js"></script>
320320
<script src="js/xrp_blockly_toolbox.js"></script>
321321

322-
<script src="js/editor_wrapper.js?version=1.1.0"></script>
323-
<script src="js/filesystem_wrapper.js?version=1.1.0"></script>
324-
<script src="js/dir_chooser.js?version=1.1.0"></script>
325-
<script src="js/active_terminal_wrapper.js?version=1.1.0"></script>
326-
<script src="js/joystick_wrapper.js?version=1.1.0"></script>
327-
<script src="js/repl.js?version=1.1.0"></script>
328-
<script type="module" src="golden-layout/bundle/esm/golden-layout.js?version=1.1.0"></script>
329-
<script type="module" src="js/main.js?version=1.1.0"></script>
322+
<script src="js/editor_wrapper.js?version=1.2.1"></script>
323+
<script src="js/filesystem_wrapper.js?version=1.2.1"></script>
324+
<script src="js/dir_chooser.js?version=1.2.1"></script>
325+
<script src="js/active_terminal_wrapper.js?version=1.2.1"></script>
326+
<script src="js/joystick_wrapper.js?version=1.2.1"></script>
327+
<script src="js/repl.js?version=1.2.1"></script>
328+
<script type="module" src="golden-layout/bundle/esm/golden-layout.js?version=1.2.1"></script>
329+
<script type="module" src="js/main.js?version=1.2.1"></script>
330330
</body>
331331
</html>

js/editor_wrapper.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class EditorWrapper{
3535
this.EDITOR_DIV.classList.add("editor");
3636
this._container.element.appendChild(this.EDITOR_DIV);
3737

38+
this.ERROR_DIV = document.createElement("div");
39+
this.ERROR_DIV.style.position = "absolute";
40+
this.ERROR_DIV.innerHTML = "The code in this program will not work on a Beta board.";
41+
3842
this.defaultCode = "from XRPLib.defaults import *\n\n" +
3943
"# available variables from defaults: left_motor, right_motor, drivetrain,\n" +
4044
"# imu, rangefinder, reflectance, servo_one, board, webserver\n" +
@@ -252,7 +256,12 @@ class EditorWrapper{
252256
if(this.BLOCKLY_WORKSPACE && data != undefined){
253257
console.log("loaded workspace early notice");
254258
this.LOADING_BLOCKLY = true; //let the onchange event know that we are loading
255-
Blockly.serialization.workspaces.load(JSON.parse(data), this.BLOCKLY_WORKSPACE);
259+
try{
260+
Blockly.serialization.workspaces.load(JSON.parse(data), this.BLOCKLY_WORKSPACE);
261+
}
262+
catch{
263+
console.log("blockly load failed turnIntoBlocklyViewer")
264+
}
256265
}
257266

258267
// This must run after the Editor is added to the DOM document
@@ -317,12 +326,19 @@ class EditorWrapper{
317326

318327
// Restoring of editor state
319328
var lastEditorValue = localStorage.getItem("EditorValue" + this.ID);
320-
if(data != undefined){
321-
this.LOADING_BLOCKLY = true; //let the onchange event know that we are loading
322-
Blockly.serialization.workspaces.load(JSON.parse(data), this.BLOCKLY_WORKSPACE);
323-
}else if(lastEditorValue != null){
329+
if(data != undefined || lastEditorValue != null){
330+
var data2 = data;
331+
if(data == undefined){
332+
data2 = lastEditorValue;
333+
}
324334
this.LOADING_BLOCKLY = true; //let the onchange event know that we are loading
325-
Blockly.serialization.workspaces.load(JSON.parse(lastEditorValue), this.BLOCKLY_WORKSPACE);
335+
try{
336+
Blockly.serialization.workspaces.load(JSON.parse(data2), this.BLOCKLY_WORKSPACE);
337+
}
338+
catch(e){
339+
//console.log(e);
340+
this.EDITOR_DIV.replaceChild(this.ERROR_DIV, this.EDITOR_DIV.childNodes[0]);
341+
}
326342
}else{
327343
// When adding default editors, give them a path but make each unique by looking at all other open editors
328344
this.setPath("/untitled-" + this.ID + ".blocks");

js/main.js

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { GoldenLayout, LayoutConfig } from "../golden-layout/bundle/esm/golden-layout.js";
2+
import { configNonBeta } from './nonbetaConfig.js';
3+
24

35

46
/*
57
VERSION NUMBERS
68
*/
79

8-
const showChangelogVersion = "1.1.0"; //update all instances of ?version= in the index file to match the version. This is needed for local cache busting
9-
window.latestMicroPythonVersion = [1, 23, 0];
10+
const showChangelogVersion = "1.2.1"; //update all instances of ?version= in the index file to match the version. This is needed for local cache busting
11+
window.latestMicroPythonVersion = [1, 25, 0];
1012
window.xrpID = "";
1113

1214

@@ -678,7 +680,56 @@ function registerShell(_container, state){
678680
document.getElementById('IDXRPName').innerHTML = "XRP-" + window.xrpID.slice(-5);
679681
document.getElementById('IDXRPName').style.display = "block";
680682
}
683+
}
684+
685+
REPL.pluginCheck = async () =>{
686+
//check if this is a beta or nonbeta board
687+
// set the localstorage for this type
688+
// Add to Blockly if this is a nonbeta board
689+
// refresh the editors.
690+
691+
var needsUpdate = false;
692+
xrpConfig = localStorage.getItem("xrpconfig");
693+
if(REPL.PROCESSOR == 2350){
694+
if(xrpConfig == null || xrpConfig === "beta"){
695+
//we need to set things up
696+
localStorage.setItem("xrpconfig", "nonbeta");
697+
await configNonBeta();
698+
needsUpdate = true;
699+
}
700+
}
701+
else{
702+
if(xrpConfig != null && xrpConfig === "nonbeta"){
703+
//we need to go back to beta
704+
localStorage.setItem("xrpconfig", "beta");
705+
blocklyToolbox = baseToolbox;
706+
servoNames = [["1", "1"], ["2", "2"]];
707+
needsUpdate = true;
708+
}
681709

710+
}
711+
if(needsUpdate){
712+
for( var editor in EDITORS){
713+
if(EDITORS[editor].isBlockly){
714+
var ed = EDITORS[editor];
715+
ed.BLOCKLY_WORKSPACE.updateToolbox(blocklyToolbox);
716+
717+
//make sure the editor is pointing to blockly div incase there was an error before.
718+
ed.EDITOR_DIV.replaceChild(ed.BLOCKLY_DIV, ed.EDITOR_DIV.childNodes[0]);
719+
720+
ed.BLOCKLY_WORKSPACE.clear();
721+
//ed.BLOCKLY_DIV.innerHTML = "";
722+
var data = localStorage.getItem("EditorValue" + editor)
723+
try{
724+
Blockly.serialization.workspaces.load(JSON.parse(data), ed.BLOCKLY_WORKSPACE);
725+
}
726+
catch(e){
727+
ed.EDITOR_DIV.replaceChild(ed.ERROR_DIV, ed.EDITOR_DIV.childNodes[0]);
728+
//console.log(e);
729+
}
730+
}
731+
}
732+
}
682733
}
683734
REPL.onFSData = (jsonStrData, fsSizeData) => {
684735
FS.updateTree(jsonStrData);
@@ -709,7 +760,11 @@ function registerShell(_container, state){
709760
message += "<br>Would you like to update now? If so, click OK to proceed with the update."
710761
let answer = await confirmMessage(message);
711762
if(answer){
712-
await alertMessage("When the <b>Select Folder</b> window comes up, select the <b>RPI-RP2</b> drive when it appears.<br>Next, click on 'Edit Files' and wait for the XRP to connect.<br> This process may take a few seconds.");
763+
let drive = "RPI-RP2"
764+
if(REPL.PROCESSOR == 2350){
765+
drive = "RP2350"
766+
}
767+
await alertMessage("When the <b><i>Select Folder</i></b> window comes up, select the <b><i>" + drive +"</i></b> drive when it appears.<br>Next, click on <b><i>Edit Files</i></b> and wait for the XRP to reconnect.<br> This process may take a few seconds.");
713768
REPL.updateMicroPython();
714769
}
715770

@@ -889,23 +944,28 @@ function registerEditor(_container, state) {
889944
//if Cable attached check to see that the power switch is on.
890945
// if BLE make sure the voltage is high enough
891946
const voltage = await REPL.batteryVoltage();
947+
var image = '/images/XRP_Controller-Power.jpg'
948+
if(REPL.PROCESSOR == 2350){
949+
image = '/images/XRP-nonbeta-controller-power.jpg'
950+
}
951+
892952
if(REPL.BLE_DEVICE == undefined){
893-
if(voltage < 0.4) {
953+
if(voltage < 0.45) {
894954
if(! await window.confirmMessage("The power switch on the XRP is not on. Motors and Servos will not work.<br>Turn on the switch before continuing." +
895-
"<br><img src='/images/XRP_Controller-Power.jpg' width=300>")) {
955+
"<br><img src=" + image + " width=300>")) {
896956
return;
897957
}
898958
}
899959
}else{
900-
if(voltage < 0.4) { //the device must be connected to a USB power with the power switch turned off.
960+
if(voltage < 0.45) { //the device must be connected to a USB power with the power switch turned off.
901961
if(! await window.confirmMessage("The power switch on the XRP is not on. Motors and Servos will not work.<br>Turn on the switch before continuing." +
902-
"<br><img src='/images/XRP_Controller-Power.jpg' width=300>")) {
962+
"<br><img src==" + image + " width=300>")) {
903963
return;
904964
}
905965

906966
}else if(voltage < 5.0) {
907967
if(await window.confirmMessage("<h1 style='text-align:center'>Low Battery Power! - Please Replace the Batteries</h1>" +
908-
"<br><div style='text-align:center'> <img src='/images/sad-battery.png' width=200></div>")) {
968+
"<br><div style='text-align:center'> <img src='/images/sad-battery.jpg' width=200></div>")) {
909969
return;
910970
}
911971
}
@@ -1009,6 +1069,13 @@ function registerEditor(_container, state) {
10091069
EDITORS[editor.ID] = editor;
10101070
}
10111071

1072+
// determine the last XRP configuration (Beta or Non-Beta) and setup the Blockly editor appropriately
1073+
// This check is re-done when an actual XRP is attached.
1074+
var xrpConfig = localStorage.getItem("xrpconfig");
1075+
if (xrpConfig != null && xrpConfig === "nonbeta"){
1076+
//add non-beta blocks
1077+
await configNonBeta();
1078+
}
10121079

10131080
// Register Golden layout panels
10141081
myLayout.registerComponentConstructor("Filesystem", registerFilesystem);

js/nonbetaConfig.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
3+
export async function configNonBeta() {
4+
servoNames = [["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"]];
5+
addBlocks();
6+
await loadScript("js/nonbeta_blocks.js?version=1.1.0");
7+
}
8+
9+
async function loadScript(src) {
10+
return new Promise((resolve, reject) => {
11+
const script = document.createElement('script');
12+
script.src = src;
13+
script.onload = () => {
14+
console.log(`Loaded script: ${src}`);
15+
resolve(script);
16+
};
17+
script.onerror = () => {
18+
reject(new Error(`Failed to load script: ${src}`));
19+
};
20+
document.head.appendChild(script);
21+
});
22+
}
23+
24+
//add blocks
25+
function addBlocks(){
26+
// Parse the JSON string into an object.
27+
//console.log(typeof blocklyToolbox); // should log "string" if it needs parsing
28+
let toolboxObj = blocklyToolbox;
29+
30+
// Define the new block you want to add.
31+
let newBlock = {
32+
"kind": "BLOCK",
33+
"type": "xrp_color_LED"
34+
};
35+
36+
// Choose the category where you want to add the block.
37+
const targetCategoryName = "Control Board";
38+
39+
// Find that category in the toolbox.
40+
for (let i = 0; i < toolboxObj.contents.length; i++) {
41+
let category = toolboxObj.contents[i];
42+
if (category.kind === "CATEGORY" && category.name === targetCategoryName) {
43+
// Ensure the category has a contents array.
44+
if (!category.contents) {
45+
category.contents = [];
46+
}
47+
// Add the new block to the category.
48+
category.contents.push(newBlock);
49+
break;
50+
}
51+
}
52+
blocklyToolbox = toolboxObj;
53+
}

0 commit comments

Comments
 (0)