From e4cab6992c2b73f88f2eef1c5fe143e78947ccea Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Tue, 12 Jan 2021 11:08:31 -0500 Subject: [PATCH] Fixes --- python/api.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/python/api.py b/python/api.py index bcf066a..973a5ec 100644 --- a/python/api.py +++ b/python/api.py @@ -15,7 +15,23 @@ GPIO.setmode(GPIO.BCM) GPIO.setup(6, GPIO.IN) app = Flask(__name__) +def readVoltage(bus): + address = 0x36 + read = bus.read_word_data(address, 2) + swapped = struct.unpack("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", read))[0] + capacity = swapped/256 + return capacity + @app.route('/battery',methods = ['POST','GET']) def writeJSON(): capacity = readCapacity(bus) @@ -80,19 +96,4 @@ def after_request(response): if __name__ == '__main__': app.run() -def readVoltage(bus): - address = 0x36 - read = bus.read_word_data(address, 2) - swapped = struct.unpack("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", read))[0] - capacity = swapped/256 - return capacity