View Single Post
Old 01-15-2024, 06:57 PM   #4
elinkser
Addict
elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.
 
Posts: 242
Karma: 146236
Join Date: Oct 2022
Device: Kobo Clara HD
***


Or, just run a shell script like f2c.sh from the terminal:

#!/mnt/onboard/.adds/koreader/luajit
--f2c.lua
print('*** Converting between the different temperature scales ***')
print('1. Convert Celsius temperature into Fahrenheit')
print('2. Convert Fahrenheit temperatures into Celsius')
print('Select your choice (1-2) : ')
choice = io.read('*n')
if choice==tonumber("1") then
print('Enter temperature (C) : ')
tc = io.read('*n')
-- formula Tf=(9/5)*Tc+32
tf=(9/5) * tc + 32
print('Temperature (F) = ', tf)
elseif choice==tonumber("2") then
print('Enter temperature (F) : ')
tf = io.read('*n')
-- formula Tc=(5/9)*(Tf-32)
tc=(5/9)*(tf-32)
print('Temperature (C) = ', tc)
else
print('Invalid choice')
end


***

Or, from NickelMenu:
(requires NickelDBus .

Add a NickelMenu entry to /mnt/onboard/.adds/nm/config.txt:
Code:
menu_item :main :convert :cmd_spawn :quiet:exec /mnt/onboard/.adds/koreader/scripts/convert.sh
    chain_success                      :dbg_toast          :Started convert       
    chain_failure                      :dbg_toast          :Error

And a convert.sh script to /mnt/onboard/.adds/koreader/scripts/:
Code:
#!/bin/sh                                        
# convert selection menu
choice=0                              
qndb -m dlgConfirmCreate true                                       
qndb -m dlgConfirmSetTitle "1- Convert Celsius temperature into Fahrenheit; 2- Convert Fahrenheit temperatures into Celsius; Select option (1-2):"
qndb -m dlgConfirmSetLEPlaceholder "1"
qndb -m dlgConfirmShow                           
result=$(qndb -s dlgConfirmTextInput)            
textIn=$(echo $result | sed 's/dlgConfirmTextInput //')
choice=$(echo $textIn | sed 's/[^0-9]//g')
if [ "$choice" == "1" ]; then
	tc=0                              
	qndb -m dlgConfirmCreate true                                       
	qndb -m dlgConfirmSetTitle "Enter temperature (C) : "
	qndb -m dlgConfirmSetLEPlaceholder "0"
	qndb -m dlgConfirmShow                           
	result=$(qndb -s dlgConfirmTextInput)            
	textIn=$(echo $result | sed 's/dlgConfirmTextInput //')
	tc=$(echo $textIn | sed 's/[^0-9\-]//g')
	echo $tc
	tf=$(/mnt/onboard/.adds/koreader/luajit -e "print((9/5) * tonumber($tc) + 32)")
	qndb -m mwcToast 3000 "Temperature (F) = $tf"
elif [ "$choice" == "2" ]; then
	tf=0                              
	qndb -m dlgConfirmCreate true                                       
	qndb -m dlgConfirmSetTitle "Enter temperature (F) : "
	qndb -m dlgConfirmSetLEPlaceholder "0"
	qndb -m dlgConfirmShow                           
	result=$(qndb -s dlgConfirmTextInput)            
	textIn=$(echo $result | sed 's/dlgConfirmTextInput //')
	tf=$(echo $textIn | sed 's/[^0-9\-]//g')
	tc=$(/mnt/onboard/.adds/koreader/luajit -e "print((5/9)*(tonumber($tf)-32))")
	qndb -m mwcToast 3000 "Temperature (C) = $tc"
else
		qndb -m mwcToast 3000 "You selected an invalid option" 
fi
qndb -m mwcToast 1000 "${fberr:-"Bye!"}"

***


Or, make an rmkit Simple App Script:
https://www.mobileread.com/forums/sh...d.php?t=356282

Modify the /mnt/onboard/.adds/rmkit/bin/apps/menu.sh to:
Code:
while true; do
  app="
textinput 250 100 200 50 
label 250 200 200 50 you entered: ${temp}
button 150 400 200 50 c2f
button 350 400 200 50 f2c
label 250 600 200 50 you clicked: ${option}
[paragraph 250 800 500 500 Result = ${output}]
"
  echo "APP IS"
  echo "${app}"
  option=`echo "${app}" | /mnt/onboard/.adds/rmkit/bin/apps/simple | grep 'selected:' | sed 's/selected: //'`
  temp=`echo "${app}" | /mnt/onboard/.adds/rmkit/bin/apps/simple | grep 'input:' | sed 's/input: //'`
  if (${option} == "c2f") then
  	output=`/mnt/onboard/.adds/koreader/luajit -e "print((9/5) * tonumber(${temp}) + 32 + ' C')"`
  fi
  if (${option} == "f2c") then
  	output=`/mnt/onboard/.adds/koreader/luajit -e "print((5/9)*(tonumber(${temp}))-32 + ' F')"`
  fi
  sleep 0.1
done
OK, that one didn't actually work...

UPDATE : Now working!
https://www.mobileread.com/forums/sh...57&postcount=8

***



***BEST SOLUTION***

But why all that if you can just:

From:
https://koreader.rocks/user_guide/

Search:
https://github.com/search?q=koplugin&type=repositories
* Edit: on second thought, is unvetted github content becoming a security concern? (re malware found.)

Find:
https://github.com/zwim/calculator.koplugin
zwim/calculator.koplugin

$ wget https://github.com/zwim/calculator.k...ugin-1.2.0.zip

Install:
calculator.koplugin
A calculator plugin for KOReader.

Installation:
Go to https://github.com/zwim/calculator.koplugin/releases and download the desired koreader.plugin-x.x.x.zip and unpack it to koreader/plugins/calculator.koplugin.
Predefined physical constants, are in init.calc. You can autoload them (see settings menu). If you don't need them delete init.calc.

Usage:
You find the calculator in More tools/calculator additionally you can set a gesture (in the device submenu) to call it.


***

Last edited by elinkser; 02-15-2024 at 07:22 PM. Reason: rmkit script working
elinkser is offline   Reply With Quote