@elinkser:
Quote:
Another cool feature of rmkit is the scriptable GUI with SAS, but I wasn't successful with this script, which is supposed to invoke luajit to convert temperature between Farenheit and Celsius:
|
i adjusted the code a bit:
Code:
#!/bin/ash
while true; do
app="
textinput 250 100 200 50 ${temp}
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 = ${result}]
"
echo "APP IS"
echo "${app}"
output=`echo "${app}" | /mnt/onboard/.adds/rmkit/bin/apps/simple`
echo "SELECTED: ${output}"
if (expr "${output}" : "input" > /dev/null); then
echo "CLICKED INPUT"
temp=`echo ${output} | sed 's/input:.*://'`
fi
if (expr "${output}" : ".*c2f" > /dev/null); then
echo "CLICKED C2F"
option="c2f"
result=`/mnt/onboard/.adds/koreader/luajit -e "print((9/5)*(tonumber(${temp}))+32, ' F')"`
fi
if (expr "${output}" : ".*f2c" > /dev/null); then
echo "CLICKED F2C"
option="f2c"
result=`/mnt/onboard/.adds/koreader/luajit -e "print((5/9)*(tonumber(${temp})-32), ' C')"`
fi
sleep 0.1
done
Quote:
Anything obvious I'm doing wrong?
|
it was not obvious! it took me about a half hour to re-write the script, it turns out that there's a couple things going on.
1) when I use usbnet and ssh in, I am put into NiLuJe's version of `ash` (oops), which supports more operations than the built in `ash` from busybox in /bin/
2) the formulas were slightly off - i adjusted them
3) when you finish typing a value into the textinput, simple exits and prints the selected value - this is why you had to do it twice: once for the textinput, once for the button being clicked. i re-arranged the logic so it is only one invocation of simple per loop
PS: take a look at the source of nao in the repo: that's a bash script that supports multiple scenes. I didn't rewrite this script into such a structured form, but we could possibly come up with a similar template to make it easier to write future apps (by creating functions for common operations). screenshots here:
https://rmkit.dev/apps/nao
---
i will re-visit the NickelMenu stubs in a few days (or sooner) and check them in.