From 6eb92ef98b6008aae1b180926f1c0b8430c57657 Mon Sep 17 00:00:00 2001 From: Stephen Hawes Date: Tue, 23 Jan 2024 12:44:24 -0500 Subject: [PATCH] lets the user pick the address for the slot programmer --- feederBus.js | 17 +++++++---------- index.html | 1 + modal.js | 29 +++++++++++++++++++++++++++-- style.css | 5 +++++ 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/feederBus.js b/feederBus.js index e932870..daeac6e 100644 --- a/feederBus.js +++ b/feederBus.js @@ -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){ @@ -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; } @@ -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--; - } - + } } } } diff --git a/index.html b/index.html index 41a2e3d..a050b6e 100644 --- a/index.html +++ b/index.html @@ -123,6 +123,7 @@

Tests

+
diff --git a/modal.js b/modal.js index 8c1084d..819effc 100644 --- a/modal.js +++ b/modal.js @@ -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; @@ -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; } diff --git a/style.css b/style.css index 6e7ae78..42282ad 100644 --- a/style.css +++ b/style.css @@ -420,3 +420,8 @@ button:focus-visible { width:100%; color:#222; } + +#modal-num-input { + margin:0px auto; + margin-bottom: 20px; +}