0.03: Cope with identical duplicate buttons (fix #3260)

Set 'n' for buttons in Bangle.btHomeData correctly (avoids adding extra buttons on end of advertising)
pull/3308/head
Gordon Williams 2024-04-02 16:22:12 +01:00
parent e769b346b7
commit 21a17cc751
5 changed files with 42 additions and 27 deletions

View File

@ -1,2 +1,4 @@
0.01: New App!
0.02: Fix double-button press if you press the next button within 30s (#3243)
0.03: Cope with identical duplicate buttons (fix #3260)
Set 'n' for buttons in Bangle.btHomeData correctly (avoids adding extra buttons on end of advertising)

View File

@ -5,20 +5,26 @@ function showMenu() {
var settings = require("Storage").readJSON("bthome.json",1)||{};
if (!(settings.buttons instanceof Array))
settings.buttons = [];
var menu = { "": {title:"BTHome", back:load} };
var menu = [];
menu[""] = {title:"BTHome", back:load };
settings.buttons.forEach((button,idx) => {
var img = require("icons").getIcon(button.icon);
menu[/*LANG*/"\0"+img+" "+button.name] = function() {
menu.push({
title : /*LANG*/"\0"+img+" "+button.name,
onchange : function() {
Bangle.btHome([{type:"button_event",v:button.v,n:button.n}],{event:true});
E.showMenu();
E.showMessage("Sending Event");
Bangle.buzz();
setTimeout(showMenu, 500);
};
}
});
menu[/*LANG*/"Settings"] = function() {
});
menu.push({
title : /*LANG*/"Settings",
onchange : function() {
eval(require("Storage").read("bthome.settings.js"))(()=>showMenu());
};
}});
E.showMenu(menu);
}

View File

@ -13,7 +13,7 @@ Bangle.btHomeData = [];
if (settings.buttons instanceof Array) {
let n = settings.buttons.reduce((n,b)=>b.n>n?b.n:n,-1);
for (var i=0;i<=n;i++)
Bangle.btHomeData.push({type:"button_event",v:"none",n:n});
Bangle.btHomeData.push({type:"button_event",v:"none",n:i});
}
}

View File

@ -1,7 +1,7 @@
{ "id": "bthome",
"name": "BTHome",
"shortName":"BTHome",
"version":"0.02",
"version":"0.03",
"description": "Allow your Bangle to advertise with BTHome and send events to Home Assistant via Bluetooth",
"icon": "icon.png",
"type": "app",

View File

@ -67,24 +67,31 @@
}
function showMenu() {
var menu = { "": {title:"BTHome", back:back},
/*LANG*/"Show Battery" : {
var menu = [];
menu[""] = {title:"BTHome", back:back};
menu.push({
title : /*LANG*/"Show Battery",
value : !!settings.showBattery,
onchange : v=>{
settings.showBattery = v;
saveSettings();
}
}
};
});
settings.buttons.forEach((button,idx) => {
var img = require("icons").getIcon(button.icon);
menu[/*LANG*/"Button"+(img ? " \0"+img : (idx+1))] = function() {
menu.push({
title : /*LANG*/"Button"+(img ? " \0"+img : (idx+1)),
onchange : function() {
showButtonMenu(button, false);
};
}
});
menu[/*LANG*/"Add Button"] = function() {
});
menu.push({
title : /*LANG*/"Add Button",
onchange : function() {
showButtonMenu(undefined, true);
};
}
});
E.showMenu(menu);
}
showMenu();