Alternative suspend without ousaged
authorEnrico Zini <enrico@enricozini.org>
Fri, 2 Oct 2009 14:51:40 +0000 (15:51 +0100)
committerEnrico Zini <enrico@enricozini.org>
Fri, 2 Oct 2009 14:51:40 +0000 (15:51 +0100)
src/app_power.vala

index 740c3803946201a8b7fe25ad7c5d83e1bc01afea..ad1f2f1b07c6f9782f15e4e4ca85a639bf1b0d45 100644 (file)
@@ -33,6 +33,7 @@ static long timediff(Posix.timeval* a, Posix.timeval* b)
 public class Power : zavai.Resource, Object
 {
        public dynamic DBus.Object usage;
+       public dynamic DBus.Object gsm_device;
        public bool screen_locked;
        private int screen_lock_fd;
        // Timestamp of the past power button pressed even (0 if the button has
@@ -63,6 +64,10 @@ public class Power : zavai.Resource, Object
                        "org.freesmartphone.ousaged",
                        "/org/freesmartphone/Usage",
                        "org.freesmartphone.Usage");
+               gsm_device = zavai.registry.sbus.get_object(
+                       "org.freesmartphone.ogsmd",
+                       "/org/freesmartphone/GSM/Device",
+                       "org.freesmartphone.Resource");
 
                zavai.input.power_button.power_button += on_power_button;
                zavai.input.power_button.request("zavai.ui.powerbutton.power");
@@ -78,10 +83,39 @@ public class Power : zavai.Resource, Object
 
        public void do_suspend()
        {
-               try {
-                       usage.Suspend();
-               } catch (Error e) {
-                       zavai.log.error("Suspending phone: " + e.message);
+               bool done = false;
+               if (!done)
+               {
+                       try {
+                               usage.Suspend();
+                               done = true;
+                       } catch (Error e) {
+                               zavai.log.error("Suspending phone with ousaged: " + e.message);
+                       }
+               }
+               if (!done)
+               {
+                       // From http://lindi.iki.fi/lindi/openmoko/susp
+                       try {
+                               gsm_device.Suspend();
+                       } catch (Error e) {
+                               zavai.log.error("Cannot tell GSM to suspend (but never mind): " + e.message);
+                       }
+                       // amixer -q -d sset "Amp Spk" mute
+                       // sync;sync;sync
+                       // echo 0 | sudo tee /proc/sysrq-trigger
+                       FileStream state = FileStream.open("/sys/power/state", "w");
+                       if (state != null)
+                       {
+                               state.puts("mem\n");
+                       }
+                       // amixer -q -d sset "Amp Spk" unmute
+                       try {
+                               gsm_device.Resume();
+                       } catch (Error e) {
+                               zavai.log.error("Cannot tell GSM to resume (but never mind): " + e.message);
+                       }
+                       done = true;
                }
        }
        public void do_shutdown()
@@ -252,7 +286,6 @@ public class BatteryIcon : Gtk.StatusIcon
        protected void update_icon()
        {
                string name = zavai.config.icondir + "/battery/";
-               bool charging = false;
                Dkp.DeviceState state = (Dkp.DeviceState)battery.state;
 
 stderr.printf("New battery status: %s\n", Dkp.Device.state_to_text(state));
@@ -360,7 +393,6 @@ public class Backlight: zavai.Service
        // Turn the backlight on and then let it fade off
        public void wiggle()
        {
-               // There must be a better method
                try {
                        zavai.app.run_script(zavai.config.homedir + "/display wiggle");
                } catch (Error e) {