Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Clock face battery

I have built a face for my Versa 3 with a basic battery (meter from.. import { battery } from "power";).   I am playing around and wanting something a bit fancier.   Can some one point me to an example of using images to associate with the battery meter %, and displaying it.  Something fairly basic please, I'm a baby developer  🙂   Thanks

Best Answer
0 Votes
7 REPLIES 7

Hi @Punzai - if you place the PNG images in the projects resources folder simply add an image SVG entry with href="image name".

You can have multiple defined in the same place and choose which one you want with opacity = 1;

Author | ch, passion for improvement.

Best Answer
0 Votes

hey guy_

im a complete newbie at this, would you be able to post a demo scipt to show how this works?

Best Answer
0 Votes

Hi @mickslsnikt - see the link in the previous post for displaying the image.

 

In Fitbit Studio best to start a new project example with clock and modify that.

Author | ch, passion for improvement.

Best Answer
0 Votes

<svg class="background">

  <image id="myBatteryLevels" x="15%" y="92%" width="70%" height="5%"/>

</svg>

Index.js

import * as document from "document";

import { preferences } from "user-settings";

import * as util from "../common/utils";

import { battery } from "power";

 

const myBatteryLevels = document.getElementById("myBatteryLevels");

 

//battery levels

 

if (battery.chargeLevel > 90) {

myBatteryLevels.href = "BatFull.png";

} else if (battery.chargeLevel > 80) {

  myBatteryLevels.href = "Bat80.png";

} else if (battery.chargeLevel > 60) {

myBatteryLevels.href = "Bat60.png";

} else if (battery.chargeLevel > 40) {

myBatteryLevels.href = "Bat40.png";

} else if (battery.chargeLevel > 20) {

myBatteryLevels.href = "Bat20.png";

} else if (battery.chargeLevel > 10) {

myBatteryLevels.href = "BatLow.png";

} else {

myBatteryLevels.href = "BatEmpty.png";}

Best Answer

batterywithimages.JPG

Best Answer

This is the battery bit I separated from the rest of my code.  Hope it helps

Add your battery images .png to the root of Resources.

Best Answer

Nice one, thanks for this! I find it easier to learn when I can see how things work!

Best Answer
0 Votes