]> git.gag.com Git - fw/quantimotor/commitdiff
add endpoint and button to arm system, more to do to make it a toggle
authorBdale Garbee <bdale@gag.com>
Mon, 26 May 2025 18:07:47 +0000 (12:07 -0600)
committerBdale Garbee <bdale@gag.com>
Mon, 26 May 2025 18:07:47 +0000 (12:07 -0600)
ui/app.py
ui/index.html

index dbda57215b094ec20d333c9af363526559c7dd65..b3588d6f4349ade67391d6d6f940515acd1b24de 100755 (executable)
--- a/ui/app.py
+++ b/ui/app.py
@@ -25,6 +25,9 @@ thrust = 0
 pyro = 0
 battery = 0
 
+# global to keep track of whether user wants system armed
+armreq = "disarm"
+
 ctx = iio.LocalContext()
 ctrl = ctx.find_device('ads8688')
 # configuration for each channel on ADS8688
@@ -70,9 +73,13 @@ def sense_armed():
     ) as request:
         value = request.get_value(12)
         if value == Value.ACTIVE:
-          return 'armed'
+          if armreq == "arm":
+            return 'armed'
+          else:
+            return 'remote'
         else:
-          return 'safe'
+          return armreq
+          #return 'safe'
 
 path   = os.path.abspath(os.path.dirname(__file__))
 config = {
@@ -110,6 +117,19 @@ class App:
     else:
       return "Method not allowed", 405
 
+  # end point for arming the system
+  @cherrypy.expose
+  @cherrypy.tools.json_in()
+  def armsystem(self):
+    global armreq
+    if cherrypy.request.method == 'POST':
+      jsondata = cherrypy.request.json
+      cherrypy.log(jsondata["request"].strip())
+      armreq = jsondata["request"]
+      return "state requested: " + armreq
+    else:
+      return "Method not allowed", 405
+
   # end point for starting a test
   @cherrypy.expose
   def starttest(self):
index 58104a50a1a3f612154786382fb3d88b08cfd75b..b968e4a845e975fb8047784a5c7497b7a8095d04 100644 (file)
 
     </script>
     <script>
+      // change system armed state
+      function armSystem() {
+        const jsonString = '{"request": "arm"}';
+        const fetchOptions = {
+          method: "POST",
+          headers: {
+            "Content-Type": "application/json",
+            Accept: "application/json",
+          },
+          body: jsonString,
+        };
+       const response = fetch("/armsystem", fetchOptions);
+      }
+
       // start current test by just hitting an endpoint
       function startTest() {
         const fetchOptions = {