Changeset 161
- Timestamp:
- Jul 16, 2010, 1:52:47 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
powerbar/serial-npm4000.py
r160 r161 302 302 --changetimerdelay= Change internal timer delay [TODO: Implement] 303 303 --pinballtest=<int> Randomly toggle ports for number of times] 304 --wheel_of_fortune Wheel of fortune implementation 304 305 [-p <port>|--port=<port>] Ports needed to be used 305 306 … … 329 330 opts, args = getopt.getopt(sys.argv[1:], 330 331 "adhf:s:t:ro:p:v", 331 ["ampere", "debug", "delay=", "help", "verbose", "serialport=", "port=", "password=", 332 "addresscode=","toggle=","off=", "on=", "status=", "buadrate=", "raw=", "pinballtest="]) 332 ["ampere", "debug", "delay=", "help", "verbose", "serialport=", 333 "port=", "password=", "addresscode=","toggle=","off=", "on=", 334 "status=", "buadrate=", "raw=", "pinballtest=", 335 "wheel_of_fortune"]) 333 336 except getopt.GetoptError, err: 334 337 usage(str(err),2) … … 376 379 opt_action = "on" 377 380 opt_port = a 381 elif o in ["--wheel_of_fortune"]: 382 opt_action = 'wheel_of_fortune' 383 opt_port = "all" 378 384 else: 379 385 assert False, "unhandled option" … … 402 408 debug(serial) 403 409 404 if opt_ pinballtest:410 if opt_action == 'pinballtest': 405 411 for count in range(0,opt_pinballtest): 406 412 port = random.choice(ports) … … 409 415 # Backoff time 410 416 time.sleep(opt_delay) 417 sys.exit(0) 418 elif opt_action == 'wheel_of_fortune': 419 # First turn all ports off 420 for port in ports: 421 action_port_off(port) 422 423 port = random.choice(ports) 424 total_time = 0.0 425 for c in range(1,random.randint(10,200)): 426 # Not all should be evaluated (50%) 427 if random.randint(0,200) > 100: 428 continue 429 action_port_on(port) 430 sleep_time = float(c) / 1000 431 total_time += sleep_time 432 time.sleep(sleep_time) 433 action_port_off(port) 434 print "[%03i] Port %i (%f)" % (c, port, sleep_time) 435 port = ((port + 1) % 25) 436 if port == 0: 437 port += 1 438 439 print "Total time: %f" % total_time 440 # Initial result 441 action_port_on(port) 411 442 sys.exit(0) 412 443
Note:
See TracChangeset
for help on using the changeset viewer.