Skip to content

Commit

Permalink
Merge pull request #27 from SK1Y101/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mergify[bot] authored Feb 14, 2022
2 parents b75a9c7 + 5b4bec6 commit bb34943
Show file tree
Hide file tree
Showing 48 changed files with 3,752 additions and 409 deletions.
1 change: 1 addition & 0 deletions FitbitPoketch-Export/SDK4.3/app/Poketch/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export let CalendarView = function(doc, settings) {

// Function to update the time
this.drawTime = function(now) {
now = Date.now();
// Fetch the time elements
var year = now.getFullYear();
var mon = now.getMonth() + 1;
Expand Down
21 changes: 16 additions & 5 deletions FitbitPoketch-Export/SDK4.3/app/Poketch/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let debug = false;
import * as utils from "../../common/utils";

// Define this module
export let TimeIndicator = function(doc) {
export let TimeIndicator = function(doc, settings) {
// Simple radians to degrees
const deg2rad = (Math.PI / 180);

Expand All @@ -17,10 +17,13 @@ export let TimeIndicator = function(doc) {
const minsHand = doc.getElementById("minute_hand");
const hourHand = doc.getElementsByClassName("hour_hand");

// Fetch the pikachu sprite
const backSprite = doc.getElementById("back_sprite");
const daySprite = doc.getElementById("day_sprite");
const nightSprite = doc.getElementById("night_sprite");
// Fetch the pikachu and eevee sprite layers
const pikaSprite = doc.getElementById("pikachu_sprite");
const eeveeSprite = doc.getElementById("eevee_sprite");
// and fetch their three layers
//const backSprite = doc.getElementsByClassName("back_sprite");
const daySprite = doc.getElementsByClassName("day_sprite");
const nightSprite = doc.getElementsByClassName("night_sprite");

// Update the position of an analogue clock hand
let updateHand = function(ele, angle=0) {
Expand Down Expand Up @@ -54,4 +57,12 @@ export let TimeIndicator = function(doc) {
utils.showElement(daySprite, daytime);
utils.showElement(nightSprite, !daytime);
};

//Function to choose which pokemon to display
this.switchMascot = function(mascot) {
mascot = mascot ?? 0;
// update the sprite
utils.showElement(pikaSprite, mascot==0);
utils.showElement(eeveeSprite, mascot==1);
}
};
7 changes: 5 additions & 2 deletions FitbitPoketch-Export/SDK4.3/app/Poketch/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export let StatsIndicator = function(doc, settings) {
if (me.permissions.granted("access_user_profile")) { maxHr = Math.round(211 - user.age * .64); };

// fetch a reference to the heartRateSensor
let hrm = new HeartRateSensor();
let hrm = new HeartRateSensor();

// Function to set the properties correctly
let setStat = function(bar, txt, value, maxval=100, unit="%", icon=null) {
Expand All @@ -61,6 +61,9 @@ export let StatsIndicator = function(doc, settings) {
setStat(eleBar, eleTxt, today.adjusted.elevationGain, goals.elevationGain, "floors", eleIcon);
setStat(azmBar, azmTxt, today.adjusted.activeZoneMinutes.total, goals.activeZoneMinutes.total, "mins", azmIcon);
};
if (me.permissions.granted("access_heart_rate")) {
setStat(heartBar, heartTxt, hrm.heartRate ?? "--", maxHr, "bpm");
};
};

// function to start the heartrate monitor
Expand All @@ -78,7 +81,7 @@ export let StatsIndicator = function(doc, settings) {
// function to fetch a heartrate reading
hrm.addEventListener("reading", () => {
// update the display
setStat(heartBar, heartTxt, hrm.heartRate, maxHr, "bpm");
setStat(heartBar, heartTxt, hrm.heartRate ?? "--", maxHr, "bpm");
});
};

Expand Down
159 changes: 159 additions & 0 deletions FitbitPoketch-Export/SDK4.3/app/Poketch/typecalc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@

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

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

// fetch the button container
const moveTypeBut = doc.getElementsByClassName("move_type_button");
const typeOneBut = doc.getElementsByClassName("type_one_button");
const typeTwoBut = doc.getElementsByClassName("type_two_button");

// Fetch the text on a button
const moveTypeText = doc.getElementById("move_type_text");
const typeOneText = doc.getElementById("type_one_text");
const typeTwoText = doc.getElementById("type_two_text");

// Fetch the effectiveness display
const effectiveDisplay = doc.getElementById("effectiveness_display");
const effectiveText = doc.getElementById("effectiveness_display_text");
effectiveDisplay.href = "icons/effectiveness_3.png";
effectiveText.text = "Regularaly effective";

// And the actual trigger
const mtb = doc.getElementById("move_type_but");
const otb = doc.getElementById("type_one_but");
const ttb = doc.getElementById("type_two_but");
utils.changeLayer(mtb, 110);
utils.changeLayer(otb, 110);
utils.changeLayer(ttb, 110);

// the type as a number
const numToType = ["Normal", "Fire", "Water", "Electric", "Grass", "Ice", "Fighting", "Poison", "Ground", "Flying", "Psychic", "Bug", "Rock", "Ghost", "Dragon", "Dark", "Steel", "Fairy"];
const effToText = ["Not effective", "Not very effective", "Regularaly effective", "Super effective"];
const numTypes = numToType.length;
// store the weakness table. Row defines attacker, column defines defender
const weakness = [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, 2, 2, 1, 2],
[2, 1, 1, 2, 4, 4, 2, 2, 2, 2, 2, 4, 1, 2, 1, 2, 4, 2],
[2, 4, 1, 2, 1, 2, 2, 2, 4, 2, 2, 2, 4, 2, 1, 2, 2, 2],
[2, 2, 4, 1, 1, 2, 2, 2, 0, 4, 2, 2, 2, 2, 1, 2, 2, 2],
[2, 1, 4, 2, 1, 2, 2, 1, 4, 1, 2, 1, 4, 2, 1, 2, 1, 2],
[2, 1, 1, 2, 4, 1, 2, 2, 4, 4, 2, 2, 2, 2, 4, 2, 1, 2],
[4, 2, 2, 2, 2, 4, 2, 1, 2, 1, 1, 1, 4, 0, 2, 4, 4, 1],
[2, 2, 2, 2, 4, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 0, 4],
[2, 4, 2, 4, 1, 2, 2, 4, 2, 0, 2, 1, 4, 2, 2, 2, 4, 2],
[2, 2, 2, 1, 4, 2, 4, 2, 2, 2, 2, 4, 1, 2, 2, 2, 1, 2],
[2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 1, 2, 2, 2, 2, 0, 1, 2],
[2, 1, 2, 2, 4, 2, 1, 1, 2, 1, 4, 2, 2, 1, 2, 4, 1, 1],
[2, 4, 2, 2, 2, 4, 1, 2, 1, 4, 2, 4, 2, 2, 2, 2, 1, 2],
[0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 2, 1, 2, 2],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 1, 0],
[2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 4, 2, 2, 4, 2, 1, 2, 1],
[2, 1, 1, 1, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 1, 4],
[2, 1, 2, 2, 2, 2, 4, 1, 2, 2, 2, 2, 2, 2, 4, 4, 1, 2],];

// Fetch the selected move type
var moveTypeDisplay = settings.getOrElse("MoveTypeValue", 0);
var typeOneDisplay = settings.getOrElse("TypeOneValue", 0);
var typeTwoDisplay = settings.getOrElse("TypeTwoValue", 0);
var held = 0;

// compute effectiveness
let compEffect = function(move_type, type_one, type_two) {
var eff_row = weakness[move_type];
return eff_row[type_one] * ((type_one == type_two) ? 2 : eff_row[type_two]);
};

// change effectiveness given typings
let changeEffect = function() {
// fetch the weaknesses and convert to unique int
var effectiveness = compEffect(moveTypeDisplay, typeOneDisplay, typeTwoDisplay);
// set href based on effectiveness
if (effectiveness == 16) {
effectiveDisplay.href = "icons/effectiveness_5.png";
effectiveText.text = effToText[3];
} else if (effectiveness == 8 ) {
effectiveDisplay.href = "icons/effectiveness_4.png";
effectiveText.text = effToText[3];
} else if (effectiveness == 4 ) {
effectiveDisplay.href = "icons/effectiveness_3.png";
effectiveText.text = effToText[2];
} else if (effectiveness == 2) {
effectiveDisplay.href = "icons/effectiveness_2.png";
effectiveText.text = effToText[1];
} else if (effectiveness == 1) {
effectiveDisplay.href = "icons/effectiveness_1.png";
effectiveText.text = effToText[1];
} else {
effectiveDisplay.href = "icons/effectiveness_0.png";
effectiveText.text = effToText[0];
};
};

// update the buttons So they show the correct type values
let updateTyping = function() {
// update text saved
settings.replaceSettings({"MoveTypeValue":moveTypeDisplay});
settings.replaceSettings({"TypeOneValue":typeOneDisplay});
settings.replaceSettings({"TypeTwoValue":typeTwoDisplay});
// and update the display after 150 ms
moveTypeText.text = numToType[moveTypeDisplay];
typeOneText.text = numToType[typeOneDisplay];
typeTwoText.text = numToType[typeTwoDisplay];
// compute the effectiveness
changeEffect();
};
updateTyping();

// -----< Move Typing >-----
mtb.addEventListener("mousedown", (evt) => {
// start a timer
held = Date.now();
// animate
utils.animateElement(moveTypeBut, "select");
});

mtb.addEventListener("mouseup", (evt) => {
// increment
moveTypeDisplay = (moveTypeDisplay + 1 + numTypes) % numTypes;
// reset if held
if ((Date.now() - held) > 1000) { moveTypeDisplay = 0; };
// update the display
utils.animateElement(moveTypeBut, "unselect"); updateTyping();
});

// -----< First Typing >-----
otb.addEventListener("mousedown", (evt) => {
// start a timer
held = Date.now();
// animate
utils.animateElement(typeOneBut, "select");
});

otb.addEventListener("mouseup", (evt) => {
// increment
typeOneDisplay = (typeOneDisplay + 1 + numTypes) % numTypes;
// reset if held
if ((Date.now() - held) > 1000) { typeOneDisplay = 0; };
// update the display
utils.animateElement(typeOneBut, "unselect"); updateTyping();
});

// -----< Second Typing >-----
ttb.addEventListener("mousedown", (evt) => {
// start a timer
held = Date.now();
// animate
utils.animateElement(typeTwoBut, "select");
});

ttb.addEventListener("mouseup", (evt) => {
// increment
typeTwoDisplay = (typeTwoDisplay + 1 + numTypes) % numTypes;
// reset if held
if ((Date.now() - held) > 1000) { typeTwoDisplay = 0; };
// update the display
utils.animateElement(typeTwoBut, "unselect"); updateTyping();
});
};
21 changes: 14 additions & 7 deletions FitbitPoketch-Export/SDK4.3/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { peerSocket } from "messaging";
// Import the modules I have written
import * as utils from "../common/utils";
import { Settings } from "../common/settings";
import { TypeCalc } from "./Poketch/typecalc";
import { SwitchView } from "./Poketch/switch";
import { StepCounter } from "./Poketch/steps";
import { KitchenTimer } from "./Poketch/timer";
import { TimeIndicator } from "./Poketch/clock";
import { CountCounter } from "./Poketch/counter";
import { StatsIndicator } from "./Poketch/stats";
import { CalendarView } from "./Poketch/calendar";
import { StatsIndicator} from "./Poketch/stats";

// Log the memory usage once the entire program is loaded
console.log("Device JS memory at import: " + memory.js.used + "/" + memory.js.total);
Expand All @@ -30,6 +31,7 @@ let DefSet = function() {
edgeColour: "#3050F8",
faceColour: "#303030",
screenColour: "#70B070",
mascotSprite: 0,
// switch view
viewnum: 0,
activeApps: [1],
Expand All @@ -49,10 +51,11 @@ String.prototype.splice = function(start, end, replacement) {

// And fetch a reference to the modules
let settings = new Settings("settings.cbor", DefSet);
let timeInd = new TimeIndicator(document);
let timeInd = new TimeIndicator(document, settings);
let statsInd = new StatsIndicator(document);
let kitchenTimer = new KitchenTimer(document);
let moveCalc = new TypeCalc(document, settings);
let stepCounter = new StepCounter(document, settings);
let kitchenTimer = new KitchenTimer(document);
let calendarView = new CalendarView(document, settings);
let countCounter = new CountCounter(document, settings);

Expand All @@ -77,6 +80,7 @@ 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 bdspskin = document.getElementsByClassName("bdsp_skin");
const face = document.getElementById("screen");

// Update elements once a minute
Expand Down Expand Up @@ -127,13 +131,14 @@ let updateColour = function(colour, ele) {
// Change the skin
let updateSkin = function(skinType) {
// Hide all the skins
utils.showElement(bdspskin, skinType==2);
utils.showElement(ptskin, skinType==1);
utils.showElement(dpskin, skinType==0);
// 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 / 81.5: 1);
face.groupTransform.scale.y = (skinType==2 ? 100 / 93.5: 1);
face.groupTransform.translate.x = -Math.ceil((skinType==3 ? 0.035 * device.screen.width: 0));
face.groupTransform.translate.y = -Math.ceil((skinType==3 ? 0.03 * device.screen.height: 0));
face.groupTransform.scale.x = (skinType==3 ? 100 / 81.5: 1);
face.groupTransform.scale.y = (skinType==3 ? 100 / 93.5: 1);
}

// Define a function to apply our settings
Expand All @@ -148,6 +153,8 @@ let applySettings = function() {
settings.isPresent("faceColour", updateColour, fc);
settings.isPresent("screenColour", updateColour, sc);
settings.isPresent("activeApps", switchView.appSettings);
// Choose the mascot
settings.isPresent("mascotSprite", timeInd.switchMascot);
// Show that settings have been loaded
console.log("Settings applied");
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions FitbitPoketch-Export/SDK4.3/companion/setdefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function fetchdefs() {
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."},
mascotSprite: {name:"Pikachu", value:0, subname:"The Original Poketch Mascot."},
activeApps: {name:"Pedometer", value:1, selected:[0]},
};

Expand Down
2 changes: 1 addition & 1 deletion FitbitPoketch-Export/SDK4.3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@fitbit/sdk-cli": "^1.7.3"
},
"fitbit": {
"appUUID": "c69cadcb-a312-4be3-a51f-681b259364c4",
"appUUID": "6bfe843c-0d8f-4985-b92c-db4feb28afa4",
"appType": "clockface",
"appDisplayName": "Poketch",
"iconFile": "resources/icon.png",
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.
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.
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.
Loading

0 comments on commit bb34943

Please sign in to comment.