Skip to content
Snippets Groups Projects
Commit 8f42abff authored by Nemanja Stefanovic's avatar Nemanja Stefanovic
Browse files

remove old test

parent 8f910151
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<style type="text/css">
body {
background: #222;
color: #ddd;
font: 15px verdana;
}
#connectionStatus {
font-weight: bold;
font-size: 20px;
}
label {
display: block;
width: 100px;
margin: 10px 0 0 0;
}
input {
width: 400px;
height: 25px;
margin: 10px 20px;
}
span.value {
font: 20px monospace;
}
</style>
<script type="text/javascript">
/*
* Janky experiment with the Ganzfeld effect.
* This just flashes the entire array uniformly.
* Also this makes a good stress-test for the USB driver :)
*/
$(function() {
function hexToRgb(hex) {
// http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
// Scrape values from our form
var color, frequency, contrast;
var updateSettings = function() {
frequency = $('#frequency').val();
$('#frequencyValue').text(frequency);
}
$('input').on('change', updateSettings);
updateSettings();
// Set all pixels to a given color
function writeFrame(red, green, blue) {
var leds = 60;
var packet = new Uint8ClampedArray(4 + leds * 3);
if (socket.readyState != 1 /* OPEN */) {
// The server connection isn't open. Nothing to do.
return;
}
if (socket.bufferedAmount > packet.length) {
// The network is lagging, and we still haven't sent the previous frame.
// Don't flood the network, it will just make us laggy.
// If fcserver is running on the same computer, it should always be able
// to keep up with the frames we send, so we shouldn't reach this point.
return;
}
// Dest position in our packet. Start right after the header.
var dest = 4;
// Sample the center pixel of each LED
for (var led = 0; led < leds; led++) {
packet[dest++] = red;
packet[dest++] = green;
packet[dest++] = blue;
}
//socket.send(packet.buffer);
}
// Animation parameters
var lastTime = 0;
var phase = 0;
var last_led = 0;
// Animation loop
var animate = function() {
var leds = 60;
var packet = new Uint8ClampedArray(4 + leds * 3);
if (socket.readyState != 1 /* OPEN */) {
// The server connection isn't open. Nothing to do.
//return;
}
if (socket.bufferedAmount > packet.length) {
// The network is lagging, and we still haven't sent the previous frame.
// Don't flood the network, it will just make us laggy.
// If fcserver is running on the same computer, it should always be able
// to keep up with the frames we send, so we shouldn't reach this point.
//return;
}
// Dest position in our packet. Start right after the header.
var dest = 4;
// Sample the center pixel of each LED
for (var led = 0; led < leds; led++)
{
if(led == last_led)
{
packet[dest++] = 255;
packet[dest++] = 255;
packet[dest++] = 255;
}
else
{
packet[dest++] = 0;
packet[dest++] = 0;
packet[dest++] = 0;
}
}
socket.send(packet.buffer);
last_led = last_led+1;
if(last_led > leds)
{
last_led=0;
}
//console.log("laste_led is "+last_led);
setTimeout(animate, frequency);
}
// Connect to a Fadecandy server running on the same computer, on the default port
//var socket = new WebSocket('ws://localhost:7890');
var socket = new WebSocket('ws://192.168.1.208:7890');
// Put some connection status text in the corner of the screen
$('#connectionStatus').text('Connecting to fcserver...');
socket.onclose = function(event) {
$('#connectionStatus').text('Not connected to fcserver');
}
socket.onopen = function(event) {
$('#connectionStatus').text('Connected');
animate();
}
})
</script>
</head>
<body>
<form>
<div id="connectionStatus"></div>
<label for="frequency">Frequency</label>
<input type="range" id="frequency" name="frequency" min="1" max="100" value="30" step="1">
<span class="value" id="frequencyValue"></span>
<br/>
</form>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment