slotUI/SlotCli.py

Mon, 05 Dec 2011 17:14:32 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Mon, 05 Dec 2011 17:14:32 +0100
changeset 38
ff76255904c4
parent 36
aea84f4f5a12
child 50
84b8ab4cd79e
permissions
-rwxr-xr-x

implemented response reader to carrerashark

#!/usr/bin/env python
"""
Freeslot project
Command line interface
"""

from freeslot import Blackbox
from optparse import OptionParser
import time, sys

VERSION = "1.0"

class SlotCli():
    def __init__(self):
        self.box = Blackbox()
        self.box.connect()

    def run(self):
        """
        Keyboard loop to control it???
        """
        return None

if __name__ == "__main__":
    parser = OptionParser(version="%prog " + VERSION)
    parser.add_option("--carid", dest="carid",
        help="Required for programming a car directly", metavar="[0-5]")
    parser.add_option("--fuel", dest="fuel",
        help="Set maximum CAR fuel level", metavar="[0-15]")
    parser.add_option("--brake", dest="brake",
        help="Set CAR brake strength", metavar="[0-15]")
    parser.add_option("--speed", dest="speed",
        help="Set maximum CAR speed", metavar="[0-15]")
    parser.add_option("--blink", dest="blink",
        help="Set car lights blinking state", metavar="[on|off]")
    parser.add_option("--limit", dest="limit",
        help="Controlled SPEED LIMIT (15 = no limit)", metavar="[0-15]")

    (options, args) = parser.parse_args()
    cli = SlotCli()
    # should a CLI function be started?


    # check commandline if we have to program something
    if options.carid == None:
        print "Option --carid is required for all car programming commands!\nUse --help to get a list of available commands"
        sys.exit(1)

    if options.fuel != None:
        print "setFuel: " + cli.box.progcar(int(options.carid), "fuel", int(options.fuel))

    if options.speed != None:
        print "setSpeed: " + cli.box.progcar(int(options.carid), "speed", int(options.speed))

    if options.brake != None:
        print "setBrake: " + cli.box.progcar(int(options.carid), "brake", int(options.brake))

    if options.blink != None:
        state = False
        if options.blink == "on":
            state = True
        print "setBlink: " + cli.box.blinkcar(int(options.carid), state)

    if options.limit != None:
        print "Change Speed Limit: " + cli.box.speedlimit(int(options.carid), int(options.limit))

mercurial