Changeset 161


Ignore:
Timestamp:
Jul 16, 2010, 1:52:47 PM (14 years ago)
Author:
Rick van der Zwet
Message:

Wheel of fortune application

File:
1 edited

Legend:

Unmodified
Added
Removed
  • powerbar/serial-npm4000.py

    r160 r161  
    302302  --changetimerdelay=           Change internal timer delay [TODO: Implement]
    303303  --pinballtest=<int>           Randomly toggle ports for number of times]
     304  --wheel_of_fortune            Wheel of fortune implementation
    304305  [-p <port>|--port=<port>]     Ports needed to be used
    305306
     
    329330        opts, args = getopt.getopt(sys.argv[1:],
    330331            "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"])
    333336    except getopt.GetoptError, err:
    334337        usage(str(err),2)
     
    376379            opt_action = "on"
    377380            opt_port = a
     381        elif o in ["--wheel_of_fortune"]:
     382            opt_action = 'wheel_of_fortune'
     383            opt_port = "all"
    378384        else:
    379385            assert False, "unhandled option"
     
    402408    debug(serial)
    403409
    404     if opt_pinballtest:
     410    if opt_action == 'pinballtest':
    405411      for count in range(0,opt_pinballtest):
    406412        port = random.choice(ports)
     
    409415        # Backoff time
    410416        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)
    411442      sys.exit(0)
    412443
Note: See TracChangeset for help on using the changeset viewer.