Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
#! /usr/bin/python
# -*- coding: utf-8 -*-
################################################################################
# For ThinkPads with more than one battery this script can be useful to force #
# one desired battery to discharge. Therefore the primary battery has to be #
# defined. It will be discharged down to a certain threshold, specified in #
# percent. Thereby a certain battery can be protected from several charges. If #
# primary battery's capacity exceeds this threshold the one battery with the #
# highest remaining capacity will be discharged then. At low batteries this #
# leads to alternate the power source. In this way the risk of deep discharges #
# can be lowered. #
# !!! CAUTION - absolute no warranty !!! This is just a dirty hack and misuses #
# the 'foce_discharge' feature of ThinkPads 'tpsmapi' module. #
################################################################################
from glob import glob
from time import sleep
primary_bat = 'BAT0' # battery which will be discharged first
tsh = 15 # threshold for symmetric discharge
increment = 120 # every 120s capacities are checked
################################################################################
# below no changes should be necessary #
################################################################################
path = '/sys/devices/platform/smapi/'
batteries = {} # init dictionary for batteries
while 1: # infinite loop
# TODO: at least this infinite loop should become event orientated
# is the power supply connected
f = open( path+'/ac_connected')
ac_connected = bool( int( f.readline() ) )
f.close()
# determine batteries and its values
for bat_path in glob( path+'/BAT*' ):
# naming
bat_name = bat_path.rsplit('/',1)[1]
# status
f = open( bat_path+'/state' )
bat_state = f.readline().strip()
f.close()
if ( 'none' != bat_state ):
batteries[bat_name] = {'path':bat_path, 'state':bat_state }
# remaining capacity in percent
f = open( bat_path+'/remaining_percent' )
bat_remaining_percent = int( f.readline() )
f.close()
batteries[bat_name]['remaining_percent'] = bat_remaining_percent
# determine 'foce_discharge' status
f = open( bat_path+'/force_discharge' )
bat_force_discharge = bool( int( f.readline() ) )
f.close()
batteries[bat_name]['force_discharge'] = bat_force_discharge
# set 'force_discharge' flag if necessary
if ( ac_connected ): # on ac
# reset 'force_discharge'
# this structure collides with 'force_discharge's origin meaning
for bat in batteries.values():
if ( bat['force_discharge'] ):
f = open( bat['path']+'/force_discharge', 'w')
f.write('0')
f.close()
else: # on battery
if ( batteries[primary_bat]['remaining_percent'] > tsh ):
if ( batteries[primary_bat]['state'] != 'discharging' and \
batteries[primary_bat]['force_discharge'] == False ):
# force primary battery to discharge
f=open(batteries[primary_bat]['path']+'/force_discharge','w')
f.write('1')
f.close
else:
# determine battery with highest remaining capacity
bat = sorted( batteries.iteritems(), \
key = lambda (k,v): v['remaining_percent'], \
reverse = True )[0][1]
# below the threshold this leads to a symmetric discharge
# TODO: total remaining capacity shuld also be taken into account
if ( not bat['force_discharge'] ):
# force battery with highest capacity to discharge
f = open( bat['path']+'/force_discharge', 'w' )
f.write('1')
f.close
# pauses for 'increment' seconds
sleep( increment )
Wir verwenden essentielle Cookies, damit diese Website funktioniert, und optionale Cookies, um den Komfort bei der Nutzung zu verbessern.
Siehe weitere Informationen und konfiguriere deine Einstellungen






