Skip to content
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

12 coundown #20

Open
wants to merge 15 commits 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
49 changes: 0 additions & 49 deletions app/index.js

This file was deleted.

58 changes: 58 additions & 0 deletions common/CountdownTimer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import clock from "clock";
import document from "document";
import { vibration } from "haptics";
import { me } from "appbit";


// napTime to be user input
export const napTime = '1';

// Get a handle on the <text> element
export const myLabel = document.getElementById("myLabel");

// button function: up to start countdown timer
export const listenButton = function() {
// CONTROL BUTTON to start countdown
document.onkeypress = function(e) {
if (e.key === "up") {
console.log("Key pressed: " + e.key); //just prints to log that button has been pressed
console.log("Countdown started.")
startCountdownTimer();
}
else {
console.log("Key pressed: " + e.key); //just prints to log that button has been pressed
me.exit();
}
}
}

// set naptTime & allow user to start timer with button
export const setNapTime = function(t) {
napTime = t;
// show nap time on clockface
myLabel.text = `${napTime}`;
// CONTROL BUTTON
listenButton();
}

// start countdown timer
export const startCountdownTimer = function() {
let cdTime = napTime + 1;
// updates the clock every minute
clock.granularity = "minutes";
// start ticking (per minute) the clock
clock.ontick = (evt) => {
napTime--;
// stop ticking clock & ring alarm
if (napTime === 0) {
clock.granularity = "off";
vibration.start("ring");
console.log("Fitbit alarm vibrating.")
}
}
}

// update minutes left on clock face
export const updateTimer = (minsLeft) => {
myLabel.text = `${minsLeft}`;
}
14 changes: 14 additions & 0 deletions common/time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const getTimeStamp = () => {
const now = new Date();
return now.getTime();
}

export const getMinutes = () => {
const now = new Date();
return now.getMinutes();
}

export const getSeconds = () => {
const now = new Date();
return now.getSeconds();
}
7 changes: 7 additions & 0 deletions common/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Add zero in front of numbers < 10
export function zeroPad(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions resources/index.gui
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<svg>
<rect id="background" />
<svg class="background">
<text id="myLabel" />
</svg>
17 changes: 9 additions & 8 deletions resources/styles.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.defaultText {
font-size: 32;
font-family: System-Regular;
font-weight: regular;
text-length: 32;
.background {
viewport-fill: blue;
}

#background {
width: 100%;
height: 100%;
#myLabel {
font-size: 80;
font-family: System-Bold;
text-length: 32;
text-anchor: middle;
x: 50%;
y: 50%+40;
fill: white;
}