Skip to content

Commit

Permalink
slave: +custom keymap,+custom mouse speed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dazhou committed Jan 6, 2019
1 parent 7a42fe2 commit c66011f
Show file tree
Hide file tree
Showing 21 changed files with 3,038 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
host/host
slave/slave
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,17 @@ init_uart_baud=4000000

`cmdline.txt`
dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=a34c07ff-02 rootfstype=ext4 elevator=deadline fsck.repair=yes usbhid.mousepoll=2 rootwait


**Slave PI Zero Config**
`config.txt`
dtoverlay=dwc2 #Open otg mode
dr_mode=peripheral #unknow
dtoverlay=pi3-disable-bt # disable bt and use hardware serialport.
enable_uart=1
init_uart_clock=64000000
init_uart_baud=4000000

`cmdline.txt`
dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=18d2a8c5-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

161 changes: 161 additions & 0 deletions slave/assets/nonwin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>NON-WINDOWS Mouse</title>
<link rel="stylesheet" href="/style.css">
<script src="/jquery.js"></script>
</head>

<body>
<div class="box">
<ul>
<li><a href="/">Settings</a></li>
<li><a href="/win">Win Mouse</a></li>
<li><a href="/nonwin" class="active">Non-Win Mouse</a></li>
</ul>
<div id="content" class="row content"></div>
</div>
</div>

<script>
var Step = "";
var canvas = document.createElement('canvas');
canvas.id = "CursorLayer";
pW = $('#content').width() - 40, pH = $('#content').height() - 20;
canvas.width = pW - pW % 100;
canvas.height = pH - pH % 100;
canvas.style.border = "1px solid";
canvas.style.margin = (pH - canvas.height) / 2 + "px " + (pW - canvas.width) / 2 + "px";
$('#content').append(canvas);
var ctx = canvas.getContext("2d");
drawGrid();

var centerX = canvas.width / 4, centerY = canvas.height / 4;

var clickCount = 0;
canvas.onmousedown = function (event) {
if (Step == "") {
alert("press enter and leave your hand from mouse !!!")
Step = "zero"
return;
}
console.log(event.button);
if (Step == "draw") {
if (event.button == 1) {
event.preventDefault();
Step = "done";
console.log("done!");
return;
}
clickCount++;
var x = event.pageX - canvas.offsetLeft, y = event.pageY - canvas.offsetTop;
console.log("click " + clickCount + ": " + (x - centerX) + "," + (y - centerY));
drawPoint(x, y, "blue");
if (clickCount % 10 == 0)
drawText(x, y);


drawLine(LastPoint.X, LastPoint.Y, x, y)

LastPoint.X = x;
LastPoint.Y = y;

}




};

canvas.onmousemove = function (event) {
CurrentPoint = { X: event.pageX - canvas.offsetLeft, Y: event.pageY - canvas.offsetTop };
}




function drawPoint(x, y, color) {
ctx.beginPath();
ctx.rect(x, y, 2, 2);
ctx.fillStyle = color;
ctx.fill();
}
function drawText(x, y) {
ctx.fillText("" + (x - centerX) + "," + (y - centerY), x, y);
}
function drawLine(sx, sy, dx, dy) {
ctx.beginPath();
ctx.moveTo(sx, sy);
ctx.lineTo(dx, dy);
ctx.strokeStyle = '#00ff00';
ctx.stroke();
}

function drawGrid() {
var grid_size = 10;
var canvas_width = canvas.width;
var canvas_height = canvas.height;
var num_lines_x = Math.floor(canvas_height / grid_size);
var num_lines_y = Math.floor(canvas_width / grid_size);
for (var i = 0; i <= num_lines_x; i++) {
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = "#efefef";
if (i == num_lines_x) {
ctx.moveTo(0, grid_size * i);
ctx.lineTo(canvas_width, grid_size * i);
}
else {
ctx.moveTo(0, grid_size * i + 0.5);
ctx.lineTo(canvas_width, grid_size * i + 0.5);
}
ctx.stroke();
}
// Draw grid lines along Y-axis
for (i = 0; i <= num_lines_y; i++) {
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle = "#efefef";
if (i == num_lines_y) {
ctx.moveTo(grid_size * i, 0);
ctx.lineTo(grid_size * i, canvas_height);
}
else {
ctx.moveTo(grid_size * i + 0.5, 0);
ctx.lineTo(grid_size * i + 0.5, canvas_height);
}
ctx.stroke();
}
}



var CurrentPoint = { X: -1, Y: -1 };
var LastPoint = { X: 0, Y: 0 };
var MoveTimer = setInterval(Frame, 20);
function Frame() {
if (Step == "zero") {
var xOffset = centerX - CurrentPoint.X;
var yOffset = centerY - CurrentPoint.Y;
if (xOffset != 0 || yOffset != 0) {
console.log("zero: ", CurrentPoint.X, "," + CurrentPoint.Y + " -> " + centerX + "," + centerY)
if (xOffset != 0)
$.get("/nonwin?hid=M:X:" + (xOffset < 0 ? -1 : 1), function (data) { });
if (yOffset != 0)
$.get("/nonwin?hid=M:Y:" + (yOffset < 0 ? -1 : 1), function (data) { });
} else {
Step = "draw";
clearInterval(MoveTimer);
LastPoint.X = centerX;
LastPoint.Y = centerY;
$.get("/nonwin?draw=1&centerx=" + centerX + "&centery=" + centerY, function (data) { });
}
}
}

</script>
</body>

</html>
Loading

0 comments on commit c66011f

Please sign in to comment.