]> Pileus Git - ~andy/csm213a-hw/commitdiff
Rename serial to device and clean up
authorAndy Spencer <andy753421@gmail.com>
Sun, 2 Feb 2014 00:54:53 +0000 (00:54 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 2 Feb 2014 00:54:53 +0000 (00:54 +0000)
vis/config.py
vis/device.py [new file with mode: 0644]
vis/main.py
vis/serial.py [deleted file]
vis/settings.cfg
vis/visual.py
vis/visual.ui
vis/xively.py

index b40d09bef7256c9e923e082c5c2f00f00c2825bb..c3ea321978c41e635b2805e9b4c83698920aef1d 100644 (file)
@@ -6,8 +6,9 @@ class Config:
 
        defaults = {
                'baudrate': '9600',
-               'stopbits': '1',
+               'parity':   'N',
                'databits': '8',
+               'stopbits': '1',
                'username': '<username>',
                'password': '<password>',
                'apikey':   '<apikey>',
@@ -25,8 +26,9 @@ class Config:
                self.parser.read(self.filename)
 
                self.baudrate = self.parser.getint('serial', 'baudrate')
-               self.stopbits = self.parser.getint('serial', 'stopbits')
+               self.parity   = self.parser.get('serial', 'parity')
                self.databits = self.parser.getint('serial', 'databits')
+               self.stopbits = self.parser.getint('serial', 'stopbits')
 
                self.username = self.parser.get('xively', 'username')
                self.password = self.parser.get('xively', 'password')
diff --git a/vis/device.py b/vis/device.py
new file mode 100644 (file)
index 0000000..a205033
--- /dev/null
@@ -0,0 +1,18 @@
+from serial import Serial
+
+class Device:
+       # Attributes
+       port = "/dev/ttyACM0"
+
+       # Constructors
+       def __init__(self, config):
+               self.config = config
+
+       # Methods
+       def connect(self):
+               self.conn = Serial(self.port, \
+                       baudrate = self.config.baudrate, \
+                       parity   = self.config.parity,   \
+                       bytesize = self.config.databits, \
+                       stopbits = self.config.stopbits)
+
index 897a4f7e340838c885a71789a31016f48693e765..4f4fcd295c8be991e4cd460d2e5521ad94e17603 100755 (executable)
@@ -2,15 +2,15 @@
 
 from config import Config
 from xively import Xively
-from serial import Serial
+from device import Device
 from visual import Visual
 
 class Main:
        def __init__(self):
                self.config = Config();
-               self.xively = Xively();
-               self.serial = Serial();
-               self.visual = Visual(self.config);
+               self.device = Device(self.config);
+               self.xively = Xively(self.config);
+               self.visual = Visual(self.config, self.device, self.xively);
 
        def main(self):
                self.visual.run()
diff --git a/vis/serial.py b/vis/serial.py
deleted file mode 100644 (file)
index e1de341..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-class Serial:
-       def __init__(self):
-               pass
index 2ce5b07ab27c2ffe972797a74b796d0db22fc9cb..e83fece414dbc8d0e432bd2e19be13562f819b4d 100644 (file)
@@ -1,7 +1,8 @@
 [serial]
 buadrate = 9600
-stopbits = 1
+parity   = N
 databits = 8
+stopbits = 1
 
 [xively]
 username = andy
index aed73ae70aa7e6b0667bdd1ecc1b21830859b00c..908304d908da2b374d93211d51c1982fbe2db559 100644 (file)
@@ -4,13 +4,16 @@ import pygtk
 import gtk
 
 class Visual:
-       def __init__(self, config):
-               self.builder = gtk.Builder()
+       def __init__(self, config, device, xively):
+               self.config   = config
+               self.device   = device
+               self.xively   = xively
+               self.builder  = gtk.Builder()
+
                self.builder.add_from_file('visual.ui')
                self.builder.connect_signals(self)
                self.window   = self.builder.get_object("window")
                self.settings = self.builder.get_object("settings")
-               self.config   = config
 
        # Signal handlers
        def on_hide(self, win, *args):
@@ -21,8 +24,12 @@ class Visual:
                self.settings.show()
                return True
 
-       def on_connect(self, win):
-               print "Unimplemented: on_connect"
+       def on_serial(self, win):
+               self.device.connect()
+               return True
+
+       def on_xively(self, win):
+               self.xively.connect()
                return True
 
        def on_enable(self, _):
@@ -43,12 +50,14 @@ class Visual:
         # Methods
        def load_config(self):
                # Serial settings
-               baud  = self.builder.get_object("baudrate")
-               stopb = self.builder.get_object("stopbits")
-               datab = self.builder.get_object("databits")
+               baud   = self.builder.get_object("baudrate")
+               parity = self.builder.get_object("parity")
+               datab  = self.builder.get_object("databits")
+               stopb  = self.builder.get_object("stopbits")
                baud.set_value(self.config.baudrate)
-               stopb.set_value(self.config.stopbits)
+               parity.set_text(self.config.parity)
                datab.set_value(self.config.databits)
+               stopb.set_value(self.config.stopbits)
 
                # Xively settings
                user  = self.builder.get_object("username")
index 6b6209f564e246ad812245a29920c56a564403ea..e8cfec5344f6dee877dd4a2f1172d9da21af04f9 100644 (file)
@@ -2,10 +2,20 @@
 <interface>
   <requires lib="gtk+" version="2.24"/>
   <!-- interface-naming-policy project-wide -->
+  <object class="GtkAction" id="serial_con">
+    <property name="label" translatable="yes">Serial</property>
+    <property name="stock_id">gtk-connect</property>
+    <signal name="activate" handler="on_serial" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="setting_act">
+    <property name="label" translatable="yes">Settings</property>
+    <property name="stock_id">gtk-preferences</property>
+    <signal name="activate" handler="on_show" swapped="no"/>
+  </object>
   <object class="GtkAction" id="xively_con">
     <property name="label" translatable="yes">Xively</property>
     <property name="stock_id">gtk-connect</property>
-    <signal name="activate" handler="on_connect" swapped="no"/>
+    <signal name="activate" handler="on_xively" swapped="no"/>
   </object>
   <object class="GtkAdjustment" id="a2d_adj">
     <property name="upper">100</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
-  <object class="GtkAction" id="setting_act">
-    <property name="label" translatable="yes">Settings</property>
-    <property name="stock_id">gtk-preferences</property>
-    <signal name="activate" handler="on_show" swapped="no"/>
-  </object>
   <object class="GtkTextBuffer" id="serial_buf"/>
-  <object class="GtkAction" id="serial_con">
-    <property name="label" translatable="yes">Serial</property>
-    <property name="stock_id">gtk-connect</property>
-    <signal name="activate" handler="on_connect" swapped="no"/>
-  </object>
-  <object class="GtkAdjustment" id="stopb_adj">
-    <property name="lower">1</property>
-    <property name="upper">2</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
   <object class="GtkDialog" id="settings">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
                   <object class="GtkTable" id="table1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="n_rows">3</property>
+                    <property name="n_rows">4</property>
                     <property name="n_columns">2</property>
                     <property name="column_spacing">20</property>
                     <child>
                         <property name="label" translatable="yes">Stop bits</property>
                       </object>
                       <packing>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options">GTK_FILL</property>
                       </packing>
                         <property name="label" translatable="yes">Data bits</property>
                       </object>
                       <packing>
-                        <property name="top_attach">2</property>
-                        <property name="bottom_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options">GTK_FILL</property>
                       </packing>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="y_options">GTK_FILL</property>
                       </packing>
                     </child>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">2</property>
-                        <property name="bottom_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="parity_lbl">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Parity</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkEntry" id="parity">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">●</property>
+                        <property name="invisible_char_set">True</property>
+                        <property name="primary_icon_activatable">False</property>
+                        <property name="secondary_icon_activatable">False</property>
+                        <property name="primary_icon_sensitive">True</property>
+                        <property name="secondary_icon_sensitive">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
                         <property name="y_options">GTK_FILL</property>
                       </packing>
                     </child>
       <action-widget response="0">close</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkAdjustment" id="stopb_adj">
+    <property name="lower">1</property>
+    <property name="upper">2</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkAdjustment" id="touch_adj">
     <property name="upper">100</property>
     <property name="value">1</property>
index 15e536cb5880cc80476a59db5e984f59c8c5ab0b..ae8d5252ecc858215070ca9c44b14d619ce12c3a 100644 (file)
@@ -1,3 +1,6 @@
 class Xively:
-       def __init__(self):
+       def __init__(self, config):
+               self.config = config
+
+       def connect(self):
                pass