def __init__(self): # allow rpi bluetooth to be discoverable os.system("sudo hciconfig hci0 piscan") # initialize connections self.bt = Android() self.ard = Arduino() self.pc = Pc() self.pc.connect() self.bt.connect(uuid) self.ard.connect() # initialize sendImg # self.sendImg = sendImg() # initialize queues self.btQueue = queue.Queue(maxsize=0) self.ardQueue = queue.Queue(maxsize=0) self.pcQueue = queue.Queue(maxsize=0) print ("===========================") print ("===Starting Transmission===") print ("===========================")
def TakeScreenshot(): basewidth = 750 / 10 picurl = Android.TakeScreenshot(udid) img = Image.open(picurl) area = (45, 337, 1375, 2150) cropped_img = img.crop(area) wpercent = (basewidth / float(cropped_img.size[0])) hsize = int((float(cropped_img.size[1]) * float(wpercent))) cropped_img = cropped_img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) cropped_img.show() time.sleep(2) for proc in psutil.process_iter(): if proc.name() == "display": proc.kill() return picurl
import numpy as np print 'NumPy version: ', np.__version__ import matplotlib as mlib print'Matplotlib version:', mlib.__version__ import sympy as sp print 'SymPy version:', sp.__version__ import panda s as pd print 'Pandas version:', pd.__version__ import Android from android import Android android=Android() android.ttsSpeak('hola') https://github.com/kuri65536/python-for-android/releases descargar el r26 --EN SECCION DE DOWNLOAD instalar el apk en el telefono configurar una variable de entorno agregar el sdk-adb C:\Users\KMENDEZ.SEFIPLAN\AppData\Local\Android\sdk\platform-tools cerrar todo en una nueva notebook- --!adb devices
def test_Instantiate(): android = Android.Android() android.LaunchBot(Android.Coords(1, 3), Android.Bearing.NORTH, Android.Coords(5,6)) assert android.area == Android.Coords(5,6)
def test_TurnRightValid(): android = Android.Android() android.LaunchBot(Android.Coords(2, 2), Android.Bearing.NORTH, Android.Coords(6,6)) android.Move(Android.Movement.RIGHT) assert android.facing == Android.Bearing.EAST
def test_TurnLeftValid(): android = Android.Android() android.LaunchBot(Android.Coords(2, 2), Android.Bearing.NORTH, Android.Coords(6,6)) android.Move(Android.Movement.LEFT) assert android.facing == Android.Bearing.WEST
def test_MoveForwardValidEast(): android = Android.Android() android.LaunchBot(Android.Coords(2, 2), Android.Bearing.EAST, Android.Coords(6,6)) android.Move(Android.Movement.FORWARD) assert android.position == Android.Coords(3, 2)
def func2(): import Android Android.main()
def test_RunCommandsFromFileandOutput(capsys): android = Android.Android() commands = android.RunCommandsFromFile(path) android.SendOutput(commands) captured = capsys.readouterr() assert """{"bearing": "north", "position": {"x": 1, "y": 3}, "type": "robot"}""" in captured.out
def test_MoveForwardValidNorth(): android = Android.Android() android.LaunchBot(Android.Coords(2, 2), Android.Bearing.NORTH, Android.Coords(6,6)) android.Move(Android.Movement.FORWARD) assert android.position == Android.Coords(2, 3)
def test_RunCommandsFromFile(): android = Android.Android() commands = android.RunCommandsFromFile(path) assert commands[0].position.x == 1 and commands[0].position.y == 3 and commands[1].position.x == 5 and commands[1].position.y == 1
def test_Instantiate_invalid_params(): android = Android.Android() with pytest.raises(ValueError): android.LaunchBot(Android.Coords(5, 6), Android.Bearing.NORTH, Android.Coords(4,5))
def NotLike(): Android.Scroll(udid, 1350, 1100, 23, 1300)
import Android import Mapping import Manipulator import time xStart=6 yStart=7 xB=0 yB=0 myOrientation=-90 while True: #Wifi [xB,yB,C]=Android.getWifiData(xB,yB) #Mapping myOrientation=Mapping.drive(xStart,yStart,yB,xB,myOrientation) time.sleep(30) #Manipulator #Manipulator.grab(C) #2-Yelow Ball,1-Blue Ball #Mapping myOrientation=Mapping.drive(yB,xB,xStart,yStart,myOrientation)
def test_MoveForwardInvalidTop(): android = Android.Android() android.LaunchBot(Android.Coords(0, 5), Android.Bearing.NORTH, Android.Coords(5,5)) with pytest.raises(ValueError): android.Move(Android.Movement.FORWARD)
import Android [X,Y,C]=Android.getWifiData() print X print Y print C
def test_MoveForwardInvalidBottom(): android = Android.Android() android.LaunchBot(Android.Coords(0, 0), Android.Bearing.SOUTH, Android.Coords(6,6)) with pytest.raises(ValueError): android.Move(Android.Movement.FORWARD)
class Main: def __init__(self): # allow rpi bluetooth to be discoverable os.system("sudo hciconfig hci0 piscan") # initialize connections self.bt = Android() self.ard = Arduino() self.pc = Pc() self.pc.connect() self.bt.connect(uuid) self.ard.connect() # initialize sendImg # self.sendImg = sendImg() # initialize queues self.btQueue = queue.Queue(maxsize=0) self.ardQueue = queue.Queue(maxsize=0) self.pcQueue = queue.Queue(maxsize=0) print ("===========================") print ("===Starting Transmission===") print ("===========================") # read/write from Android (Bluetooth) def readBt(self, pcQueue, ardQueue): while 1: msg = self.bt.read() # pcQueue.put_nowait(msg) strmsg = msg.decode('utf-8') if len(strmsg)!=0: newmsg = strmsg[1:] if strmsg[0] == "A": print ("Read from Bluetooth: %s\n" % msg) ardQueue.put_nowait(bytes(newmsg+'\n', 'utf-8')) elif strmsg[0] == "P": print ("Read from Bluetooth: %s\n" % msg) pcQueue.put_nowait(bytes(newmsg+'\n', 'utf-8')) elif strmsg[0] == "Z": print ("Read from Bluetooth: %s\n" % msg) pcQueue.put_nowait(bytes(newmsg+'\n', 'utf-8')) ardQueue.put_nowait(bytes(newmsg+'\n', 'utf-8')) # else: # print("Read from Bluetooth:%s\n" % # msg+" incorrect format received") # pass def writeBt(self, btQueue): while 1: if not btQueue.empty(): msg = btQueue.get_nowait() self.bt.write(msg) print ("Write to Bluetooth: %s\n" % msg) # read/write from Arduino (Serial comm) def readArd(self, pcQueue, btQueue): while 1: msg = self.ard.read() strmsg = msg.decode('utf-8') if len(strmsg)!=0: if strmsg[0] == "D": print ("Read from serial: %s\n" % msg) btQueue.put_nowait(msg[1:]) elif strmsg[0] == "P": print ("Read from serial: %s\n" % msg) pcQueue.put_nowait(msg[1:]) elif strmsg[0] == "Z": print ("Read from serial: %s\n" % msg) btQueue.put_nowait(msg[1:]) pcQueue.put_nowait(msg[1:]) # else: # print("Read from serial: %s\n" % # msg+" incorrect format received") # pass def writeArd(self, ardQueue): while 1: if not ardQueue.empty(): msg = ardQueue.get_nowait() self.ard.write(msg) print ("Write to Serial: %s\n" % msg) # read/write from PC (Serial comm) def readPc(self, ardQueue, btQueue): with open("pc_log.txt","w",newline="") as f: f.write("start\n") while 1: msg = self.pc.read() strmsg = msg.decode('utf-8') if len(strmsg)!=0: msgs = strmsg.split('\r\n') with open("pc_log.txt", "a", newline="") as f: for m in msgs: if m is not None: f.write(m+"\n") for msg in msgs: newmsg = msg[1:]+'\r\n' if strmsg[0] == "A": if strmsg[1]=="M" or strmsg[1]=="L" or strmsg[1]=="R" or strmsg[1]=="T": threading.Thread(target=self.sendImg.run).start() # start image recog thread print ("Read from WIFI: %s\n" % msg) ardQueue.put_nowait(bytes(newmsg, 'utf-8')) elif strmsg[0] == "D": print ("Read from WIFI: %s\n" % msg) btQueue.put_nowait(bytes(newmsg, 'utf-8')) elif strmsg[0] == "Z": print ("Read from WIFI: %s\n" % msg) btQueue.put_nowait(bytes(newmsg, 'utf-8')) ardQueue.put_nowait(bytes(newmsg, 'utf-8')) # else: # print("Read from WIFI: %s\n" % # msg+" incorrect format received") # pass def writePc(self, pcQueue): while 1: if not pcQueue.empty(): msg = pcQueue.get_nowait() # len1=len(msg) # msg= "hello world" if not (msg is None): self.pc.write(msg) print ("Write over WIFI : %s\n" % msg) # print "Length: %d\n" %len1 # multithreading def multithread(self): try: _thread.start_new_thread( self.readBt, (self.pcQueue, self.ardQueue)) _thread.start_new_thread( self.readArd, (self.pcQueue, self.btQueue)) _thread.start_new_thread( self.readPc, (self.ardQueue, self.btQueue)) _thread.start_new_thread(self.writeBt, (self.btQueue,)) _thread.start_new_thread(self.writeArd, (self.ardQueue,)) _thread.start_new_thread(self.writePc, (self.pcQueue,)) except Exception as e: print ("Error in threading: %s" % str(e)) while 1: pass def disconnectAll(self): try: self.bt.disconnect() # self.ard.disconnect() self.pc.disconnect() except Exception as e: pass
def test_MoveForwardInvalidEast(): android = Android.Android() android.LaunchBot(Android.Coords(5, 0), Android.Bearing.EAST, Android.Coords(5, 5)) with pytest.raises(ValueError): android.Move(Android.Movement.FORWARD)
GPIO.setmode(GPIO.BCM) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) def ForceClose(udid, app): os.system('adb -s {} shell am force-stop {}'.format(udid, app)) while True: time.sleep(.5) input_state = GPIO.input(24) if input_state == False: break a = Android.ConnectedDevices()[0] ForceClose(a, 'com.robinhood.android') time.sleep(1) Android.StartApplication(a, 'com.robinhood.android') time.sleep(2) Android.Scroll(a, 10, 1000, 10, 400) interactions.GrabUiAutomator(a) interactions.click(a, text="TSLA") time.sleep(3) interactions.GrabUiAutomator(a) interactions.click(a, text="BUY") time.sleep(2) interactions.InputText(a, '10000') interactions.GrabUiAutomator(a) interactions.click(a, resource_id="com.robinhood.android:id/review_order_btn")
#! /usr/bin/env python2 import Pots import Iphone import Android #Phone.Pots() #Phone.Iphone() #Phone.Android() Pots.Pots() Iphone.Iphone() Android.Android()