4
Keep button backlights on [root]

  1. elanglois
    Lollipop Mar 22, 2017

    elanglois , Mar 22, 2017 :
    OK. You may think that the button backlight is really stupid if it only turns on when you touch the buttons. If you can't see the buttons to touch them how do you get the light on, and once you touch it, you don't need it anymore!

    The following script will keep the backlight on for as long as you are touching the buttons or your touchscreen with an off delay of about 4s. You can configure this in 2s increments. To use it, turn off the backlight in Settings so the OS doesn't try to control the backlights then run the script as root. You can have it run at boot with init.d (I use a Magisk module to provide init.d support). It's a bit of a hack, but it's pretty harmless, and while its not terribly efficient because it polls rather than using events, and runs in a shell, not C, the poll frequency is set very low.

    Here is the script ...
    Code:
    #!/system/bin/sh
    
    TOUCH=/dev/input/event3
    BUTTONS=/dev/input/event4
    LEDS=/sys/class/leds/button-backlight/brightness
    LVL=1
    POLLTIME=2
    ONTIME=2
    FLAG=/mnt/.flag
    
    #- backlight stays on for seconds equal to 2 x ontime
    
    touch $FLAG
    echo '3' >$FLAG
    
    PollDevice() {
        DEV=$1
        while [ true ]; do
          sleep $POLLTIME
          getevent -c 1 $DEV >/dev/null
          echo "$LVL" >>$LEDS
          echo "2" >$FLAG
        done
    }
    
    CleanUp() {
        echo -e "Cleanup\n"
        kill $TSPID &
        kill $BTPID &
        rm $FLAG
        sleep 1
        echo '0' >>$LEDS
        exit
    }
    
    trap "CleanUp" 1 2 3 6 15
    
    #- Turn on immediately
    echo "$LVL" >>$LEDS
    
    #- Reset flag and turn on LEDs for touchscreen
    (
        PollDevice $TOUCH
    ) &
    TSPID=$!
     
    #- Reset flag and turn on LEDs for buttons
    (
        PollDevice $BUTTONS
    ) &
    BTPID=$!
    
    #- Decrement flag and turn off LEDs at 0
    sleep $ONTIME
    while [ true ]; do
        sleep $ONTIME
        read VFLAG <$FLAG
        if [ "$VFLAG" -eq 0 ]; then
            echo "0" >>$LEDS
        else
            echo $(( $VFLAG - 1)) >$FLAG
        fi
    done
    
     

    #1
  2. elanglois
    Lollipop Apr 7, 2017

    elanglois , Apr 7, 2017 :
    OK, here is a new version that ups the default Max brightness to over 400, and also adds a "High Brightness Mode" hack. Add a file called /sdcard/maxbrite and when you touch the screen it will tell the kernel you want the blazing "direct sunlight" mode.

    I use tasker to write the file when the light sensor is between 80 and 100%. The exit task erases the file. I combine this with automatic brightness and while the difference isn't much, every little bit helps in direct light.

    Script follows .... Again, use init.d to run at boot (via Magisk for me, but if you need help using it, let me know).

    Note that there is a Widget on Play that will enable High Brightness Mode for 99 cents, but if I can do it myself for free and not have to touch a widget ....
     

    #2
  3. elanglois
    Lollipop Apr 7, 2017

    elanglois , Apr 7, 2017 :
    #!/system/bin/sh

    TOUCH=/dev/input/event3
    BUTTONS=/dev/input/event4
    LEDS=/sys/class/leds/button-backlight/brightness
    HBM=/sys/devices/virtual/graphics/fb0/hbm
    LVL=1
    POLLTIME=2
    ONTIME=2
    FLAG=/mnt/.flag

    #- backlight stays on for seconds equal to 2 x ontime

    touch $FLAG
    echo '3' >$FLAG
    echo '1' >$HBM

    PollDevice() {
    DEV=$1
    while [ true ]; do
    sleep $POLLTIME
    getevent -c 1 $DEV >/dev/null
    if [ -f /sdcard/maxbrite ]; then
    echo "2" >$HBM
    fi
    echo "$LVL" >>$LEDS
    echo "2" >$FLAG
    done
    }

    CleanUp() {
    echo -e "Cleanup\n"
    kill $TSPID &
    kill $BTPID &
    rm $FLAG
    sleep 1
    echo '0' >>$LEDS
    exit
    }

    trap "CleanUp" 1 2 3 6 15

    #- Turn on immediately
    echo "$LVL" >>$LEDS

    #- Reset flag and turn on LEDs for touchscreen
    (
    PollDevice $TOUCH
    ) &
    TSPID=$!

    #- Reset flag and turn on LEDs for buttons
    (
    PollDevice $BUTTONS
    ) &
    BTPID=$!

    #- Decrement flag and turn off LEDs at 0
    sleep $ONTIME
    while [ true ]; do
    sleep $ONTIME
    read VFLAG <$FLAG
    if [ "$VFLAG" -eq 0 ]; then
    echo "0" >>$LEDS
    else
    echo $(( $VFLAG - 1)) >$FLAG
    fi
    if [ ! -f /sdcard/maxbrite ]; then
    echo "1" >$HBM
    fi
    done
     

    #3
  4. freddyabbes
    Honeycomb Apr 8, 2017


    #4
  5. elanglois
    Lollipop Apr 8, 2017

    elanglois , Apr 8, 2017 :
    yeah, I think OnePlus dropped the ball on both of these issues. The HBM doesn't help sunlight readability much, but every little bit helps. The automatic brightness doesn't scale right unless you set the screen Max brightness higher and the most common complaint about the screen is brightness. Then the button backlights are useless since they only light up AFTER you found them! You can make them brighter than what I have set. I may crank up the brightness of the buttons when HBM is set.

    I think the default low brightness should only be used in night mode.
     

    #5
  6. freddyabbes
    Honeycomb Apr 8, 2017

    freddyabbes , Apr 8, 2017 :
    Haha yeah, Great job man!
     

    #6
  7. freddyabbes
    Honeycomb Apr 8, 2017

    freddyabbes , Apr 8, 2017 :
    @elanglois Maybe you could help me out on my thread I just created (coz u seem to be pretty smart haha..) I have this "problem" with my Open Beta 13 build.. When I check system updates - log files, It's showing me log files from the official OOS 4.1.1 OTA update.. since this is my first time in beta, I'm pretty worried about it, cuz I don't know if I'll just receive new beta OTA's with this issue now..
     

    #7
  8. elanglois
    Lollipop Apr 8, 2017

    elanglois , Apr 8, 2017 :
    Likely someone just included the wrong Changelog. The Beta updater should have the URL of the beta channel. I think its embedded, so once you go beta, you stay beta.

    I unlock and root and run Freedom OS (also same OpenBeta if you use CE version; I do), so I tend to either wait on Freedom or stick the latest download from OnePlus into a Freedom archive and flash it that way.
     

    #8
  9. freddyabbes
    Honeycomb Apr 8, 2017

    freddyabbes , Apr 8, 2017 :
    hmm.. but do you think I still receive new BETA updates the way my phone is now?
     

    #9
  10. elanglois
    Lollipop Apr 9, 2017

    elanglois , Apr 9, 2017 :
    you should, but if you are using twrp or have touched boot or system in any way then you should only apply full updates, never an incremental
     

    #10
  11. YoruTen
    Cupcake Sep 30, 2017


    #11
  12. elanglois
    Lollipop Sep 30, 2017

    elanglois , Sep 30, 2017 :
    Yes. It should. There is a slight chance that some of the device numbers have changed, but if so, let me know that it doesn't work and I can show you how to figure out the right device names. It won't hurt anything
     

    #12
  13. YoruTen
    Cupcake Sep 30, 2017

    YoruTen , Sep 30, 2017 :
    I've rooted my device, but I'm a bit unsure of the best way to run scripts on android. Been using rooted devices but mostly flashing custom roms, not doing to much tweeking.
    Think I understand the tasker approach of creating a file. But how to run a script and which module to use in magisk and how to set it up is not clear yet.
     

    #13
  14. elanglois
    Lollipop Sep 30, 2017

    elanglois , Sep 30, 2017 :
    Couple ways. You can open a terminal and run the script like you would on a PC (or run it from adb) or use a file manager (I use FX from Nextapp) to run the script as root. Once tested, install the init.d module for Magisk (are picture) and copy the file into the /Magisk/init/init.d directory with a root file manager (again, FX does a great job). It will run every boot.


    1506770268239.jpg
     

    #14
  15. Buntaci
    Donut Nov 20, 2017


    #15
  16. elanglois
    Lollipop Nov 20, 2017

    elanglois , Nov 20, 2017 :
    What is sc? And it doesn't end. If it ends, it won't work. It needs to work to then the lights on and off!
     

    #16
  17. Buntaci
    Donut Nov 20, 2017


    #17
  18. elanglois
    Lollipop Nov 20, 2017

    elanglois , Nov 20, 2017 :
    it works as his on a 3 I can't help you get it working on a 5 since I don't have access to one
     

    #18