def runCube(): with picamera.PiCamera() as camera: camera.start_preview() usart.write(scan(0)) #send first move for i in range(6): #camera.start_preview() read_data = usart.readline() #wait for massage #print(read_data) read_data = read_data.strip() print("in for: {0}").format(read_data) while(read_data != "Done"): if(read_data == "Ready"): usart.write("R") camera.stop_preview() return read_data = usart.readline() #wait for massage 'Done' read_data = read_data.strip() print("in while: {0}").format(read_data) time.sleep(2) #take a picture camera.capture("img.jpg") image = cv2.imread("img.jpg") #camera.stop_preview() #send next move to stm usart.write(scan(i+1)) #get colors from picture color = detect.getColorsFromPic(image) saveToArr(color, i) print(color) camera.stop_preview() #classify readed colors string = classify.classify(color_arr) print(string) #send string of state to Kociemba's algorithm sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = ('localhost', 8080) sock.connect(server_address) try: sock.sendall(string) data = sock.recv(128) finally: sock.close() #print(data) #raw_input() commands = ref.refactor(data) print(commands) #send solution to stm usart.write(commands)
def main(): cparse = argparse.ArgumentParser(add_help=False) glob.add_args(cparse) cparse.add_argument("--help", action="help", help="Print this message") args = cparse.parse_args() glob.parse_args(cparse, args) glob.g_outfile = args.outfile # test_regexpr() # return 1 glob.g_file = args.infile if args.infile == None: print("cc.py: no input files") return -1 f = open(args.infile, "r") data = f.read() f.close() doloops = not glob.g_emit_code and glob.g_expand_iterators if glob.g_refactor_mode: from refactor import refactor buf, node = refactor(data) if args.outfile == "": print(buf) elif glob.g_gen_log_code: buf, node = parse(data, expand_loops=doloops, create_logger=True) else: buf, node = parse(data, expand_loops=doloops) if glob.g_emit_code: import type_emit type_emit.emit(node) if not glob.g_error: if args.outfile != "": f = open(args.outfile, "w") f.write(buf) f.close() else: return -1 return 0
def main(): cparse = argparse.ArgumentParser(add_help=False) glob.add_args(cparse) cparse.add_argument("--help", action="help", help="Print this message") args = cparse.parse_args() glob.parse_args(cparse, args) glob.g_outfile = args.outfile #test_regexpr() #return 1 glob.g_file = args.infile if args.infile == None: print("cc.py: no input files") return -1 f = open(args.infile, "r") data = f.read() f.close() doloops = not glob.g_emit_code and glob.g_expand_iterators if glob.g_refactor_mode: from refactor import refactor buf, node = refactor(data) if args.outfile == "": print(buf) elif glob.g_gen_log_code: buf, node = parse(data, expand_loops=doloops, create_logger=True) else: buf, node = parse(data, expand_loops=doloops) if glob.g_emit_code: import type_emit type_emit.emit(node) if not glob.g_error: if args.outfile != "": f = open(args.outfile, "w") f.write(buf) f.close() else: return -1 return 0
def run(compiler): from collect import collectAllVars from compile import compileRefactored, compileFull, compilePath from refactor import refactor, refactorCompile import os pwd = os.getcwd() newargs = [] args = sys.argv[1:] length = len(args) idx = 0 dotOs = [] srcs = [] asmBuild = False while idx < length: arg = args[idx] if arg == "-o": idx += 1 dotOs.append(args[idx]) elif arg == "-c": pass elif os.path.isfile(arg): if arg.endswith(".cc") or arg.endswith(".c") or arg.endswith( ".cpp"): srcs.append(args[idx]) elif arg.endswith(".S"): asmBuild = True else: newargs.append("'%s'" % arg) else: newargs.append("'%s'" % arg) idx += 1 isCompileMode = False if os.environ.has_key("SSTMAC_FAKE_BUILD"): isCompileMode = bool(os.environ["SSTMAC_FAKE_BUILD"]) notObjectBuild = (not "-c" in args) or "-E" in args if isCompileMode or notObjectBuild or asmBuild: #link or preprocess return compileFull(compiler, args) variables = [] if not os.environ.has_key("SSTMAC_GLOBALS_FILE"): raise Exception("Must set SSTMAC_GLOBALS_FILE environment variable") configFile = os.environ["SSTMAC_GLOBALS_FILE"] if not os.path.isfile: raise Exception("Config file %s is not a valid path" % configFile) text = open(configFile).read() for line in text.splitlines(): line = line.strip() if not line: continue variables.append(line) if not srcs: sys.exit("No source file given") if not dotOs: for src in srcs: relsrc = os.path.split(src)[-1] dotO = ".".join(relsrc.split(".")[:-1]) + ".o" dotOs.append(dotO) for i in range(len(srcs)): src = srcs[i] dotO = dotOs[i] if not dotO.startswith("/"): #not an abs path dotO = os.path.join(pwd, dotO) rc = refactor(compiler, newargs, src, dotO, variables) if not rc == 0: return rc return 0
def run(compiler): from collect import collectAllVars from compile import compileRefactored, compileFull, compilePath from refactor import refactor, refactorCompile import os pwd = os.getcwd() newargs = [] args = sys.argv[1:] length = len(args) idx = 0 dotOs = [] srcs = [] asmBuild = False while idx < length: arg = args[idx] if arg == "-o": idx += 1 dotOs.append(args[idx]) elif arg == "-c": pass elif os.path.isfile(arg): if arg.endswith(".cc") or arg.endswith(".c") or arg.endswith(".cpp"): srcs.append(args[idx]) elif arg.endswith(".S"): asmBuild = True else: newargs.append("'%s'" % arg) else: newargs.append("'%s'" % arg) idx += 1 isCompileMode = False if os.environ.has_key("SSTMAC_FAKE_BUILD"): isCompileMode = bool(os.environ["SSTMAC_FAKE_BUILD"]) notObjectBuild = (not "-c" in args) or "-E" in args if isCompileMode or notObjectBuild or asmBuild: #link or preprocess return compileFull(compiler, args) variables = [] if not os.environ.has_key("SSTMAC_GLOBALS_FILE"): raise Exception("Must set SSTMAC_GLOBALS_FILE environment variable") configFile = os.environ["SSTMAC_GLOBALS_FILE"] if not os.path.isfile: raise Exception("Config file %s is not a valid path" % configFile) text = open(configFile).read() for line in text.splitlines(): line = line.strip() if not line: continue variables.append(line) if not srcs: sys.exit("No source file given") if not dotOs: for src in srcs: relsrc = os.path.split(src)[-1] dotO=".".join(relsrc.split(".")[:-1]) + ".o" dotOs.append(dotO) for i in range(len(srcs)): src = srcs[i] dotO = dotOs[i] if not dotO.startswith("/"): #not an abs path dotO = os.path.join(pwd, dotO) rc = refactor(compiler, newargs, src, dotO, variables) if not rc == 0: return rc return 0