RE: 23-MAR-2021 Simple Units
(03-24-2021 02:17 AM)Han Wrote: User mode is required. This program basically takes over the [Shift][_] key and provides a super-simple units menu for facilitating unit conversion. When the user types the _ symbol via [Shift][_], a units menu is automatically shown (and if applicable, the last menu used will be displayed). The first menu is the category, and the second menu is the list of units within that category. So if one were to convert 5 kilometers to miles, the keystrokes are:
5
[Shift][_]
(select distance)
(select km)
(press the Sto> menu button on the screen)
[Shift][_]
(select mile)
[Enter]
Press [Esc] to traverse back a menu (i.e. from units to category). Escaping out of the category menu will simply place the _ symbol onto the command line (in case you need to type the underscore character inside a string, for example). Pressing [On] will escape all menus (i.e. to avoid pressing [Esc] twice while inside a menu of unit symbols.
Adding one's own custom units can be easily done by simply adding to the existing lists named catlist (category) and symlist (unit symbols), which should be fairly obvious to do when looking at the source code (toward the very top). Just make sure to keep the lists ordered properly.
To install, simply create a new program called UNITS (or whatever name you want) and copy and paste the code below into your new program (easiest if done via the connectivity kit). Then drag/drop to your calculator. If you already have custom keys set up, then just add this to your existing custom keys program.
If you find any typos in the unit symbols, please let me know and I'll update here accordingly. Maybe in the (far?) future I'll focus on creating a custom menu that takes advantage of the large screen so that all categories and unit symbols are visible at once (with keyboard shortcuts) to remove the need to scroll the menu and improve efficiency.
Code:
#pragma mode( separator(.,;) integer(h32) )
// simple units conversion by Han Duong 23-MAR-2021
lastunit:={0,0};
catlist:={
"Length",
"Area",
"Volume",
"Time",
"Speed",
"Mass",
"Force",
"Acceleration",
"Energy",
"Power",
"Pressure",
"Temperature",
"Electrical",
"Angle",
"Light",
"Radiation",
"Viscosity"
};
symlist:={
{"m","cm","mm","yd","ft","in","mpc","pc","lyr","au","km","mile","nmi","miUS","chain","rod","fath","ftUS","mil","Å","fermi"},
{"m^2","cm^2","b","yd^2","ft^2","in^2","km^2","ha","a","mile^2","miUS^2","acre"},
{"m^3","st","cm^3","yd^3","ft^3","in^3","l","galUK","galUS","qt","liqpt","ptUK","ml","cu","ozfl","ozUK","tbsp","tsp","bbl","buUS", "bu","pk","fbm"},
{"yr","d","h","min","s","Hz"},
{"m/s","cm/s","ft/s","kph","km/h","mph","mile/h","knot","rad/s","tr/min","tr/s"},
{"kg","g","lb","oz","slug","lbt","tonUS","tonUK","t","ozt","ct","grain","u","mol"},
{"N","dyn","gf","kip","lbf","pdl","kg*m/s^2"},
{"m/s^2","ft/s^2","grav","Gal","rad/sec^2"},
{"J","erg","kcal","cal","Btu","ft*lbf","thermEC","thermUS","thermUK","eV","MeV","toe","tec","lep","boe","Wh","kWh","kg*m^2/s^2"},
{"W","MW","hp","kg*m^2/s^3","ft*lbf/s"},
{"Pa","atm","bar","psi","torr","mmHg","inHg","inH2O","kg/m*s^2"},
{"°C","°F","K","°R"},
{"V", "A", "C", "Ohm", "F", "W","Fdy","H","mho","S","T","Wb","A*h"},
{"deg","rad","grad","arcmin","arcs","gon","tr"},
{"flam","cd"},
{"Gy","rd","rem","Sv","Bq","Ci","R"},
{"P","St","kg/(m*s)","lb/(ft*h)","m^2/S","ft^2/S"}
};
KEY KS_Space()
BEGIN
local c1,c2;
if lastunit(1) OR lastunit(2) then
c1:=lastunit(1); c2:=lastunit(2);
if NOT(choose(c2,catlist(c1),symlist(c1))) then
c2:=0;
end;
else
c1:=0; c2:=0;
end;
if c2==0 then
repeat
if choose(c1,"Units",catlist) then
if c1 then
choose(c2,catlist(c1),symlist(c1));
end;
else
c1:=0; c2:=0;
end;
until c1==0 OR c2;
lastunit:={c1,c2};
end;
if c2 then return("_"+symlist(c1,c2)); else return("_"); end;
END;
I will check this out later. thanks!
|