Working on interface functionality
parent
f6efbf82e9
commit
602679c6bc
|
|
@ -63,12 +63,12 @@ const SpecialReport = new Uint8Array([
|
|||
]);
|
||||
|
||||
const MouseButton = {
|
||||
NONE : 0,
|
||||
LEFT : 1,
|
||||
RIGHT : 2,
|
||||
MIDDLE : 4,
|
||||
BACK : 8,
|
||||
FORWARD: 16
|
||||
NONE : 0,
|
||||
LEFT : 1,
|
||||
RIGHT : 2,
|
||||
MIDDLE : 4,
|
||||
BACK : 8,
|
||||
FORWARD: 16
|
||||
};
|
||||
|
||||
const kb = require("ble_hid_keyboard");
|
||||
|
|
@ -76,9 +76,9 @@ const kb = require("ble_hid_keyboard");
|
|||
const Layout = require("Layout");
|
||||
const Locale = require("locale");
|
||||
let mainLayout = new Layout( {
|
||||
'type': 'v',
|
||||
filly: 1,
|
||||
c: [
|
||||
'type': 'v',
|
||||
filly: 1,
|
||||
c: [
|
||||
{
|
||||
type: 'txt',
|
||||
font: '6x8',
|
||||
|
|
@ -124,12 +124,12 @@ let mainLayout = new Layout( {
|
|||
}, {
|
||||
type: 'txt',
|
||||
font: '15%',
|
||||
label: 'Subject',
|
||||
label: 'Presenting',
|
||||
id: 'Subject'
|
||||
}, {
|
||||
type: 'txt',
|
||||
font: '6x8',
|
||||
label: 'Notes...',
|
||||
label: 'Swipe down to start the time.',
|
||||
id: 'Notes',
|
||||
col: '#ff0',
|
||||
fillx: 1,
|
||||
|
|
@ -137,69 +137,119 @@ let mainLayout = new Layout( {
|
|||
valign: 1
|
||||
}
|
||||
|
||||
]
|
||||
]
|
||||
}, {lazy:true});
|
||||
|
||||
let settings = require("Storage").readJSON('presentor.json');
|
||||
let settings = {pparts: [], sversion: 0};
|
||||
let HIDenabled = false;
|
||||
|
||||
// Application variables
|
||||
let pparti = 0;
|
||||
let pparti = -1;
|
||||
|
||||
let lastx = 0;
|
||||
let lasty = 0;
|
||||
let timeoutId = -1;
|
||||
|
||||
// Mouse states
|
||||
let holding = false;
|
||||
let trackPadMode = false;
|
||||
|
||||
// Timeout IDs.
|
||||
let timeoutId = -1;
|
||||
let timeoutHolding = -1;
|
||||
let timeoutDraw = -1;
|
||||
let timeoutDrawTimer = -1;
|
||||
|
||||
|
||||
let homeRoll = 0;
|
||||
let homePitch = 0;
|
||||
|
||||
let trackPadMode = false;
|
||||
|
||||
let mCal = 0;
|
||||
|
||||
let clearToSend = true;
|
||||
let mttl = 0;
|
||||
let cttl = 0;
|
||||
|
||||
// BT helper.
|
||||
let clearToSend = true;
|
||||
|
||||
// Presentation Timers
|
||||
let ptimers = [];
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentTimer() {
|
||||
if (pparti < 0) return '00:00';
|
||||
if (!settings.pparts || pparti >= settings.pparts.length) return '00:00';
|
||||
if (ptimers[pparti].tracked == -1) return '00:00';
|
||||
ptimers[pparti].left -= (getTime() - ptimers[pparti].tracked);
|
||||
ptimers[pparti].tracked = getTime();
|
||||
return `${Math.floor(ptimers[pparti].left/60)}:${Math.floor(ptimers[pparti].left%60)}`;
|
||||
}
|
||||
|
||||
function getRestTime() {
|
||||
let rem = 0;
|
||||
// Add all remaining time from previous presentation parts.
|
||||
for (let i = 0; i < pparti; i++) {
|
||||
rem += ptimers[i].left;
|
||||
}
|
||||
return `${rem >= 0 ? '+':'-'}${Math.floor(rem/60)}:${Math.floor(rem%60)}`;
|
||||
}
|
||||
|
||||
function drawMainFrame() {
|
||||
var d = new Date();
|
||||
// update time
|
||||
mainLayout.Time.label = Locale.time(d,1);
|
||||
mainLayout.render();
|
||||
// schedule a draw for the next minute
|
||||
if (timeoutDraw != -1) clearTimeout(timeoutDraw);
|
||||
timeoutDraw = setTimeout(function() {
|
||||
var d = new Date();
|
||||
// update time
|
||||
mainLayout.Time.label = Locale.time(d,1);
|
||||
// update timer
|
||||
mainLayout.Timer.label = getCurrentTimer();
|
||||
mainLayout.RestTime.label = getRestTime();
|
||||
mainLayout.render();
|
||||
// schedule a draw for the next minute
|
||||
if (timeoutDraw != -1) clearTimeout(timeoutDraw);
|
||||
timeoutDraw = setTimeout(function() {
|
||||
timeoutDraw = -1;
|
||||
drawMainFrame();
|
||||
}, 60000 - (Date.now() % 60000));
|
||||
}, 1000 - (Date.now() % 1000));
|
||||
}
|
||||
|
||||
function drawMain() {
|
||||
g.clear();
|
||||
mainLayout.forgetLazyState();
|
||||
drawMainFrame();
|
||||
// mainLayout.render();
|
||||
// E.showMessage('Presentor');
|
||||
g.clear();
|
||||
mainLayout.forgetLazyState();
|
||||
drawMainFrame();
|
||||
// mainLayout.render();
|
||||
// E.showMessage('Presentor');
|
||||
}
|
||||
|
||||
function doPPart(r) {
|
||||
pparti += r;
|
||||
if (pparti < 0) return;
|
||||
if (!settings.pparts || pparti >= settings.pparts.length) return;
|
||||
let ppart = settings.pparts[pparti];
|
||||
mainLayout.Subject.label = ppart.subject;
|
||||
mainLayout.Notes.label = ppart.notes;
|
||||
ptimers[pparti].tracked = getTime();
|
||||
drawMainFrame();
|
||||
}
|
||||
|
||||
NRF.setServices(undefined, { hid : SpecialReport });
|
||||
// TODO: figure out how to detect HID.
|
||||
NRF.on('HID', function() {
|
||||
HIDenabled = true;
|
||||
HIDenabled = true;
|
||||
});
|
||||
|
||||
function moveMouse(x,y,b,wheel,hwheel,callback) {
|
||||
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 (!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();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// function getSign(x) {
|
||||
|
|
@ -207,60 +257,60 @@ function moveMouse(x,y,b,wheel,hwheel,callback) {
|
|||
// }
|
||||
|
||||
function scroll(wheel,hwheel,callback) {
|
||||
moveMouse(0,0,0,wheel,hwheel,callback);
|
||||
moveMouse(0,0,0,wheel,hwheel,callback);
|
||||
}
|
||||
|
||||
// Single click a certain button (immidiatly release).
|
||||
function clickMouse(b, callback) {
|
||||
if (!HIDenabled) return;
|
||||
NRF.sendHIDReport([1,b,0,0,0,0,0,0], function() {
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function pressKey(keyCode, modifiers, callback) {
|
||||
if (!HIDenabled) return;
|
||||
if (!modifiers) modifiers = 0;
|
||||
NRF.sendHIDReport([2, modifiers,0,keyCode,0,0,0,0], function() {
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function handleAcc(acc) {
|
||||
let rRoll = acc.y * -50;
|
||||
let rPitch = acc.x * -100;
|
||||
if (mCal > 10) {
|
||||
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 {
|
||||
} else {
|
||||
//console.log("homeroll: " +homeRoll +"homepitch: " + homePitch);
|
||||
homeRoll = rRoll * 0.7 + homeRoll * 0.3;
|
||||
homePitch = rPitch * 0.7 + homePitch * 0.3;
|
||||
mCal = mCal + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Bangle.on('lock', function(on) {
|
||||
if (on && holding) {
|
||||
if (on && holding) {
|
||||
Bangle.setLocked(false);
|
||||
Bangle.setLCDPower(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function startHolding() {
|
||||
pressKey(kb.KEY.F10);
|
||||
holding = true;
|
||||
Bangle.buzz();
|
||||
E.showMessage('Holding');
|
||||
Bangle.on('accel', handleAcc);
|
||||
Bangle.setLCDPower(1);
|
||||
pressKey(kb.KEY.F10);
|
||||
holding = true;
|
||||
Bangle.buzz();
|
||||
E.showMessage('Holding');
|
||||
Bangle.on('accel', handleAcc);
|
||||
Bangle.setLCDPower(1);
|
||||
}
|
||||
function stopHolding() {
|
||||
clearTimeout(timeoutId);
|
||||
if (holding) {
|
||||
clearTimeout(timeoutId);
|
||||
if (holding) {
|
||||
pressKey(kb.KEY.F10);
|
||||
homePitch = 0;
|
||||
homeRoll = 0;
|
||||
|
|
@ -269,16 +319,16 @@ function stopHolding() {
|
|||
Bangle.removeListener('accel', handleAcc);
|
||||
Bangle.buzz();
|
||||
drawMain();
|
||||
} else {
|
||||
} else {
|
||||
timeoutId = setTimeout(drawMain, 1000);
|
||||
}
|
||||
clearTimeout(timeoutHolding);
|
||||
timeoutHolding = -1;
|
||||
}
|
||||
clearTimeout(timeoutHolding);
|
||||
timeoutHolding = -1;
|
||||
}
|
||||
|
||||
Bangle.on('drag', function(e) {
|
||||
if (cttl == 0) { cttl = getTime(); }
|
||||
if (trackPadMode) {
|
||||
if (cttl == 0) { cttl = getTime(); }
|
||||
if (trackPadMode) {
|
||||
if (lastx + lasty == 0) {
|
||||
lastx = e.x;
|
||||
lasty = e.y;
|
||||
|
|
@ -315,15 +365,15 @@ Bangle.on('drag', function(e) {
|
|||
lastx = 0;
|
||||
lasty = 0;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
if(!e.b){
|
||||
Bangle.buzz(100);
|
||||
if(lasty > 40){
|
||||
doPPart(1);
|
||||
E.showMessage('down');
|
||||
scroll(0,1);
|
||||
} else if(lasty < -40){
|
||||
E.showMessage(kb.KEY.A);
|
||||
pressKey(kb.KEY.A);
|
||||
doPPart(-1);
|
||||
E.showMessage('up');
|
||||
} else if(lastx > 40){
|
||||
E.showMessage('right');
|
||||
//kb.tap(kb.KEY.RIGHT, 0);
|
||||
|
|
@ -346,22 +396,23 @@ Bangle.on('drag', function(e) {
|
|||
timeoutHolding = setTimeout(startHolding, 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function onBtn() {
|
||||
if (trackPadMode) {
|
||||
if (trackPadMode) {
|
||||
trackPadMode = false;
|
||||
stopHolding();
|
||||
drawMain();
|
||||
} else {
|
||||
} else {
|
||||
clearToSend = true;
|
||||
trackPadMode = true;
|
||||
E.showMessage('Mouse');
|
||||
}
|
||||
Bangle.buzz();
|
||||
}
|
||||
Bangle.buzz();
|
||||
}
|
||||
setWatch(onBtn, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat: true});
|
||||
|
||||
loadSettings();
|
||||
drawMain();
|
||||
Loading…
Reference in New Issue