Skip to content

Commit

Permalink
Merge pull request #6 from SK1Y101/develop
Browse files Browse the repository at this point in the history
v0.3
  • Loading branch information
mergify[bot] authored Aug 29, 2021
2 parents 8815315 + b32d244 commit 3a1af15
Show file tree
Hide file tree
Showing 17 changed files with 468 additions and 134 deletions.
46 changes: 7 additions & 39 deletions FitbitPoketch-Export/app/Poketch/clock.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
// Import the fitbit builtins

// Define any helper functions
// Change a digit display
function showDigit(ele, digit) {
try {
ele.href = "digits/digit_" + digit + ".png";
} catch(err) {
console.log(err + ": Couldn't assign digit '" + digit + "'")
};
};

// Hide a set of gui elemetns
function showElement(ele, val) {
try {
ele.forEach(function(eles) {
eles.style.display = (val ? "inline" : "none");
});
} catch(err) {
ele.style.display = (val ? "inline" : "none");
};
};

// Pad a value such that it has a defined length
function pad(val, def="00") {
return (def + val.toString()).slice(-def.length);
};
import * as utils from "../../common/utils";

// Define this module
export let TimeIndicator = function(doc) {
Expand All @@ -33,15 +10,11 @@ export let TimeIndicator = function(doc) {

// Fetch the gui elements for the time
// Digital clock
const hourTen = doc.getElementById("hour_ten");
const hourOne = doc.getElementById("hour_one");
const minsTen = doc.getElementById("min_ten");
const minsOne = doc.getElementById("min_one");
let digitHandler = new utils.DigitDisplay(doc, "time_", "0000");

// Analogue clock
const minsHand = doc.getElementById("minute_hand");
const hourHand = doc.getElementById("hour_hand");
const hourHandBack = doc.getElementById("hour_hand_back");
const hourHand = doc.getElementsByClassName("hour_hand");

// Fetch the pikachu sprite
const daySprite = doc.getElementsByClassName("day");
Expand All @@ -63,25 +36,20 @@ export let TimeIndicator = function(doc) {
this.drawTime = function(now) {
// Fetch the time elements
var hour = now.getHours();
var hourT = pad(hour);
var mins = now.getMinutes();
var minsT = pad(mins);
var time = utils.pad(hour)+utils.pad(mins);
var daytime = (hour >= 10) && (hour < 20);

// update the time elements
// Digital time
showDigit(hourTen, hourT[0]);
showDigit(hourOne, hourT[1]);
showDigit(minsTen, minsT[0]);
showDigit(minsOne, minsT[1]);
digitHandler.update(time);

// Analogue time
updateHand(hourHand, (hour%12)*30 + mins*.5);
updateHand(hourHandBack, (hour%12)*30 + mins*.5);
updateHand(minsHand, mins * 6);

// And update the sprite
showElement(daySprite, daytime);
showElement(nightSprite, !daytime);
utils.showElement(daySprite, daytime);
utils.showElement(nightSprite, !daytime);
};
};
56 changes: 56 additions & 0 deletions FitbitPoketch-Export/app/Poketch/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Import the fitbit builtins
import { me } from "appbit";
import * as activity from "user-activity";

// Define any helper functions
import * as utils from "../../common/utils";

// Define this module
export let CountCounter = function(doc, settings) {

// Fetch the digit handler
let digitHandler = new utils.DigitDisplay(doc, "count_", "00000");

// Fetch the decorative button element
const ccb = doc.getElementsByClassName("count_count_button");
// And the actual trigger
const cct = doc.getElementById("count_count_but");
// Move the trigger to layer 110 so that it is above the view change buttons
utils.changeLayer(cct, 110);

// Fetch the counter amount
var count = settings.getOrElse("counterValue", 0);
// A blank timer
var held = 0;

// function to draw the display
this.draw = function() {
// update the counter
digitHandler.update(count);
// and save the value
settings.replaceSettings({"counterValue":count})
};

// Function to trigger if the button is set
cct.addEventListener("mousedown", (evt) => {
// cite the held time
held = Date.now();
// activate the buttons
utils.animateElement(ccb, "select");
});

// Function to trigger if the button is unset
cct.addEventListener("mouseup", (evt) => {
// increase the counter
count++;
// Check if we are reseting the counter
if ((Date.now() - held) > 1000) { count = 0; };
// activate the button
utils.animateElement(ccb, "unselect");
// and update the step display
this.draw();
});

//and draw the initial state
this.draw();
};
89 changes: 89 additions & 0 deletions FitbitPoketch-Export/app/Poketch/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Import the fitbit builtins
import { me } from "appbit";
import * as activity from "user-activity";

// Define any helper functions
import * as utils from "../../common/utils";

// Define this module
export let StepCounter = function(doc, settings) {

// Fetch the digit handler
let digitHandler = new utils.DigitDisplay(doc, "step_", "00000");

// fetch the step counter edge reference
const sce = doc.getElementById("step_count_edge");

// Fetch the decorative button element
const csb = doc.getElementsByClassName("step_count_button");
// And the actual trigger
const cst = doc.getElementById("step_count_but");
// Move the trigger to layer 110 so that it is above the view change buttons
utils.changeLayer(cst, 110);

// Fetch whether we are showing the total steps or offset steps
var stepView = settings.getOrElse("stepView", 0);
sce.style.opacity = stepView ? 1 : .4;
// Fetch the step offset
var offset = 5400;//settings.getOrElse("stepOffset", 0);
// A blank timer
var held = 0;

// change the offset and save it
let newOffset = function(ost = 0) {
offset = ost; settings.replaceSettings({"stepOffset":offset})
};

// Function to reset the step counter at midnight
this.reset = function() {
newOffset(0);
};

// function to draw the steps on screen
this.draw = function() {
// Check we have permissions
if (me.permissions.granted("access_activity")) {
// Fetch the number of steps
var steps = activity.today.adjusted.steps;
// update the offset on long press
if ((offset == -1) || (offset > steps)) { newOffset(steps); };
// And show the desired step counter
if (stepView == 0) {
digitHandler.update(steps);
} else {
digitHandler.update(steps - offset);
};
} else {
// Otherwise, draw nothing
digitHandler.update("-----");
};
};

// Function to trigger if the button is set
cst.addEventListener("mousedown", (evt) => {
// cite the held time
held = Date.now();
// activate the buttons
utils.animateElement(csb, "select");
});

// Function to trigger if the button is unset
cst.addEventListener("mouseup", (evt) => {
// Check if we had a long click
if ((Date.now() - held) > 1000) {
// update the offset to the current steps
offset = -1;
} else {
// switch the stepView
stepView = stepView ? 0 : 1;
// and store the new stepview counter
settings.replaceSettings({"stepView":stepView});
// update the opacity of the border
sce.style.opacity = stepView ? 1 : .4;
};
// activate the button
utils.animateElement(csb, "unselect");
// and update the step display
this.draw();
});
};
52 changes: 33 additions & 19 deletions FitbitPoketch-Export/app/Poketch/switch.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// Import the fitbit builtins

// Define any helper functions
// Animate an element
let animateElement = function(ele, trigger) {
ele.forEach(function(eles) {
eles.animate(trigger);
});
};
import * as utils from "../../common/utils";

// Define this module
export let SwitchView = function(doc) {
export let SwitchView = function(doc, settings, viewUpdate) {
// Fetch the elements that detect a click
const foreBut = doc.getElementById("fore_button");
const backBut = doc.getElementById("back_button");
// Move the elements to layer 100, so that we can stack other buttons on top of them
utils.changeLayer(foreBut, 100);
utils.changeLayer(backBut, 100);

//Fetch the ui buttons to animate
const upBut = doc.getElementsByClassName("button_top");
Expand All @@ -29,6 +27,14 @@ export let SwitchView = function(doc) {
var vnum = 0;
var vlen = 0;

// Update any views that need it
let drawView = function() {
var vu = viewUpdate[vnum];
if (vu) {
vu()
};
};

// Function to fetch the available views
let fetchViews = function() {
do {
Expand All @@ -37,35 +43,39 @@ export let SwitchView = function(doc) {
++vnum;
++vlen;
} while (doc.getElementById("view"+vnum) != null);
vnum=0;
// Load the view number from settings, or use the clock ace by default
vnum = settings.getOrElse("viewnum", 0);
};

// Function to switch to the next view
let changeView = function(inc=0) {
let changeView = function(inc=0, forceUpdate=false) {
// compute the new view to change to
var vnew = (vnum + inc + vlen) % vlen;
console.log("new view: "+vnew, "old view: "+vnum);
// If it is different to the current one
if (vnew != vnum) {
// If it is different to the current one, or we are forcing an update
if ((vnew != vnum) || (forceUpdate)) {
// change the display visibility of the elements
views[vnum].style.display = "none";
views[vnew].style.display = "inline";
// And update the view number
vnum = (vnum + inc + vlen) % vlen;
drawView();
};
console.log("vnum is now:"+vnum);
// Update the view settins
settings.replaceSettings({"viewnum":vnum});
};

// And fetch all of the views
// fetch all of the views
fetchViews();
// And update them initially
changeView(0, true);

// Create event listeners
let buttonEvent = function(button, inc=0) {
// Ensure we can animate
if (!updating) {
// start the animations
animateElement(view, "enable");
animateElement(button, "click");
utils.animateElement(view, "enable");
utils.animateElement(button, "click");
// force the ui to stop until the animations are done
updating = true;
// wait until the view is greyed out
Expand All @@ -80,13 +90,17 @@ export let SwitchView = function(doc) {

// forward button is released
foreBut.addEventListener("mousedown", (evt) => {
//activate the buttons
// activate the buttons
buttonEvent(downBut, 1);
});

// forward button is released
backBut.addEventListener("mousedown", (evt) => {
//activate the buttons
buttonEvent(upBut, 1);
// activate the buttons
buttonEvent(upBut, -1);
});

this.draw = function() {
drawView();
};
};
Loading

0 comments on commit 3a1af15

Please sign in to comment.