mirror of https://github.com/espruino/BangleApps
refactor: rename sleepasandroid to accelsender
parent
8348aabc15
commit
ce42dfb3e9
|
@ -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.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
@ -12,13 +12,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
var max_acceleration = {x: 0, y: 0, z: 0, mag: 0};
|
||||
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;
|
||||
|
||||
|
@ -28,27 +30,25 @@
|
|||
}
|
||||
|
||||
/**
|
||||
* Updates the Sleep as Android data and sends it to gadgetbridge.
|
||||
* Updates the acceleration data and sends it to gadgetbridge.
|
||||
* Resets the maximum acceleration.
|
||||
* Acceleration values in g are converted to m/s^2, as expected by Sleep as Android.
|
||||
* Note: If your interval setting is too short, the last value gets sent again.
|
||||
*/
|
||||
function sendSleepAsAndroidData() {
|
||||
var accel = Bangle.getAccel();
|
||||
var health = Bangle.getHealthStatus();
|
||||
function sendAccelerationData() {
|
||||
accel = hasData ? max_acceleration : Banlejs.getAccel();
|
||||
|
||||
var update_data = {
|
||||
t: "sleep_as_android", accel: {
|
||||
x: accel.x * 9.80665, y: accel.y * 9.80665, z: accel.z * 9.80665
|
||||
}, bpm: health.bpm
|
||||
t: "accel", accel: accel
|
||||
};
|
||||
gbSend(update_data);
|
||||
|
||||
max_acceleration = {x: 0, y: 0, z: 0, mag: 0};
|
||||
max_acceleration = { x: 0, y: 0, z: 0, mag: 0, diff: 0, td: 0 };
|
||||
hasData = false;
|
||||
}
|
||||
|
||||
var config = require("Storage").readJSON("sleepasandroid.json") || {};
|
||||
if (config.enabled) { // Gadgetbridge needs to enable and disable tracking by writing {enabled: true} to "sleepasandroid.json" and reloading
|
||||
setInterval(sendSleepAsAndroidData, 10000); // Sleep as Android wants a 10-second maximum
|
||||
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
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
(()=>{function a(A){try {Bluetooth.println('');Bluetooth.println(JSON.stringify(A))} catch (_) {console.error('Failed to send message via Bluetooth:',_)}}var b={x:0,y:0,z:0,diff:0,td:0,mag:0},c=!1,f=require('Storage').readJSON('sleepasandroid.json')||{};function d(B){c=!0;var C=B.mag,_c=b.mag;C>_c&&(b=B)}function e(){accel=c?b:Banlejs.getAccel();a({t:'accel',accel:accel});b={x:0,y:0,z:0,mag:0,diff:0,td:0};c=!1}f.enabled&&(setInterval(e,f.interval),Bangle.on('accel',d))})();
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"enabled": false,
|
||||
"interval": 10000
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -293,8 +293,8 @@
|
|||
if (Array.isArray(event.d))
|
||||
require("Storage").writeJSON("android.cards.json", event.d);
|
||||
},
|
||||
"sleepasandroid": function () {
|
||||
require("Storage").writeJSON("sleepasandroid.json", {enabled: event.enable});
|
||||
"accelsender": function () {
|
||||
require("Storage").writeJSON("accelsender.json", {enabled: event.enable, interval: event.interval});
|
||||
load();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
# Sleep as Android Integration
|
||||
|
||||
This app provides support for Sleep as Android using Gadgetbridge.
|
||||
|
||||
## Usage
|
||||
|
||||
This boot code runs in the background and has no user interface.
|
||||
For this to work you have to enable Sleep as Android support in Gadgetbridge and
|
||||
select your Banglejs device.
|
||||
|
||||
**Please Note**: This app does not activate the HRM sensor. It only listens to HRM events.
|
||||
You may want to adjust the HRM sampling rate in the Health APP. I recommend at least one sample
|
||||
every 10 minutes.
|
||||
|
||||
## 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.
|
|
@ -1 +0,0 @@
|
|||
(()=>{function a(A){try {Bluetooth.println('');Bluetooth.println(JSON.stringify(A))} catch (_) {console.error('Failed to send message via Bluetooth:',_)}}var b={x:0,y:0,z:0,mag:0},e=require('Storage').readJSON('sleepasandroid.json')||{};function c(B){var C=B.mag,_c=b.mag;C>_c&&(b=B)}function d(){var _a=Bangle.getAccel(),_b=Bangle.getHealthStatus();a({t:'sleep_as_android',accel:{x:_a.x*9.80665,y:_a.y*9.80665,z:_a.z*9.80665},bpm:_b.bpm});b={x:0,y:0,z:0,mag:0}}e.enabled&&(setInterval(d,10000),Bangle.on('accel',c))})();
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"enabled": false
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"id": "sleepasandroid",
|
||||
"name": "Sleep as Android data provider",
|
||||
"shortName": "BLE Sleep as Android",
|
||||
"version": "0.01",
|
||||
"description": "This app sends accelerometer and heart rate data from your Bangle.js to the Sleep as Android app via Bluetooth (Gadgetbridge required), enabling advanced sleep tracking features.",
|
||||
"icon": "bluetooth.png",
|
||||
"type": "bootloader",
|
||||
"tags": "hrm,health,ble,bluetooth",
|
||||
"supports": [
|
||||
"BANGLEJS",
|
||||
"BANGLEJS2"
|
||||
],
|
||||
"readme": "README.md",
|
||||
"storage": [
|
||||
{
|
||||
"name": "sleepasandroid.boot.js",
|
||||
"url": "boot.min.js"
|
||||
}
|
||||
],
|
||||
"data": [
|
||||
{
|
||||
"name": "sleepasandroid.json",
|
||||
"url": "config.json"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue