How to add volume control in stand alone emulators

IMPORTANT!! BACK UP BEFORE COPYING ANY SYSTEM FILES!! If you don’t do this correctly, your device may not start up, and you will need to reflash your system!!

I’ve just uploaded my rc.local file, pre edited.

Copy it to the etc directory.

This is basically Step 2 of the readme file. I would however strongly recommend you use nano or another editor to edit the file yourself.

2.add reboot command shell

"sudo nano /etc/rc.local" open rc.local file and input this to the last line

nohup python /home/cpi/launcher/sys.py/backlight_hotkey.py &

IMPORTANT!
You WILL need permission attributes set to this:
-rwxr-xr-x
Change it using the command,

chmod 755 /etc/rc.local

Just for your information:
rwx,r-x,r-x = 755
rwx = 7, read, write, and execute
r-x = 5, read and execute
r-x = 5, read and execute

2.add reboot command shell

"sudo nano /etc/rc.local" open rc.local file and input this to the last line

nohup python /home/cpi/launcher/sys.py/backlight_hotkey.py &

The only other changes I’ve made are to backlight_hotkey.py, changing the direction of the brightness adjustment hotkey, and the incremental step size for volume. It was mentioned by another user, @Dowdheur, but not directly printed out.

import time
from evdev import InputDevice
from select import select
from tools.brightness_tool import BrightnessTool
import alsaaudio

m = alsaaudio.Mixer()
sound_volume=m.getvolume()[0]
# print("cur aound volume:%d",sound_volume)

dev = InputDevice('/dev/input/event1')

select_press=False
while True:
    select([dev], [], [])
    for event in dev.read():
        # print "code:%s value:%s" % (event.code, event.value)
        if (event.code==57 and event.value==1):
            select_press=True
            # print("sel press")
        elif(event.code==57 and event.value==0):
            select_press=False
        
        if(select_press==True and event.code==103 and event.value==1):
            brightnessTool = BrightnessTool()
            brightnessTool.Further()
            del brightnessTool
        elif(select_press==True and event.code==108 and event.value==1):
            brightnessTool = BrightnessTool()
            brightnessTool.StepBack()
            del brightnessTool
        elif(select_press==True and event.code==105 and event.value==1):
            sound_volume=sound_volume - 4
            if(sound_volume<0):
                sound_volume=0
            try:
                m = alsaaudio.Mixer()
                m.setvolume(sound_volume)
            except Exception,e:
                print(str(e))
        elif(select_press==True and event.code==106 and event.value==1):
            sound_volume=sound_volume + 4
            if(sound_volume>100):
                sound_volume=98

            try:
                m = alsaaudio.Mixer()
                m.setvolume(sound_volume)
            except Exception,e:
                print(str(e))

        
            


1 Like