aboutsummaryrefslogtreecommitdiff
path: root/src_frontend/Components/LEDConfig
diff options
context:
space:
mode:
Diffstat (limited to 'src_frontend/Components/LEDConfig')
-rw-r--r--src_frontend/Components/LEDConfig/LEDConfig.svelte204
-rw-r--r--src_frontend/Components/LEDConfig/MatrixSegment.svelte57
-rw-r--r--src_frontend/Components/LEDConfig/Segment.svelte38
3 files changed, 299 insertions, 0 deletions
diff --git a/src_frontend/Components/LEDConfig/LEDConfig.svelte b/src_frontend/Components/LEDConfig/LEDConfig.svelte
new file mode 100644
index 0000000..2cf9aa2
--- /dev/null
+++ b/src_frontend/Components/LEDConfig/LEDConfig.svelte
@@ -0,0 +1,204 @@
+<script>
+ import Segment from "./Segment.svelte";
+ import MatrixSegment from "./MatrixSegment.svelte";
+ import { onMount } from "svelte";
+
+ import { authorizedSocket, authorizedSocketNeeded } from "../../stores/socketStore.js";
+ authorizedSocketNeeded.set(true);
+
+ let segments = [];
+
+ function addSegment() {
+ console.log(segments);
+ segments.push(null);
+ segments = segments; // This is needed because svelte is weird :)
+ saveConfig();
+ }
+ function removeSegment() {
+ segments.pop();
+ segments = segments; // This is needed because svelte is weird :)
+ saveConfig();
+ }
+ function segmentChange(ev) {
+ saveConfig();
+ }
+
+ let matrix = [[[null, false]]];
+
+ function addRow() {
+ matrix.push([[null, false]]);
+ matrix = matrix; // This is needed because svelte is weird :)
+ saveConfig();
+ }
+ function removeRow() {
+ matrix.pop();
+ matrix = matrix; // This is needed because svelte is weird :)
+ saveConfig();
+ }
+ function addCell(ev) {
+ matrix[ev.target.dataset.id].push([null, false]);
+ matrix = matrix; // This is needed because svelte is weird :)
+ saveConfig();
+ }
+ function removeCell() {
+ matrix[ev.target.dataset.id].pop();
+ matrix = matrix; // This is needed because svelte is weird :)
+ saveConfig();
+ }
+
+ let led_channel;
+ let led_dma;
+ let led_freq_hz;
+ let led_invert;
+ let led_pin;
+
+ authorizedSocket.on("led_config", (data) => {
+ segments = data.segments;
+ matrix = data.matrix;
+ led_channel = data.led_channel.toString();
+ led_dma = data.led_dma.toString();
+ led_freq_hz = data.led_freq_hz.toString();
+ led_invert = data.led_invert;
+ led_pin = data.led_pin.toString();
+ });
+
+ onMount(async () => {
+ authorizedSocket.emit("led_config:get");
+ });
+
+ function saveConfig() {
+ authorizedSocket.emit("led_config:set", {
+ segments: segments,
+ matrix: matrix,
+ led_channel: parseInt(led_channel, 10),
+ led_dma: parseInt(led_dma, 10),
+ led_freq_hz: parseInt(led_freq_hz, 10),
+ led_invert: led_invert,
+ led_pin: parseInt(led_pin, 10)
+ });
+ }
+</script>
+
+<style>
+ .wrapper {
+ padding-bottom: 15px;
+ }
+ h1 {
+ margin-bottom: 0;
+ font-weight: 100;
+ }
+
+ .row {
+ width: 100%;
+ overflow-x: auto;
+ white-space: nowrap;
+ }
+
+ .segment {
+ display: inline-block;
+ margin-bottom: 5px;
+ }
+ .segment:not(:first-child) {
+ margin-left: 5px;
+ }
+
+ button {
+ background-color: var(--grey-200);
+ border: none;
+ border-radius: 50px;
+ padding: 10px;
+ }
+ button:hover { background-color: var(--grey-300); }
+ button:active { background-color: var(--grey-400); }
+ button > * { pointer-events: none; }
+
+ select {
+ width: 100%;
+ }
+
+</style>
+
+<div class="wrapper">
+ <h1>Segments</h1>
+ <p>Here you are defining the "segments" of your light-display. Use this to split the strip in stairs, blocks or any other configuration. Normally you would define a segment, for each cut you have made in the strip. But you could do other things to get fancy results. Each segment will be represented in the "matrix", by the number just below the number. Each segment should have it's own box below.</p>
+
+ <div class="row">
+ {#each segments as segment, i}
+ <div class="segment">
+ <Segment on:change={segmentChange} on:blur={segmentChange} bind:ledCount={segment} id={i} />
+ </div>
+ {/each}
+ <button on:click={addSegment}><i class="fas fa-plus"></i></button>
+ <button on:click={removeSegment}><i class="fas fa-minus"></i></button>
+ </div>
+
+ <h1>Matrix</h1>
+ <p>Here you are defining your matrix. A matrix is really nothing more than a 2-dimentional array, or a list of lists. This is not a mathematical array, meaning each "row" can have different lengths. Use this to stitch your segments together. Each "box" should contain the number of the segment it is representing. By pressing the double-arrows on the box, you can "invert" a segment. This means counting from the other end. Use this if you have the segments in a snake-layout.</p>
+
+ <div class="row">
+ {#each matrix as row, i}
+ <div class="">
+ {#each row as cell}
+ <div class="segment">
+ <MatrixSegment on:change={saveConfig} bind:segmentId={cell[0]} bind:inverted={cell[1]} />
+ </div>
+ {/each}
+ <button on:click={addCell} data-id={i}><i class="fas fa-plus"></i></button>
+ <button on:click={removeCell} data-id={i}><i class="fas fa-minus"></i></button>
+ </div>
+ {/each}
+ <button on:click={addRow}><i class="fas fa-plus"></i></button>
+ <button on:click={removeRow}><i class="fas fa-minus"></i></button>
+ </div>
+
+ <h1>Advanced</h1>
+ <div class="">
+ <label for="gpioPin">GPIO pin</label>
+ <select id="gpioPin" bind:value={led_pin} on:change={saveConfig} >
+ <option value="10">10 (SPI)</option>
+ <option value="12">12 (PWM)</option>
+ <option value="18">18 (PWM) (Luxcena neo hat)</option>
+ <option value="21">21 (PCM)</option>
+ <option value="31">31 (PCM)</option>
+ <option value="38">39 (SPI)</option>
+ <option value="40">40 (PWM)</option>
+ <option value="52">52 (PWM)</option>
+ </select>
+
+ <label for="dmaChannel">DMA channel</label>
+ <select id="dmaChannel" bind:value={led_dma} on:change={saveConfig} >
+ <option value="0">0</option>
+ <option value="1">1</option>
+ <option value="2">2</option>
+ <option value="3">3</option>
+ <option value="4">4</option>
+ <option value="5">5</option>
+ <option value="6">6</option>
+ <option value="7">7</option>
+ <option value="8">8</option>
+ <option value="9">9</option>
+ <option value="10">10 (Recommended)</option>
+ <option value="11">11</option>
+ <option value="12">12</option>
+ <option value="13">13</option>
+ <option value="14">14</option>
+ <option value="15">15</option>
+ </select>
+
+ <label for="frequency">Frequency</label>
+ <select id="frequency" bind:value={led_freq_hz} on:change={saveConfig} >
+ <option value="800000">80k</option>
+ <option value="100000">10k</option>
+ </select>
+
+ <label for="ledChannel">LED Channel</label>
+ <select id="ledChannel" bind:value={led_channel} on:change={saveConfig} >
+ <option value="0">0</option>
+ <option value="1">1</option>
+ </select>
+
+ <input type="checkbox" id="invertSignal" bind:checked={led_invert} on:change={saveConfig} />
+ <label for="invertSignal">Invert signal</label>
+
+ </div>
+</div> \ No newline at end of file
diff --git a/src_frontend/Components/LEDConfig/MatrixSegment.svelte b/src_frontend/Components/LEDConfig/MatrixSegment.svelte
new file mode 100644
index 0000000..c2c1934
--- /dev/null
+++ b/src_frontend/Components/LEDConfig/MatrixSegment.svelte
@@ -0,0 +1,57 @@
+<script>
+ import { createEventDispatcher } from 'svelte';
+ const dispatch = createEventDispatcher();
+
+ export let segmentId;
+ export let inverted;
+
+ function toggleInvert() {
+ inverted = !inverted;
+ dispatch("change");
+ }
+
+ function forwardOnChange() {
+ dispatch("change")
+ }
+</script>
+
+<style>
+ div {
+ display: flex;
+ }
+ input {
+ padding: 10px 0 10px 10px;
+ width: 38px;
+ text-align: center;
+ background-color: var(--grey-300);
+ border: none;
+ border-radius: 5px 0 0 5px;
+ margin-right: -5px;
+ transition: background-color 0.5s ease;
+ }
+ input:focus {
+ outline: none;
+ background-color: var(--grey-400);
+ }
+ button {
+ background-color: var(--grey-300);
+ border: none;
+ border-radius: 0 10px 10px 0;
+ padding: 10 5px;
+ margin-left: 0;
+ }
+ .inverted input, .inverted button{
+ background-color: var(--amber-500);
+ }
+ button:hover {
+ background-color: var(--grey-400);
+ }
+ button:active {
+ background-color: var(--grey-500);
+ }
+</style>
+
+<div class:inverted={inverted}>
+ <input on:change={forwardOnChange} on:blur={forwardOnChange} type="number" step=1 bind:value={segmentId} />
+ <button on:click={toggleInvert}><i class="fas fa-exchange-alt"></i></button>
+</div> \ No newline at end of file
diff --git a/src_frontend/Components/LEDConfig/Segment.svelte b/src_frontend/Components/LEDConfig/Segment.svelte
new file mode 100644
index 0000000..3b71451
--- /dev/null
+++ b/src_frontend/Components/LEDConfig/Segment.svelte
@@ -0,0 +1,38 @@
+<script>
+ import { fade } from 'svelte/transition';
+ export let id;
+ export let ledCount;
+</script>
+
+<style>
+ div {
+ display: flex;
+ flex-direction: column;
+ }
+ input {
+ display: inline-block;
+ padding: 10px 10px 10px 10px;
+ width: 38px;
+ text-align: right;
+ background-color: var(--grey-300);
+ border: none;
+ border-radius: 5px 5px 0 0;
+ margin: 0;
+ }
+ input:focus {
+ outline: none;
+ background-color: var(--grey-400);
+ }
+ span {
+ background-color: var(--grey-500);
+ font-size: 12px;
+ padding: 2px;
+ border-radius: 0 0 5px 5px;
+ text-align: center;
+ }
+</style>
+
+<div transition:fade|local>
+ <input on:change on:blur type="number" data-id={id} step=1 bind:value={ledCount} />
+ <span>{id}</span>
+</div> \ No newline at end of file