slotUI/SlotCli.py

Thu, 08 Dec 2011 17:40:40 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Thu, 08 Dec 2011 17:40:40 +0100
changeset 51
ec9e8cc27012
parent 50
84b8ab4cd79e
child 54
68eca8057d68
permissions
-rwxr-xr-x

car id setting for slot 5+6 working via pressing pacecar button

#!/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]")
    parser.add_option("--drive", dest="drive",
        help="Controlled SPEED MINIMUM (0 = disabled)", 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))

    if options.drive != None:
        print "Change minimum Speed drive: " + cli.box.speedminimum(int(options.carid), int(options.drive))

mercurial