Skip to content

Commit 064a425

Browse files
authored
Merge pull request #3970 from only-meeps/master
Added new imperial to metric converter app
2 parents 91cf1ca + 2b0ddf6 commit 064a425

File tree

6 files changed

+221
-0
lines changed

6 files changed

+221
-0
lines changed

apps/imc/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New App!

apps/imc/IMC.png

2.52 KB
Loading

apps/imc/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Imperial Metric Converter
2+
3+
A simple app for converting measurements from metric to imperial and imperial to metric.
4+
5+
## Controls
6+
7+
Scroll through the menus and select the measurement you want to convert, choose it, and then type in the number you want to convert.
8+
9+
Click the button (on the side of the watch) to confirm and then click it again if you want to go back to the main menu
10+
11+
## Other stuff
12+
Credit to the contacts app for the keypad, I took some (very) heavy inspiration from that
13+
14+
Also if anyone notices that one of the equations are wrong (at least one probably is) then either just change it or let me know, its very easy to change the equations when editing the code.

apps/imc/app-icon.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("heatshrink").decompress(atob("lEowMB/4A/8+H+H+h/HAgP4gYEB8HwofHwfg8PzAgXj/4EB4AECwPIAgWJAgeIxAEDzAECxkY8fxAgM4+IED+A2Bx04/EHJIcfQ3YA=="))

apps/imc/app.js

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
var Layout = require("Layout");
2+
var mainmenu = {
3+
"" : { title : "Main Menu" }, // options
4+
"Metric to Imperial" : function() { E.showMenu(MetricToImperial); activateBackButton();},
5+
"Imperial to Metric" : function() { E.showMenu(ImperialToMetric); activateBackButton();}
6+
};
7+
//Example Equation: 50 F to C would be written as 5/9(E - 32)
8+
//The E is the number that is inserted
9+
function activateBackButton()
10+
{
11+
setWatch(function() {E.showMenu(mainmenu);}, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat:false, edge:"falling"});
12+
}
13+
var MetricToImperial = {
14+
"" : { title : "Select Type", },
15+
"Weight" : function() { E.showMenu(MetricToImperialWeight); activateBackButton();},
16+
"Distance" : function() { E.showMenu(MetricToImperialDistance); activateBackButton();},
17+
"Temperature" : function() { E.showMenu(MetricToImperialTemp); activateBackButton();},
18+
"Liquid" : function() { E.showMenu(MetricToImperialLiquid); activateBackButton();},
19+
};
20+
var MetricToImperialDistance = {
21+
"" : { title : "Select Measurement", },
22+
"MM-IN" : () => { convertAndPrint("E/25.4", "IN");},
23+
"CM-IN" : () => { convertAndPrint("E/2.54", "IN");},
24+
"M-FT" : () => { convertAndPrint("3.2808399*E", "FT");},
25+
"KM-MI" : () => { convertAndPrint("E/1.609344", "MI");}
26+
};
27+
var MetricToImperialWeight = {
28+
"" : { title : "Select Measurement", },
29+
"MG-OZ" : () => { convertAndPrint("E/28349.5231", "OZ");},
30+
"KG-LB" : () => { convertAndPrint("E*2.20462262", "LB");},
31+
"MT-US Ton" : () => { convertAndPrint("E*1.1023109950010197", "US TON");},
32+
"G-OZ" : () => { convertAndPrint("E/28.3495231", "OZ");}
33+
};
34+
var MetricToImperialLiquid = {
35+
"" : { title : "Select Measurement", },
36+
"ML-FL OZ" : () => { convertAndPrint("E/29.5735295", "FL OZ");},
37+
"ML-PT" : () => { convertAndPrint("E*0.002113", "PT");},
38+
"L-QT" : () => { convertAndPrint("E*1.056688", "QT");},
39+
"L-GAL" : () => { convertAndPrint("E*0.2641720524", "GAL");},
40+
"ML-C" : () => { convertAndPrint("E/236.588236", "C");}
41+
};
42+
var MetricToImperialTemp = {
43+
"" : { title : "Select Measurement", },
44+
"C-F" : () => { convertAndPrint("(E*1.8)+32", "F");},
45+
"K-F" : () => { convertAndPrint("((E-273.15)*1.8)+32", "F");}
46+
};
47+
var ImperialToMetric = {
48+
"" : { title : "Select Type", },
49+
"Weight" : function() { E.showMenu(ImperialToMetricWeight); activateBackButton();},
50+
"Distance" : function() { E.showMenu(ImperialToMetricDistance); activateBackButton();},
51+
"Temperature" : function() { E.showMenu(ImperialToMetricTemp); activateBackButton();},
52+
"Liquid" : function() { E.showMenu(ImperialToMetricLiquid); activateBackButton();},
53+
};
54+
var ImperialToMetricDistance = {
55+
"" : { title : "Select Measurement", },
56+
"IN-MM" : () => { convertAndPrint("E*25.4", "MM");},
57+
"IN-CM" : () => { convertAndPrint("E*2.54", "MM");},
58+
"FT-M" : () => { convertAndPrint("E/3.2808399", "M");},
59+
"MI-KM" : () => { convertAndPrint("E*1.609344", "KM");}
60+
};
61+
var ImperialToMetricWeight = {
62+
"" : { title : "Select Measurement", },
63+
"OZ-MG" : () => { convertAndPrint("E*28349.5231", "MG");},
64+
"LB-KG" : () => { convertAndPrint("E/2.20462262", "KG");},
65+
"US Ton-MT" : () => { convertAndPrint("E/1.1023109950010197", "MT");},
66+
"OZ-G" : () => { convertAndPrint("E*28.3495231", "G");}
67+
};
68+
var ImperialToMetricLiquid = {
69+
"" : { title : "Select Measurement", },
70+
"FL OZ-ML" : () => { convertAndPrint("E*29.5735295", "ML");},
71+
"PT-ML" : () => { convertAndPrint("E/0.002113", "ML");},
72+
"QT-L" : () => { convertAndPrint("E/1.056688", "L");},
73+
"GAL-L" : () => { convertAndPrint("E/0.2641720524", "L");},
74+
"C-ML" : () => { convertAndPrint("E*236.588236", "ML");}
75+
};
76+
var ImperialToMetricTemp = {
77+
"" : { title : "Select Measurement", },
78+
"F-C" : () => { convertAndPrint("(E-32)/1.8", "C");},
79+
"F-K" : () => { convertAndPrint("((E-32)/1.8)+273.15", "K");}
80+
};
81+
E.showMenu(mainmenu);
82+
function convertAndPrint(equation, endText)
83+
{
84+
E.showMenu();
85+
g.clear();
86+
showNumpad().then((number) => {
87+
g.clear();
88+
equation = equation.replace("E", number);
89+
var textToWrite = "";
90+
var layout = new Layout({});
91+
if (equation.includes("."))
92+
{
93+
console.log(eval(equation).toString().split(".")[1].length);
94+
if(eval(equation).toString().split(".")[1].length < 3)
95+
{
96+
console.log("decimal but no need for round");
97+
textToWrite = eval(equation);
98+
textToWrite = textToWrite + " " + endText;
99+
layout = new Layout({
100+
type: "txt",
101+
font: "Vector:20",
102+
label: textToWrite
103+
});
104+
layout.render();
105+
}
106+
else
107+
{
108+
console.log("decimal rounded");
109+
textToWrite = Math.round(eval(equation) * 1000) / 1000;
110+
textToWrite = "ABT " + textToWrite + " " + endText;
111+
layout = new Layout({
112+
type: "txt",
113+
font: "Vector:20",
114+
label: textToWrite
115+
});
116+
layout.render();
117+
}
118+
}
119+
else
120+
{
121+
console.log("no decimal");
122+
textToWrite = eval(equation);
123+
textToWrite = textToWrite + " " + endText;
124+
layout = new Layout({
125+
type: "txt",
126+
font: "Vector:20",
127+
label: textToWrite
128+
});
129+
layout.render();
130+
}
131+
activateBackButton();
132+
});
133+
134+
}
135+
function showNumpad() {
136+
return new Promise((resolve, reject) => {
137+
let number = '';
138+
E.showMenu();
139+
function addDigit(digit) {
140+
if(digit == "." && !number.includes("."))
141+
{
142+
number += digit;
143+
Bangle.buzz(20);
144+
update();
145+
}
146+
else if(digit != ".")
147+
{
148+
number += digit;
149+
Bangle.buzz(20);
150+
update();
151+
}
152+
else
153+
{
154+
console.log("Already includes .");
155+
}
156+
}
157+
function removeDigit() {
158+
number = number.slice(0, -1);
159+
Bangle.buzz(20);
160+
update();
161+
}
162+
function update() {
163+
g.reset();
164+
g.clearRect(0,0,g.getWidth(),23);
165+
g.setFont("Vector:24").setFontAlign(1,0).drawString(number, g.getWidth(),12);
166+
console.log(number.length);
167+
if(number.length > 0){setWatch(function() {resolve(number);}, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat:false, edge:"falling"});}
168+
}
169+
const ds="12%";
170+
const digitBtn = (digit) => ({type:"btn", font:ds, width:58, label:digit, cb:l=>{addDigit(digit);}});
171+
var numPad = new Layout ({
172+
type:"v", c: [{
173+
type:"v", c: [
174+
{type:"", height:24},
175+
{type:"h",filly:1, c: [digitBtn("1"), digitBtn("2"), digitBtn("3")]},
176+
{type:"h",filly:1, c: [digitBtn("4"), digitBtn("5"), digitBtn("6")]},
177+
{type:"h",filly:1, c: [digitBtn("7"), digitBtn("8"), digitBtn("9")]},
178+
{type:"h",filly:1, c: [
179+
{type:"btn", font:ds, width:58, label:"<", cb: removeDigit},
180+
digitBtn('0'),
181+
{type:"btn", font:ds, width:58, id:".", label:".", cb: l => addDigit(".")}
182+
]}
183+
]}
184+
], lazy:true});
185+
g.clear();
186+
numPad.render();
187+
update();
188+
189+
});
190+
}

apps/imc/metadata.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ "id": "imc",
2+
"name": "Metric Imperial Converter",
3+
"shortName":"imc",
4+
"icon": "IMC.png",
5+
"version":"0.01",
6+
"allow_emulator": true,
7+
"description": "A tool for converting metric and imperial measurements",
8+
"readme": "README.md",
9+
"tags": "tool",
10+
"supports": ["BANGLEJS2"],
11+
"storage": [
12+
{"name":"imc.app.js","url":"app.js"},
13+
{"name":"imc.img","url":"app-icon.js","evaluate":true}
14+
]
15+
}

0 commit comments

Comments
 (0)