Skip to content

Commit

Permalink
Merge pull request #2 from SK1Y101/develop
Browse files Browse the repository at this point in the history
v0.2
  • Loading branch information
mergify[bot] authored Aug 27, 2021
2 parents 3760502 + 38d3232 commit accc5af
Show file tree
Hide file tree
Showing 28 changed files with 217 additions and 220 deletions.
58 changes: 58 additions & 0 deletions FitbitPoketch-Export/app/Poketch/clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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);
};

// Define this module
export let TimeIndicator = function(doc) {
// Fetch the gui elements for the time
const hourTen = doc.getElementById("hour_ten");
const hourOne = doc.getElementById("hour_one");
const minsTen = doc.getElementById("min_ten");
const minsOne = doc.getElementById("min_one");

// Fetch the pikachu sprite
const daySprite = doc.getElementsByClassName("day")
const nightSprite = doc.getElementsByClassName("night")

// Function to update the time
this.drawTime = function(now) {
// Fetch the time elements
var hour = pad(now.getHours());
var mins = pad(now.getMinutes());
var daytime = Math.abs(15 - now.getHours()) < 5;

// update the time elements
showDigit(hourTen, hour[0]);
showDigit(hourOne, hour[1]);
showDigit(minsTen, mins[0]);
showDigit(minsOne, mins[1]);

// And update the sprite
showElement(daySprite, daytime);
showElement(nightSprite, !daytime);
};
};
53 changes: 33 additions & 20 deletions FitbitPoketch-Export/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,52 @@ import clock from "clock";
import { memory } from "system";
import document from "document";
import { display } from "display";
import { me as device } from "device";
import { me as appbit } from "appbit";
import { peerSocket } from "messaging";

// Import the modules I have written
import * as utils from "../common/utils";
import { Settings } from "../common/settings";
import { TimeIndicator } from "./Poketch/clock";

// Quick debug log
console.log("Device JS memory: " + memory.js.used + "/" + memory.js.total);
// And fetch a reference to the modules
let timeInd = new TimeIndicator(document);

// Set the default values of all options
let DefSet = function() {
var defaults = {
skin: 1,
edgeColour: 2,
edgeColour: "#3050F8",
faceColour: "#030303",
screenColour: "#70B070",
};
return defaults;
};

// Fetch the settings, passing the defaults too
let settings = new Settings("settings.cbor", DefSet);

// Show the memory usage once the settings have been loaded
console.log("Device JS memory: " + memory.js.used + "/" + memory.js.total);

// Define the clock tick rate
clock.granularity = "minutes"; // seconds, minutes, hours

const hourTen = document.getElementById("hour_ten");
const hourOne = document.getElementById("hour_one");
const minTen = document.getElementById("min_ten");
const minOne = document.getElementById("min_one");

const bg = document.getElementById("background");
const fc = document.getElementsByClassName("face_colour");
const sc = document.getElementsByClassName("screen_colour");

const dpskin = document.getElementsByClassName("dp_skin");
const ptskin = document.getElementsByClassName("pt_skin");

const face = document.getElementById("screen");
console.log(face)
console.log((0x70b070 + 0x103010).toString(16));

// Update elements once a minute
clock.addEventListener("tick", (evt) => {
let timeString = evt.date.toTimeString().slice(0, 5);
hourTen.href = "icons/digit_" + timeString[0] + ".png";
hourOne.href = "icons/digit_" + timeString[1] + ".png";
minTen.href = "icons/digit_" + timeString[3] + ".png";
minOne.href = "icons/digit_" + timeString[4] + ".png";
// Fetch the current time
let now = evt.date;
// Update the watch
timeInd.drawTime(now);
});

// Change the skin
Expand All @@ -60,12 +61,22 @@ let updateSkin = function(skinType) {
dpskin.forEach(function(ele) {
ele.style.display=(skinType==0 ? "inline" : "none")
});
// Update the size of the screen
face.groupTransform.translate.x = -Math.ceil((skinType==2 ? 0.035 * device.screen.width: 0));
face.groupTransform.translate.y = -Math.ceil((skinType==2 ? 0.03 * device.screen.height: 0));
face.groupTransform.scale.x = (skinType==2 ? 100 / 82: 1);
face.groupTransform.scale.y = (skinType==2 ? 100 / 94: 1);
}

// Change the colour
let updateEdge = function(edgeColour) {
let colour = ["#3050F8", "#FF41BC", "#E28B55", "#4C8CB9", "#EC5E6A"];
bg.style.fill=colour[edgeColour];
let updateColour = function(colour, ele) {
try {
ele.forEach(function(eles) {
eles.style.fill = colour;
});
} catch(err) {
ele.style.fill=colour;
};
}

// Define a function to apply our settings
Expand All @@ -76,7 +87,9 @@ let applySettings = function() {
try {
// Set element colours
settings.isPresent("skin", updateSkin);
settings.isPresent("edgeColour", updateEdge);
settings.isPresent("edgeColour", updateColour, bg);
settings.isPresent("faceColour", updateColour, fc);
settings.isPresent("screenColour", updateColour, sc);
// Show that settings have been loaded
console.log("Settings applied");
} catch (err) {
Expand Down
Binary file modified FitbitPoketch-Export/build/app.fba
Binary file not shown.
135 changes: 6 additions & 129 deletions FitbitPoketch-Export/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,145 +2,22 @@
import { me as device } from "device";
import { readFileSync, unlinkSync, writeFileSync } from "fs"

//Set some default values
var scale = 0;
// Set some default values

//Show an error message alongside a log
// Show an error message alongside a log
export function logerror(error, text) {
console.log(error+"; "+text);
};

//Fetch an element from the document
export function fetch(doc,name,idType) {
if (idType) {
return doc.getElementsByClassName(name);
} else {
return doc.getElementById(name);
};
};

//rescale the background such that everything is square
export function getScale(doc) {
let background = fetch(doc,"background");
scale = device.screen.height/300;
background.x = (device.screen.width-device.screen.height)/2;
background.height = device.screen.height;
background.width = device.screen.height;
return scale
};

//Rescale all text elements
export function reScale(doc,elemname,scale) {
let ele = fetch(doc,elemname,1);
ele.forEach(function(elem) {
elem.style.fontSize*=scale;
elem.style.width*=scale;
elem.style.height*=scale;
});
};

// Update the analogue time elements
export function updateHand(arc,hand,angle) {
arc.sweepAngle = angle;
hand.groupTransform.rotate.angle = angle;
};

// Update angle of an arc, as defined by it's maximum value
export function setAngle(arc, maxVal, curVal, sweepAngle) {
let sweep = (sweepAngle ? sweepAngle : 360);
try {
try {
arc.forEach(function(ele) {
ele.sweepAngle = sweep*Math.min(1,(maxVal > 0 ? curVal / maxVal : 0));
});
} catch {
arc.sweepAngle = sweep*Math.min(1,(maxVal > 0 ? curVal / maxVal : 0));
};
} catch(err) {
logerror(err,"set angle");
};
};

//get the text of an element(s)
export function getText(ele) {
try {
let text = "";
try {
ele.forEach(function(eles) {
text = eles.text;
});
} catch(err) {
text = ele.text;
};
return text
} catch(err) {
logerror(err,"get text");
return null
};
};

//set the text of an element(s)
export function setText(ele,text) {
try {
text = (typeof(text) !== "string" ? text.toString() : text);
try {
ele.forEach(function(eles) {
eles.style.textLength = text.length;
eles.text=text;
});
} catch(err) {
ele.style.textLength = text.length;
ele.text=text;
};
} catch(err) {
logerror(err,"set text");
};
};

//Capitalise the word well
export function toCap(text) {
text = (typeof(text) !== "string" ? text.toString() : text);
return text.charAt(0).toUpperCase() + text.slice(1)
};

//Return the padded form of text
export function getPad(text,def) {
return (def+text).slice(-def.length);
};

//Pad the text provided so it has a fixed length
export function padText(ele,text,def) {
setText(ele,getPad(text,def));
};

//Set the text of an element(s) such that it will automatically scale
export function textSize(ele,text,size,scalar) {
try {
text = (typeof(text) !== "string" ? text.toString() : text);
try {
ele.forEach(function(eles) {
eles.text = text;
eles.style.textLength = text.length;
eles.style.fontSize=Math.floor(Math.min(1,size/(1+text.length)) * scalar * scale);
});
} catch(err) {
ele.text = text;
ele.style.textLength = text.length;
ele.style.fontSize=Math.floor(Math.min(1,size/(1+text.length)) * scalar * scale);
};
} catch(err) {
logerror(err,"scaled text");
};
};

//Force a field to be an array
// Force a field to be an array
export function forceArray(arr) {
if (typeof(arr) !== "object") {
return [arr];
}
return arr;
};

// Save data to the watch
export function saveData(filename,data,overwriteFilename) {
try {
filename = (overwriteFilename ? "" : "_skiylian_") + filename;
Expand All @@ -150,7 +27,7 @@ export function saveData(filename,data,overwriteFilename) {
};
};

//Fetch data saved to the disk
// Fetch data saved to the disk
export function loadData(filename,defaults,overwriteFilename) {
try {
filename = (overwriteFilename ? "" : "_skiylian_") + filename;
Expand All @@ -161,7 +38,7 @@ export function loadData(filename,defaults,overwriteFilename) {
return defaults;
};

//Remove data saved to the disk
// Remove data saved to the disk
export function removeData(fName,defName) {
try {
filename = (defName ? "" : "_skiylian_") + fName;
Expand Down
4 changes: 3 additions & 1 deletion FitbitPoketch-Export/companion/setdefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { settingsStorage } from "settings";
function fetchdefs() {
var defaults = {
skin: {name:"Platinum", value:1, subname:"The Pokétch given to the protagonist in Platinum."},
edgeColour: {name: "D/P Blue", icon:"https://www.colorhexa.com/3050F8.png", value: 0, subname:"The Male Pokétch colour in in Diamond and Pearl."},
edgeColour: {name: "D/P Blue", icon:"https://www.colorhexa.com/3050F8.png", value: "#3050F8", subname:"The Male Pokétch colour in Diamond and Pearl."},
faceColour: {name: "D/P", icon:"https://www.colorhexa.com/303030.png", value: "#303030", subname:"The Pokétch face colour in Diamond and Pearl."},
screenColour: {name: "Green", icon:"https://www.colorhexa.com/70B070.png", value: "#70B070", subname:"The default Pokétch screen colour."},
};

let Defaults = {};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FitbitPoketch-Export/resources/icons/pikachu_day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit accc5af

Please sign in to comment.