Auto generate button number

no 0 button number
pull/3490/head
pinq- 2024-07-03 21:16:25 +03:00
parent 31c08d149f
commit 66bbdd1242
3 changed files with 18 additions and 7 deletions

View File

@ -4,3 +4,4 @@
Set 'n' for buttons in Bangle.btHomeData correctly (avoids adding extra buttons on end of advertising) Set 'n' for buttons in Bangle.btHomeData correctly (avoids adding extra buttons on end of advertising)
0.04: Fix duplicate button on edit->save 0.04: Fix duplicate button on edit->save
0.05: Use the bleAdvert module 0.05: Use the bleAdvert module
0.06: button number can't be 0. Now generates number automatically

View File

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

View File

@ -11,10 +11,24 @@
require("Storage").writeJSON("bthome.json",settings) require("Storage").writeJSON("bthome.json",settings)
} }
function getNewIdNumber(){
var id_start = 1;
var select = false;
while(!select){
select = true;
settings.buttons.forEach((button, idx) => {
if (id_start == button.n){
id_start++;
select = false;
}
});
}
return id_start;
}
function showButtonMenu(button, isNew) { function showButtonMenu(button, isNew) {
var isNew = false;
if (!button) { if (!button) {
button = {name:"home", icon:"home", n:0, v:"press"}; button = {name:"home", icon:"home", n:getNewIdNumber(), v:"press"};
isNew = true; isNew = true;
} }
var actions = ["press","double_press","triple_press","long_press","long_double_press","long_triple_press"]; var actions = ["press","double_press","triple_press","long_press","long_double_press","long_triple_press"];
@ -51,10 +65,6 @@
format : v => actions[v], format : v => actions[v],
onchange : v => button.v=actions[v] onchange : v => button.v=actions[v]
}, },
/*LANG*/"Button #" : {
value : button.n, min:0, max:3,
onchange : v => button.n=v
},
/*LANG*/"Save" : () => { /*LANG*/"Save" : () => {
if (isNew) settings.buttons.push(button); if (isNew) settings.buttons.push(button);
saveSettings(); saveSettings();