Skip to content

Commit

Permalink
adds sent command buffer so up and down arrows work as expected in th…
Browse files Browse the repository at this point in the history
…e repl
  • Loading branch information
sphawes committed Jan 22, 2024
1 parent 0f1d9f8 commit 094ea23
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
14 changes: 9 additions & 5 deletions feederBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class feederBus {


// find response in receiveBuffer
let response;
let response = "";
const regex = new RegExp('rs485-reply:');
for (let i=0, x=this.serial.receiveBuffer.length; i<x; i++) {
let currLine = this.serial.receiveBuffer[i];
Expand All @@ -219,6 +219,11 @@ export class feederBus {
return false;
}

if(response == ""){
alert("Your version of Marlin does not support Photon. Please update Marlin to the version in the latest LumenPnP release.");
return false;
}

//converts response to array
let responseArray = this.hexStringToIntArray(response);

Expand Down Expand Up @@ -447,9 +452,10 @@ export class feederBus {
return false;
}
else{
//this line does the programming, but it fails because programming takes too long, rs-485 library has too short a timeout
let prgmResponse = await this.sendPacket(commands.PROGRAM_FEEDER_FLOOR, 0xFF, response.slice(6).concat(i));
//fails because programming takes too long?


//instead we confirm by just checking to see if the address has actually been updated
let currentAddress = await this.sendPacket(commands.GET_FEEDER_ADDRESS, 0xFF, response.slice(6))

if(currentAddress != false && currentAddress[1] == i){
Expand All @@ -463,9 +469,7 @@ export class feederBus {
}
}
}

}
}

}

28 changes: 27 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,36 @@ function clearReplInput(){

// clicks the send button if you hit the enter key while repl filed is focused
document.getElementById("repl-input").addEventListener("keyup", function(event) {
if (event.keyCode === 13){
if (event.code === "Enter"){
event.preventDefault();
document.getElementById("send").click();
}
else if (event.code === "ArrowUp"){
event.preventDefault();

//check to see that our index isnt at the end of commands sent
if(serial.sentCommandBufferIndex == serial.sentCommandBuffer.length - 1){
return false;
}
//update the buffer index
serial.sentCommandBufferIndex++;
//then drop that new element into the field
document.getElementById("repl-input").value = serial.sentCommandBuffer[serial.sentCommandBufferIndex];

}
else if (event.code === "ArrowDown"){
event.preventDefault();

//check to see that our index isnt at the end of commands sent
if(serial.sentCommandBufferIndex == 0){
return false;
}
//update the buffer index
serial.sentCommandBufferIndex--;
//then drop that new element into the field
document.getElementById("repl-input").value = serial.sentCommandBuffer[serial.sentCommandBufferIndex];

}
});

//hide/reveal unicast fields if certain dropdowns are selected
Expand Down
23 changes: 16 additions & 7 deletions serialManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export class serialManager {

this.receiveBuffer = [];

this.sentCommandBuffer = [""];
this.sentCommandBufferIndex = 0;

}

appendToConsole(message, direction){
Expand Down Expand Up @@ -133,6 +136,13 @@ export class serialManager {

async sendRepl() {
let command = [document.querySelector("#repl-input").value];

//adding current command to buffer for uparrow access later, at position 1 to preserve a "" option
this.sentCommandBuffer.splice(1, 0, command[0])

//making sure we reset the index back to 0
this.sentCommandBufferIndex = 0;

this.send(command);

}
Expand Down Expand Up @@ -342,11 +352,9 @@ export class serialManager {
let testDataBuffer = "";

const commandArray = [
"M122"
"M122"
]

//TODO add motor current to this test

//clean out receive buffer
await this.clearBuffer();

Expand All @@ -358,16 +366,17 @@ export class serialManager {
//check receieve buffer
console.log(this.receiveBuffer);

//adding to test buffer
for(let i = 0; i<this.receiveBuffer.length; i++){
testDataBuffer = testDataBuffer.concat(this.receiveBuffer[i] + "\n");
}

alert("Downloading test results.");

//alert user
let filename = new Date().toISOString();
filename = filename + "-tmctest.txt"

for(let i = 0; i<this.receiveBuffer.length; i++){
testDataBuffer = testDataBuffer.concat(this.receiveBuffer[i] + "\n");
}

this.download(filename, testDataBuffer);


Expand Down

0 comments on commit 094ea23

Please sign in to comment.