diff --git a/app/index.js b/app/index.js deleted file mode 100644 index 3183fb3..0000000 --- a/app/index.js +++ /dev/null @@ -1,49 +0,0 @@ -// nApp/app/index.js - -import document from "document"; -import * as messaging from "messaging"; -import { HeartRateSensor } from "heart-rate"; -import { vibration } from "haptics"; - -let background = document.getElementById("background"); - -// Message is received -messaging.peerSocket.onmessage = evt => { - console.log(`App received: ${JSON.stringify(evt)}`); - if (evt.data.key === "color" && evt.data.newValue) { - let color = JSON.parse(evt.data.newValue); - console.log(`Setting background color: ${color}`); - background.style.fill = color; - } -}; - -// Message socket opens -messaging.peerSocket.onopen = () => { - console.log("App Socket Open"); -}; - -// Message socket closes -messaging.peerSocket.onclose = () => { - console.log("App Socket Closed"); -}; - - -//Function to make device vibrate when heart rate falls below resting pulse rate - -//resting pulse rate is hardcoded to 20 for now--we will figure out user input later -var resting_pulse_rate = 77; - -var hrm = new HeartRateSensor(); - -hrm.start(); - -// Declare an event handler that will be called every time a new HR value is received. -hrm.onreading = function() { - console.log(`Reading pulse`); - // make device vibrate if heart rate falls below resting pulse rate - if (hrm.heartRate < resting_pulse_rate) { - console.log(`target hit`); - vibration.start("ring"); - hrm.stop(); - } -} diff --git a/common/CountdownTimer.js b/common/CountdownTimer.js new file mode 100644 index 0000000..b34b1b3 --- /dev/null +++ b/common/CountdownTimer.js @@ -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 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}`; +} \ No newline at end of file diff --git a/common/time.js b/common/time.js new file mode 100644 index 0000000..c396725 --- /dev/null +++ b/common/time.js @@ -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(); +} \ No newline at end of file diff --git a/common/utils.js b/common/utils.js new file mode 100644 index 0000000..d401564 --- /dev/null +++ b/common/utils.js @@ -0,0 +1,7 @@ +// Add zero in front of numbers < 10 +export function zeroPad(i) { + if (i < 10) { + i = "0" + i; + } + return i; +} diff --git a/resources/icon.png b/resources/icon.png new file mode 100644 index 0000000..864d5a4 Binary files /dev/null and b/resources/icon.png differ diff --git a/resources/index.gui b/resources/index.gui index ce89ed7..daf45c1 100644 --- a/resources/index.gui +++ b/resources/index.gui @@ -1,3 +1,3 @@ - - + + diff --git a/resources/styles.css b/resources/styles.css index d4e1979..987ec82 100644 --- a/resources/styles.css +++ b/resources/styles.css @@ -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; }