Skip to content

Commit 79e19cf

Browse files
authored
Merge branch 'espruino:master' into master
2 parents 326b97d + 20b602c commit 79e19cf

52 files changed

Lines changed: 1883 additions & 531 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/ateatimer/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
0.03: Flash time in green when starting the timer
44
0.04: Buzz when starting and resetting timer. Fix initial draw when timer is
55
running.
6+
0.05: Make fastload-able.

apps/ateatimer/app.js

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
{
12
// Tea Timer Application for Bangle.js 2 using sched library
23

4+
"Bangle.loadWidgets()" // HACK: Trick launch_utils that we load widgets so we get a pass to be fastloaded into. We don't mind widgets here but have no use for them either.
5+
if (global.WIDGETS) require("widget_utils").hide();
6+
37
const APP_RECT = Bangle.appRect;
4-
const CENTER_Y = APP_RECT.y+APP_RECT.w/2;
5-
const CENTER_X = APP_RECT.x+APP_RECT.h/2;
8+
const CENTER_Y = APP_RECT.y+APP_RECT.h/2;
9+
const CENTER_X = APP_RECT.x+APP_RECT.w/2;
610

711
let timerDuration = (() => {
812
let file = require("Storage").open("ateatimer.data", "r");
@@ -12,12 +16,12 @@ let timerDuration = (() => {
1216
let timeRemaining = timerDuration;
1317
let timerRunning = false;
1418

15-
function saveDefaultDuration() {
19+
const saveDefaultDuration = function() {
1620
let file = require("Storage").open("ateatimer.data", "w");
1721
file.write(timerDuration.toString());
1822
}
1923

20-
function drawTime() {
24+
const drawTime = function() {
2125
const TIME_RECT = {x:APP_RECT.x, y:CENTER_Y-20, w:APP_RECT.w, h:40}
2226
g.clearRect(TIME_RECT);
2327
g.setFont("Vector", 40);
@@ -33,37 +37,39 @@ function drawTime() {
3337
g.flip();
3438
}
3539

36-
function drawButtons() {
40+
const drawButtons = function() {
41+
42+
const ADJUST_FOR_WIDGETS_Y = APP_RECT.y == 0 ? 0 : APP_RECT.y/4;
3743
// Draw Increase button (triangle pointing up)
3844
g.fillPoly([
39-
CENTER_X, CENTER_Y - 80, // Top vertex
40-
CENTER_X - 20, CENTER_Y - 60, // Bottom-left vertex
41-
CENTER_X + 20, CENTER_Y - 60 // Bottom-right vertex
45+
CENTER_X, CENTER_Y - 80 + ADJUST_FOR_WIDGETS_Y, // Top vertex
46+
CENTER_X - 20, CENTER_Y - 60 + ADJUST_FOR_WIDGETS_Y, // Bottom-left vertex
47+
CENTER_X + 20, CENTER_Y - 60 + ADJUST_FOR_WIDGETS_Y // Bottom-right vertex
4248
]);
4349

4450
// Draw Decrease button (triangle pointing down)
4551
g.fillPoly([
46-
CENTER_X, CENTER_Y + 80, // Bottom vertex
47-
CENTER_X - 20, CENTER_Y + 60, // Top-left vertex
48-
CENTER_X + 20, CENTER_Y + 60 // Top-right vertex
52+
CENTER_X, CENTER_Y + 80 - ADJUST_FOR_WIDGETS_Y, // Bottom vertex
53+
CENTER_X - 20, CENTER_Y + 60 - ADJUST_FOR_WIDGETS_Y, // Top-left vertex
54+
CENTER_X + 20, CENTER_Y + 60 - ADJUST_FOR_WIDGETS_Y // Top-right vertex
4955
]);
5056

5157
g.flip();
5258
}
5359

54-
function drawInit() {
60+
const drawInit = function() {
5561
g.clear(true);
5662
drawButtons();
5763
drawTime();
5864
}
5965

6066
let updateIntervalID;
6167
let clearUpdateInterval = ()=>{
62-
clearInterval(updateIntervalID);
68+
if (updateIntervalID) clearInterval(updateIntervalID);
6369
updateIntervalID = undefined;
6470
}
6571

66-
function startTimer() {
72+
const startTimer = function() {
6773
if (timerRunning) return;
6874
if (timeRemaining == 0) return;
6975
timerRunning = true;
@@ -85,7 +91,7 @@ function startTimer() {
8591
updateIntervalID = setInterval(updateDisplay, 1000);
8692
}
8793

88-
function scheduleTimer() {
94+
const scheduleTimer = function() {
8995
// Schedule a new timer using the sched library
9096
require("sched").setAlarm("ateatimer", {
9197
msg: "Tea is ready!",
@@ -97,7 +103,7 @@ function scheduleTimer() {
97103
require("sched").reload();
98104
}
99105

100-
function resetTimer() {
106+
const resetTimer = function() {
101107
// Cancel the existing timer
102108
require("sched").setAlarm("ateatimer", undefined);
103109
require("sched").reload();
@@ -109,7 +115,7 @@ function resetTimer() {
109115
Bangle.buzz(75);
110116
}
111117

112-
function adjustTime(amount) {
118+
let adjustTime = function(amount) {
113119
if (-amount > timeRemaining) {
114120
// Return if result will be negative
115121
return;
@@ -122,7 +128,7 @@ function adjustTime(amount) {
122128
if (alarm) {
123129
// Cancel the current alarm
124130
require("sched").setAlarm("ateatimer", undefined);
125-
131+
126132
// Set a new alarm with the updated time
127133
scheduleTimer();
128134
}
@@ -131,8 +137,7 @@ function adjustTime(amount) {
131137
drawTime();
132138
}
133139

134-
function handleTouch(x, y) {
135-
140+
let handleTouch = (_, xy)=>{((_, y)=>{
136141
if (y < CENTER_Y - 40) {
137142
// Increase button area
138143
adjustTime(60);
@@ -145,15 +150,15 @@ function handleTouch(x, y) {
145150
startTimer();
146151
}
147152
}
148-
}
153+
})(_, xy.y)}
149154

150155
let updateTimeRemaining = ()=>{
151156
let alarm = require("sched").getAlarm("ateatimer");
152157
timeRemaining = Math.floor(require("sched").getTimeToAlarm(alarm) / 1000);
153158
}
154159

155160
// Function to update the display every second
156-
function updateDisplay() {
161+
const updateDisplay = function() {
157162
if (timerRunning) {
158163
updateTimeRemaining();
159164
drawTime();
@@ -166,7 +171,7 @@ function updateDisplay() {
166171
}
167172

168173
// Handle physical button press for resetting timer
169-
setWatch(() => {
174+
const BTN_HANDLER = setWatch(() => {
170175
if (timerRunning) {
171176
resetTimer();
172177
} else {
@@ -175,9 +180,7 @@ setWatch(() => {
175180
}, BTN1, { repeat: true, edge: "falling" });
176181

177182
// Handle touch
178-
Bangle.on("touch", (zone, xy) => {
179-
handleTouch(xy.x, xy.y, false);
180-
});
183+
Bangle.on("touch", handleTouch);
181184

182185
let isRunning = require("sched").getAlarm("ateatimer");
183186
if (isRunning) {
@@ -188,3 +191,12 @@ if (isRunning) {
188191
}
189192
// Draw the initial timer display
190193
drawInit();
194+
global.BACK = Bangle.load; // Compatibility with backswipe app.
195+
Bangle.uiRemove = ()=>{ // Make it possible to fastload out of the app.
196+
Bangle.removeListener("touch", handleTouch);
197+
if (BTN_HANDLER) clearWatch(BTN_HANDLER);
198+
clearUpdateInterval();
199+
delete global.BACK;
200+
if (global.WIDGETS) require("widget_utils").show();
201+
}
202+
}

apps/ateatimer/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "A Tea Timer",
33
"author": "vovcia-clug",
44
"icon": "app.png",
5-
"version":"0.04",
5+
"version":"0.05",
66
"description": "Simple app for setting timers for tea. Touch up and down to change time, and time or button to start counting. When timer is running, button will stop timer and reset counter to last used value.",
77
"tags": "timer",
88
"supports": ["BANGLEJS2"],

apps/bluewatch/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
0.01: New App!
22
0.02: Use new device handshake method for more reliable connections (Requires BlueWatch on iOS version 1.1)
33
0.03: Fix data intervals firing randomly, pairing issues, increased time between battery pushing, and queued data sending (Requires BlueWatch on iOS version 1.2)
4+
0.04: Add sending of calories (if installed), fix myLocation not saving if file doesn't exist, and emit BlueWatchMessage event upon message received

apps/bluewatch/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Bangle.js 1 support coming soon!
1414
- Automatic weather updates without any additional setup
1515
- Find my phone support
1616
- Use of the phone's GPS for Bangle.js GPS.
17+
- Sending and storing of heart rate, steps, battery, and active/resting calories (if installed) to Apple Health/BlueWatch app
18+
19+
Additionally, the iOS app provides shortcuts actions to create your own workflows and automations. By hooking into when BlueWatch receives a message (see developer info), you can send messages through shortcuts that your watch receives and handles. This allows you to create complex workflows such as:
20+
- When you reach home, alert your watch to change the clock to an inexact clock face to relax
21+
- When CarPlay is connected to your car, send a message to your watch to turn on quiet mode for driving
22+
- When you receive a message from a specific person, vibrate continuously so you never miss the message
1723

1824
**Note:** This app still uses the `iOS Integration app` to handle pushing notifications from the phone to the watch.
1925

@@ -36,6 +42,13 @@ To send a string or a JSON, you can use the following:
3642
require("bluewatch").sendData("string or object", true);
3743
```
3844
with an optional second parameter `forceSend`. When true, it sends even if BlueWatch is not connected at the time. By default it doesn't send info unless the device handshake is completed and BlueWatch is connected
45+
46+
In the iOS app version 1.4, you can also use the Shortcuts app to send custom messages to the watch, as well as checking connection, and pushing weather/location via shortcuts. In the Bangle app version v0.04, the watch will emit the `BlueWatchMessage` event when a new message is received, allowing you to create your own workflows and automations using shortcuts and a receiving script:
47+
```
48+
Bangle.on("BlueWatchMessage", (message) => {
49+
// your receiving code here
50+
});
51+
```
3952
## Author and Creator of the iOS App
4053
RKBoss6
4154

apps/bluewatch/boot.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ function setMyLocation(d) {
9999
numFields.forEach((field) => {
100100
if (locationJson[field] != null) locationJson[field] = +locationJson[field];
101101
});
102-
102+
let myLocationSaved = require("Storage").readJSON("mylocation.json", true) || {}
103+
104+
103105
//load mylocation file
104106
let myLocationJson = Object.assign(
105107
{
@@ -110,12 +112,14 @@ function setMyLocation(d) {
110112
require("Storage").readJSON("mylocation.json", true) || {}
111113
);
112114
//remove notification from phone
113-
if (
114-
Math.abs(myLocationJson.lat - locationJson.lat) < 0.0001 &&
115-
Math.abs(myLocationJson.lon - locationJson.lon) < 0.0001
116-
) {
117-
//same location, do not write
118-
return;
115+
if(myLocationSaved.lat){
116+
if (
117+
Math.abs(myLocationJson.lat - locationJson.lat) < 0.0001 &&
118+
Math.abs(myLocationJson.lon - locationJson.lon) < 0.0001
119+
) {
120+
//same location, do not write
121+
return;
122+
}
119123
}
120124

121125
myLocationJson.lon = locationJson.lon;
@@ -131,6 +135,5 @@ function saveData() {
131135
}
132136

133137
E.on("kill", function () {
134-
//save cals counted
135138
saveData();
136139
});

apps/bluewatch/lib.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ function sendRawHealthData(data) {
9393
sendableData.movement = data.movement;
9494
sendableData.state = data.movement <= 150 ? "sedentary" : "moving";
9595
}
96+
if (global.calories) {
97+
sendableData.activeCalories = global.calories.activeCaloriesBurned || 0;
98+
sendableData.bmrCalories = global.calories.bmrCaloriesBurned || 0;
99+
}
96100
if (data.bpmConfidence && data.bpm) {
97101
if (data.bpmConfidence > 75 && data.bpm != 0) sendableData.hr = data.bpm;
98102
sendableData.confidence = data.bpmConfidence;
@@ -118,7 +122,7 @@ function onConnect() {
118122
function processMessage(raw) {
119123
raw = raw.trim();
120124
print("Processing complete message:", raw.length, "chars");
121-
125+
Bangle.emit("BlueWatchMessage", raw);
122126
let obj;
123127
try {
124128
obj = JSON.parse(raw);

apps/bluewatch/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "bluewatch",
33
"name": "BlueWatch iOS Integration",
44
"shortName": "BlueWatch",
5-
"version": "0.03",
5+
"version": "0.04",
66
"description": "Uses the native iOS app 'BlueWatch' to fetch weather, location, use phone GPS, find phone/watch, and more.",
77
"icon": "app.png",
88
"tags": "tool,bluetooth,apple,ios,system",

apps/bttfclock/ChangeLog

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
0.01: Back to the future clock first version.
22
0.02: Added more icons to the status field. Made it posible to custemize the step goal thrue the Health Tracking app.
3-
0.03: Added charging screen.
3+
0.03: Added charging screen.
4+
0.04: Optimised performance: cached modules, event-driven status updates, removed debug logging.
5+
0.05: Made the layout dynamic so the clock scales to any screen size.

0 commit comments

Comments
 (0)