Skip to content

Commit

Permalink
Prevent patternlist from sending multiple request simultaneously (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeionSi authored Mar 25, 2024
1 parent b50bf33 commit f831c23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion UI/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h3>Stim Configuration</h3>
<div class="row">
<div class="col-6 col-4-medium col-12-small">Simulated Pattern: </div>
<div class="col-1 col-6-medium col-12-small tooltip">
<select id="patternSelect" onChange="updatePattern()">
<select id="patternSelect" onChange="updatePatternQueue()">
</select>
</div>
</div>
Expand Down
31 changes: 26 additions & 5 deletions UI/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function refreshPatternNumber(data)
port.unpipe();
select.value = patternID;
console.log("Currently selected Pattern: " + patternID);
updatePattern();
updatePatternQueue();
}

function readPattern()
Expand All @@ -266,16 +266,29 @@ function readPattern()
var patternRow = 0;
var newPattern;
var patternDegrees;

var nextPatternID = null;
var currentPatternID = null;
function updatePatternQueue()
{
nextPatternID = document.getElementById('patternSelect').value;

if (currentPatternID === null) {
updatePattern();
}
}

function updatePattern()
{
var patternID = document.getElementById('patternSelect').value;
currentPatternID = nextPatternID;
nextPatternID = null;

const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
console.log(`Sending 'S' command with pattern ${patternID}`);
console.log(`Sending 'S' command with pattern ${currentPatternID}`);

var buffer = Buffer.alloc(2);
buffer[0] = 0x53; // Ascii 'S'
buffer[1] = parseInt(patternID);
buffer[1] = parseInt(currentPatternID);
port.write(buffer); //Send the new pattern ID

//Send the command to save the pattern to EEPROM
Expand Down Expand Up @@ -316,7 +329,15 @@ function refreshPattern(data)
initComplete = true;
}

}
if (nextPatternID !== null) {
updatePattern();
}
else {
currentPatternID = null;
}

}

}

//Simply redraw the gear pattern using the existing details (Used when the draw style is changed)
Expand Down

0 comments on commit f831c23

Please sign in to comment.