mirror of https://github.com/espruino/BangleApps
commit
9625bc8214
|
@ -0,0 +1 @@
|
|||
0.01: New App!
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"id": "widbtstates",
|
||||
"name": "Bluetooth States",
|
||||
"version": "0.01",
|
||||
"description": "If active, shows a white bluetooth icon, if connected, a blue one (nothing if sleeping)",
|
||||
"icon": "widget.png",
|
||||
"type": "widget",
|
||||
"tags": "widget,bluetooth,clkinfo",
|
||||
"provides_widgets" : ["bluetooth"],
|
||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||
"storage": [
|
||||
{"name":"widbtstates.wid.js","url":"widget.js"}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
"use strict";
|
||||
(function () {
|
||||
"ram";
|
||||
var _a;
|
||||
var state = (function () {
|
||||
var status = NRF.getSecurityStatus();
|
||||
if (status.connected)
|
||||
return 2;
|
||||
if (status.advertising)
|
||||
return 1;
|
||||
return 0;
|
||||
})();
|
||||
var width = function () { return state > 0 ? 15 : 0; };
|
||||
var update = function (newState) {
|
||||
state = newState;
|
||||
WIDGETS["bluetooth"].width = width();
|
||||
setTimeout(Bangle.drawWidgets, 50);
|
||||
};
|
||||
var colours = (_a = {},
|
||||
_a[1] = {
|
||||
false: "#fff",
|
||||
true: "#fff",
|
||||
},
|
||||
_a[2] = {
|
||||
false: "#0ff",
|
||||
true: "#00f",
|
||||
},
|
||||
_a);
|
||||
WIDGETS["bluetooth"] = {
|
||||
area: "tl",
|
||||
sortorder: -1,
|
||||
draw: function () {
|
||||
if (state == 0)
|
||||
return;
|
||||
g.reset();
|
||||
g.setColor(colours[state]["".concat(g.theme.dark)]);
|
||||
g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), this.x + 2, this.y + 2);
|
||||
},
|
||||
width: width(),
|
||||
};
|
||||
NRF.on("connect", update.bind(null, 2));
|
||||
NRF.on("disconnect", update.bind(null, 1));
|
||||
var origWake = NRF.wake;
|
||||
var origSleep = NRF.sleep;
|
||||
NRF.wake = function () {
|
||||
update(1);
|
||||
return origWake.apply(this, arguments);
|
||||
};
|
||||
NRF.sleep = function () {
|
||||
update(0);
|
||||
return origSleep.apply(this, arguments);
|
||||
};
|
||||
})();
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,77 @@
|
|||
(() => {
|
||||
"ram";
|
||||
|
||||
const enum State {
|
||||
Asleep,
|
||||
Active,
|
||||
Connected
|
||||
}
|
||||
|
||||
let state: State = (() => {
|
||||
const status = NRF.getSecurityStatus();
|
||||
|
||||
if (status.connected) return State.Connected;
|
||||
if (status.advertising) return State.Active;
|
||||
return State.Asleep;
|
||||
})();
|
||||
|
||||
const width = () => state > State.Asleep ? 15 : 0;
|
||||
|
||||
const update = (newState: State) => {
|
||||
state = newState;
|
||||
WIDGETS["bluetooth"]!.width = width();
|
||||
setTimeout(Bangle.drawWidgets, 50); // no need for .bind()
|
||||
};
|
||||
|
||||
type DarkTheme = `${boolean}`;
|
||||
const colours: {
|
||||
[key in State.Active | State.Connected]: {
|
||||
[key in DarkTheme]: ColorResolvable
|
||||
}
|
||||
} = {
|
||||
[State.Active]: {
|
||||
false: "#fff",
|
||||
true: "#fff",
|
||||
},
|
||||
[State.Connected]: {
|
||||
false: "#0ff",
|
||||
true: "#00f",
|
||||
},
|
||||
};
|
||||
|
||||
WIDGETS["bluetooth"] = {
|
||||
area: "tl",
|
||||
sortorder: -1,
|
||||
draw: function() {
|
||||
if (state == State.Asleep)
|
||||
return;
|
||||
|
||||
g.reset();
|
||||
|
||||
g.setColor(colours[state][`${g.theme.dark}`]);
|
||||
|
||||
g.drawImage(
|
||||
atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="),
|
||||
this.x! + 2,
|
||||
this.y! + 2
|
||||
);
|
||||
},
|
||||
width: width(),
|
||||
};
|
||||
|
||||
NRF.on("connect", update.bind(null, State.Connected));
|
||||
NRF.on("disconnect", update.bind(null, State.Active));
|
||||
|
||||
const origWake = NRF.wake;
|
||||
const origSleep = NRF.sleep;
|
||||
|
||||
NRF.wake = function() {
|
||||
update(State.Active);
|
||||
return origWake.apply(this, arguments);
|
||||
};
|
||||
|
||||
NRF.sleep = function() {
|
||||
update(State.Asleep);
|
||||
return origSleep.apply(this, arguments);
|
||||
};
|
||||
})();
|
|
@ -183,6 +183,23 @@ type NRFFilters = {
|
|||
manufacturerData?: object;
|
||||
};
|
||||
|
||||
type NRFSecurityStatus = {
|
||||
advertising: boolean,
|
||||
} & (
|
||||
{
|
||||
connected: true,
|
||||
encrypted: boolean,
|
||||
mitm_protected: boolean,
|
||||
bonded: boolean,
|
||||
connected_addr?: string,
|
||||
} | {
|
||||
connected: false,
|
||||
encrypted: false,
|
||||
mitm_protected: false,
|
||||
bonded: false,
|
||||
}
|
||||
);
|
||||
|
||||
type ImageObject = {
|
||||
width: number;
|
||||
height: number;
|
||||
|
@ -721,7 +738,7 @@ declare class NRF {
|
|||
* @returns {any} An object
|
||||
* @url http://www.espruino.com/Reference#l_NRF_getSecurityStatus
|
||||
*/
|
||||
static getSecurityStatus(): any;
|
||||
static getSecurityStatus(): NRFSecurityStatus;
|
||||
|
||||
/**
|
||||
* @returns {any} An object
|
||||
|
@ -1898,6 +1915,7 @@ declare class NRF {
|
|||
* encrypted // Communication on this link is encrypted.
|
||||
* mitm_protected // The encrypted communication is also protected against man-in-the-middle attacks.
|
||||
* bonded // The peer is bonded with us
|
||||
* advertising // Are we currently advertising?
|
||||
* connected_addr // If connected=true, the MAC address of the currently connected device
|
||||
* }
|
||||
* ```
|
||||
|
@ -1906,7 +1924,7 @@ declare class NRF {
|
|||
* @returns {any} An object
|
||||
* @url http://www.espruino.com/Reference#l_NRF_getSecurityStatus
|
||||
*/
|
||||
static getSecurityStatus(): any;
|
||||
static getSecurityStatus(): NRFSecurityStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -4553,7 +4571,7 @@ declare class BluetoothRemoteGATTServer {
|
|||
* @returns {any} An object
|
||||
* @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getSecurityStatus
|
||||
*/
|
||||
getSecurityStatus(): any;
|
||||
getSecurityStatus(): NRFSecurityStatus;
|
||||
|
||||
/**
|
||||
* See `NRF.connect` for usage examples.
|
||||
|
|
Loading…
Reference in New Issue