|
| 1 | +#!/usr/bin/python3 |
| 2 | +# -*- python -*- |
| 3 | +# Test N900 phone |
| 4 | + |
| 5 | +import sys |
| 6 | +sys.path += [ "/usr/share/unicsy/lib" ] |
| 7 | + |
| 8 | +import dbus |
| 9 | +import dbus.mainloop.glib |
| 10 | +import os |
| 11 | +import time |
| 12 | +from hardware import * |
| 13 | + |
| 14 | +class _Getch: |
| 15 | + """Gets a single character from standard input. Does not echo to the |
| 16 | +screen.""" |
| 17 | + def __init__(self): |
| 18 | + self.impl = _GetchUnix() |
| 19 | + |
| 20 | + def __call__(self): return self.impl() |
| 21 | + |
| 22 | + |
| 23 | +class _GetchUnix: |
| 24 | + def __init__(self): |
| 25 | + import tty, sys |
| 26 | + |
| 27 | + def __call__(self): |
| 28 | + import sys, tty, termios |
| 29 | + fd = sys.stdin.fileno() |
| 30 | + old_settings = termios.tcgetattr(fd) |
| 31 | + try: |
| 32 | + tty.setraw(sys.stdin.fileno()) |
| 33 | + ch = sys.stdin.read(1) |
| 34 | + finally: |
| 35 | + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) |
| 36 | + return ch |
| 37 | + |
| 38 | +getch = _Getch() |
| 39 | + |
| 40 | +class Suspend(Test): |
| 41 | + hotkey = "s" |
| 42 | + name = "Suspend" |
| 43 | + |
| 44 | + def run(m): |
| 45 | + os.system("echo mem > /sys/power/state") |
| 46 | + |
| 47 | +class GPS(Test): |
| 48 | + hotkey = "g" |
| 49 | + name = "GPS" |
| 50 | + |
| 51 | + def run(m): |
| 52 | + os.system("echo ofono must be running and modem connected for this.") |
| 53 | + os.system("sudo ./gps3 -d") |
| 54 | + |
| 55 | +class Bluetooth(Test): |
| 56 | + hotkey = "e" |
| 57 | + name = "bluEtooth" |
| 58 | + |
| 59 | + def run(m): |
| 60 | + #os.system("sudo insmod /my/modules/nokia_h4p.ko") |
| 61 | + os.system("sudo /my/bluez-5.26/tools/btmgmt public-addr 01:02:03:04:05:06") |
| 62 | + os.system("sudo hciconfig hci0 up") |
| 63 | + os.system("sudo hcitool inq") |
| 64 | + os.system("sudo hciconfig hci0 down") |
| 65 | + |
| 66 | +class WIFI(Test): |
| 67 | + hotkey = "w" |
| 68 | + name = "WIFI" |
| 69 | + |
| 70 | + def run(m): |
| 71 | + sy("ping -c 5 10.0.0.6") |
| 72 | + |
| 73 | +class Autosleep(Test): |
| 74 | + hotkey = "u" |
| 75 | + name = "aUtosleep" |
| 76 | + |
| 77 | + def handle_uart(m, path, on): |
| 78 | + if not os.path.exists(path): |
| 79 | + print("Skipping", path); |
| 80 | + return |
| 81 | + m.write_root(path+"device/power/autosuspend_delay_ms", "3000") |
| 82 | + m.write_root(path+"power/wakeup", "enabled") |
| 83 | + m.write_root(path+"power/control", "auto") |
| 84 | + |
| 85 | + def sleep_on(m, on): |
| 86 | + for i in [ 0, 1, 2, 3 ]: |
| 87 | + m.handle_uart( "/sys/class/tty/ttyO%d/" % i, on ) |
| 88 | + |
| 89 | + def run(m): |
| 90 | + sy("sudo mount /dev/zero -t debugfs /sys/kernel/debug/") |
| 91 | + m.sleep_on(True) |
| 92 | + |
| 93 | + sy("killall mond") |
| 94 | + sy("./mond -s &") |
| 95 | + time.sleep(1) |
| 96 | + sy("killall mond") |
| 97 | + |
| 98 | + twl_test = "/sys/devices/platform/68000000.ocp/48070000.i2c/i2c-1/1-0048/48070000.i2c:twl@48:twl4030-usb/test" |
| 99 | + debug_brightness = "/sys/class/leds/debug::sleep/brightness" |
| 100 | + |
| 101 | + enable_access(debug_brightness) |
| 102 | + enable_access(twl_test) |
| 103 | + |
| 104 | + sy("echo 0xdead > " + twl_test) |
| 105 | + |
| 106 | + sy("echo 255 > " + debug_brightness) |
| 107 | + sy("sudo iw dev wlan0 set power_save on") |
| 108 | + m.verify() |
| 109 | + |
| 110 | + def verify(m): |
| 111 | + sy("sudo cat /sys/kernel/debug/pm_debug/count") |
| 112 | + |
| 113 | +class AutosleepVerify(Autosleep): |
| 114 | + hotkey = "U" |
| 115 | + name = "aUtosleep_verify" |
| 116 | + |
| 117 | + def run(m): |
| 118 | + m.verify() |
| 119 | + |
| 120 | + |
| 121 | +class UI: |
| 122 | + def __init__(m): |
| 123 | + m.tests = ( Vibrations(), LEDs(), Backlight(), Battery(), |
| 124 | + ChargeBattery(), Audio(), Suspend(), GPS(), |
| 125 | + Bluetooth(), LightSensor(), Camera(), Temperature(), |
| 126 | + WIFI(), Accelerometer(), Autosleep(), AutosleepVerify(), |
| 127 | + AccelLED()) |
| 128 | + |
| 129 | + def status(m): |
| 130 | + print("Hello, world") |
| 131 | + |
| 132 | + def run(m): |
| 133 | + print("Ready, press ? for help.") |
| 134 | + while True: |
| 135 | + c = getch() |
| 136 | + for t in m.tests: |
| 137 | + if t.hotkey == c: |
| 138 | + print("Running", t.name) |
| 139 | + t.run() |
| 140 | + print("Done", t.name) |
| 141 | + c = None |
| 142 | + break |
| 143 | + if c == None: |
| 144 | + continue |
| 145 | + if c == "\r": |
| 146 | + m.status() |
| 147 | + continue |
| 148 | + if c == "s": |
| 149 | + m.status() |
| 150 | + continue |
| 151 | + if c == "q": |
| 152 | + break |
| 153 | + if c == "?": |
| 154 | + print("Quit Status ?help") |
| 155 | + for t in m.tests: |
| 156 | + print(t.name) |
| 157 | + continue |
| 158 | + print("Got unknown character "+c) |
| 159 | + |
| 160 | +ui = UI() |
| 161 | +ui.run() |
| 162 | + |
| 163 | + |
0 commit comments