I'm calling
Hardware.gpio_active(True)
This is my Hardware class:
import os
import glob
import time
import RPi.GPIO as GPIO
#class to manage hardware -- sensors, pumps, etc
class Hardware(object):
#global vars for sensor
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
#global var for program
temp_unit = 'F' #temperature unit, choose C for Celcius or F for F for Farenheit
gpio_pin = 17
#function to enable GPIO
@classmethod
def gpio_active(active):
#system params for sensor
if active is True:
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
GPIO.setmode(GPIO.BCM)
GPIO.setup(Hardware.gpio_pin, GPIO.OUT)
print 'activating GPIO'
else:
print 'deactivating GPIO'
GPIO.cleanup()
I get this error:
TypeError: unbound method gpio_active() must be called with Hardware instance as first argument (got bool instance instead)
I don't want to pass an instance -- I want gpio_active() to basically act as a function but retain accessibility to static class variables. I thought this is what @classmethod was for. I get the same error with @staticmethod.
What am I misunderstanding?
staticmethodyou should not be getting the same error. That's the description of staticmethod it does not implicitly pass an argument to a function.