Skip to content

Commit

Permalink
Improved timings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexter committed May 9, 2022
1 parent a918386 commit 8f53388
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lights",
"version": "0.3.1",
"version": "0.3.2",
"private": true,
"scripts": {
"build": "rollup -c",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "lights",
"version": "0.3.1"
"version": "0.3.2"
},
"build": {
"distDir": "../public",
Expand Down
41 changes: 33 additions & 8 deletions src/lib/Stage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,54 @@
export const fill = (color) => {
rgbSpots.update(spots => spots.map(() => color))
console.log('filled', color)
}
</script>

<script lang='ts'>
let count = 0
const sendSacn = async (data) => {
function debounce(func, timeout = 100) {
let timer;
let lastargs;
const rundelayed = () => {
timer = undefined;
if (lastargs) {
func.apply(this, lastargs)
timer = setTimeout(rundelayed, timeout)
lastargs = undefined
}
console.log('clearing')
}
return (...args) => {
console.log("OK")
if (!timer) {
console.log("APPLY")
func.apply(this, args);
timer = setTimeout(rundelayed, timeout);
} else {
// Called with timer running
lastargs = args
}
};
}
const sendSacn = debounce((data) => {
console.log("Sending", data)
const response = await invoke('send_sacn', {
invoke('send_sacn', {
data: data.map(v => v|0)
})
count ++
}
.then(() => count++)
.catch(e => console.error('error', e))
})
$: {
// Should be calling send on max hz
console.log("Update", $rgbSpots, $spots)
sendSacn([
...$rgbSpots.flatMap(color => [0, 0, ...color.rgb().array()]),
...$spots
])
.then(() => {})
.catch(e => console.error('error', e))
}
</script>

Expand Down
3 changes: 1 addition & 2 deletions src/lib/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const wipe: Pattern = {
let row = 0
let state = true
const run = ({ primary, secondary }: Parameters) => {
console.log("Tick", row)
const width = 4
const color = state ? secondary : primary
rgbSpots.update(spots => {
Expand All @@ -64,7 +63,7 @@ export const wipe: Pattern = {
}

rgbSpots.update(spots => {
return spots.map(color => color.darken(0.1))
return spots.map(color => color.darken(0.4))
})
time ++
run(params)
Expand Down

0 comments on commit 8f53388

Please sign in to comment.