Skip to content

Commit

Permalink
lets the user pick the address for the slot programmer
Browse files Browse the repository at this point in the history
  • Loading branch information
sphawes committed Jan 23, 2024
1 parent 25bdca5 commit 6eb92ef
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
17 changes: 7 additions & 10 deletions feederBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,14 @@ export class feederBus {
return false;
}

for(let i=1; i<51; i++){
while(true){

resp = await this.modal.show("Insert a Feeder","Insert a feeder into slot " + i + ". Once you've done this, click ok.");
if(!resp){
let address = await this.modal.show("Insert a Feeder","Insert a feeder into the slot you'd like to program. Enter the address you'd like to program in the field below. Once you've done this, click ok.", 1);
if(!address){
return false;
}


//program
let response = await this.sendPacket(commands.UNINITIALIZED_FEEDERS_RESPOND, 0xFF);
if(response == false){
Expand All @@ -466,14 +467,14 @@ export class feederBus {
}
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));
let prgmResponse = await this.sendPacket(commands.PROGRAM_FEEDER_FLOOR, 0xFF, response.slice(6).concat(address));

//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){

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.");
resp = await this.modal.show("Success","Slot has been programmed with address " + address + "! Remove the feeder from the slot, then click OK to program another.");
if(!resp){
return false;
}
Expand All @@ -482,11 +483,7 @@ export class feederBus {
resp = await this.modal.show("Failure","Programming Failed for slot " + i + ". Click OK to retry.");
if(!resp){
return false;
}
else{
i--;
}

}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ <h2 style="width:100%">Tests</h2>

<h2 id="modal-title">test</h2>
<p id="modal-content">test</p>
<input id="modal-num-input" min="1" max="254" type="number">
<div class="flex">
<button id="modal-ng">Cancel</button>
<button id="modal-ok">OK</button>
Expand Down
29 changes: 27 additions & 2 deletions modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export class modalManager {

this.modalTitle = document.getElementById("modal-title");
this.modalContent = document.getElementById("modal-content");
this.modalClose = document.getElementById("modal-close");

this.modalNumInput = document.getElementById("modal-num-input");

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

this.receivedInput = undefined;
Expand All @@ -20,17 +22,40 @@ export class modalManager {
this.overlay.style.display = "none";
}

async show(title, contents) {
//styles are:
// 0 = classic ok and cancel
// can return true for ok, false for cancel
// 1 = num input field, ok and cancel
// returns false for cancel, input field value for ok
async show(title, contents, style) {

if(style === undefined){
style = 0;
}

this.modalTitle.innerHTML = title;
this.modalContent.innerHTML = contents;

this.modalObject.style.display = "flex";
this.overlay.style.display = "block";

// if no input field
if(style == 0){
this.modalNumInput.style.display = "none";
}
else if (style == 1){
this.modalNumInput.style.display = "block";
this.modalNumInput.value = 1;
}

this.modalOK.focus();

let response = await this.waitForUserSelection();

if(response && style == 1){
response = this.modalNumInput.value;
}

return response;

}
Expand Down
5 changes: 5 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,8 @@ button:focus-visible {
width:100%;
color:#222;
}

#modal-num-input {
margin:0px auto;
margin-bottom: 20px;
}

0 comments on commit 6eb92ef

Please sign in to comment.