#!/usr/bin/env python # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------- # (c) Disabler Production LabAratory # ------------------------------------------------------------------------------- # import os,time # type of view - console or popup console_mode = True # default size if coords line line_size = 90 # accelerometer calibration -56..56 calibrate_x = -7 calibrate_y = 4 calibrate_z = 0 tmp_file = 'tmp' presence_script = 'run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"%s"' def readfile(filename): fp = file(filename) data = fp.read() fp.close() return data def sh(cmd): cmd = shh(cmd) try: os.remove(tmp_file) except: pass return cmd def shh(cmd): try: os.remove(tmp_file) except: pass try: os.system('%s >> %s' % (cmd.encode('utf-8'),tmp_file)) return readfile(tmp_file) except: return None def crd(pos,name): if pos < -1008: pos += 2016 elif pos > 1008: pos -= 2016 ps = int(pos/(2016/line_size))+(line_size/2) strn = ['-']*line_size #strn[line_size/4],strn[line_size/4*3] = '+','+' strn[line_size/2] = '+' try: strn[ps] = '|' except: pass return '%s %s %s\n\n' % (name,''.join(strn),pos/18) line_size = int(sh('zenity --scale --min-value=40 --max-value=112 --value=%s --step=4 --text="Line length"' % line_size).split()[0]) while 1: f = open("/sys/class/i2c-adapter/i2c-3/3-001d/coord") coords = [int(w) for w in f.readline().split()] f.close() X = coords[0] + calibrate_x * 18 msg = crd(X,'X') Y = coords[1] + calibrate_y * 18 msg += crd(Y,'Y') Z = coords[2] + calibrate_z * 18 msg += crd(Z,'Z') if console_mode: print '%sPush CTRL+C for terminate...' % msg else: os.system(presence_script % msg[:-2]) time.sleep(0.25) if console_mode: os.system('clear')