teste das mal in der console.
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# improved and completed by PiModules Version 1.0 29.08.2015
# picoStatus-v3.py by KTB is based on upisStatus.py by Kyriakos Naziris
# Kyriakos Naziris / University of Portsmouth / kyriakos@naziris.co.uk
import sys
import os
# import xbmc
import smbus
import time
import datetime
# You can install psutil using: sudo pip install psutil
# import psutil
def set_kodi_prop(property, value, id=10000):
xbmc.executebuiltin('SetProperty(%s,%s,%s)' % (property, value, id))
def year():
return i2c.read_byte_data(0x6A, 0x06)[1][2:]
def month():
return i2c.read_byte_data(0x6A, 0x05)[1][2:]
def day():
return i2c.read_byte_data(0x6A, 0x04)[1][2:]
def day_of_week():
days_of_the_week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
dow = i2c.read_byte_data(0x6A, 0x03)
return days_of_the_week[int(dow[1][3:]) - 1]
def hour():
return i2c.read_byte_data(0x6A, 0x02)[1][2:]
def minute():
return i2c.read_byte_data(0x6A, 0x01)[1][2:]
def seconds():
return i2c.read_byte_data(0x6A, 0x00)[1][2:]
def ccf():
return i2c.read_byte_data(0x6A, 0x07)[1][2:]
def pwr_mode():
data = i2c.read_byte_data(0x69, 0x00)
data = data & ~(1 << 7)
if (data == 1):
return "RPi"
elif (data == 2):
return "BAT"
else:
return "ERR"
def bat_level_2():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x01)
data = format(data, "02x")
return (float(data) / 100)
def bat_level_1():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x02)
data = format(data, "02x")
return (float(data) / 100)
def rpi_level_2():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x03)
data = format(data, "02x")
return (float(data) / 100)
def rpi_level_1():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x04)
data = format(data, "02x")
return (float(data) / 100)
def ad1_read():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x05)
data = format(data, "02x")
return (float(data) / 100)
def ad2_read():
time.sleep(0.1)
data = i2c.read_word_data(0x69, 0x07)
data = format(data, "02x")
return (float(data) / 100)
def temp_celsius():
return i2c.read_word_data(0x69, 0x12)
def sot23_temp():
time.sleep(0.1)
data = i2c.read_byte_data(0x69, 0x0C)
data = format(data, "02x")
return data
def to92_temp():
time.sleep(0.1)
data = i2c.read_byte_data(0x69, 0x0d)
data = format(data, "02x")
return data
def fw_version():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x00)
data = format(data, "02x")
return data
def error_code():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x01)
data = format(data, "02x")
return data
def rpi_serror_2():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x02)
data = format(data, "02x")
return data
def rpi_serror_1():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x03)
data = format(data, "02x")
return data
def bat_serror_2():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x04)
data = format(data, "02x")
return data
def bat_serror_1():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x05)
data = format(data, "02x")
return data
def tmp_serror_2():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x07)
data = format(data, "02x")
return data
def tmp_serror_1():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x06)
data = format(data, "02x")
return data
def sta_counter():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x08)
data = format(data, "02x")
return data
def fssd_batime():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x09)
data = format(data, "02x")
return data
def lprsta():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x10)
data = format(data, "02x")
return data
def btto():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x11)
data = format(data, "02x")
return data
def led_blue():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x12)
data = format(data, "02x")
return data
def led_red():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x13)
data = format(data, "02x")
return data
def buzmode():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x14)
data = format(data, "02x")
return data
def fanmode():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x15)
data = format(data, "02x")
return data
def fanspeed():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x16)
data = format(data, "02x")
return data
def picoxbmc():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x23)
data = format(data, "02x")
return data
def fssd_tout():
time.sleep(0.1)
data = i2c.read_byte_data(0x6b, 0x23)
data = format(data, "02x")
return data
def main():
status = ['OFF', 'ON']
buz_fan_modes = ['Disabled', 'Enabled', 'Automatic']
fan_speeds = ['0', '100', '25', '50', '75']
print " "
print " pico status V1.0"
print "***********************************"
print " ", "UPS PIco Firmware:", fw_version()
print " ", "Powering Mode:", pwr_mode()
print " ", "BAT Volatge:", bat_level(), "V"
print " ", "RPi Voltage:", rpi_level(), "V"
print " ", "SOT23 Temperature:", sot23_temp(), "C"
print " ", "TO-92 Temperature:", to92_temp(), "C"
print " ", "A/D1 Voltage:", ad1_read(), "V"
print " ", "A/D2 Voltage:", ad2_read(), "V"
print "***********************************"
print " "
print "--- RTC data ---"
print year() + "-" + month() + "-" + day() + " " + day_of_week() + " " + hour() + ":" + minute() + ":" + seconds() + " /" + ccf()
print "--- Status registers --- "
print "Mode\t\tBat_lvl\t\tRPi_lvl\t\tTemp"
print '%s \t\t %s \t\t %s \t\t %s' % (pwr_mode(), bat_level_1(), rpi_level_2(), temp_celsius())
print "--- Status commands ---"
print "Firmware: %s" % fw_version()
print "Error code: %s" % '{0:08b}'.format(int(error_code()[1][2:]))
print "rpi_serror: %s" % rpi_serror_1()[1][3:] + "." + rpi_serror_2()[1][2:] + " V"
print "bat_serror: %s" % bat_serror_1()[1][3:] + "." + bat_serror_2()[1][2:] + " V"
print "tmp_serror: %s" % tmp_serror_1()[1][2:] + "." + tmp_serror_2()[1][2:] + " " + unichr(176) + "C"
print "Still Alive Timeout Counter: %d s (255=disabled)" % int(sta_counter()[1], 16)
print "Battery Running Time: %d s (255=disabled)" % int(fssd_batime()[1], 16)
print "Low Power Restart Time: %d s" % int(lprsta()[1], 16)
print "Battery Powering Testing Timeout: %d s" % int(btto()[1], 16)
print "led_blue: %s" % status[int(led_blue()[1][3:])]
print "led_red: %s" % status[int(led_red()[1][3:])]
print "Integrated Buzzer Mode: %s" % buz_fan_modes[int(buzmode()[1][3:])]
print "Integrated Fan Mode: %s" % buz_fan_modes[int(fanmode()[1][3:])]
print "Integrated Fan Speed: %s %%" % fan_speeds[int(fanspeed()[1][3:])]
print "XBMC Mode: %s" % status[int(picoxbmc()[1][3:])]
print "FSSD Timeout: %d s" % int(fssd_tout()[1], 16)
i2c = smbus.SMBus(1)
if __name__ == '__main__':
main()