Skip to content

Commit

Permalink
added modal to slot programming utility
Browse files Browse the repository at this point in the history
  • Loading branch information
sphawes committed Jan 23, 2024
1 parent 1107a3c commit 25bdca5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
29 changes: 23 additions & 6 deletions feederBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,24 @@ export class feederBus {
}

async programSlotsUtility(){
alert("To program your slots, first remove all Photon feeders from your machine. Once you've done this, click ok.");


let resp = await this.modal.show("Before Beginning", "To program your slots, first remove all Photon feeders from your machine. Once you've done this, click ok.\n\nIf at any point you'd like to exit this utility, click cancel.");
console.log(resp);
if(!resp){
return false;
}

for(let i=1; i<51; i++){
alert("Insert a feeder into slot " + i + ". Once you've done this, click ok.");

resp = await this.modal.show("Insert a Feeder","Insert a feeder into slot " + i + ". Once you've done this, click ok.");
if(!resp){
return false;
}

//program
let response = await this.sendPacket(commands.UNINITIALIZED_FEEDERS_RESPOND, 0xFF);
if(response == false){
alert("Programming feeder not found. Exiting.");
resp = await this.modal.show("Programming Feeder Not Found","The feeder you inserted was not detected. Exiting.");
return false;
}
else{
Expand All @@ -462,14 +472,21 @@ export class feederBus {
let currentAddress = await this.sendPacket(commands.GET_FEEDER_ADDRESS, 0xFF, response.slice(6))

if(currentAddress != false && currentAddress[1] == i){
if(!confirm("Slot has been programmed with address " + i + "! Remove the feeder from the slot, then click ok to move to the next address. Click cancel to stop.")){

resp = await this.modal.show("Success","Slot has been programmed with address " + i + "! Remove the feeder from the slot, then click ok to move to the next address.");
if(!resp){
return false;
}
}
else{
if(!confirm("Programming Failed for slot " + i + ". Would you like to continue?")){
resp = await this.modal.show("Failure","Programming Failed for slot " + i + ". Click OK to retry.");
if(!resp){
return false;
}
else{
i--;
}

}
}
}
Expand Down
8 changes: 4 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ let serial = new serialManager(modal);
let feeder = new feederBus(serial, modal);

document.getElementById("modal-close").addEventListener("click", () => {
modal.receivedInput = 0;
modal.receivedInput = false;
modal.hide();
});

document.getElementById("modal-ok").addEventListener("keyup", function(event) {
if (event.code === "Enter"){
event.preventDefault();
modal.receivedInput = 1;
modal.receivedInput = true;
modal.hide();
}
});

document.getElementById("modal-ok").addEventListener("click", () => {
modal.receivedInput = 1;
modal.receivedInput = true;
modal.hide();
});

document.getElementById("modal-ng").addEventListener("click", () => {
modal.receivedInput = 0;
modal.receivedInput = false;
modal.hide();
});

Expand Down
6 changes: 3 additions & 3 deletions modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class modalManager {

this.modalOK = document.getElementById("modal-ok");

this.receivedInput = -1;
this.receivedInput = undefined;
}

timeout = async ms => new Promise(res => setTimeout(res, ms));
Expand All @@ -37,12 +37,12 @@ export class modalManager {

async waitForUserSelection() {
//wait for a buttonpress in another function to ste received input to something other than -1
while (this.receivedInput == -1) await this.timeout(50);
while (this.receivedInput === undefined) await this.timeout(50);

//grab value
let userValue = this.receivedInput;
//reset for the next thing
this.receivedInput = -1;
this.receivedInput = undefined;

return userValue;

Expand Down
4 changes: 2 additions & 2 deletions serialManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export class serialManager {

let resp = await this.modal.show("Stepper Driver Test Complete", "Test is complete. Click OK to download test report.");

if(resp == 1){
if(resp == true){
let filename = new Date().toISOString();
filename = filename + "-tmctest.txt"

Expand Down Expand Up @@ -532,7 +532,7 @@ export class serialManager {

let resp = await this.modal.show("Vacuum Sensor Test Complete", "Test is complete. Click OK to download test report.");

if(resp == 1){
if(resp == true){
let filename = new Date().toISOString();
filename = filename + "-vactest.txt"
this.download(filename, testDataBuffer);
Expand Down

0 comments on commit 25bdca5

Please sign in to comment.