-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix arduino websockets poll lag. Adding weather.
- Loading branch information
1 parent
7e09c9b
commit 8286ed6
Showing
11 changed files
with
352 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>DotMatrix Sandbox</title> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
|
||
<head> | ||
<title>DotMatrix Sandbox</title> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
|
||
<body> | ||
<div id="app"></div> | ||
|
||
<script type="module" src="src/client.ts"> | ||
</script> | ||
</body> | ||
|
||
</html> | ||
<script type="module" src="src/sender.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { rgb565ToRGBA } from './utils'; | ||
|
||
const canvas = document.createElement('canvas'); | ||
canvas.width = 1280; | ||
canvas.height = 320; | ||
canvas.style = 'zoom: 10'; | ||
document.body.appendChild(canvas); | ||
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; | ||
|
||
let hasDisconnected = false; | ||
|
||
const connect = () => { | ||
const ws = new WebSocket(`ws://rgb.mun.sh/sub`); | ||
ws.onopen = evt => { | ||
console.log('connected!', evt); | ||
|
||
if (hasDisconnected) { | ||
// Force refresh to get new client | ||
window.location.reload(); | ||
} | ||
}; | ||
|
||
ws.onmessage = async evt => { | ||
const data = (await evt.data.arrayBuffer()) as ArrayBuffer; | ||
const rgba = rgb565ToRGBA(new Uint16Array(data)); | ||
const imageData = new ImageData(new Uint8ClampedArray(rgba), 128, 32); | ||
|
||
ctx.putImageData(imageData, 0, 0); | ||
}; | ||
|
||
ws.onerror = ws.onclose = () => { | ||
console.log('websocket closed! refreshing!'); | ||
|
||
hasDisconnected = true; | ||
|
||
setTimeout(() => { | ||
connect(); | ||
}, 1000); | ||
}; | ||
}; | ||
|
||
// Draw to RGB | ||
setTimeout(() => { | ||
connect(); | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.