Skip to content

Commit

Permalink
circlesclock: load circles from clkinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Monaco committed Nov 16, 2022
1 parent ae1bf1c commit 14744a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/circlesclock/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
0.15: Use Bangle.setUI({remove:...}) to allow loading the launcher without a full reset on 2v16
0.16: Fix const error
Use widget_utils if available
0.17: Load circles from clkinfo
36 changes: 36 additions & 0 deletions apps/circlesclock/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
let clock_info = require("clock_info");
let locale = require("locale");
let storage = require("Storage");
Graphics.prototype.setFontRobotoRegular50NumericOnly = function(scale) {
Expand Down Expand Up @@ -211,6 +212,8 @@ function drawCircle(index) {
case "empty":
// we draw nothing here
return;
default:
drawClkInfo(type, w);
}
}

Expand Down Expand Up @@ -625,6 +628,39 @@ function drawTimer(w) {
g.drawImage(getImage(timerIcon, getCircleIconColor("timer", color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset);
}

function drawClkInfo(type, w) {
var parts = type.split("/");
var infoName = parts[0], itemName = parts[1];
var info = clock_info.load().find(e=>e.name==infoName);
if(!info || !info.items) {
//TODO draw empty?
return;
}
var item;
//TODO do hide()+get() here, the item isn't that thing there
if(itemName)
item = info.items.find(i=>i.name==itemName);
else
//suppose unnamed are varying (like timers or events), pick the first
item = info.items[0];
item.show();
item.hide();
item=item.get();
var img = item.img;
if(!img) img = info.img;
if (!w) w = getCircleXPosition(type);
drawCircleBackground(w);
const color = getCircleColor(type);
let percent = (item.v-item.min) / item.max;
if(!percent) percent = 0;
drawGauge(w, h3, percent, color);
writeCircleText(w, item.text);
drawInnerCircleAndTriangle(w);
g.setColor(getCircleIconColor(type, color, percent))
.drawImage(img, w - iconOffset, h3 + radiusOuter - iconOffset, {scale: 16/24});
//g.drawImage(getImage(img, getCircleIconColor(type, color, percent)), w - iconOffset, h3 + radiusOuter - iconOffset, {scale: 16/24});
}

/*
* wind goes from 0 to 12 (see https://en.wikipedia.org/wiki/Beaufort_scale)
*/
Expand Down
23 changes: 21 additions & 2 deletions apps/circlesclock/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(function(back) {
const SETTINGS_FILE = "circlesclock.json";
const storage = require('Storage');
const clock_info = require("clock_info");
let settings = Object.assign(
storage.readJSON("circlesclock.default.json", true) || {},
storage.readJSON(SETTINGS_FILE, true) || {}
Expand All @@ -11,8 +12,26 @@
storage.write(SETTINGS_FILE, settings);
}

const valuesCircleTypes = ["empty", "steps", "stepsDist", "hr", "battery", "weather", "sunprogress", "temperature", "pressure", "altitude", "timer"];
const namesCircleTypes = ["empty", "steps", "distance", "heart", "battery", "weather", "sun", "temperature", "pressure", "altitude", "timer"];
//const valuesCircleTypes = ["empty", "steps", "stepsDist", "hr", "battery", "weather", "sunprogress", "temperature", "pressure", "altitude", "timer"];
//const namesCircleTypes = ["empty", "steps", "distance", "heart", "battery", "weather", "sun", "temperature", "pressure", "altitude", "timer"];
var valuesCircleTypes = ["empty","weather", "sunprogress"];
var namesCircleTypes = ["empty","weather", "sun"];
clock_info.load().forEach(e=>{
//TODO filter for hasRange and other
//FIXME needs to do the get()/show()/hide() stuff
let values = e.items.map(i=>e.name+"/"+i.name);
let names =e.name=="Bangle" ? e.items.map(i=>i.name) : values;
if(!e.items[0].name) {
//suppose unnamed are varying (like timers or events), pick the first
item = e.items[0];
valuesCircleTypes = valuesCircleTypes.concat([e.name]);
namesCircleTypes = namesCircleTypes.concat([e.name]);
} else {
valuesCircleTypes = valuesCircleTypes.concat(values);
namesCircleTypes = namesCircleTypes.concat(names);
}
})


const valuesColors = ["", "#ff0000", "#00ff00", "#0000ff", "#ffff00", "#ff00ff",
"#00ffff", "#fff", "#000", "green-red", "red-green", "fg"];
Expand Down

0 comments on commit 14744a8

Please sign in to comment.