widhid: regenerate JS

master
Rob Pilling 2023-05-08 15:02:54 +01:00
parent 2fc4fdedac
commit 69bfcfeb99
2 changed files with 79 additions and 43 deletions

View File

@ -1,72 +1,103 @@
(function () {
var settings = require('Storage').readJSON('setting.json', true) || { HID: false };
var settings = require("Storage").readJSON("setting.json", true) || { HID: false };
if (settings.HID !== "kbmedia") {
console.log("widhid: can't enable, HID setting isn't \"kbmedia\"");
return;
}
var start = { x: 0, y: 0 }, end = { x: 0, y: 0 };
var anchor = { x: 0, y: 0 };
var start = { x: 0, y: 0 };
var dragging = false;
var activeTimeout;
var waitForRelease = true;
Bangle.on("swipe", function (_lr, ud) {
if (ud > 0) {
if (!activeTimeout && ud > 0) {
listen();
Bangle.buzz();
Bangle.buzz(20);
}
});
Bangle.on('drag', function (e) {
if (!activeTimeout)
return;
if (!dragging) {
dragging = true;
start.x = e.x;
start.y = e.y;
return;
}
var released = e.b === 0;
if (released) {
var dx = end.x - start.x;
var dy = end.y - start.y;
if (Math.abs(dy) < 10) {
if (dx > 40)
next();
else if (dx < 40)
prev();
var onDrag = (function (e) {
if (e.b === 0) {
var wasDragging = dragging;
dragging = false;
if (waitForRelease) {
waitForRelease = false;
return;
}
else if (Math.abs(dx) < 10) {
if (dy > 40)
down();
else if (dy < 40)
up();
}
else if (dx === 0 && dy === 0) {
if (!wasDragging
|| (Math.abs(e.x - anchor.x) < 2 && Math.abs(e.y - anchor.y) < 2)) {
toggle();
onEvent();
return;
}
Bangle.buzz();
listen();
}
if (waitForRelease)
return;
if (e.b && !dragging) {
dragging = true;
setStart(e);
Object.assign(anchor, start);
return;
}
end.x = e.x;
end.y = e.y;
var dx = e.x - start.x;
var dy = e.y - start.y;
if (Math.abs(dy) > 25 && Math.abs(dx) > 25) {
setStart(e);
return;
}
if (dx > 40) {
next();
onEvent();
waitForRelease = true;
}
else if (dx < -40) {
prev();
onEvent();
waitForRelease = true;
}
else if (dy > 30) {
down();
onEvent();
setStart(e);
}
else if (dy < -30) {
up();
onEvent();
setStart(e);
}
});
var setStart = function (_a) {
var x = _a.x, y = _a.y;
start.x = x;
start.y = y;
};
var onEvent = function () {
Bangle.buzz(20);
listen();
};
var listen = function () {
suspendOthers();
var wasActive = !!activeTimeout;
clearTimeout(activeTimeout);
if (!wasActive) {
suspendOthers();
waitForRelease = true;
Bangle.on("drag", onDrag);
redraw();
}
if (activeTimeout)
clearTimeout(activeTimeout);
activeTimeout = setTimeout(function () {
activeTimeout = undefined;
Bangle.removeListener("drag", onDrag);
resumeOthers();
redraw();
}, 5000);
if (!wasActive)
redraw();
}, 3000);
};
WIDGETS["hid"] = {
area: "tr",
sortorder: -20,
draw: function () {
g.drawImage(activeTimeout
? require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A/AG8gkAvvAAYvvGVIvIGcwvMGMQv/F/4vTGpQvmNJAvqBggvtAEQv/F/4v/F/4nbFIYvlFooAHF1wvgFxwvfFx4v/Fz4v/F/4v/F/4wfFzwvwGBwugGBouiGBYukGJAtnAH4A/AH4A/ACIA=="))
: require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A/AG9lsovvAAYvvGVIvIGcwvMGMQv/F/4vTGpQvmNJAvqBggvtAEQv/F/4v/F/4nbFIYvlFooAHF1wvgFxwvfFx4v/Fz4v/F/4v/F/4wfFzwvwGBwugGBouiGBYukGJAtnAH4A/AH4A/ACIA==")), this.x + 2, this.y + 2);
? require("heatshrink").decompress(atob("jEYxH+AEfH44XXAAYXXDKIXZDYp3pC/6KHUMwWHC/4XvUy4YGdqoA/AFoA=="))
: require("heatshrink").decompress(atob("jEYxH+AEcdjoXXAAYXXDKIXZDYp3pC/6KHUMwWHC/4XvUy4YGdqoA/AFoA==")), this.x + 2, this.y + 2);
},
width: 24,
};

View File

@ -1584,7 +1584,7 @@ declare class NRF {
* @param {any} callback - A callback function to be called when the data is sent
* @url http://www.espruino.com/Reference#l_NRF_sendHIDReport
*/
static sendHIDReport(data: any, callback: any): void;
static sendHIDReport(data: number[], callback?: () => void): void
/**
* Check if Apple Notification Center Service (ANCS) is currently active on the BLE
@ -3188,8 +3188,10 @@ declare class Puck {
* Check out [the Puck.js page on the
* accelerometer](http://www.espruino.com/Puck.js#on-board-peripherals) for more
* information.
* **Note:** Puck.js cannot currently read every sample from the
* accelerometer at sample rates above 208Hz.
*
* @param {number} samplerate - The sample rate in Hz, or undefined
* @param {number} samplerate - The sample rate in Hz, or `undefined` (default is 12.5 Hz)
* @url http://www.espruino.com/Reference#l_Puck_accelOn
*/
static accelOn(samplerate: number): void;
@ -3819,6 +3821,9 @@ declare class Bangle {
* and polling rate may not be exact. The algorithm's filtering is tuned for
* 20-40ms poll intervals, so higher/lower intervals may effect the reliability
* of the BPM reading.
* * `hrmSportMode` - on the newest Bangle.js 2 builds with with the proprietary
* heart rate algorithm, this is the sport mode passed to the algorithm. See `libs/misc/vc31_binary/algo.h`
* for more info. 0 = normal (default), 1 = running, 2 = ...
* * `seaLevelPressure` (Bangle.js 2) Normally 1013.25 millibars - this is used for
* calculating altitude with the pressure sensor
* Where accelerations are used they are in internal units, where `8192 = 1g`
@ -13222,7 +13227,7 @@ declare module "Storage" {
* @returns {any} An object containing parsed JSON from the file, or undefined
* @url http://www.espruino.com/Reference#l_Storage_readJSON
*/
function readJSON(name: string, noExceptions: boolean): any;
function readJSON(name: string, noExceptions: ShortBoolean): any;
/**
* Read a file from the flash storage area that has been written with