# HG changeset patch # User Malte Bayer # Date 1322907066 -3600 # Node ID b83d239fe71948480c4305d0353ac791405afbe7 # Parent a8f082503782cb05cda13c98c0dcc9e4846dbd00# Parent 3e617fcf999a61283db0449a9bc39a958d936c3d merge diff -r a8f082503782 -r b83d239fe719 slotUI/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slotUI/README Sat Dec 03 11:11:06 2011 +0100 @@ -0,0 +1,3 @@ +At the moment just for testing stuff & rudimentary protocol definition + ++ GTK GUI testing \ No newline at end of file diff -r a8f082503782 -r b83d239fe719 slotUI/SlotCli.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slotUI/SlotCli.py Sat Dec 03 11:11:06 2011 +0100 @@ -0,0 +1,22 @@ +#!/usr/bin/env python +""" +Freeslot project +Command line interface +""" + +from freeslot import Blackbox + +class SlotCli(): + def __init__(self): + self.box = Blackbox() + self.box.connect() + + def run(self): + """ + Keyboard loop to control it??? + """ + return None + +if __name__ == "__main__": + app = SlotCli() + app.run() \ No newline at end of file diff -r a8f082503782 -r b83d239fe719 slotUI/SlotUi.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slotUI/SlotUi.py Sat Dec 03 11:11:06 2011 +0100 @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +import pygtk +pygtk.require('2.0') +import gtk + +class Window: + """ + Base Window Class + """ + def delete_event(self, widget, event, data=None): + return False + + def __init__(self, title="unnamed window"): + self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) + self.window.connect("delete_event", self.delete_event) + self.window.set_title(title) + +class SlotCars(Window): + """ + Car configuration window + """ + def __init__(self): + Window.__init__(self, "Car configuration") + #self.slot = gtk.ComboBox("Select car") + #self.slot.show() + #window.add(self.slot) + +class SlotUi(Window): + """ + Graphical User Interface + using GTK + """ + def delete_event(self, widget, event, data=None): + if widget == self.window: + self.destroy(widget, data) + Window.delete_event(self, widget, event, data) + return False + + def destroy(self, widget, data=None): + gtk.main_quit() + + def __init__(self): + Window.__init__(self, "FreeSlot UI") + + # define toolbar buttons + self.buttons = { + "config": gtk.Button("Settings"), + "cars": gtk.Button("Car Config"), + } + self.buttons["config"].connect("clicked", self.openwindow, "config") + self.buttons["cars"].connect("clicked", self.openwindow, "cars") + #setup the toolbar box + self.toolbar = gtk.HBox(False, 0) + self.toolbar.show() + for btn in self.buttons: + self.toolbar.add(self.buttons[btn]) + self.buttons[btn].show() + + # create subwindow objects + self.cars = SlotCars() + self.windows = { + "config": None, + "cars": self.cars.window, + } + + self.window.add(self.toolbar) + self.window.show() + + def openwindow(self, widget, name): + self.windows[name].show() + + def main(self): + gtk.main() + +if __name__ == "__main__": + print "FreeSlot UI starting..." + print "Note: this will be part of paepke development, no function at the moment :)" + app = SlotUi() + app.main() \ No newline at end of file diff -r a8f082503782 -r b83d239fe719 slotUI/freeslot.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slotUI/freeslot.py Sat Dec 03 11:11:06 2011 +0100 @@ -0,0 +1,83 @@ +""" +FreeSlot project +Blackbox communication library +""" + +import serial +import sys + +class SerialCommunicator(): + def __init__(self, device, speed): + self.device = device + self.speed = speed + self.com = None + self.connected = False + + def connect(self): + if self.connected: + return True + try: + self.com = serial.Serial(self.device, baudrate=self.speed, xonxoff=0, timeout=1) + except serial.SerialException, err: + print err + sys.exit(1) + self.connected = True + return True + + def disconnect(self): + self.com = None + return True + + def write(self, msg, getanswer=False): + self.com.write(msg + "\n") + if getanswer: + return self.readline() + return None + + def readline(self): + answer = self.com.readline() + return string.strip(answer, "\n") + +class Blackbox(): + def __init__(self): + self.com = None + self.info = None + + def connect(self, device="/dev/ttyUSB0", speed=115200): + if self.com == None: + self.com = SerialCommunicator(device, speed) + if self.com.connected: + self.com.disconnect() + self.com.connect() + self.info = self.readinfo() + + def disconnect(): + self.com.disconnect() + + def readinfo(): + """ + Read complete Information from connected box + This does not include race+car status! + """ + return None + + def progcar(self, carid, command, value): + """ + Send program packets to specified car id + valid command: speed, brake + valid value: 4 bit integer (0..15) + """ + return True + + def setmode(self, mode): + """ + Switch the Blackbox mode + Valid modes are: idle, prepare, race + note: box will permanently send status info in race mode, so no + polling is required + """ + return True + + def getmode(self): + self.readinfo() + return self.info["mode"] \ No newline at end of file