Skip to content

Commit

Permalink
Alert if layout index doesn't start at zero.
Browse files Browse the repository at this point in the history
Update instructions with zero index start requirement.
  • Loading branch information
jasoncoon committed Sep 22, 2023
1 parent 7bfa773 commit 04491c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ <h6 class="mb-2 text-muted">Choose one of the tabs below and paste in your input
<div class="text-muted">
Paste an LED layout copied from
<a href="https://sheets.google.com" target="_blank" rel="noopener noreferrer">Google Sheets</a>
or other spreadsheet in tab-delimited text format, with a unique LED index in each cell. Cells without an LED should be empty.
or other spreadsheet in tab-delimited text format, with a unique LED index in each cell. LED indexes should start at zero. Cells without an LED should be empty.
</div>
<textarea class="form-control" id="textAreaLayout" rows="7">
0 1 2 3 4 5 6 7 8 9 10 11 12 13
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ function parseLayout(value) {
if (!value) value = textAreaLayout.value;
const results = parseLayoutText(value);

if (results.minIndex !== 0) {
alert(`Layout should start at 0 instead of ${results.minIndex}`);
}

// destructure the results into our global variables
({ height, leds, maxX, maxY, minX, minY, rows, width } = results);

Expand Down
7 changes: 5 additions & 2 deletions js/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export function parseLayoutText(text) {

const leds = [];

let minX, minY, maxX, maxY, width, height;
let minX, minY, maxX, maxY, width, height, minIndex;

minX = minY = 1000000;
minX = minY = minIndex = 1000000;
maxX = maxY = -1000000;

for (let y = 0; y < rows.length; y++) {
Expand All @@ -32,6 +32,8 @@ export function parseLayoutText(text) {
if (y < minY) minY = y;
if (y > maxY) maxY = y;

if (index < minIndex) minIndex = index;

leds.push({
index,
x,
Expand All @@ -52,5 +54,6 @@ export function parseLayoutText(text) {
minY,
rows,
width,
minIndex,
};
}

0 comments on commit 04491c1

Please sign in to comment.