Commits

Adam M Dutko  committed 395c94c

Add some error handling.

  • Participants
  • Parent commits 55f7c44

Comments (0)

Files changed (2)

     screen.addstr(y, x, message) 
     refresh()
 
-def cleanup(handle):
+def cleanup(handle=""):
     curses.nocbreak()
     screen.keypad(0)
     curses.echo()
 
 def enable():
     data = SensorTag()
+    error = data.get_error()
+    if error != "":
+        print error
+        cleanup()
+        exit(-1) 
     data.connect()
     data.enable()
     home("Logging data. Press q to stop.")

File sensors/SensorTag.py

 
 class SensorTag:
     def __init__(self):
-        self.tags = dict()
+        self.error = ""
         self.hciconfig = find_executable("hciconfig")
         if not self.hciconfig:
-            print "ERROR: hciconfig must be installed."
-            exit(-1)
+            self.error = "ERROR: hciconfig must be installed.\n"
         self.hcitool = find_executable("hcitool")
         if not self.hcitool:
-            print "ERROR: hcitool must be installed."
-            exit(-1)
+            self.error = "ERROR: hcitool must be installed.\n"
         self.gatttool = find_executable("gatttool")
         if not self.gatttool:
-            print "ERROR: gatttool must be installed."
-            exit(-1)
+            self.error = "ERROR: gatttool must be installed.\n"
+        self.tags = dict()
         self.SENSORS = "sensors/SENSORS"
 
+    def get_error(self):
+        return self.error    
+
     def detect(self):
         pass