Skip to content

Commit

Permalink
first implementation to fix bug #160
Browse files Browse the repository at this point in the history
Signed-off-by: nicolaskolbenschlag <[email protected]>
  • Loading branch information
nicolaskolbenschlag committed Jan 12, 2023
1 parent 2ce33fe commit afe8c41
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
28 changes: 27 additions & 1 deletion Apps/frontend/src/components/Waves.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
CANVAS_WIDTH,
NUM_CHANNELS,
NUM_INTERVALS_HORIZONTAL,
NUM_INTERVALS_VERTICAL,
MIN_SWEEP,
MAX_SWEEP,
DEFAULT_STEP_SIZE,
LINE_COLORS,
WAVE_CURSOR_SIZE,
LINE_THICKNESS_SMALL,
LINE_THICKNESS_BIG,
UPDATE_DISPLAY_SPEED_AFTER_UPDATES,
} from "../const";
import { timeSweep } from "../stores";
import { timeSweep, displaySpeed } from "../stores";
export let scalesY;
Expand Down Expand Up @@ -47,6 +49,10 @@
};
resetLogVars();
let displaySpeedUpdateCounter = 0;
const pixelsPerDiv = CANVAS_WIDTH / NUM_INTERVALS_VERTICAL;
let updateTimeStorage = new Array(NUM_CHANNELS).fill(null);
// ----- Svelte lifecycle hooks -----
onMount(() => {
resizeCanvas();
Expand Down Expand Up @@ -74,12 +80,21 @@
};
export const updateBuffer = (samples, startIndex, endIndex) => {
let updateDisplaySpeedBuffer =
displaySpeedUpdateCounter++ % UPDATE_DISPLAY_SPEED_AFTER_UPDATES == 0;
let now;
if (updateDisplaySpeedBuffer) {
now = Date.now();
}
displaySpeedUpdateCounter %= UPDATE_DISPLAY_SPEED_AFTER_UPDATES;
for (
let channelIndex = startIndex;
channelIndex < endIndex;
channelIndex++
) {
if (!startStopLine[channelIndex]) {
$displaySpeed[channelIndex] = null;
continue;
}
let xCurr = xArr[channelIndex];
Expand All @@ -102,6 +117,17 @@
while (xArr[channelIndex] >= CANVAS_WIDTH) {
xArr[channelIndex] -= CANVAS_WIDTH;
}
// update display speed
if (updateDisplaySpeedBuffer) {
let last = updateTimeStorage[channelIndex];
updateTimeStorage[channelIndex] = now;
if (last != null) {
let timePerPixel = (now - last) / 1000.0 / delta;
let timePerDiv = timePerPixel * pixelsPerDiv;
$displaySpeed[channelIndex] = timePerDiv;
}
}
}
bufferCounter++;
Expand Down
1 change: 1 addition & 0 deletions Apps/frontend/src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const MIN_SWEEP = 0.1; // <= 1
export const MAX_SWEEP = 2.0; // >= 1
export const MIN_SWEEP_SLIDER_VALUE = 0;
export const MAX_SWEEP_SLIDER_VALUE = 10;
export const UPDATE_DISPLAY_SPEED_AFTER_UPDATES = 10000;
export const DEFAULT_STEP_SIZE = 1.0;
export const MIN_AMPLITUDE = 0.0;
export const MAX_AMPLITUDE = NUM_INTERVALS_HORIZONTAL / 2;
Expand Down
1 change: 1 addition & 0 deletions Apps/frontend/src/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export const thicknessAdjustment = writable(

export const expandedPanelOpen = writable(false);
export const isGND = writable(false);
export const displaySpeed = writable(new Array(NUM_CHANNELS).fill(null));
6 changes: 5 additions & 1 deletion Apps/frontend/src/views/ControlPanelBottom.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
MIN_SWEEP_SLIDER_VALUE,
NUM_CHANNELS,
} from "../const";
import { expandedPanelOpen, timeSweep } from "../stores";
import { expandedPanelOpen, timeSweep, displaySpeed } from "../stores";
export let waveElement;
export let indicatorElement;
Expand Down Expand Up @@ -85,6 +85,10 @@
min={MIN_SWEEP_SLIDER_VALUE}
max={MAX_SWEEP_SLIDER_VALUE}
bind:value={$timeSweep[index]}
calculateDisplayedValue={(_) => {
let speed = $displaySpeed[index];
return (speed != null ? speed.toFixed(2) : "-") + " sec/div";
}}
dataCy={`timesweepSlider-${index}`}
/>
</td>
Expand Down

0 comments on commit afe8c41

Please sign in to comment.