#!/bin/bash
trap ctrl_c INT

function ctrl_c() {
    echo "** Trapped CTRL-C"
    # state 0xa [HDMI CEA (16) RGB lim 16:9], 1920x1080 @ 60.00Hz, progressive
    #/boot/config.txt:
    # #hdmi_safe=1
    # # uncomment if hdmi display is not detected and composite is being output
    # hdmi_force_hotplug=1
    # hdmi_group=1
    # hdmi_mode=16
    # #hdmi_drive=2
    # #config_hdmi_boost=4
    sudo tvservice -p
    sudo chvt 2                      # change to different virtual terminal
    sudo chvt 1                      # change back to the previous virtual terminal
    # need to do this automatically from saved tvservice output:
    fbset -g 1920 1080 1920 1080 32  # adjust the size of the framebuffer
    echo -n ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor > /dev/null
}

echo -n performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor > /dev/null
sudo tvservice --off
sudo ./gyrocks
sudo tvservice -p
sudo chvt 2                      # change to different virtual terminal
sudo chvt 1                      # change back to the previous virtual terminal
# need to do this automatically from saved tvservice output:
fbset -g 1920 1080 1920 1080 32  # adjust the size of the framebuffer
echo -n ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor > /dev/null
