2022-01-01 22:40:34 +00:00
|
|
|
// Presentor by 7kasper (Kasper Müller)
|
2022-01-02 21:45:16 +00:00
|
|
|
// Version 3.0
|
2021-12-26 16:14:08 +00:00
|
|
|
|
2022-01-01 22:40:34 +00:00
|
|
|
const SpecialReport = new Uint8Array([
|
2022-01-02 19:13:56 +00:00
|
|
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
|
|
0x09, 0x02, // USAGE (Mouse)
|
|
|
|
0xa1, 0x01, // COLLECTION (Application)
|
|
|
|
0x85, 0x01, // REPORT_ID (1)
|
|
|
|
0x09, 0x01, // USAGE (Pointer)
|
|
|
|
0xa1, 0x00, // COLLECTION (Physical)
|
|
|
|
0x05, 0x09, // USAGE_PAGE (Button)
|
|
|
|
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
|
|
|
0x29, 0x05, // USAGE_MAXIMUM (Button 5)
|
|
|
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
|
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
|
|
|
0x95, 0x05, // REPORT_COUNT (5)
|
|
|
|
0x75, 0x01, // REPORT_SIZE (1)
|
|
|
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
|
|
|
0x95, 0x01, // REPORT_COUNT (1)
|
|
|
|
0x75, 0x03, // REPORT_SIZE (3)
|
|
|
|
0x81, 0x03, // INPUT (Cnst,Var,Abs)
|
|
|
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
|
|
0x09, 0x30, // USAGE (X)
|
|
|
|
0x09, 0x31, // USAGE (Y)
|
|
|
|
0x09, 0x38, // USAGE (Wheel)
|
|
|
|
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
|
|
|
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
|
|
|
|
0x75, 0x08, // REPORT_SIZE (8)
|
|
|
|
0x95, 0x03, // REPORT_COUNT (3)
|
|
|
|
0x81, 0x06, // INPUT (Data,Var,Rel)
|
|
|
|
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
|
|
|
|
0x0a, 0x38, 0x02, // USAGE (AC Pan)
|
|
|
|
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
|
|
|
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
|
|
|
|
0x75, 0x08, // REPORT_SIZE (8)
|
|
|
|
0x95, 0x01, // REPORT_COUNT (1)
|
|
|
|
0x81, 0x06, // INPUT (Data,Var,Rel)
|
|
|
|
0xc0, // END_COLLECTION
|
|
|
|
0xc0, // END_COLLECTION
|
|
|
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
|
|
0x09, 0x06, // USAGE (Keyboard)
|
|
|
|
0xa1, 0x01, // COLLECTION (Application)
|
|
|
|
0x85, 0x02, // REPORT_ID (2)
|
|
|
|
0x05, 0x07, // USAGE_PAGE (Keyboard)
|
|
|
|
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
|
|
|
|
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
|
|
|
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
|
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
|
|
|
0x75, 0x01, // REPORT_SIZE (1)
|
|
|
|
0x95, 0x08, // REPORT_COUNT (8)
|
|
|
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
|
|
|
0x75, 0x08, // REPORT_SIZE (8)
|
|
|
|
0x95, 0x01, // REPORT_COUNT (1)
|
|
|
|
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
|
|
|
|
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
|
|
|
|
0x29, 0x73, // USAGE_MAXIMUM (Keyboard F24)
|
|
|
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
|
|
0x25, 0x73, // LOGICAL_MAXIMUM (115)
|
|
|
|
0x95, 0x05, // REPORT_COUNT (5)
|
|
|
|
0x75, 0x08, // REPORT_SIZE (8)
|
|
|
|
0x81, 0x00, // INPUT (Data,Ary,Abs)
|
|
|
|
0xc0 // END_COLLECTION
|
2021-12-26 16:14:08 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
const MouseButton = {
|
2022-01-02 19:29:28 +00:00
|
|
|
NONE : 0,
|
|
|
|
LEFT : 1,
|
|
|
|
RIGHT : 2,
|
|
|
|
MIDDLE : 4,
|
|
|
|
BACK : 8,
|
|
|
|
FORWARD: 16
|
2021-12-26 16:14:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const kb = require("ble_hid_keyboard");
|
|
|
|
|
2022-01-01 22:40:34 +00:00
|
|
|
const Layout = require("Layout");
|
|
|
|
const Locale = require("locale");
|
2022-01-02 19:29:28 +00:00
|
|
|
let mainLayout = new Layout({
|
|
|
|
'type': 'v',
|
|
|
|
filly: 1,
|
|
|
|
c: [
|
|
|
|
{
|
|
|
|
type: 'txt',
|
|
|
|
font: '6x8',
|
|
|
|
label: 'Presentor',
|
|
|
|
valign: -1,
|
|
|
|
halign: 0,
|
|
|
|
col: g.theme.fg1,
|
|
|
|
// bgCol: g.theme.bg2,
|
|
|
|
bgCol: '#00F',
|
|
|
|
fillx: 1,
|
|
|
|
}, {
|
|
|
|
type: 'h',
|
|
|
|
fillx: 1,
|
|
|
|
c: [
|
|
|
|
{
|
|
|
|
type: 'txt',
|
|
|
|
font: '15%',
|
|
|
|
label: '00:00',
|
|
|
|
id: 'Time',
|
|
|
|
halign: -1,
|
|
|
|
pad: 3
|
|
|
|
}, {
|
|
|
|
fillx: 1
|
|
|
|
}, {
|
|
|
|
type: 'txt',
|
|
|
|
font: '15%',
|
|
|
|
label: '00:00',
|
|
|
|
id: 'Timer',
|
|
|
|
halign: 1,
|
|
|
|
pad: 3
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}, {
|
|
|
|
type: 'txt',
|
|
|
|
font: '10%',
|
|
|
|
label: '+00:00',
|
|
|
|
id: 'RestTime',
|
|
|
|
col: '#fff'
|
|
|
|
}, {
|
|
|
|
type: 'txt',
|
|
|
|
font: '10%',
|
|
|
|
label: '--------------'
|
|
|
|
}, {
|
|
|
|
type: 'txt',
|
|
|
|
font: '15%',
|
|
|
|
label: 'Presenting',
|
|
|
|
id: 'Subject'
|
|
|
|
}, {
|
|
|
|
type: 'txt',
|
|
|
|
font: '6x8',
|
2022-01-02 21:41:52 +00:00
|
|
|
label: 'Swipe up to start the time.',
|
2022-01-02 19:29:28 +00:00
|
|
|
id: 'Notes',
|
|
|
|
col: '#ff0',
|
|
|
|
fillx: 1,
|
|
|
|
filly: 1,
|
|
|
|
valign: 1
|
|
|
|
}
|
|
|
|
]
|
2022-01-01 22:40:34 +00:00
|
|
|
}, {lazy:true});
|
2021-12-26 16:14:08 +00:00
|
|
|
|
2022-01-02 19:13:56 +00:00
|
|
|
let settings = {pparts: [], sversion: 0};
|
2022-01-02 21:44:52 +00:00
|
|
|
let HIDenabled = true;
|
2022-01-01 22:40:34 +00:00
|
|
|
|
|
|
|
// Application variables
|
2022-01-02 19:13:56 +00:00
|
|
|
let pparti = -1;
|
2022-01-02 21:03:15 +00:00
|
|
|
let ppartBuzzed = false;
|
2022-01-02 21:41:52 +00:00
|
|
|
let restBuzzed = false;
|
2022-01-02 16:03:48 +00:00
|
|
|
|
2021-12-26 16:14:08 +00:00
|
|
|
let lastx = 0;
|
|
|
|
let lasty = 0;
|
2022-01-02 19:13:56 +00:00
|
|
|
|
|
|
|
// Mouse states
|
2021-12-26 16:14:08 +00:00
|
|
|
let holding = false;
|
2022-01-02 19:13:56 +00:00
|
|
|
let trackPadMode = false;
|
|
|
|
|
|
|
|
// Timeout IDs.
|
|
|
|
let timeoutId = -1;
|
2021-12-26 16:14:08 +00:00
|
|
|
let timeoutHolding = -1;
|
2022-01-01 22:40:34 +00:00
|
|
|
let timeoutDraw = -1;
|
2022-01-02 19:13:56 +00:00
|
|
|
|
2021-12-26 16:14:08 +00:00
|
|
|
|
|
|
|
let homeRoll = 0;
|
|
|
|
let homePitch = 0;
|
|
|
|
let mCal = 0;
|
|
|
|
let mttl = 0;
|
|
|
|
let cttl = 0;
|
|
|
|
|
2022-01-02 19:13:56 +00:00
|
|
|
// BT helper.
|
|
|
|
let clearToSend = true;
|
|
|
|
|
|
|
|
// Presentation Timers
|
|
|
|
let ptimers = [];
|
|
|
|
|
2022-01-02 21:03:15 +00:00
|
|
|
function delay(t, v) {
|
2022-01-02 21:41:52 +00:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(resolve, t)
|
2022-01-02 21:03:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-02 19:29:28 +00:00
|
|
|
function formatTimePart(time) {
|
|
|
|
time = Math.floor(Math.abs(time));
|
|
|
|
return time < 10 ? `0${time}` : `${time}`;
|
2022-01-02 19:13:56 +00:00
|
|
|
}
|
2022-01-02 19:29:28 +00:00
|
|
|
|
|
|
|
function formatTime(time, doPlus) {
|
2022-01-02 21:03:15 +00:00
|
|
|
if (time == Infinity) return ' --:-- ';
|
2022-01-02 19:29:28 +00:00
|
|
|
return `${time < 0 ? '-' : (doPlus ? '+' : '')}${formatTimePart(time/60)}:${formatTimePart(time%60)}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadSettings() {
|
|
|
|
settings = require("Storage").readJSON('presentor.json');
|
|
|
|
for (let i = 0; i < settings.pparts.length; i++) {
|
|
|
|
ptimers[i] = {
|
|
|
|
active: false,
|
|
|
|
tracked: -1,
|
|
|
|
left: settings.pparts[i].minutes * 60 + settings.pparts[i].seconds
|
|
|
|
};
|
|
|
|
}
|
2022-01-02 19:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentTimer() {
|
2022-01-02 21:03:15 +00:00
|
|
|
if (pparti < 0) return Infinity;
|
|
|
|
if (!settings.pparts || pparti >= settings.pparts.length) return Infinity;
|
|
|
|
if (ptimers[pparti].tracked == -1) return Infinity;
|
2022-01-02 19:29:28 +00:00
|
|
|
ptimers[pparti].left -= (getTime() - ptimers[pparti].tracked);
|
|
|
|
ptimers[pparti].tracked = getTime();
|
2022-01-02 21:03:15 +00:00
|
|
|
// if we haven't buzzed yet and timer became negative just buzz here.
|
|
|
|
// TODO better place?
|
|
|
|
if (ptimers[pparti].left <= 0 && !ppartBuzzed) {
|
2022-01-02 21:41:52 +00:00
|
|
|
Bangle.buzz(400)
|
|
|
|
.then(() => delay(400))
|
|
|
|
.then(() => Bangle.buzz(400));
|
2022-01-02 21:03:15 +00:00
|
|
|
ppartBuzzed = true;
|
|
|
|
}
|
|
|
|
return ptimers[pparti].left;
|
2022-01-02 19:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getRestTime() {
|
2022-01-02 19:29:28 +00:00
|
|
|
let rem = 0;
|
|
|
|
// Add all remaining time from previous presentation parts.
|
|
|
|
for (let i = 0; i < pparti; i++) {
|
|
|
|
rem += ptimers[i].left;
|
|
|
|
}
|
2022-01-02 21:41:52 +00:00
|
|
|
if (pparti >= 0 && pparti < ptimers.length && ptimers[pparti].left < 0) {
|
2022-01-02 21:03:15 +00:00
|
|
|
rem += ptimers[pparti].left;
|
|
|
|
}
|
2022-01-02 21:41:52 +00:00
|
|
|
// if we haven't buzzed yet and timer became negative just buzz here.
|
|
|
|
// TODO better place?
|
|
|
|
if (rem < 0 && !restBuzzed) {
|
|
|
|
Bangle.buzz(200)
|
|
|
|
.then(() => delay(400))
|
|
|
|
.then(() => Bangle.buzz(200))
|
|
|
|
.then(() => delay(400))
|
|
|
|
.then(() => Bangle.buzz(200));
|
|
|
|
restBuzzed = true;
|
|
|
|
}
|
2022-01-02 21:03:15 +00:00
|
|
|
return rem;
|
2022-01-02 19:13:56 +00:00
|
|
|
}
|
2022-01-01 22:40:34 +00:00
|
|
|
|
|
|
|
function drawMainFrame() {
|
2022-01-02 19:29:28 +00:00
|
|
|
var d = new Date();
|
|
|
|
// update time
|
|
|
|
mainLayout.Time.label = Locale.time(d,1);
|
|
|
|
// update timer
|
2022-01-02 21:03:15 +00:00
|
|
|
mainLayout.Timer.label = formatTime(getCurrentTimer());
|
|
|
|
let restTime = getRestTime();
|
|
|
|
mainLayout.RestTime.label = formatTime(restTime, true);
|
|
|
|
mainLayout.RestTime.col = restTime < 0 ? '#f00' : (restTime > 0 ? '#0f0' : '#fff');
|
2022-01-02 19:29:28 +00:00
|
|
|
mainLayout.render();
|
|
|
|
// schedule a draw for the next minute
|
|
|
|
if (timeoutDraw != -1) clearTimeout(timeoutDraw);
|
|
|
|
timeoutDraw = setTimeout(function() {
|
|
|
|
timeoutDraw = -1;
|
|
|
|
drawMainFrame();
|
|
|
|
}, 1000 - (Date.now() % 1000));
|
2022-01-01 22:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawMain() {
|
2022-01-02 19:29:28 +00:00
|
|
|
g.clear();
|
|
|
|
mainLayout.forgetLazyState();
|
|
|
|
drawMainFrame();
|
|
|
|
// mainLayout.render();
|
|
|
|
// E.showMessage('Presentor');
|
2022-01-02 19:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function doPPart(r) {
|
2022-01-02 19:29:28 +00:00
|
|
|
pparti += r;
|
2022-01-02 21:41:52 +00:00
|
|
|
if (pparti < 0) {
|
|
|
|
pparti = -1;
|
|
|
|
mainLayout.Subject.label = 'PAUSED';
|
|
|
|
mainLayout.Notes.label = 'Swipe up to start again.';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!settings.pparts || pparti >= settings.pparts.length) {
|
|
|
|
pparti = settings.pparts.length;
|
|
|
|
mainLayout.Subject.label = 'FINISHED';
|
|
|
|
mainLayout.Notes.label = 'Good Job!';
|
|
|
|
return;
|
|
|
|
}
|
2022-01-02 19:29:28 +00:00
|
|
|
let ppart = settings.pparts[pparti];
|
|
|
|
mainLayout.Subject.label = ppart.subject;
|
|
|
|
mainLayout.Notes.label = ppart.notes;
|
|
|
|
ptimers[pparti].tracked = getTime();
|
2022-01-02 21:03:15 +00:00
|
|
|
// We haven't buzzed if there was time left.
|
|
|
|
ppartBuzzed = ptimers[pparti].left <= 0;
|
2022-01-02 21:41:52 +00:00
|
|
|
// Always reset buzzstate for the rest timer.
|
|
|
|
restBuzzed = getRestTime() < 0;
|
2022-01-02 19:29:28 +00:00
|
|
|
drawMainFrame();
|
2022-01-01 22:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NRF.setServices(undefined, { hid : SpecialReport });
|
|
|
|
// TODO: figure out how to detect HID.
|
2021-12-26 16:14:08 +00:00
|
|
|
NRF.on('HID', function() {
|
2022-01-02 19:29:28 +00:00
|
|
|
HIDenabled = true;
|
2021-12-26 16:14:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function moveMouse(x,y,b,wheel,hwheel,callback) {
|
2022-01-02 19:29:28 +00:00
|
|
|
if (!HIDenabled) return;
|
|
|
|
if (!b) b = 0;
|
|
|
|
if (!wheel) wheel = 0;
|
|
|
|
if (!hwheel) hwheel = 0;
|
|
|
|
NRF.sendHIDReport([1,b,x,y,wheel,hwheel,0,0], function() {
|
|
|
|
if (callback) callback();
|
|
|
|
});
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
|
|
|
|
2022-01-01 22:40:34 +00:00
|
|
|
// function getSign(x) {
|
|
|
|
// return ((x > 0) - (x < 0)) || +x;
|
|
|
|
// }
|
2021-12-26 16:14:08 +00:00
|
|
|
|
|
|
|
function scroll(wheel,hwheel,callback) {
|
2022-01-02 19:29:28 +00:00
|
|
|
moveMouse(0,0,0,wheel,hwheel,callback);
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Single click a certain button (immidiatly release).
|
|
|
|
function clickMouse(b, callback) {
|
2022-01-02 19:29:28 +00:00
|
|
|
if (!HIDenabled) return;
|
|
|
|
NRF.sendHIDReport([1,b,0,0,0,0,0,0], function() {
|
|
|
|
NRF.sendHIDReport([1,0,0,0,0,0,0,0], function() {
|
|
|
|
if (callback) callback();
|
|
|
|
});
|
2021-12-26 16:14:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function pressKey(keyCode, modifiers, callback) {
|
2022-01-02 19:29:28 +00:00
|
|
|
if (!HIDenabled) return;
|
|
|
|
if (!modifiers) modifiers = 0;
|
|
|
|
NRF.sendHIDReport([2, modifiers,0,keyCode,0,0,0,0], function() {
|
|
|
|
NRF.sendHIDReport([2,0,0,0,0,0,0,0], function() {
|
|
|
|
if (callback) callback();
|
|
|
|
});
|
2021-12-26 16:14:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleAcc(acc) {
|
2022-01-02 19:29:28 +00:00
|
|
|
let rRoll = acc.y * -50;
|
|
|
|
let rPitch = acc.x * -100;
|
|
|
|
if (mCal > 10) {
|
|
|
|
//console.log("x: " + (rRoll - homeRoll) + " y:" + (rPitch - homePitch));
|
|
|
|
moveMouse(acc.y * -50 - homeRoll, acc.x * -100 - homePitch);
|
|
|
|
} else {
|
|
|
|
//console.log("homeroll: " +homeRoll +"homepitch: " + homePitch);
|
|
|
|
homeRoll = rRoll * 0.7 + homeRoll * 0.3;
|
|
|
|
homePitch = rPitch * 0.7 + homePitch * 0.3;
|
|
|
|
mCal = mCal + 1;
|
|
|
|
}
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
|
|
|
Bangle.on('lock', function(on) {
|
2022-01-02 19:29:28 +00:00
|
|
|
if (on && holding) {
|
|
|
|
Bangle.setLocked(false);
|
|
|
|
Bangle.setLCDPower(1);
|
|
|
|
}
|
2021-12-26 16:14:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function startHolding() {
|
|
|
|
pressKey(kb.KEY.F10);
|
2022-01-02 19:29:28 +00:00
|
|
|
holding = true;
|
2021-12-26 16:14:08 +00:00
|
|
|
Bangle.buzz();
|
2022-01-02 19:29:28 +00:00
|
|
|
E.showMessage('Holding');
|
|
|
|
Bangle.on('accel', handleAcc);
|
|
|
|
Bangle.setLCDPower(1);
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
2022-01-02 19:29:28 +00:00
|
|
|
function stopHolding() {
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
if (holding) {
|
|
|
|
pressKey(kb.KEY.F10);
|
|
|
|
homePitch = 0;
|
|
|
|
homeRoll = 0;
|
|
|
|
holding = false;
|
|
|
|
mCal = 0;
|
|
|
|
Bangle.removeListener('accel', handleAcc);
|
|
|
|
Bangle.buzz();
|
|
|
|
drawMain();
|
|
|
|
} else {
|
|
|
|
timeoutId = setTimeout(drawMain, 1000);
|
|
|
|
}
|
|
|
|
clearTimeout(timeoutHolding);
|
|
|
|
timeoutHolding = -1;
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Bangle.on('drag', function(e) {
|
2022-01-02 19:29:28 +00:00
|
|
|
if (cttl == 0) { cttl = getTime(); }
|
|
|
|
if (trackPadMode) {
|
|
|
|
if (lastx + lasty == 0) {
|
|
|
|
lastx = e.x;
|
|
|
|
lasty = e.y;
|
|
|
|
mttl = getTime();
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
2022-01-02 19:29:28 +00:00
|
|
|
if (clearToSend) {
|
|
|
|
clearToSend = false;
|
|
|
|
let difX = e.x - lastx, difY = e.y - lasty;
|
|
|
|
let dT = getTime() - mttl;
|
|
|
|
let vX = difX / dT, vY = difY / dT;
|
|
|
|
//let qX = getSign(difX) * Math.pow(Math.abs(difX), 1.2);
|
|
|
|
//let qY = getSign(difY) * Math.pow(Math.abs(difY), 1.2);
|
|
|
|
let qX = difX + 0.02 * vX, qY = difY + 0.02 * vY;
|
|
|
|
moveMouse(qX, qY, 0, 0, 0, function() {
|
|
|
|
setTimeout(function() {clearToSend = true;}, 50);
|
|
|
|
});
|
|
|
|
lastx = e.x;
|
|
|
|
lasty = e.y;
|
|
|
|
mttl = getTime();
|
|
|
|
console.log("Dx: " + (qX) + " Dy: " + (qY));
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
2022-01-02 19:29:28 +00:00
|
|
|
if (!e.b) {
|
|
|
|
// short press
|
|
|
|
if (getTime() - cttl < 0.2) {
|
|
|
|
clickMouse(MouseButton.LEFT);
|
|
|
|
console.log("click left");
|
|
|
|
}
|
|
|
|
// longer press in center
|
|
|
|
else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) {
|
|
|
|
clickMouse(MouseButton.RIGHT);
|
|
|
|
console.log("click right");
|
|
|
|
}
|
|
|
|
cttl = 0;
|
|
|
|
lastx = 0;
|
|
|
|
lasty = 0;
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
2022-01-02 19:29:28 +00:00
|
|
|
} else {
|
|
|
|
if(!e.b){
|
|
|
|
Bangle.buzz(100);
|
|
|
|
if(lasty > 40){
|
|
|
|
doPPart(-1);
|
2022-01-02 21:41:52 +00:00
|
|
|
// E.showMessage('down');
|
|
|
|
} else if(lasty < -40){
|
|
|
|
doPPart(1);
|
|
|
|
// E.showMessage('up');
|
2022-01-02 19:29:28 +00:00
|
|
|
} else if(lastx > 40){
|
2022-01-02 21:41:52 +00:00
|
|
|
// E.showMessage('right');
|
2022-01-02 19:29:28 +00:00
|
|
|
//kb.tap(kb.KEY.RIGHT, 0);
|
|
|
|
scroll(-1);
|
|
|
|
} else if(lastx < -40){
|
2022-01-02 21:41:52 +00:00
|
|
|
// E.showMessage('left');
|
2022-01-02 19:29:28 +00:00
|
|
|
//kb.tap(kb.KEY.LEFT, 0);
|
|
|
|
scroll(1);
|
|
|
|
} else if(lastx==0 && lasty==0 && holding == false){
|
2022-01-02 21:41:52 +00:00
|
|
|
// E.showMessage('press');
|
2022-01-02 19:29:28 +00:00
|
|
|
clickMouse(MouseButton.LEFT);
|
|
|
|
}
|
|
|
|
stopHolding();
|
|
|
|
lastx = 0;
|
|
|
|
lasty = 0;
|
|
|
|
} else{
|
|
|
|
lastx = lastx + e.dx;
|
|
|
|
lasty = lasty + e.dy;
|
|
|
|
if (timeoutHolding == -1) {
|
|
|
|
timeoutHolding = setTimeout(startHolding, 500);
|
|
|
|
}
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function onBtn() {
|
2022-01-02 19:29:28 +00:00
|
|
|
if (trackPadMode) {
|
|
|
|
trackPadMode = false;
|
|
|
|
stopHolding();
|
|
|
|
drawMain();
|
|
|
|
} else {
|
|
|
|
clearToSend = true;
|
|
|
|
trackPadMode = true;
|
|
|
|
E.showMessage('Mouse');
|
|
|
|
}
|
|
|
|
Bangle.buzz();
|
2021-12-26 16:14:08 +00:00
|
|
|
}
|
|
|
|
setWatch(onBtn, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat: true});
|
|
|
|
|
2022-01-02 19:13:56 +00:00
|
|
|
loadSettings();
|
|
|
|
drawMain();
|