code

* GPS http://aprs.gids.nl/nmea/

* 螢幕旋轉

#!/usr/bin/python
#http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval
 
from os import system
import struct
from math import sqrt
 
x = 0
y = 0
z = 0
 
secondsensorfile = "/dev/input/event3"
#int, int, short, short, int
fmt = 'iihhi'
#open file in binary mode
in_file = open(secondsensorfile,"rb")
event = in_file.read(16)
now = 90
 
while event:
  (time1,time2, type1, code, value) = struct.unpack(fmt,event)
  #time = time1 + time2 / 1000000.0
 
  if type1 == 2:
    if code == 0:
      x = value
    if code == 1:
      y = value
    if code == 2:
      z = value
 
  if now != 90:
    if ((x > -150) and (x < 200)):
      if (( y > -1100 ) and ( y < -600 )):
        if z > -100:
          rotation = 'xrandr -o 0 -d :0'
          system(rotation)
          now = 90
 
  elif now != 180:
    if ((x > -900) and (x < -400)):
      if (( y > -500 ) and ( y < 300 )):
        if z > -100:
          rotation = 'xrandr -o 3 -d :0'
          system(rotation)
          now = 180
 
  event = in_file.read(16)
in_file.close()
 
openmoko_進度.txt · 上一次變更: 2017/07/05 21:14 (外部編輯)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki