]> git.gag.com Git - fw/quantimotor/commitdiff
showing current iio voltages and safe/armed on each ajax call
authorBdale Garbee <bdale@gag.com>
Wed, 7 May 2025 22:34:23 +0000 (16:34 -0600)
committerBdale Garbee <bdale@gag.com>
Wed, 7 May 2025 22:34:23 +0000 (16:34 -0600)
application/app.py

index 1a2b6afb9b46ba123c01166d2e39b6a6713904ed..5aaa322eb507f22933a4df0750672ccdf75e65d4 100755 (executable)
@@ -9,10 +9,22 @@ import cherrypy
 from cherrypy.lib.static import serve_file
 import gpiod
 from gpiod.line import Direction, Value
+import iio
 import signal
 import sys
 
-n=0
+n = 0
+pressure = 0
+thrust = 0
+pyro = 0
+battery = 0
+
+ctx = iio.LocalContext()
+ctrl = ctx.find_device('ads8688')
+# configuration for each channel on ADS8688
+OFFSET = "0"
+SCALE = "0.078127104"
+VOLTAGES = ['voltage0', 'voltage1', 'voltage2', 'voltage3']
 
 # set gpio output lines
 def set_line_values(chip_path, line_values):
@@ -80,20 +92,32 @@ class App:
   @cherrypy.tools.json_out()
   def getData(self):
     global n
-    n = n + 1
-    a = ' psi'
-    b = ' N'
-    p = str(n) + a
-    t = str(n) + b
-    pyro_v = str(n) + ' volts'
-    batt_v = str(n) + ' volts'
+    global pressure
+    global thrust
+    global pyro
+    global battery
+
+    for id in VOLTAGES:
+      chan = ctrl.find_channel(id)
+      rawstring = chan.attrs['raw'].value
+      voltage = (float(rawstring) + float(OFFSET)) * float(SCALE) / 1000
+      match chan.id:
+        case 'voltage0':
+          pressure = voltage
+        case 'voltage1':
+          thrust = voltage
+        case 'voltage2':
+          pyro = voltage
+        case 'voltage3':
+          battery = voltage
+
     armed = sense_armed()
 
     return {
-      'pressure' : p,
-      'thrust' : t,
-      'pyro' : pyro_v,
-      'battery' : batt_v,
+      'pressure' : pressure,
+      'thrust' : thrust,
+      'pyro' : pyro,
+      'battery' : battery,
       'armed' : armed
     }
 
@@ -112,6 +136,12 @@ if __name__ == '__main__':
       }
   )
 
+  # configure ADC channels
+  for id in VOLTAGES:
+    chan = ctrl.find_channel(id)
+    chan.attrs['scale'].value = SCALE
+    chan.attrs['offset'].value = OFFSET
+
   # launch web user interface
   cherrypy.quickstart(App(), '/', config)