Created
July 12, 2012 11:13
-
-
Save alexciarlillo/3097496 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG=/tmp/switch_log | |
TMP=/tmp/switch_tmp | |
SWITCH_FILE=/sys/kernel/debug/vgaswitcheroo/switch | |
DIS_CHECK=DIS:+ | |
IGD_CHEClK=IGD:+ | |
NOW=`date` | |
case $1 in | |
sleep) | |
echo "--${NOW}--" >> $LOG | |
echo "Sleeping" >> $LOG | |
# check if DIS is active | |
grep -q $DIS_CHECK $SWITCH_FILE | |
if [ "$?" -eq "0" ]; then | |
echo "DIS active" >> $LOG | |
# record current state | |
echo "DIS:+" > $TMP | |
# activate IGD | |
echo "DIGD" > $SWITCH_FILE | |
# restart gdm - activates switch | |
/etc/rc.d/gdm restart | |
else | |
# record IGD state for wakeup | |
echo "IGD:+" > $TMP | |
fi | |
# assume we are on IGD already | |
# power on un-used (discrete) card (somehow this prevents issues) | |
echo "ON" > $SWITCH_FILE | |
;; | |
wake) | |
echo "--${NOW}--" >> $LOG | |
echo "Waking" >> $LOG | |
# check if DIS *was* active | |
grep -q $DIS_CHECK $TMP | |
if [ "$?" -eq "0" ]; then | |
echo "DIS *was* active. Re-enabling." >> $LOG | |
# activate DIS | |
echo "DDIS" > $SWITCH_FILE | |
# restart gdm - activates switch | |
/etc/rc.d/gdm restart | |
# power on IGD for brightness | |
echo "ON" > $SWITCH_FILE | |
else | |
echo "IGD *was* active. Turning off DIS for power saving." >> $LOG | |
echo "OFF" > $SWITCH_FILE | |
fi | |
;; | |
ac-on) | |
echo "--${NOW}--" >> $LOG | |
echo "AC power. Enable DIS" >> $LOG | |
echo "DDIS" > $SWITCH_FILE | |
if [ $2 != "boot" ]; then | |
/etc/rc.d/gdm restart | |
fi | |
echo "ON" > $SWITCH_FILE | |
;; | |
ac-off) | |
echo "--${NOW}--" >> $LOG | |
echo "Battery power. Enable IGD" >> $LOG | |
echo "DIGD" > $SWITCH_FILE | |
if [ $2 != "boot" ]; then | |
/etc/rc.d/gdm restart | |
fi | |
echo "OFF" > $SWITCH_FILE | |
;; | |
esac | |
# alway log switch state after running this | |
cat $SWITCH_FILE >> $LOG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment