2018-12-13 11:05:32 +00:00
|
|
|
// Send points lists to redis server
|
|
|
|
// In compatible LJay string format (pythonic lists)
|
|
|
|
|
|
|
|
var redis = require("redis"),
|
2018-12-15 19:03:32 +00:00
|
|
|
client = redis.createClient(6379,'127.0.0.1');
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function rgb2int(r,g,b) {
|
|
|
|
// Generate color from r g b components
|
|
|
|
var color = hex(r) + hex(g) + hex(b);
|
|
|
|
return parseInt(color, 16)
|
|
|
|
}
|
|
|
|
|
|
|
|
function hex(v) {
|
|
|
|
// Get hexadecimal numbers.
|
|
|
|
var hex = v.toString(16);
|
|
|
|
if (v < 16) {
|
|
|
|
hex = "0" + hex;
|
|
|
|
}
|
|
|
|
return hex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add one dot to Laser 0 point list
|
|
|
|
function adddot0(dotdata){
|
|
|
|
var dotstring = "(" + dotdata + "),";
|
|
|
|
pl0 += dotstring;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add one dot to Laser 1 point list
|
|
|
|
function adddot1(dotdata){
|
|
|
|
var dotstring = "(" + dotdata + "),";
|
|
|
|
pl1 += dotstring;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate same square to laser 0 and laser 1
|
|
|
|
function GenPoints()
|
|
|
|
{
|
|
|
|
var pt = {};
|
|
|
|
|
2018-12-28 00:11:43 +00:00
|
|
|
// direct colors, i.e white
|
2018-12-13 11:05:32 +00:00
|
|
|
pt.r = 255;
|
2018-12-28 00:11:43 +00:00
|
|
|
pt.g = 255;
|
|
|
|
pt.b = 255;
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
// named colors
|
|
|
|
var white = rgb2int(255, 255, 255);
|
|
|
|
|
|
|
|
pt.x = 100;
|
|
|
|
pt.y = 200;
|
|
|
|
adddot0([pt.x, pt.y, rgb2int(pt.r, pt.g, pt.b)]);
|
|
|
|
adddot1([pt.x, pt.y, rgb2int(pt.r, pt.g, pt.b)]);
|
|
|
|
|
|
|
|
pt.x = 100;
|
|
|
|
pt.y = 300;
|
|
|
|
adddot0([pt.x, pt.y, white]);
|
|
|
|
adddot1([pt.x, pt.y, white]);
|
|
|
|
|
|
|
|
pt.x = 200;
|
|
|
|
pt.y = 300;
|
|
|
|
adddot0([pt.x, pt.y, white]);
|
|
|
|
adddot1([pt.x, pt.y, white]);
|
|
|
|
|
|
|
|
pt.x = 200;
|
|
|
|
pt.y = 200;
|
|
|
|
adddot0([pt.x, pt.y, white]);
|
|
|
|
adddot1([pt.x, pt.y, white]);
|
|
|
|
|
|
|
|
pt.x = 100;
|
|
|
|
pt.y = 200;
|
|
|
|
adddot0([pt.x, pt.y, white]);
|
|
|
|
adddot1([pt.x, pt.y, white]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Point lists strings
|
|
|
|
var pl0 = "[";
|
|
|
|
var pl1 = "[";
|
|
|
|
GenPoints();
|
|
|
|
pl0 = pl0.slice(0,-1) + "]"
|
|
|
|
pl1 = pl1.slice(0,-1) + "]"
|
|
|
|
|
|
|
|
console.log(pl0);
|
|
|
|
console.log(pl1);
|
|
|
|
|
|
|
|
// Send points lists to redis server
|
2018-12-19 11:39:54 +00:00
|
|
|
// /pl/clientnumber/lasernumber pointlist
|
|
|
|
// you're client 0 and want to send points to laser 0 and 1
|
|
|
|
|
2018-12-18 01:45:23 +00:00
|
|
|
client.set("/pl/0/0",pl0);
|
|
|
|
client.set("/pl/0/1",pl1);
|
2018-12-13 11:05:32 +00:00
|
|
|
|
|
|
|
// Quit
|
|
|
|
client.quit()
|
|
|
|
|