Merge pull request #3422 from AnotherStranger/feature/gadgetbridge-sleep-as-android

Feature/gadgetbridge sleep as android
pull/3432/head
Rob Pilling 2024-05-21 21:54:43 +01:00
commit e8187b9c01
11 changed files with 114 additions and 7 deletions

View File

@ -0,0 +1 @@
0.01: Initial release.

View File

@ -0,0 +1,19 @@
# Accerleration Data Provider
This app provides acceleration data via Bluetooth, which can be used in Gadgetbridge.
## Usage
This boot code runs in the background and has no user interface.
Currently this app is used to enable Sleep as Android tracking for your Banglejs using Gadgetbridge.
**Please Note**: This app only listens to "accel" events and sends them to your phone using Bluetooth.
## Creator
[Another Stranger](https://github.com/anotherstranger)
## Aknowledgements
Special thanks to [José Rebelo](https://github.com/joserebelo) and [Rob Pilling](https://github.com/bobrippling)
for their Code Reviews and guidance.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

55
apps/accelsender/boot.js Normal file
View File

@ -0,0 +1,55 @@
(() => {
/**
* Sends a message to the gadgetbridge via Bluetooth.
* @param {Object} message - The message to be sent.
*/
function gbSend(message) {
try {
Bluetooth.println("");
Bluetooth.println(JSON.stringify(message));
} catch (error) {
console.error("Failed to send message via Bluetooth:", error);
}
}
var max_acceleration = { x: 0, y: 0, z: 0, diff: 0, td: 0, mag: 0 };
var hasData = false;
/**
* Updates the maximum acceleration if the current acceleration is greater.
* @param {Object} accel - The current acceleration object with x, y, z, and mag properties.
*/
function updateAcceleration(accel) {
hasData = true;
var current_max_raw = accel.mag;
var max_raw = max_acceleration.mag;
if (current_max_raw > max_raw) {
max_acceleration = accel;
}
}
/**
* Updates the acceleration data and sends it to gadgetbridge.
* Resets the maximum acceleration.
* Note: If your interval setting is too short, the last value gets sent again.
*/
function sendAccelerationData() {
var accel = hasData ? max_acceleration : Bangle.getAccel();
var update_data = {
t: "accel", accel: accel
};
gbSend(update_data);
max_acceleration = { x: 0, y: 0, z: 0, mag: 0, diff: 0, td: 0 };
hasData = false;
}
var config = require("Storage").readJSON("accelsender.json") || {};
if (config.enabled) { // Gadgetbridge needs to enable and disable tracking by writing {enabled: true} to "accelsender.json" and reloading
setInterval(sendAccelerationData, config.interval);
Bangle.on("accel", updateAcceleration); // Log all acceleration events
}
})();

1
apps/accelsender/boot.min.js vendored Normal file
View File

@ -0,0 +1 @@
(()=>{function e(a){c=!0;a.mag>b.mag&&(b=a)}function f(){var a={t:"accel",accel:c?b:Bangle.getAccel()};try{Bluetooth.println(""),Bluetooth.println(JSON.stringify(a))}catch(g){console.error("Failed to send message via Bluetooth:",g)}b={x:0,y:0,z:0,mag:0,diff:0,td:0};c=!1}var b={x:0,y:0,z:0,diff:0,td:0,mag:0},c=!1,d=require("Storage").readJSON("accelsender.json")||{};d.enabled&&(setInterval(f,d.interval),Bangle.on("accel",e))})();

View File

@ -0,0 +1,4 @@
{
"enabled": false,
"interval": 10000
}

View File

@ -0,0 +1,27 @@
{
"id": "accelsender",
"name": "Acceleration Data Provider",
"shortName": "Accel Data Provider",
"version": "0.01",
"description": "This app sends accelerometer and heart rate data from your Bangle.js via Bluetooth.",
"icon": "bluetooth.png",
"type": "bootloader",
"tags": "accel",
"supports": [
"BANGLEJS",
"BANGLEJS2"
],
"readme": "README.md",
"storage": [
{
"name": "accelsender.boot.js",
"url": "boot.min.js"
}
],
"data": [
{
"name": "accelsender.json",
"url": "config.json"
}
]
}

View File

@ -34,3 +34,4 @@
0.32: Added support for loyalty cards from gadgetbridge 0.32: Added support for loyalty cards from gadgetbridge
0.33: Fix alarms created in Gadgetbridge not repeating 0.33: Fix alarms created in Gadgetbridge not repeating
0.34: Implement API for activity tracks fetching (Recorder app logs). 0.34: Implement API for activity tracks fetching (Recorder app logs).
0.35: Implement API to enable/disable acceleration data tracking.

View File

@ -1,3 +1,4 @@
/* global GB */
(function() { (function() {
function gbSend(message) { function gbSend(message) {
Bluetooth.println(""); Bluetooth.println("");
@ -292,6 +293,10 @@
// we receive all, just override what we have // we receive all, just override what we have
if (Array.isArray(event.d)) if (Array.isArray(event.d))
require("Storage").writeJSON("android.cards.json", event.d); require("Storage").writeJSON("android.cards.json", event.d);
},
"accelsender": function () {
require("Storage").writeJSON("accelsender.json", {enabled: event.enable, interval: event.interval});
load();
} }
}; };
var h = HANDLERS[event.t]; var h = HANDLERS[event.t];

View File

@ -2,7 +2,7 @@
"id": "android", "id": "android",
"name": "Android Integration", "name": "Android Integration",
"shortName": "Android", "shortName": "Android",
"version": "0.34", "version": "0.35",
"description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.", "description": "Display notifications/music/etc sent from the Gadgetbridge app on Android. This replaces the old 'Gadgetbridge' Bangle.js widget.",
"icon": "app.png", "icon": "app.png",
"tags": "tool,system,messages,notifications,gadgetbridge", "tags": "tool,system,messages,notifications,gadgetbridge",

View File

@ -1251,12 +1251,6 @@ module.exports = {
"no-undef" "no-undef"
] ]
}, },
"apps/android/boot.js": {
"hash": "a537b3f7772e11f44615d80d6c6bacfa69c1854c6da3c01666863bcae8a18059",
"rules": [
"no-undef"
]
},
"apps/altimeter/app.js": { "apps/altimeter/app.js": {
"hash": "054ac328db51034aa339f1d10b4d264badd49438b95f08bc6fbfb90bd88c6ae0", "hash": "054ac328db51034aa339f1d10b4d264badd49438b95f08bc6fbfb90bd88c6ae0",
"rules": [ "rules": [