How to use System Timer to run a task Periodically on my Redmi Note 5 pro [ROOTED, Busybox installed Phone]

Thread Starter

Vikram50517

Joined Jan 4, 2020
81
Hello y'all , my objective is to periodically switch on and switch off my flashlight by modifying the value of brightness file whose location is sys/class/leds/flashlight/brightness. Iam accessing the file as root user (Else, the Permission is denied if iam a non-root user!) . Let me attach my shell script below,

Script :

#!/system/bin/sh
for i in '0', '1', '1', '0', '0', '0', '1', '1', '0', '1', '1', '0', '1', '0', '0', '0', '0', '1', '1', '0', '1', '1', '1', '1', '0', '1', '1', '0', '0', '0', '1', '1', '0', '1', '1', '0', '1', '0', '1', '1', '0', '1', '1', '0', '0', '0', '0', '1', '0', '1', '1', '0', '1', '1', '0', '0', '0', '1', '1', '0', '1', '0', '0', '1', '0', '1', '1', '0', '1', '1', '1', '0', '0', '1', '1', '0', '0', '1', '1', '1', '0', '1', '1', '0', '0', '0', '0', '1', '0', '1', '1', '0', '1', '1', '0', '1'

do
if [ $i = '0', ]; then echo "100" > ~/sys/class/leds/flashlight/brightness
echo "0" > ~/sys/class/leds/flashlight/brightness; fi
if [ $i = '1', ]; then echo "100" > ~/sys/class/leds/flashlight/brightness
sleep 0.005
echo "0" > ~/sys/class/leds/flashlight/brightness; fi
done




So basically my flashlight dances according to the pattern 0 1 1 0...... and so on, the problem is when i use sleep to introduce a 5 ms delay , the actual delay varies from 5 to 15 ms, which is terrible, so is there a way where i can use the system timer to stabilize my delay, such that the delay will be precise!
 
Top