|
2010-06-07
, 11:15
|
|
Posts: 288 |
Thanked: 113 times |
Joined on Dec 2009
@ Germany
|
#2
|
|
2010-06-07
, 11:56
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#3
|
Hi,
does any know how I can retrieve the information provided by the light meter, microphone and accelerometers?
Are there ready to use classes? D-BUS?
Any hints, examples are appreciated.
Thanks and kind regards
blubbi
# -*- coding: utf-8 -*- import os import dbus def funcAccel(): print "** Start Function - Accel Co-ords **" f = open("/sys/class/i2c-adapter/i2c-3/3-001d/coord", 'r') coords = [int(w) for w in f.readline().split()] f.close() print " ** Getting orientation**" b = os.popen('run-standalone.sh dbus-send --system --type=signal /com/nokia/mce/signal com.nokia.mce.signal.sig_device_orientation_ind').read() coords = str(coords) jaccel = str(coords) + str(b) return jaccel def funcBatchrg(): print "** Start Function - Battery Charge **" gl = os.popen('hal-device bme | awk \'/l.p/ {perc = $3}; /s_c/ {isch = $3} END if (isch == "false") {print perc" %"} else {print "Charging"}\'').read() gl = gl.strip() return gl def funcBatLastChrg(): print " ** Start Function - battery last charge**" gl = os.popen('hal-device bme | awk \'/g.la/ {print $3" mAh"}\'').read() return gl.strip() def funcBattcurr(): print "** Start Function - Battery Current **" gl = os.popen('hal-device bme | awk \'/g.c/ {print $3" mAh"}\'').read() gl = gl.strip() return gl def funcCamState(): print "** Start Function - Cam Shutter State **" gl = os.popen('cat /sys/devices/platform/gpio-switch/cam_shutter/state').read() gl = gl.strip() return gl def funcFMTrans(): print "** Start Function - FM Transmitter power level **" ge = os.popen('cat /sys/class/i2c-adapter/i2c-2/2-0063/power_level').read() ge = ge.strip() return ge def funcHeadphoneState(): print "** Start Function - Headphone State **" gl = os.popen('cat /sys/devices/platform/gpio-switch/headphone/state').read() gl = gl.strip() return gl def funcKeySlider(): print "** Start Function - Keyboard Slider State **" gl = os.popen('cat /sys/devices/platform/gpio-switch/slide/state').read() gl = gl.strip() return gl def funcProxState(): print " ** Start Function - proximity sensor state**" gl = os.popen('cat /sys/devices/platform/gpio-switch/proximity/state').read() gl = gl.strip() return gl def funcSysUptime(): print "** Start Function - system uptime**" ge = os.popen('uptime | sed -e \'s/.*p *//\' -e \'s/, l.*//\' -e \'s/ / /\'').read() return ge def funcCurrentCPUFreq(): print "** Start Function - CPU Frequency **" gl = os.popen('echo $((`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq`/1000)) MHz').read() gl = gl.strip() return gl def funcAppUsed(): print "** Start Function - App Used **" gl = os.popen('df /home | awk \'/ho/ {print $5}\'').read() gl = gl.strip() return gl def funcAppFree(): print "** Start Function - App Free **" gl = os.popen('df -h /home | awk \'/ho/ {print $4}\'').read() gl = gl.strip() return gl def funcBacklightAct(): print "** Start Function - Backlight Info **" gl = os.popen('cat /sys/class/backlight/acx565akm/brightness').read() gl = gl.strip() return gl def funcBacklightMax(): print "** Start Function - Backlight Info MAX **" gl = os.popen('cat /sys/class/backlight/acx565akm/max_brightness').read() gl = gl.strip() return gl def funcKernelInfo(): print "** Start Function - Kernel Core Info **" gl = os.popen('cat /sys/kernel/vmcoreinfo').read() return gl.strip() def funcBootCount(): print "** Start Function - boot count**" gd = os.popen('cat /var/lib/dsme/boot_count').read() gd = gd.strip() return gd def funcBootReason(): print "** Start Function - Boot Reason**" gl = os.popen('cat /proc/bootreason').read() gl = gl.strip() return gl def funcMMCState(): print "** Start Function - MMC Cover/latch **" gl = os.popen('cat /sys/class/mmc_host/mmc0/cover_switch').read() gl = gl.strip() return gl def funcMemoryCUsed(): print "** Start Function - Memory Card Used **" gl = os.popen('df /media/mmc1 | awk \'/mm/ {print $5}\'').read() gl = gl.strip() return gl def funcMemoryCFree(): print "** Start Function - Memory Card Free **" gl = os.popen('df -h /media/mmc1 | awk \'/mm/ {print $4}\'').read() gl = gl.strip() return gl def funcMyDocsUsed(): print "** Start Function - MyDocs % Used **" gl = os.popen('df /home/user/MyDocs | awk \'/My/ {print $5}\'').read() gl = gl.strip() return gl def funcMyDocsFree(): print "** Start Function - myDocs MB Free **" gl = os.popen('df -h /home/user/MyDocs | awk \'/My/ {print $4}\'').read() gl = gl.strip() return gl def funcRootUsed(): print "** Start Function - rootfs % used **" gl = os.popen('df | awk \'$1 == "rootfs" {print $5}\'').read() gl = gl.strip() return gl def funcRootFree(): print "** Start Function - rootfs free MB **" gl = os.popen('df -h | awk \'$1 == "rootfs" {print $4}\'').read() gl = gl.strip() return gl def funcSysLoad(): print "** Start Function - load from uptime **" ge = os.popen('uptime | sed \'s/.*e: //\'').read() return ge def funcDevOri(): print "** Start Function - Device Orientation **" bus = dbus.SystemBus() accel = bus.get_object('com.nokia.mce','/com/nokia/mce/request','com.nokia.mce.request') orientation , stand , face , x , y , z = accel.get_device_orientation() return orientation def funcCPUfreq(): print "** Start Function - CPU Frequency File **" fh = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies","r") igot = fh.readlines() print "** Adding CPUQ Frequencies **" aa = "" counter = 0 for line in igot: s = line.split() for words in s: counter = counter +1 if counter == 5: aa = str(aa) +"\n \t\t\t\t" if counter == 9: aa = str(aa) +"\n \t\t\t\t" if counter == 13: aa = str(aa) +"\n \t\t\t\t" aa = str(aa) + str((int(words)/1000)) + "MHz, " aa = aa.strip()[:-1] return aa def funcProcInfo(): print "** Start Function - Processor Information **" ga = os.popen('cat /proc/cpuinfo | grep Processor').read() return ga.strip()[11:] def funcN900Board(): print "** Start Function - N900 Board Information **" gb = os.popen('cat /proc/cpuinfo | grep Hardware').read() return gb.strip()[11:] def funcBoardVer(): print "** Start Function - Board Version **" gj = os.popen('cat /proc/cpuinfo | grep Revision').read() return gj.strip()[11:] def funcSysLocale(): print "** Start Function - System Locale **" gc = os.popen('locale | grep LANG').read() return gc.strip()[5:] def funcHostName(): print "** Start Function - Device Hostname **" ga = os.popen('cat /etc/hostname').read() return ga.strip() def funcIMEI(): print "** Start Function - Device IMEI **" b = os.popen('run-standalone.sh dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei').read() b = str(b) b = b.strip() b = str(b)[-27:] b = b.strip() b = str(b)[:-12] return b def funcInternalIP(): print "** Start Function - Internal IP **" ga = os.popen('/sbin/ifconfig | awk \'/Bc/ {print $2}\' | cut -c6-').read() return ga.strip() def funcWifiLinkQ(): print "** Start Function - Wireless Link Quality **" ga = os.popen('cat /proc/net/wireless | awk \'/0/ {print $3}\' | awk -F. \'/./ {print $1" %"}\'').read() return ga.strip() def funcWifiRSSI(): print "** Start Function - Wireless RSSI **" ga = os.popen('cat /proc/net/wireless | awk \'/0/ {print $4" dBm"}\'').read() return ga.strip() def funcWifiNoise(): print "** Start Function - Wireless Noise **" ga = os.popen('cat /proc/net/wireless | awk \'/0/ {print $5}\' | awk -F. \'/./ {print $1" dBm"}\'').read() return ga.strip() def funcMacAddress(): print "** Start Function - MAC Address **" gl = os.popen('cat /sys/class/ieee80211/phy0/macaddress').read() return gl.strip() def funcBluetooth(): print "** Start Function - Bluetooth Name **" gl = os.popen('grep \'^Name =\' /etc/bluetooth/main.conf').read() return gl.strip()[7:] def funcBluetoothMAC(): print "** Start Function - Bluetooth MAC**" gl = os.popen('/usr/sbin/hciconfig hci0 | grep BD').read() s = gl.split(" ") return s[2].strip() def funcCPUMinMax(): print "** Start Function - Bluetooth MAC**" a = os.popen('cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq').read() a = a.strip() a = int(a) / 1000 b = os.popen('cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq').read() b = b.strip() b = int(b) / 1000 c = str(b) + "MHz" + " / " + str(a) + "MHz" return c.strip()
The Following 3 Users Say Thank You to noobmonkey For This Useful Post: | ||
|
2010-06-07
, 12:08
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#4
|
Hi,
does any know how I can retrieve the information provided by the light meter, microphone and accelerometers?
|
2010-06-07
, 12:17
|
|
Posts: 288 |
Thanked: 113 times |
Joined on Dec 2009
@ Germany
|
#5
|
def funcProxState(): print " ** Start Function - proximity sensor state**" gl = open('/sys/devices/platform/gpio-switch/proximity/state', 'r').read().strip() return gl
|
2010-06-07
, 12:18
|
Posts: 1,042 |
Thanked: 430 times |
Joined on May 2010
|
#6
|
from ctypes import * import os import sys import time from math import atan2 from pprint import pprint xlib = cdll.LoadLibrary("libX11.so.6") rr = cdll.LoadLibrary("libXrandr.so.2") def out_rotate(): f = open("/sys/class/i2c-adapter/i2c-3/3-001d/coord", 'r' ) cdinate = [int(w) for w in f.readline().split()] f.close() return cdinate print out_rotate() time.sleep(1)
The Following 3 Users Say Thank You to Radicalz38 For This Useful Post: | ||
|
2010-06-07
, 12:23
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#7
|
This answers most. Thanks a lot.
But why call external tools to read the "files"
why not simply use
There is no need to make system calls to grep, cat, awk and others in python. Python has excellent string handling capabilities.Code:def funcProxState(): print " ** Start Function - proximity sensor state**" gl = open('/sys/devices/platform/gpio-switch/proximity/state', 'r').read().strip() return gl
Cheers
blubbi
|
2010-06-07
, 12:24
|
|
Posts: 288 |
Thanked: 113 times |
Joined on Dec 2009
@ Germany
|
#8
|
Forgot to add - with the microphone part i'm struggling on that one.
Looking into and waiting for qtmultimedia/mobility
The Following 2 Users Say Thank You to blubbi For This Useful Post: | ||
|
2010-06-07
, 12:29
|
|
Posts: 288 |
Thanked: 113 times |
Joined on Dec 2009
@ Germany
|
#9
|
Because........ erm..... errr..... it worked, and i stuck with it hehehe
(Very new to python, linux and QT, so the whole thing is a learning curve!
The Following User Says Thank You to blubbi For This Useful Post: | ||
|
2010-06-07
, 12:37
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#10
|
does any know how I can retrieve the information provided by the light meter, microphone and accelerometers?
Are there ready to use classes? D-BUS?
Any hints, examples are appreciated.
Thanks and kind regards
blubbi
My website:
- olausson.de
- gallery.olausson.de
My Applications: