diff --git a/apps/cliclockJS2Enhanced/app.js b/apps/cliclockJS2Enhanced/app.js index 26ba1e7cc..64f550b60 100644 --- a/apps/cliclockJS2Enhanced/app.js +++ b/apps/cliclockJS2Enhanced/app.js @@ -7,6 +7,86 @@ var locale = require("locale"); var marginTop = 25; var flag = false; +var storage = require('Storage'); + +const settings = storage.readJSON('setting.json',1) || { HID: false }; + +var sendHid, next, prev, toggle, up, down, profile; +var lasty = 0; +var lastx = 0; + +if (settings.HID=="kbmedia") { + profile = 'Music'; + sendHid = function (code, cb) { + try { + NRF.sendHIDReport([1,code], () => { + NRF.sendHIDReport([1,0], () => { + if (cb) cb(); + }); + }); + } catch(e) { + print(e); + } + }; + next = function (cb) { sendHid(0x01, cb); }; + prev = function (cb) { sendHid(0x02, cb); }; + toggle = function (cb) { sendHid(0x10, cb); }; + up = function (cb) {sendHid(0x40, cb); }; + down = function (cb) { sendHid(0x80, cb); }; +} else { + E.showPrompt("Enable HID?",{title:"HID disabled"}).then(function(enable) { + if (enable) { + settings.HID = "kbmedia"; + require("Storage").write('setting.json', settings); + setTimeout(load, 1000, "hidmsicswipe.app.js"); + } else setTimeout(load, 1000); + }); +} + +if (next) { + setWatch(function(e) { + var len = e.time - e.lastTime; + E.showMessage('lock'); + setTimeout(drawApp, 1000); + Bangle.setLocked(true); + }, BTN1, { edge:"falling",repeat:true,debounce:50}); + Bangle.on('drag', function(e) { + if(!e.b){ + console.log(lasty); + console.log(lastx); + if(lasty > 40){ + writeLine('Down', 3); + // setTimeout(drawApp, 1000); + down(() => {}); + } + else if(lasty < -40){ + writeLine('Up', 3); + // setTimeout(drawApp, 1000); + up(() => {}); + } else if(lastx < -40){ + writeLine('Prev', 3); + // setTimeout(drawApp, 1000); + prev(() => {}); + } else if(lastx > 40){ + writeLine('Next', 3); + // setTimeout(drawApp, 1000); + next(() => {}); + } else if(lastx==0 && lasty==0){ + writeLine('play/pause', 3); + //setTimeout(drawApp, 1000); + toggle(() => {}); + } + lastx = 0; + lasty = 0; + } + else{ + lastx = lastx + e.dx; + lasty = lasty + e.dy; + } + }); + +} + let textCol = g.theme.dark ? "#0f0" : "#080"; @@ -23,7 +103,7 @@ function updateTime(){ if (!Bangle.isLCDOn()) return; let now = new Date(); writeLine(locale.time(now,1),0); - writeLine(flag?" ":"_",3); + writeLine(flag?" ":"_ ",3); flag = !flag; if(now.getMinutes() == 0) updateRest(now); @@ -49,7 +129,7 @@ function writeLine(str,line){ var y = marginTop+(line-1)*fontheight+fontheightTime; g.setFont("6x8",fontsize); g.setColor(textCol).setFontAlign(-1,-1); - g.clearRect(0,y,((str.length+1)*20),y+fontheight-1); + g.clearRect(0,y,((str.length+10)*40),y+fontheightTime-1); writeLineStart(line); g.drawString(str,25,y); }