def main(): print("\nTesting LSRealTile") tilepile = LSOpen() comPort = tilepile.selectPort() print("Attempting to open port " + comPort) theSerial = None try: # The serial read timeout may need to vary on different hosts. # On Acer netbook: # timeout = 0.003 misses a lot of sensor reads in writeAndPoll # timeout = 0.004 misses a few reads # timeout = 0.005 rarely misses a read # timeout = 0.006 never seen to miss a read theSerial = tilepile.lsSerial(comPort, 19200, timeout=0.006) print(comPort + " opened") except serial.SerialException: print(comPort + " is not available") if theSerial != None: print("\nStarting tests...") myTile = LSRealTile(tilepile.lsSerial(comPort)) # start with tile address survey address = 8 # default address myTile.assignAddress(address) tiles = addressWalk(myTile, theSerial) testChoice = 6 # initialize for repeat reply = input("What is the tile address? (0 is global, <Enter> for default): ") if reply == "": # try the first tile in the list address = tiles[0] # 64 else: address = int(reply) myTile.assignAddress(address) result = myTile.getAddress() #print("Tile address = " + result) strRes = "" #strRes = ''.join( [ "0x%02X " % x for x in result ] ).strip() strRes = repr(result) print("Tile address = " + strRes) testSleep() print("\nTesting reset") myTile.reset() testSleep(2) myTile.setDebug(0) for loop in range(1000000): print("\nTest choices or <Ctrl-C> to exit: ") print(" 0 - full test suite") print(" 1 - communications test") print(" 2 - sensor test") print(" 3 - sensorStatus test") print(" 4 - run single digit mode") print(" 5 - EEPROM tasks") # print(" 6 - discovery walk thru the address space") print(" 6 - test setSegments API") print(" 7 - set segments and poll sensor") print(" 8 - random tile address procedure") reply = input("\nWhat test do you want to run? <Enter> to repeat: ") if reply != "": testChoice = int(reply) if testChoice == 0: fullSuite(myTile) elif testChoice == 1: commTest(myTile, theSerial) elif testChoice == 2: sensorTest(myTile) elif testChoice == 3: sensorStatusTest(myTile) elif testChoice == 4: singleModeTest(theSerial) elif testChoice == 5: eepromTasks(myTile) # elif testChoice == 6: # addressWalk(myTile, theSerial) elif testChoice == 6: setSegmentsTest(myTile) elif testChoice == 7: writeAndPoll(myTile) elif testChoice == 8: setRandomTileAddress(theSerial, myTile) else: print("You did not enter a valid test choice") theSerial.close() input("\nDone - Press the Enter key to exit") # keeps double-click window open
print("No address specified, using address 0 (all tiles).") address = 0 print( "To target a tile at a specific address use the -a option...") else: print("Available addresses: " + repr(lsls.lsMatrix.get(com))) address = 0 inaddr = input("What tile address would you like to control [0]: ") if inaddr: address = int(inaddr) print("Using communications port: " + repr(com) + "...") theSerial = lsls.lsSerial(com) myTile = LSRealTile(lsls.sharedSerials[com]) myTile.assignAddress(address) if theSerial != None: if tile_command == None: print("No tile command provided, entering interactive mode...") raise NotImplementedError() # No interactive mode if tile_command == 'blank': print("Blanking tile at address " + str(address)) # myTile.blank() # Not implemented in LSRealTile myTile.setColor(0) # A TEMPORARY hack elif tile_command == 'locate': print("Setting locate mode on for the tile at address " + str(address)) myTile.locate() elif tile_command == 'demo':