Skip to content

Commit

Permalink
Merge pull request #112 from amosproj/feature/#80-signal-head
Browse files Browse the repository at this point in the history
first working draft of implementation for #80 signal head
  • Loading branch information
nicolaskolbenschlag authored Dec 6, 2022
2 parents 7eeb202 + cc1950f commit 4e3be0b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
15 changes: 13 additions & 2 deletions Apps/frontend/src/components/Waves.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { beforeUpdate, onMount } from "svelte";
import { ColorRGBA, WebglPlot, WebglThickLine } from "webgl-plot";
import { ColorRGBA, WebglPlot, WebglSquare, WebglThickLine } from "webgl-plot";
import {
CANVAS_HEIGHT,
CANVAS_WIDTH,
Expand All @@ -20,6 +20,7 @@
let webGLPlot;
let channel_samples;
let lines = [];
let heads = [];
let startStopLine = [];
let xArr;
let xLast;
Expand Down Expand Up @@ -48,7 +49,6 @@
xLast = new Array(NUM_CHANNELS).fill(0);
initChannelSamples();
webGLPlot.clear();
console.log("clear");
};
export const updateBuffer = (samples) => {
Expand Down Expand Up @@ -90,6 +90,7 @@
export const updateChannelOffsetY = (channelIndex, offsetY) => {
lines[channelIndex].offsetY = offsetY;
heads[channelIndex].offsetY = offsetY;
};
// Update the amplification of wave
Expand All @@ -114,6 +115,12 @@
for (let x = 0; x < CANVAS_WIDTH; ++x) {
lines[i].setY(x, channel_samples[i][x]);
}
const size = 0.01;
let x = (xArr[i] * 2) / CANVAS_WIDTH - 1;
let scale = lines[i].scaleY * 5;
let y = channel_samples[i][xLast[i]-1] * 100 * scale / CANVAS_HEIGHT;
heads[i].setSquare(x - (size/2), y - size, x + (size/2), y + size);
}
};
Expand Down Expand Up @@ -142,6 +149,10 @@
webGLPlot.addThickLine(line);
lines.push(line);
startStopLine[i] = true;
let head = new WebglSquare(color);
heads.push(head);
webGLPlot.addSurface(head);
}
};
Expand Down
47 changes: 21 additions & 26 deletions Apps/frontend/src/views/StartStopButton.svelte
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
<script>
import { createEventDispatcher } from 'svelte'
export let channel_id;
const dispatch = createEventDispatcher()
let play = "Start ▶";
let stop = "Stop ■";
let symbol = channel_id + " " + stop;
let hasStarted = true;
const handleStartStop = async () => {
hasStarted = !hasStarted;
hasStarted ? symbol = stop : symbol = play;
symbol = channel_id + " " + symbol;
dispatch('startStop', {buttonValue: hasStarted})
}
import { createEventDispatcher } from "svelte";
export let channel_id;
const dispatch = createEventDispatcher();
let play = "Start ▶";
let stop = "Stop ■";
let symbol = channel_id + " " + stop;
let hasStarted = true;
const handleStartStop = async () => {
hasStarted = !hasStarted;
hasStarted ? (symbol = stop) : (symbol = play);
symbol = channel_id + " " + symbol;
dispatch("startStop", { buttonValue: hasStarted });
};
</script>

<button class="button-style" on:click={handleStartStop}>
{symbol}
{symbol}
</button>


<style>
.button-style {
border-style: solid;
border-color: grey;
.button-style {
border-style: solid;
border-color: grey;
}
</style>
</style>

0 comments on commit 4e3be0b

Please sign in to comment.