h = getInt(bytearray(buf[20:24]))
? ? ? ? tfb.blue_offset = getInt(bytearray(buf[24:28]))
? ? ? ? tfb.blue_length = getInt(bytearray(buf[28:32]))
? ? ? ? tfb.green_offset = getInt(bytearray(buf[32:36]))
? ? ? ? tfb.green_length = getInt(bytearray(buf[36:40]))
? ? ? ? tfb.alpha_offset = getInt(bytearray(buf[40:44]))
? ? ? ? tfb.alpha_length = getInt(bytearray(buf[44:48]))
? ? else:
? ? ? ? return False
? ? return True
# Find the Touch input device and event
def get_touch_event():
? ? tp_names = ['ft5x06', 'gt818']
? ? output = adbshellcommand('getevent -S')
? ? if output == None:
? ? ? ? return None
? ? if DEBUG:
? ? ? ? print output
? ? dev = ''
? ? name = ''
? ? for line in output.splitlines():
? ? ? ? if '/dev/input/event' in line:
? ? ? ? ? ? line = line.split(':')
? ? ? ? ? ? if len(line) == 2:
? ? ? ? ? ? ? ? line = line[1]
? ? ? ? ? ? ? ? line = line.strip(' ')
? ? ? ? ? ? ? ? line = line.strip('"')
? ? ? ? ? ? ? ? dev = line
? ? ? ? elif 'name:' in line:
? ? ? ? ? ? line = line.split(':')
? ? ? ? ? ? if len(line) == 2:
? ? ? ? ? ? ? ? line = line[1]
? ? ? ? ? ? ? ? line = line.strip(' ')
? ? ? ? ? ? ? ? line = line.strip('"')
? ? ? ? ? ? ? ? name = line
? ? ? ? if (dev != '') and (name in tp_names):
? ? ? ? ? ? break
? ? if DEBUG:
? ? ? ? print '%s : %s' % (name, dev)
? ? if name in tp_names:
? ? ? ? return (name, dev)
? ? else:
? ? ? ? return None
# Do the touch action
def send_touch_event(action, x0, y0, x1 = None, y1 = None):
? ? # Note: input support tap & swipe after 4.1
? ? # so we need emulate TP via sendevent if tap or swipe fail
? ? if action == 'tap':
? ? ? ? resp = adbshellcommand('input tap %d %d' % (x0, y0))
? ? ? ? if 'Error' in resp:
? ? ? ? ? ? print 'Not support tap command'
? ? ? ? ? ? # get tp device
? ? ? ? ? ? tp = get_touch_event()
? ? ? ? ? ? if tp == None:
? ? ? ? ? ? ? ? return
? ? ? ? ? ? # down
? ? ? ? ? ? cmd_str = ''
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 53, x0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 54, y0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 57, 0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 48, 0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 2, 0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 1, 330, 1)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 0, 0)
? ? ? ? ? ? # up
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 1, 330, 0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 2, 0)
? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 0, 0)
? ? ? ? ? ? if DEBUG:
? ? ? ? ? ? ? ? print cmd_str
? ? ? ? ? ? adbshellcommand(cmd_str)
? ? elif action == 'swipe':
? ? ? ? resp = adbshellcommand('input swipe %d %d %d %d' % (x0, y0, x1, y1))
? ? ? ? if 'Error' in resp:
? ? ? ? ? ? print 'Not support tap command'
? ? ? ? ? ?
? ? ? ? ? ? # get tp device
? ? ? ? ? ? tp = get_touch_event()
? ? ? ? ? ? if tp == None:
? ? ? ? ? ? ? ? return
? ? ? ? ? ? step = 3
? ? ? ? ? ? stepx = abs(x1 - x0) / step
? ? ? ? ? ? stepy = abs(y1 - y0) / step
? ? ? ? ? ? x = x0
? ? ? ? ? ? y = y0
? ? ? ? ? ? for i in range(0, step + 1):
? ? ? ? ? ? ? ? if x0 < x1:
? ? ? ? ? ? ? ? ? ? x = x0 + i * stepx
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? x = x0 - i * stepx
? ? ? ? ? ? ? ? if y0 < y1:
? ? ? ? ? ? ? ? ? ? y = y0 + i * stepy
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? y = y0 - i * stepy
? ? ? ? ? ? ? ? cmd_str = ''
? ? ? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 53, x)
? ? ? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 54, y)
? ? ? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 57, 0)
? ? ? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 3, 48, 0)
? ? ? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 2, 0)
? ? ? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 1, 330, 1)
? ? ? ? ? ? ? ? cmd_str = cmd_str + 'sendevent %s %d %d %d;' % (tp[1], 0, 0, 0)
? ? ? ? ? ? ? ? adbshellcommand(cm