gbmusic: Simplify touch controls setting

Firmware 2v10 will disable touch/swipe while the LCD is off anyway.
(Next commit will just remove this setting altogether, but just in case)
pull/741/head
Richard de Boer 2021-05-13 15:14:07 +02:00
parent da8dc6cd57
commit 195f5928f6
4 changed files with 20 additions and 18 deletions

View File

@ -2,4 +2,4 @@
0.02: Increase text brightness, improve controls, (try to) reduce memory usage
0.03: Only auto-start if active app is a clock, auto close after 1 hour of inactivity
0.04: Setting to disable touch controls, minor bugfix
0.05: Reduce fadeout flicker
0.05: Simplify touch controls setting, reduce fadeout flicker

View File

@ -22,7 +22,7 @@ You can change these under `Settings`->`App/Widget Settings`->`Music Controls`.
Automatically load the app when you play music and close when the music stops.
(If the app opened automatically, it closes after music has been paused for 5 minutes.)
**Touch**:
**Touch controls**:
Enable touch controls?
## Controls

View File

@ -13,9 +13,9 @@ let info = {
};
const POUT = 300000; // auto close timeout when paused: 5 minutes (in ms)
const IOUT = 3600000; // auto close timeout for inactivity: 1 hour (in ms)
// Touch controls? 0: off, 1: when LCD on, 2: always
// Touch controls?
let s = require("Storage").readJSON("gbmusic.json", 1) || {};
const TCTL = ("touch" in s) ? (s.touch|0)%3 : 1;
const TCTL = ("touch" in s) ? !!s.touch : true; // previous versions used an int for this setting
delete s;
///////////////////////
@ -539,7 +539,7 @@ function togglePlay() {
function startTouchWatches() {
if (!TCTL) {return;}
Bangle.on("touch", side => {
if (TCTL<2 && !Bangle.isLCDOn()) {return;}
if (!Bangle.isLCDOn()) {return;} // for <2v10 firmware
switch(side) {
case 1:
sendCommand(stat==="play" ? "pause" : "previous");
@ -552,7 +552,7 @@ function startTouchWatches() {
}
});
Bangle.on("swipe", dir => {
if (TCTL<2 && !Bangle.isLCDOn()) {return;}
if (!Bangle.isLCDOn()) {return;} // for <2v10 firmware
sendCommand(dir===1 ? "previous" : "next");
});
}

View File

@ -5,12 +5,11 @@
const SETTINGS_FILE = "gbmusic.json",
storage = require("Storage"),
translate = require("locale").translate;
const TOUCH_OPTIONS = ["Off", "When LCD on", "Always"];
// initialize with default settings...
let s = {
autoStart: true,
touch: 1,
touch: true,
};
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
@ -19,24 +18,27 @@
s[key] = saved[key];
}
function save(key, value) {
s[key] = value;
storage.write(SETTINGS_FILE, s);
function save(key) {
return function (value) {
s[key] = value;
storage.write(SETTINGS_FILE, s);
}
}
const yesNo = (v) => translate(v ? "Yes" : "No");
let menu = {
"": {"title": "Music Control"},
};
menu[translate("< Back")] = back;
menu[translate("Auto start")] = {
value: s.autoStart,
format: v => translate(v ? "Yes" : "No"),
onchange: v => {save("autoStart", v);},
value: !!s.autoStart,
format: yesNo,
onchange: save("autoStart"),
};
menu[translate("Touch")] = {
value: s.touch|0,
format: v => translate(TOUCH_OPTIONS[(v+3)%3]),
onchange: v => {save("touch", (v+3)%3);},
menu[translate("Touch controls")] = {
value: !!s.touch,
format: yesNo,
onchange: save("touch"),
};
E.showMenu(menu);