From 12c8baf0420fcb3ca5cd33b6df2a721bb9fafe69 Mon Sep 17 00:00:00 2001
From: Leonardo Martinez <leonardo.martinez.hornak@fing.edu.uy>
Date: Sun, 9 May 2021 16:38:26 -0300
Subject: [PATCH] UI gets updated from BL

---
 software/hardware_interface.py | 22 +++++++++++++---------
 software/smartwatch.py         | 20 ++++++++++++++------
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/software/hardware_interface.py b/software/hardware_interface.py
index 1a09b2a..495e2a3 100644
--- a/software/hardware_interface.py
+++ b/software/hardware_interface.py
@@ -42,16 +42,20 @@ class Hardware_interface:
         self.client_socket, self.client_info = self.server_socket.accept()
         print("Accepted connection from", self.client_info)
 
-    def send_data(self):
-        self.client_socket.send("Envio desde la PC")
+    #Send data using bluetooth interface
+    def send_data(self, data):
+        self.client_socket.send(data)
 
+    #Get data from Bluetooth. Returns a tuple (Bool, CharArray). Boolean = True means data was received
     def get_data(self):
         try:
-            while True:
-                data = self.client_socket.recv(1024)
-                print(data)
-                if not data:
-                    break
-                print("Received", data)     
+            data = None
+            dataAvaialble = True
+            self.client_socket.settimeout(100)
+            data = self.client_socket.recv(1024)
+            print(data)
+            if not data:
+                dataAvaialble = False
         except OSError:
-            pass
\ No newline at end of file
+            return 0, data
+        return 1, data
\ No newline at end of file
diff --git a/software/smartwatch.py b/software/smartwatch.py
index 1b64e04..8fe50a3 100644
--- a/software/smartwatch.py
+++ b/software/smartwatch.py
@@ -28,16 +28,24 @@ def refreshUI(guiRef, model, guiQueue):
                 model.count += 1
                 guiRef.entry["state"] = 'normal'
                 guiRef.entry.delete(0,"end")
-                guiRef.entry.insert(0,"12")
+                guiRef.entry.insert(0,"Valor")
                 guiRef.entry["state"] = 'disabled'
+                
+                btInterface.send_data("Alarma HR")
 
-                guiRef.entry_two.delete(0,"end")
-                guiRef.entry_two.insert(0,"Prueba")
+                #guiRef.entry_two.delete(0,"end")
+                #guiRef.entry_two.insert(0,"Prueba")
         except queue.Empty:
             pass 
 
         #Other tasks...
-        #print("Han pasado 500 milisegundos")
+        print("Han pasado 500 milisegundos")
+        dataAvailable, data = btInterface.get_data()
+
+        if(dataAvailable == True):
+            guiRef.entry_two.delete(0,"end")
+            guiRef.entry_two.insert(0, data)
+            
 
 
 #Class for the User Interface
@@ -169,7 +177,7 @@ if __name__ == '__main__':
     btInterface.print_device_list()
     btInterface.start_server()
 
-    btInterface.send_data()
+    btInterface.send_data("Prueba 2")
     btInterface.get_data()
 
     #Thread used to separate the use interface with the front end. It is used to not slow down the GUI when processing information
@@ -178,4 +186,4 @@ if __name__ == '__main__':
     t.start()
     
     #Uncomment to show the GUI
-    #app.mainloop()
+    app.mainloop()
-- 
GitLab