Adding function to add item to log by shortname in the sensor list
authorPaul Robinson <darkraver@gmail.com>
Tue, 6 Nov 2012 13:47:13 +0000 (13:47 +0000)
committerPaul Robinson <darkraver@gmail.com>
Tue, 6 Nov 2012 13:47:13 +0000 (13:47 +0000)
obd_recorder.py

index a543b1f..7878594 100644 (file)
@@ -2,12 +2,14 @@ import obd_io
 import serial
 import platform
 import logging
+import obd_sensors
 
 from obd_utils import scanSerial
 
 class OBD_Recorder():
     def __init__(self, filename):
         self.port = None
+        self.sensorlist = []
         self.logger = logging.getLogger(__name__)
         log_handler = logging.FileHandler(filename)
         log_formatter = logging.Formatter('%(asctime)s %(message)s')
@@ -32,6 +34,14 @@ class OBD_Recorder():
     def is_connected(self):
         return self.port
         
+    def add_log_item(self, item):
+        for e in obd_sensors.SENSORS:
+            if(item == e.shortname):
+                self.sensorlist.append(e)
+                print "Logging item: "+e.name
+                break
+            
+            
 #    def record_data(self):
 #        for n in range(1,10):
 #            self.logger.info('woo %s %s %s yay', n, n, n)
@@ -39,8 +49,10 @@ class OBD_Recorder():
             
         
 o = OBD_Recorder('bikestuff.log')
+o.add_log_item("rpm")
+o.add_log_item("speed")
+o.add_log_item("throttle_pos")
 o.connect()
 if not o.is_connected():
     print "Not connected"
-    
-#o.record_data()
\ No newline at end of file
+#o.record_data()