Skip to content

feat: japanese walking #3900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/jwalk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Japanese Walking Timer

A simple timer designed to help you manage your walking intervals, whether you're in a relaxed mode or an intense workout!

![](screenshot.png)

## Usage

- The timer starts with a default total duration and interval duration, which can be adjusted in the settings.
- Tap the screen to pause or resume the timer.
- The timer will switch modes between "Relax" and "Intense" at the end of each interval.
- The display shows the current time, the remaining interval time, and the total time left.

## Creator

[Fabian Köll] ([Koell](https://github.com/Koell))


## Icon

[Icon](https://www.koreanwikiproject.com/wiki/images/2/2f/%E8%A1%8C.png)
1 change: 1 addition & 0 deletions apps/jwalk/app-icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions apps/jwalk/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
const FILE = "jwalk.json";
const DEFAULTS = {
totalDuration: 30, // in minutes
intervalDuration: 3, // in minutes
startMode: 0, // 0 for Relax, 1 for Intense
};

// Constants for time calculations
const SECONDS_IN_MINUTE = 60;
const PAUSE_BEEP_DURATION = 1000; // in milliseconds
const SECOND_BEEP_DURATION = 500; // in milliseconds
const MESSAGE_DISPLAY_DURATION = 1500; // in milliseconds
const FONT_SIZE_TIME = 40;
const FONT_SIZE_MODE = 2;
const FONT_SIZE_TOTAL = 2;
const FONT_SIZE_PAUSE = 15;
const CIRCLE_RADIUS = 5;
const TRIANGLE_OFFSET = 6;

let settings = require("Storage").readJSON(FILE, 1) || DEFAULTS;

let remainingTotal = settings.totalDuration * SECONDS_IN_MINUTE;
let intervalDuration = settings.intervalDuration * SECONDS_IN_MINUTE;
let remainingInterval = intervalDuration;
let currentMode = settings.startMode === 1 ? "Intense" : "Relax";
let paused = false;
let intervalEnd = 0;
let drawTimerInterval;

function formatTime(seconds) {
const minutes = Math.floor(seconds / SECONDS_IN_MINUTE);
const secs = (seconds % SECONDS_IN_MINUTE).toString().padStart(2, '0');
return `${minutes}:${secs}`;
}

function drawTimer() {
g.setBgColor("#000");
g.clear();
g.setColor("#FFF");

// Display current time
const now = new Date();
const timeStr = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
g.setFont("6x8", FONT_SIZE_MODE);
g.setFontAlign(1, 0);
g.drawString(timeStr, g.getWidth() - 4, 8);

// Display current mode
g.setFontAlign(0, 0);
g.drawString(currentMode, g.getWidth() / 2, 40);

// Display interval time
const displayInterval = paused ? remainingInterval : Math.max(0, Math.floor((intervalEnd - Date.now()) / 1000));
g.setFont("Vector", FONT_SIZE_TIME);
g.drawString(formatTime(displayInterval), g.getWidth() / 2, g.getHeight() / 2);

// Display paused status
if (paused) {
g.setFont("Vector", FONT_SIZE_PAUSE);
g.setFontAlign(0, 0);
g.drawString("PAUSED", g.getWidth() / 2, g.getHeight() / 2 + 40);
} else {
// Draw mode indicator
if (currentMode === "Relax") {
g.fillCircle(g.getWidth() / 2, g.getHeight() / 2 + 40, CIRCLE_RADIUS);
} else {
const cx = g.getWidth() / 2;
const cy = g.getHeight() / 2 + 40;
g.fillPoly([
cx, cy - TRIANGLE_OFFSET,
cx - TRIANGLE_OFFSET, cy + TRIANGLE_OFFSET,
cx + TRIANGLE_OFFSET, cy + TRIANGLE_OFFSET
]);
}
}

// Display total time left
g.setFont("6x8", FONT_SIZE_TOTAL);
g.drawString(`Left: ${formatTime(remainingTotal)}`, g.getWidth() / 2, g.getHeight() / 2 + 60);

g.flip();
}

function toggleMode() {
currentMode = (currentMode === "Relax") ? "Intense" : "Relax";
Bangle.buzz();
}

function startNextInterval() {
if (remainingTotal <= 0) {
clearInterval(drawTimerInterval);
Bangle.buzz(PAUSE_BEEP_DURATION);
setTimeout(() => Bangle.buzz(SECOND_BEEP_DURATION), MESSAGE_DISPLAY_DURATION);
E.showMessage("Done!");
return;
}

remainingInterval = Math.min(intervalDuration, remainingTotal);
remainingTotal -= remainingInterval;
intervalEnd = Date.now() + remainingInterval * 1000;
}

function tick() {
if (paused) return;

if (Math.floor((intervalEnd - Date.now()) / 1000) <= 0) {
toggleMode();
startNextInterval();
}

drawTimer();
}

function togglePause() {
if (!paused) {
remainingInterval = Math.max(0, Math.floor((intervalEnd - Date.now()) / 1000));
paused = true;
} else {
intervalEnd = Date.now() + remainingInterval * 1000;
paused = false;
}
drawTimer();
}

Bangle.on("touch", togglePause);
Bangle.on("swipe", () => {});
Bangle.loadWidgets();
Bangle.drawWidgets();

startNextInterval();
drawTimer();
drawTimerInterval = setInterval(tick, 1000);
Binary file added apps/jwalk/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions apps/jwalk/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": "jwalk",
"name": "Japanese Walking",
"shortName": "J-Walk",
"icon": "app.png",
"version": "0.01",
"description": "Alternating walk timer: 3 min Relax / 3 min Intense for a set time. Tap to pause/resume. Start mode, interval and total time configurable via Settings.",
"tags": "walk,timer,fitness",
"supports": ["BANGLEJS","BANGLEJS2"],
"readme": "README.md",
"data": [
{ "name": "jwalk.json" }
],
"storage": [
{ "name": "jwalk.app.js", "url": "app.js" },
{ "name": "jwalk.settings.js", "url": "settings.js" },
{ "name": "jwalk.img", "url": "app-icon.js", "evaluate": true }
]
}
Binary file added apps/jwalk/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions apps/jwalk/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
(function (back) {
const FILE = "jwalk.json";
const DEFAULTS = {
totalDuration: 30,
intervalDuration: 3,
startMode: 0,
};

let settings = require("Storage").readJSON(FILE, 1) || DEFAULTS;

function saveSettings() {
require("Storage").writeJSON(FILE, settings);
}

function showSettingsMenu() {
const menu = {
'': { title: 'Japanese Walking' },
'< Back': back,
'Total Time (min)': {
value: settings.totalDuration,
min: 10,
max: 60,
step: 1,
onchange: v => {
settings.totalDuration = v;
saveSettings();
}
},
'Interval (min)': {
value: settings.intervalDuration,
min: 1,
max: 10,
step: 1,
onchange: v => {
settings.intervalDuration = v;
saveSettings();
}
},
'Start Mode': {
value: settings.startMode,
min: 0,
max: 1,
format: v => v ? "Intense" : "Relax",
onchange: v => {
settings.startMode = v;
saveSettings();
}
}
};
E.showMenu(menu);
}

showSettingsMenu();
})