Skip to content

Commit

Permalink
Tabs removed from empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Geib committed Oct 20, 2018
1 parent 2f85c1a commit feab44d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions adc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def __init__(self, miso, mosi, clk, cs):
self._mosi = mosi
self._clk = clk
self._cs = cs

@abstractmethod
def get_resolution(self):
pass

@abstractmethod
def setup_pins(self):
pass

@abstractmethod
def read_value(self):
pass
22 changes: 11 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def change_icon(percent):

if (DEBUGMSG == 1):
print("Changed battery icon to " + percent + "%")

out = check_output("ps aux | grep pngview | awk '{ print $2 }'", shell=True)
nums = out.split('\n')
i = 0

for num in nums:
i += 1
if (i == 1):
Expand All @@ -39,12 +39,12 @@ def change_led(led):
if (led == "green"):
GPIO.output(GOODVOLTPIN, GPIO.HIGH)
GPIO.output(LOWVOLTPIN, GPIO.LOW)

printf("Changed green LED to on, red LED to off")
elif (led == "red"):
GPIO.output(GOODVOLTPIN, GPIO.LOW)
GPIO.output(LOWVOLTPIN, GPIO.HIGH)

printf("Changed green LED to off, red LED to on")

def end_process(signalnum = None, handler = None):
Expand All @@ -53,7 +53,7 @@ def end_process(signalnum = None, handler = None):
exit(0)

status = 0

# prepare handlers for process exit
signal.signal(signal.SIGTERM, end_process)
signal.signal(signal.SIGINT, end_process)
Expand All @@ -68,7 +68,7 @@ def end_process(signalnum = None, handler = None):
else:
print("Unknown ADC type " + str(ADC) + "! Please set ADC in config.py to one of the supported types.")
exit(0)

adc.setup_pins()

SVOLT100 = VOLT100 * HIGHRESVAL / (LOWRESVAL + HIGHRESVAL)
Expand All @@ -82,7 +82,7 @@ def end_process(signalnum = None, handler = None):
ADC50 = SVOLT50 / (ADCVREF / adc.get_resolution())
ADC25 = SVOLT25 / (ADCVREF / adc.get_resolution())
ADC0 = SVOLT0 / (ADCVREF / adc.get_resolution())

if (DEBUGMSG == 1):
print("Batteries 100% voltage: " + str(VOLT100))
print("Batteries 75% voltage: " + str(VOLT75))
Expand Down Expand Up @@ -117,13 +117,13 @@ def end_process(signalnum = None, handler = None):
ret3 = adc.read_value()
ret = (ret1 + ret2 + ret3) / 3
voltage = ((HIGHRESVAL + LOWRESVAL) * ret * (ADCVREF / adc.get_resolution())) / HIGHRESVAL

if (CSVOUT == 1):
print(str(count) + ";" + str(time.time()) + ";" + str(datetime.datetime.now()) + ";" + str(ret) + ";" + str(voltage))

if (DEBUGMSG == 1):
print("ADC value: " + str(ret) + " (" + str(voltage) + " V)")

if (ret < ADC0):
if (status != 0):
change_icon("0")
Expand All @@ -140,7 +140,7 @@ def end_process(signalnum = None, handler = None):
if (status != 50):
change_led("green")
change_icon("50")

status = 50
elif (ret < ADC75):
if (status != 75):
Expand Down
16 changes: 8 additions & 8 deletions mcp3001.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class MCP3001(ADC):
def setup_pins(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

GPIO.setup(self._miso, GPIO.IN)
GPIO.setup(self._clk, GPIO.OUT)
GPIO.setup(self._cs, GPIO.OUT)

def get_resolution(self):
return 1024.0

Expand All @@ -23,20 +23,20 @@ def read_value(self):
for i in range(3):
GPIO.output(self._clk, True)
GPIO.output(self._clk, False)

# clock out data, MSB first
adcout = 0

for i in range(10):
GPIO.output(self._clk, True)

adcout <<= 1

if (GPIO.input(self._miso)):
adcout |= 0x1

GPIO.output(self._clk, False)

GPIO.output(self._cs, True)

return adcout
16 changes: 8 additions & 8 deletions mcp3008.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class MCP3008(ADC):
def __init__(self, miso, mosi, clk, cs, channel):
ADC.__init__(self, miso, mosi, clk, cs)
self._channel = channel

def setup_pins(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

GPIO.setup(self._miso, GPIO.IN)
GPIO.setup(self._mosi, GPIO.OUT)
GPIO.setup(self._clk, GPIO.OUT)
GPIO.setup(self._cs, GPIO.OUT)

def get_resolution(self):
return 1024.0

def read_value(self):
if ((self._channel > 7) or (self._channel < 0)):
return -1
Expand All @@ -31,7 +31,7 @@ def read_value(self):
commandout = self._channel
commandout |= 0x18 # start bit + single-ended bit
commandout <<= 3 # we only need to send 5 bits here

for i in range(5):
if (commandout & 0x80):
GPIO.output(self._mosi, True)
Expand All @@ -43,18 +43,18 @@ def read_value(self):
GPIO.output(self._clk, False)

adcout = 0

# read in one empty bit, one null bit and 10 ADC bits
for i in range(12):
GPIO.output(self._clk, True)
GPIO.output(self._clk, False)
adcout <<= 1

if (GPIO.input(self._miso)):
adcout |= 0x1

GPIO.output(self._cs, True)

adcout /= 2 # first bit is 'null' so drop it

return adcout
14 changes: 7 additions & 7 deletions mcp3551.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class MCP3551(ADC):
def setup_pins(self):
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

GPIO.setup(self._miso, GPIO.IN)
GPIO.setup(self._clk, GPIO.OUT)
GPIO.setup(self._cs, GPIO.OUT)

def get_resolution(self):
return 2097152.0

def read_value(self):
GPIO.output(self._cs, True)
GPIO.output(self._clk, True)
Expand Down Expand Up @@ -44,7 +44,7 @@ def read_value(self):
GPIO.output(self._clk, True)

adcraw <<= 1

if (GPIO.input(self._miso)):
adcraw |= 0x1

Expand All @@ -53,15 +53,15 @@ def read_value(self):

if (adcraw & 0x400000):
print "MCP3551 error: overflow high"

if (adcraw & 0x800000):
print "MCP3551 error: overflow low"

# remove overflow and sign bits
adcout = adcraw & 0x1FFFFF

# convert to negative number if necessary
if (adcraw & 0x200000):
adcout = (~adcout & 0x1FFFFF) * -1 + 1

return adcout

0 comments on commit feab44d

Please sign in to comment.