chiark / gitweb /
Allow choice of port on the Build HAT
authorAlexandra Lanes <ajlanes@chiark.greenend.org.uk>
Sat, 4 Jun 2022 14:31:41 +0000 (16:31 +0200)
committerAlexandra Lanes <ajlanes@chiark.greenend.org.uk>
Sat, 4 Jun 2022 14:31:41 +0000 (16:31 +0200)
It appears that text values come out of the pyINDI library as 0x0a
<bytes of actual value> 0x0a 0x20 0x20 0x20 0x20

legofocuser.py
legofocuser.xml

index 3dc8f198d89733564d3330ba03dd6f876df91e33..563b58ec334610703aab38bd73b27d9addee6886 100755 (executable)
@@ -16,8 +16,6 @@ https://www.indilib.org/developers/driver-howto.html#h2-properties
 
 
 class LegoFocuser(device):
-
-    motor = Motor('A')
     
     def ISGetProperties(self, device=None):
         """Property Definiations are generated
@@ -41,6 +39,18 @@ class LegoFocuser(device):
         mainloop
         """
 
+        # BUILD_HAT_PORT - the port on the Build HAT to which the
+        # motor is connected.
+        
+        if name == "BUILD_HAT_PORT":
+            try:
+                port = self.IUUpdate(device, name, names, values)
+                port.state='Ok'
+                port["PORT"].value = port["PORT"].value.strip()
+                self.IDSet(port)
+            except Exception as error:
+                self.IDMessage(f"BUILD_HAT_PORT error: {error}")
+        
         self.IUUpdate(device, name, names, values, Set=True)
 
     def ISNewNumber(self, device, name, names, values):
@@ -133,16 +143,22 @@ class LegoFocuser(device):
                 conn = self.IUUpdate(device, name, names, values)
                 if conn["CONNECT"].value == 'Off':
                     conn.state = "Idle"
-
+                    self._is_connected = False
                 else:
+                    conn.state = "Busy"
+                    self.IDSet(conn)
+                    prt = self.IUFind("BUILD_HAT_PORT")
+                    portval = prt["PORT"].value.strip()
+                    self.motor = Motor(portval)
                     conn.state = "Ok"
+                    self._is_connected = True
 
                 self.IDSet(conn)
 
             except Exception as error:
                 self.IDMessage(f"IUUpdate error: {error}")
                 raise
-
+            
         if name == "FOCUS_MOTION":
             try:
                 focus = self.IUUpdate(device, name, names, values, Set=True)
index 8f55275c2b3ade63bb2d45410d9f59783494ce0b..713b20270cc719c70fec38a09bf1403d1ac4dffb 100644 (file)
@@ -9,6 +9,13 @@ On
     </defSwitch>
 </defSwitchVector>
 
+<defTextVector device="LegoFocuser" name="BUILD_HAT_PORT" label="HAT Port" group="Main Control" state="Idle" perm="rw"  timeout="60">
+  <defText name="PORT" label="Port">
+    A
+  </defText>
+</defTextVector>
+
+
 <defSwitchVector device="LegoFocuser" name="FOCUS_MOTION" label="DIRECTION" group="Main Control" state="Ok" perm="rw" rule="OneOfMany" timeout="60">
     <defSwitch name="FOCUS_INWARD" label="INWARD">
 On