From d9a0eaa864885d8ce3892ab756968010e5fc9107 Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Tue, 23 Mar 2021 21:07:28 +0000 Subject: [PATCH] examples/wgt18.c working with full mouse movement --- part12-wgt/controller/main.js | 11 +++++++---- part12-wgt/mouse.c | 14 ++++++++++---- part12-wgt/wgt.h | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/part12-wgt/controller/main.js b/part12-wgt/controller/main.js index d2b03a3..0c346b3 100644 --- a/part12-wgt/controller/main.js +++ b/part12-wgt/controller/main.js @@ -35,13 +35,16 @@ bleno.on('advertisingStart', function(error) { var ioHook = require('iohook'); -var buf = Buffer.allocUnsafe(1); -var obuf = Buffer.allocUnsafe(1); +var buf = Buffer.allocUnsafe(4); +var obuf = Buffer.allocUnsafe(4); const scrwidth = 1440; -const divisor = scrwidth / 160; +const scrheight = 900; +const divisorx = scrwidth / 320; +const divisory = scrheight / 200; ioHook.on( 'mousemove', event => { - buf.writeUInt8(Math.round(event.x / divisor), 0); + buf.writeUInt16LE(Math.round(event.x / divisorx), 0); + buf.writeUInt16LE(Math.round(event.y / divisory), 2); if (Buffer.compare(buf, obuf)) { e._value = buf; diff --git a/part12-wgt/mouse.c b/part12-wgt/mouse.c index 38203ce..292baa3 100644 --- a/part12-wgt/mouse.c +++ b/part12-wgt/mouse.c @@ -159,18 +159,18 @@ void acl_poll() unsigned char d2 = bt_waitReadByte(); unsigned int dlen = d1 | (d2 << 8); - unsigned char data[dlen]; if (dlen > 7) { + unsigned char data[dlen]; for (int i=0;i