Restructured Files and Updated LiveATC file

This commit is contained in:
2020-12-28 19:35:55 -05:00
parent da028f0b19
commit a716e1e8ec
34 changed files with 48126 additions and 46661 deletions
+35
View File
@@ -0,0 +1,35 @@
from flask import Flask, json, request
import os
app = Flask(__name__)
@app.route('/audio',methods = ['POST'])
def volume():
if request.method == 'POST':
json = request.get_json()
if json['direction']:
level = os.popen('vol +').read()
elif json['direction'] == 0:
level = os.popen('vol -').read()
elif json['direction'] == 2:
level = os.popen('vol').read()
return str(level)
@app.route('/cmd',methods = ['POST'])
def command():
if request.method == 'POST':
json = request.get_json()
output = os.popen("cd /usr/share/dump1090-mutability/html && "+json['command']).read()
return str(output)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'POST')
return response
if __name__ == '__main__':
app.run()
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env python
import struct
import smbus
import sys
import time
import json
import sched
import RPi.GPIO as GPIO
bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
data = {}
s = sched.scheduler(time.time, time.sleep)
GPIO.setmode(GPIO.BCM)
GPIO.setup(6, GPIO.IN)
def readVoltage(bus):
address = 0x36
read = bus.read_word_data(address, 2)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
voltage = swapped * 1.25 /1000/16
return voltage
def readCapacity(bus):
address = 0x36
read = bus.read_word_data(address, 4)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
capacity = swapped/256
return capacity
def writeJSON():
capacity = readCapacity(bus)
voltage = readVoltage(bus)
if GPIO.input(6):
# Power Adapter plugged in
adapter = "out"
else:
# Power Adapter NOT plugged in
adapter = "in"
data['percentage'] = []
data['percentage'].append({
'level': capacity,
'voltage': voltage
})
data['adapter'] = []
data['adapter'].append({
'status': adapter
})
with open('/run/dump1090-mutability/battery.json', 'w') as outfile:
json.dump(data, outfile)
while True:
s.enterabs(10, 1, writeJSON, ())
s.run()