Working on interface functionality

master
7kasper 2022-01-02 20:13:56 +01:00
parent f6efbf82e9
commit 602679c6bc
No known key found for this signature in database
GPG Key ID: 4AD2FD3E13BFB86A
1 changed files with 332 additions and 281 deletions

View File

@ -124,12 +124,12 @@ let mainLayout = new Layout( {
}, { }, {
type: 'txt', type: 'txt',
font: '15%', font: '15%',
label: 'Subject', label: 'Presenting',
id: 'Subject' id: 'Subject'
}, { }, {
type: 'txt', type: 'txt',
font: '6x8', font: '6x8',
label: 'Notes...', label: 'Swipe down to start the time.',
id: 'Notes', id: 'Notes',
col: '#ff0', col: '#ff0',
fillx: 1, fillx: 1,
@ -140,42 +140,81 @@ let mainLayout = new Layout( {
] ]
}, {lazy:true}); }, {lazy:true});
let settings = require("Storage").readJSON('presentor.json'); let settings = {pparts: [], sversion: 0};
let HIDenabled = false; let HIDenabled = false;
// Application variables // Application variables
let pparti = 0; let pparti = -1;
let lastx = 0; let lastx = 0;
let lasty = 0; let lasty = 0;
let timeoutId = -1;
// Mouse states
let holding = false; let holding = false;
let trackPadMode = false;
// Timeout IDs.
let timeoutId = -1;
let timeoutHolding = -1; let timeoutHolding = -1;
let timeoutDraw = -1; let timeoutDraw = -1;
let timeoutDrawTimer = -1;
let homeRoll = 0; let homeRoll = 0;
let homePitch = 0; let homePitch = 0;
let trackPadMode = false;
let mCal = 0; let mCal = 0;
let clearToSend = true;
let mttl = 0; let mttl = 0;
let cttl = 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() { function drawMainFrame() {
var d = new Date(); var d = new Date();
// update time // update time
mainLayout.Time.label = Locale.time(d,1); mainLayout.Time.label = Locale.time(d,1);
// update timer
mainLayout.Timer.label = getCurrentTimer();
mainLayout.RestTime.label = getRestTime();
mainLayout.render(); mainLayout.render();
// schedule a draw for the next minute // schedule a draw for the next minute
if (timeoutDraw != -1) clearTimeout(timeoutDraw); if (timeoutDraw != -1) clearTimeout(timeoutDraw);
timeoutDraw = setTimeout(function() { timeoutDraw = setTimeout(function() {
timeoutDraw = -1; timeoutDraw = -1;
drawMainFrame(); drawMainFrame();
}, 60000 - (Date.now() % 60000)); }, 1000 - (Date.now() % 1000));
} }
function drawMain() { function drawMain() {
@ -186,6 +225,17 @@ function drawMain() {
// E.showMessage('Presentor'); // 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 }); NRF.setServices(undefined, { hid : SpecialReport });
// TODO: figure out how to detect HID. // TODO: figure out how to detect HID.
NRF.on('HID', function() { NRF.on('HID', function() {
@ -319,11 +369,11 @@ Bangle.on('drag', function(e) {
if(!e.b){ if(!e.b){
Bangle.buzz(100); Bangle.buzz(100);
if(lasty > 40){ if(lasty > 40){
doPPart(1);
E.showMessage('down'); E.showMessage('down');
scroll(0,1);
} else if(lasty < -40){ } else if(lasty < -40){
E.showMessage(kb.KEY.A); doPPart(-1);
pressKey(kb.KEY.A); E.showMessage('up');
} else if(lastx > 40){ } else if(lastx > 40){
E.showMessage('right'); E.showMessage('right');
//kb.tap(kb.KEY.RIGHT, 0); //kb.tap(kb.KEY.RIGHT, 0);
@ -364,4 +414,5 @@ function onBtn() {
} }
setWatch(onBtn, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat: true}); setWatch(onBtn, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat: true});
loadSettings();
drawMain(); drawMain();