From ee4fec683238373f663938374e3e3d84eb23424d Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 6 Feb 2011 20:09:09 +1100 Subject: [PATCH] battery: add flight-mode setting. Signed-off-by: NeilBrown --- battery/battery.py | 47 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/battery/battery.py b/battery/battery.py index 2b8f6cc..9f236ff 100755 --- a/battery/battery.py +++ b/battery/battery.py @@ -61,11 +61,22 @@ def setfile(icon): def update(): global icon global configwindow + + to = gobject.timeout_add(30*1000, update) + + if file_num(usb_curlimfile) == 100: + try: + f = open(usb_curlimfile, "w") + f.write("500") + f.close() + except: + pass if configwindow: configwindow.update_labels() else: setfile(icon) - to = gobject.timeout_add(30*1000, update) + + return False ################################################################## @@ -124,6 +135,7 @@ class BatteryConfig(gtk.Window): self.addlabel('Chg Curr Lim', fd) self.addlabel('TimeToFull', fd) self.addlabel('TimeToEmpty', fd) + self.addlabel('FlightMode', fd) ev.connect('button_press_event', self.update_labels) ev.add_events( gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK) @@ -140,6 +152,10 @@ class BatteryConfig(gtk.Window): self.add_button(h, fd, "100mA", self.set_curr, 100) self.add_button(h, fd, "500mA", self.set_curr, 500) self.add_button(h, fd, "1 Amp", self.set_curr, 1000) + h = gtk.HBox(); v.pack_end(h, expand=False) + h.set_homogeneous(True); h.set_size_request(-1,80) + self.add_button(h, fd, "FlightMode", self.set_flight, True) + self.add_button(h, fd, "Normal", self.set_flight, False) v.show_all() @@ -171,6 +187,34 @@ class BatteryConfig(gtk.Window): except: pass + def set_flight(self, widget, set): + if set: + try: + f = open("/var/lib/misc/flightmode/active", "w"); + f.write("Y") + f.close(f) + except: + pass + else: + try: + f = open("/var/lib/misc/flightmode/active", "w"); + f.close(f) + except: + pass + + def get_flight(self): + try: + f = open("/var/lib/misc/flightmode/active", "r") + l = f.read(1) + f.close() + except: + l = "" + if len(l) == 0: + flight="Disabled" + else: + flight="Enabled" + return flight + def suspend(self, widget): os.system("apm -s") @@ -187,6 +231,7 @@ class BatteryConfig(gtk.Window): self.labels['Chg Curr Lim'].set_text(file_text(chg_curlimfile)) self.labels['TimeToFull'].set_text(to_time(file_num(fullfile))) self.labels['TimeToEmpty'].set_text(to_time(file_num(emptyfile))) + self.labels['FlightMode'].set_text(self.get_flight()) global icon setfile(icon) -- 2.39.5